array-flick
Never ending flick though arrays by using next() / prev()
Install
$ npm install array-flick
Usage
const Flick = ; const flick = 123 flicknext; // 1flicknext; // 2flicknext; // 3flicknext; // 1flicknext; // 2flick; // 1flick; // 3flick; // 2 flick // one of 1,2,3
Note there is also a setter for randomFn. again, useful for testing / seeding. Look at the specs to learn more.
API
new Flick(...values)
Behaves like an Array with next
and prev
methods added.
When writing database seeders and tests this expressiveness-sugar helps to make the intentions of the program easily recognizable.
next()
Type: Integer
Default: 1
How many steps to flick forward. Defaults to 1
.
const names = 'Jim' 'Fin' 'Lin'; namesnext // Jimnamesnext2 // Linnamesnext2 // Fin
prev()
Type: Integer
Default: 1
How many steps to flick backwards. Defaults to 1
.
const names = 'Jim' 'Fin' 'Lin'; names // Linnames // Jimnames // Fin
random()
const xos = ...Array99;xos 0999; // generate your own (seeded) random floats 0..1 herexos // 'o'
Returns a random entry
randomFn (setter)
Useful for reproducible random return values, for example with the help of seedrandom
Contributing
License
MIT © iilei • Jochen Preusche