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

1.2.5 • Public • Published

Magic Lottery

ci ts download-badge version commit license

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.

Package Sidebar

Install

npm i magic-lottery

Weekly Downloads

6

Version

1.2.5

License

MIT

Unpacked Size

46.2 kB

Total Files

12

Last publish

Collaborators

  • logeast