Skip to content

pavlikm/to-item

Repository files navigation

CodeQL Coverage

to-item

to-item is polyfil for mapping any javascript Object to one item of given set, which can be again any Object.

Instalation

npm install to-item

Test

npm run test

Usage

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 ;)

About

map object to one item of given set

Resources

License

Stars

Watchers

Forks

Packages

No packages published