npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

battlepass

v1.0.3

Published

The Battle Pass Manager is a class that manages the progression and rewards of a battle pass. It provides functionality to track the current level, total XP earned, and emit events when certain conditions are met. The manager extends the EventEmitter clas

Readme

Battle Pass Manager

The Battle Pass Manager is a class that manages the progression and rewards of a battle pass. It provides functionality to track the current level, total XP earned, and emit events when certain conditions are met. The manager extends the EventEmitter class from the node:events module to handle event emission and listening.

Installation

To use the Battle Pass Manager, you need to have Node.js installed on your system. You can then import the required modules and classes into your project.

npm install battlepass

Usage

First, import the necessary classes and types into your project:

import {
  BattlePassManager,
  BattlePassEvents,
  BattlePassReward,
} from "./BattlePassManager";

Creating a Battle Pass Manager

To create a new instance of the BattlePassManager class, provide an array of levels in the battle pass. Each level should have an associated XP threshold and optional rewards.

const levels = [
  { xp: 100, rewards: [{ name: "Reward 1" }] },
  { xp: 200, rewards: [{ name: "Reward 2" }] },
  { xp: 300, rewards: [{ name: "Reward 3" }] },
  // Add more levels as needed
];

const battlePass = new BattlePassManager(levels);

You can also specify the current level and total XP earned as optional parameters:

const battlePass = new BattlePassManager(levels, 2, 150);

Listening to Events

The BattlePassManager class extends the EventEmitter class, allowing you to listen for events emitted by the manager.

Listening to Battle Pass Events

To listen to any battle pass event, use the onBattlepassEvent method. Provide the event name and a callback function to handle the event.

battlePass.onBattlepassEvent("levelUp", (reward: BattlePassReward) => {
  console.log(`Level up! Reached level ${reward.level}`);
  console.log("Unlocked rewards:", reward.rewards);
});

battlePass.onBattlepassEvent("maxLevel", () => {
  console.log(
    "Congratulations! You reached the maximum level in the battle pass."
  );
});

Listening to Specific Events

The BattlePassManager class provides convenience methods to listen to specific events, such as "levelUp" and "maxLevel".

Listening to the "levelUp" Event

To listen specifically to the "levelUp" event, use the onLevelUp method. Provide a callback function that receives the reward object (BattlePassReward) as an argument.

battlePass.onLevelUp((reward: BattlePassReward) => {
  console.log(`Level up! Reached level ${reward.level}`);
  console.log("Unlocked rewards:", reward.rewards);
});
Listening to the "maxLevel" Event

To listen specifically to the "maxLevel" event, use the onMaxLevel method. Provide a callback function that does not receive any arguments.

battlePass.onMaxLevel(() => {
  console.log(
    "Congratulations! You reached the maximum level in the battle pass."
  );
});

Adding XP

You can add XP to the battle pass using the addXp method. Provide the amount of XP to add as a parameter.

battlePass.addXp(50);

The addXp method increments the total XP earned and checks if the added XP causes the player to level up. If a level up occurs, the "levelUp" event is emitted with the corresponding reward information. If the player reaches the maximum level, the "maxLevel" event is emitted.

Event Documentation

The BattlePassManager

emits the following events:

Event: "levelUp"

Emitted when the player levels up in the battle pass.

battlePass.on("levelUp", (reward: BattlePassReward) => {
  // Handle level up event
});

The event callback function receives the reward object (BattlePassReward) as an argument. The reward object contains the level number and an array of rewards for that level.

Event: "maxLevel"

Emitted when the player reaches the maximum level in the battle pass.

battlePass.on("maxLevel", () => {
  // Handle max level event
});

The event callback function does not receive any arguments.

Contributing

Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request.

License

The Battle Pass Manager is released under the MIT License.