2.0.0 • Published 1 year ago

negative-index v2.0.0

Weekly downloads
283
License
MIT
Repository
github
Last release
1 year ago

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