magic-lottery
v1.2.5
Published
A magic library makes your lucky draws simpler.
Downloads
46
Maintainers
Readme
Magic Lottery
Magic Lottery is an intuitive library aimed at simplifying your lottery experiences to make them simpler, more enjoyable, and fair.
Magic Lottery uses the Fisher-Yates Shuffle Algorithm as the default shuffling method.
Installation
To install Magic Lottery, use npm/yarn/pnpm. Execute the following command in your terminal:
npm install magic-lottery
# or
yarn add magic-lottery
# or
pnpm add magic-lottery
Usage Example
Here's a simple usage case for the Magic Lottery.
import MagicLottery from "magic-lottery";
// Create a new MagicLottery instance
const lottery = new MagicLottery(["Alice", "Bob", "Charlie"]);
// Add more entries to the lottery
lottery.add(["David", "Eve"]);
// Draw all shuffled entries
console.log(lottery.draw());
// Draw the first winner from the shuffled entries
console.log(lottery.drawWinner());
// Draw a specified number of winners from the shuffled entries
console.log(lottery.drawWinners(2));
// Check if an entry is in the lottery
console.log(lottery.hasEntry("Alice"));
// Get the size of the lottery
console.log(lottery.size());
// Check if the lottery is empty
console.log(lottery.isEmpty());
// Draw next winner async
lottery.nextWinner().then((winner) => console.log(winner));
// Reset the lottery
lottery.reset();
For more examples, please refer to the official documentation.
Contributing
Refer to our Contributing Guide.
License
MIT.