to-item is polyfil for mapping any javascript Object to one item of given set, which can be again any Object.
npm install to-item
npm run test
Basic usage for mapping any object (for example string) to one item of given set:
require('to-item');
"Some String".toItem([10, 15, 20]); //15
Run A-B test. Based of given cookie run one of method:
require('to-item');
let funcA = function(){
console.log("function A");
}
let funcB = function(){
console.log("function B");
}
cookieValue.toItem([funcA, funcB])();
Get random IP from pool:
require('to-item');
let host = Math.random().toItem(['10.0.0.120', '10.0.0.121', '10.0.0.122']);
Get tip of the day:
require('to-item');
let tip = (new Date()).getDay().toItem(arrayOfDailyTips);
... and many other use cases ;)