negative-index
DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/negative-index package

2.0.0 • Public • Published

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

Package Sidebar

Install

npm i negative-index

Weekly Downloads

330

Version

2.0.0

License

MIT

Unpacked Size

1.91 kB

Total Files

4

Last publish

Collaborators

  • dfcreative
  • dy