js-random-urn-draw

    1.0.1 • Public • Published

    JS Random Urn Draw

    npm GitHub Snyk Vulnerabilities for npm package npm npm Tests

    A simple js-class to put an array into an urn and draw random items from it - with or without replacement.

    Installation

    Download this project via Github and add it manually to your project or install the JSON File Storage npm / yarn package:

    npm i js-random-urn-draw / yarn add js-random-urn-draw

    How to Use / API

     
    const Urn = require('js-random-urn-draw'); // adjust the require path, if not installed via npm/yarn
     
     
    const items = ["🍏", "🍒", "🍌"];
     
     
    // urn WITH replacement
    const urn = new Urn(items);
     
    urn.drawOne(); // "🍌"
    urn.draw(5); // ["🍒", "🍏", "🍒", "🍌", "🍌"]
     
    urn.shake(); // ["🍌", "🍏", "🍒"]
     
     
    // urn WITHOUT replacement
    const urn_without = new Urn(items, false);
     
    urn_without.drawOne(); // "🍌"
    urn_without.content; // ["🍏", "🍒"]
    urn_without.extractedContent; // ["🍌"]
     
    urn.draw(5); //  ["🍏", "🍒"]
    urn_without.content; // []
    urn_without.extractedContent; // ["🍏", "🍒", "🍌"]
     

    Donate

    If you like the project and it saved you a while of coding, spend me a coffee (or all of your savings) to keep me motivated: paypal.me

    Install

    npm i js-random-urn-draw

    DownloadsWeekly Downloads

    3

    Version

    1.0.1

    License

    GPL-3.0

    Unpacked Size

    45.4 kB

    Total Files

    7

    Last publish

    Collaborators

    • avatar