random-item-percent

1.0.0 • Public • Published

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 enum
  • item {Object} Item object

Contributing

Feel free to submit any issues or pull requests.

License

MIT

Package Sidebar

Install

npm i random-item-percent

Weekly Downloads

5

Version

1.0.0

License

MIT

Unpacked Size

8.17 kB

Total Files

11

Last publish

Collaborators

  • thinnakrit