Circulator
Circular iteration for a list of values; step forward or backward with a simple API. Lightweight, ES2015 generator-based implementation.
Installation
npm install --save circulator
Usage
const Circulator = const c = 'A' 'B' 'C' // Methodsccurrent // -> 'A'cnext // -> 'B'c // -> 'A' (wrap to start)c // -> 'C' (wrap to end)c // -> 'B' // Propertiescsize // -> 3ccycle // The generator used for cycling // Consuming the circulator returns elements starting from the current (last returned) position...c // -> ['b', 'c', 'a']
The basic generator object can be used separately:
const Cycle = const g = gnextvalue // -> 1
Notes
- Includes TypeScript type definitions
- Requires ES2015 generator support to run without Babel (Node.js >= 5.x)