list-cycler

1.0.0 • Public • Published

node-list-cycler

Infinity cycle through list

Install:

npm install list-cycler

Current stable version

1.0.0

Examples:

Iterate from beginning of list:

var cycler = require("list-cycler"),
    colors = cycler(['red', 'green', 'blue']),
    i=6;
while (--i) {
    console.log(+ '. <span color="' + colors.current() + '">' + colors.current() + '</span>');
    colors.cycle();
}

Or using other API:

var cycler = require("list-cycler"),
    colors = cycler(['red', 'green', 'blue']),
    color,
    i=6;
while (--i) {
    color = colors.next();
    console.log(+ '. <span color="' + color + '">' + color + '</span>');
}

If should start from index other then 0 - here iterate from index 1 (letter 's') - look at second argument to cycler:

var cycler = require('list-cycler'),
    colors = cycler(['red', 'green', 'blue'], 1),
    i=6
 
while (--i) {
    console.log(+ '. <span color="' + colors.current() + '">' + colors.current() + '</span>');
    colors.cycle();
}

Readme

Keywords

Package Sidebar

Install

npm i list-cycler

Weekly Downloads

1

Version

1.0.0

License

MIT

Last publish

Collaborators

  • mysz