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

1.0.0 • Public • Published

NPM version NPM downloads

rate value

ratev is a simple rate value module to rate array of object and return value based on percent 0.1 or higher than 100

Installation

npm install ratev
yarn add ratev

CommonJS

const Ratev = require("ratev");
const MyfirstRate = new Ratev();

ES6

import Ratev from "ratev";
const MyfirstRate = new Ratev();

Example

const Ratev = require("ratev");
//new Ratev support array of object or ...args of object
const MyfirstRate = new Ratev([
  { rate: 90, value: "BRONZE" }, //90% chance to return BRONZE
  { rate: 70, value: "SILVER" }, //70% chance to return SILVER
  { rate: 50, value: "GOLD" }, //50% chance to return GOLD
  {
    rate: 20,
    value: "PLATINUM", //20% chance to return PLATINUM
  },
  {
    rate: 15,
    value: "DIAMOND", //15% chance to return DIAMOND
  },
  {
    rate: 10,
    value: "MASTER", //10% chance to return MASTER
  },
  {
    rate: 0.1,
    value: "GRANDMASTER", //0.1% chance to return GRANDMASTER
  },
]);
setInterval(function () {
  console.log(MyfirstRate.value); //return random value based on rate
}, 1000);


Methods

push


push new value if ther duplicate value it will be replace with new rate

MyfirstRate.push(...<Objects>);
//or
MyfirstRate.push([...<Objects>]);

EX


push(...<Objects>);

MyfirstRate.push({ rate: 0.1, value: "CHALLENGER" });
//return array of object with new value

push([...<Objects>]);

MyfirstRate.push([
  { rate: 0.1, value: "CHALLENGER" },
  { rate: 0.1, value: "GRANDMASTER" },
]);
//return array of object with new value

edit


edit multiple rate by push new rate with same value

same as push but it just edit rate

MyfirstRate.push(...<Objects>);
//or
MyfirstRate.push([...<Objects>]);

delete


delete object from array of object by value you can delete multiple value by passing multiple value

MyfirstRate.delete(...<valus>);

EX


MyfirstRate.delete("BRONZE", "SILVER", "GOLD");
//return array of object without BRONZE,SILVER,GOLD

Properties

value


return random value based on rate

MyfirstRate.value;

data


return array of object

MyfirstRate.data;

Links

License

Package Sidebar

Install

npm i ratev

Weekly Downloads

1

Version

1.0.0

License

Apache-2.0

Unpacked Size

19.6 kB

Total Files

5

Last publish

Collaborators

  • jamel_syr
  • naimabd
  • iarth