pickpercent
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

PickPercent

A simple library to make random choice by percentage and with some other useful tools for percentage.

Installation

npm install pickpercent

Usage

import { PickPercent } from 'pickpercent';

const loot = new PickPercent();

loot.add('diamond', 30);
loot.add('gold', 40);
loot.add('emerald', 15);
loot.add('lapis', 15);

// or

const loot = new PickPercent()
  .add('diamond', 30)
  .add('gold', 40)
  .add('emerald', 15)
  .add('lapis', 15);

// or

const loot = new PickPercent();

loot.addMany([
  { name: 'diamond', percent: 30 },
  { name: 'gold', percent: 40 },
  { name: 'emerald', percent: 15 },
  { name: 'lapis', percent: 15 },
]);


loot.pick();
// returns 'diamond', 'gold', 'emerald' or 'lapis'

Package Sidebar

Install

npm i pickpercent

Weekly Downloads

2

Version

1.0.4

License

MIT

Unpacked Size

6.29 kB

Total Files

11

Last publish

Collaborators

  • ab1smo