random-item-percent
v1.0.0
Published
For random item with percent ( I use on javascript games :D )
Downloads
30
Maintainers
Readme
random-item-percent
For random item with percent ( I use on javascript games :D )
Installation
Using npm:
$ npm install --save random-item-percent
Using yarn:
$ yarn add random-item-percent
Quick Start
import randomItem from 'random-item-percent'
const itemsList = [
{
itemEnum: 'bike',
percent: 40,
},
{
itemEnum: 'car',
percent: 30,
},
{
itemEnum: 'boat',
percent: 2,
},
{
itemEnum: 'train',
percent: 1,
},
{
itemEnum: 'plane',
percent: 0.5,
},
]
const result = randomItem({
itemsList
})
console.log('result:', result)
// { itemEnum: 'bike', item: { itemEnum: 'bike', percent: 40} }
Documentation
Parameters object
itemsList
{Array
} Items for random require{ itemEnum: String, percent: Number }
Return value
itemEnum
{String
} Item enumitem
{Object
} Item object
Contributing
Feel free to submit any issues or pull requests.
License
MIT