logeast / magic-lottery

A magic library makes your lucky draws simpler.

Home Page:https://logeast.github.io/magic-lottery/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

About

A magic library makes your lucky draws simpler.

https://logeast.github.io/magic-lottery/

License:MIT License


Languages

Language:TypeScript 92.0%Language:JavaScript 5.2%Language:HTML 2.9%