npm.io
2.0.0 • Published 3 years ago

negative-index

Licence
MIT
Version
2.0.0
Deps
0
Size
2 kB
Vulns
0
Weekly
0
Stars
1

Convert negative index to positive starting from the end. Same way Array.slice arguments work.

npm install negative-index

import idx from 'negative-index';

// idx(index, length)

idx(-5, 8); //3
idx(5, 8); //5

Works well for normalizing real numbers offset, like time etc:

import normOffset from 'negative-index';

let time = -.15, duration = 2.45;

normOffset(time, duration); //2.3

Keywords