@andersaloof/next-step

1.0.0 • Public • Published

nextStep Build Status

Steps an integer by a specified amount (+ or -), within a range from 0 to max, wrapping when the new value exceeds the range.

Install

$ npm install @andersaloof/next-step

Why?

Having made similar logic in a dozen of slideshows/galleries over the years, handling previous and next buttons to increase/decrease a current index, it was time to move it out to a separate module.

Usage

nextStep(current, max, value)

Example code

const nextStep = require('@andersaloof/next-step');

const nextValue = nextStep(1, 5, 2); // Increase current value 1 by 2, returns 3;
const anotherValue = nextStep(1, 5, -3); // Decrease current value 1 by -3, with a max value of 5, returns 4;

License

MIT. See LICENSE.md for details.

Readme

Keywords

Package Sidebar

Install

npm i @andersaloof/next-step

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

3.88 kB

Total Files

5

Last publish

Collaborators

  • andersaloof