random-serial-value-generator
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

random-serial-value-generator

GitHub license

GitHub package.json version

Description

This library generates a value randomly or you could get each value serially. Also, this lib is made with only javascript code so you could install it anywhere.

How to install

// npm
npm install random-serial-value-generator
// yarn
yarn add random-serial-value-generator
// expo
expo install random-serial-value-generator

Example

import { RandomValueGenerator } from "random-serial-value-generator";

function example () {
    const randomGenerator = new RandomValueGenerator();
    // Random value
    randomGenerator.generate(["white", "black", "orange"], true); // returns a value like "black", "white", "black", "orange" etc... randomly
    // Serial value
    randomGenerator.generate(["white", "black", "orange"], false); // returns a value "white", "black", "orange" serially
}

// USE CASE
// This method is going to generate random backgroundColor each value of the list.
function component () {
    const randomGenerator = new RandomValueGenerator();
    const list = ["cat", "lion", "dog"];

    return (
        <div>
            {list.map((v,i) => 
                <div key={i} style={{backgroundColor: randomGenerator.generate(["white", "black", "orange"], true);}}>{v}</div>)}
        </div>
    );
}

Package Sidebar

Install

npm i random-serial-value-generator

Weekly Downloads

1

Version

1.0.2

License

MIT

Unpacked Size

4.7 kB

Total Files

6

Last publish

Collaborators

  • mauvpark