1.0.0 • Published 3 years ago
ratev v1.0.0
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 ratevCommonJS
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(...\);
MyfirstRate.push({ rate: 0.1, value: "CHALLENGER" });
//return array of object with new valuepush(...\);
MyfirstRate.push([
  { rate: 0.1, value: "CHALLENGER" },
  { rate: 0.1, value: "GRANDMASTER" },
]);
//return array of object with new valueedit
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,GOLDProperties
value
return random value based on rate
MyfirstRate.value;data
return array of object
MyfirstRate.data;Links
License
1.0.0
3 years ago