randomize-with-percentage
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

randomize-with-percentage

randomize-with-percentage is a typescript library for randomized get items with percentages.

Installation

Use the package manager npm to install.

npm install randomize-with-percentage

Usage

import randomize from "randomize-with-percentage";

const { selectedListItem, value } = randomize([
  { value: 1, percent: 50 },
  { value: 2, percent: 50 },
]);

console.log(selectedListItem) // shows the selected item.   example -> { value: 1, percent: 50 }
console.log(value)            // shows the selected value.  example -> 1
import randomize from "randomize-with-percentage";

// you can set any type in value
const { selectedListItem, value } = randomize<string | boolean | number | object>([
  { value: "potato", percent: 25 },
  { value: false, percent: 25 },
  { value: 10, percent: 25 },
  { value: {}, percent: 25 },
]);

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.5
    16
    • latest

Version History

Package Sidebar

Install

npm i randomize-with-percentage

Weekly Downloads

16

Version

1.0.5

License

MIT

Unpacked Size

4.87 kB

Total Files

5

Last publish

Collaborators

  • rodrigo.pacheco