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 🙏

© 2024 – Pkg Stats / Ryan Hefner

ranking-builder

v1.2.6

Published

Ranking Builder is an NPM package that allows you to manage game rankings using Firebase as the database. It was developed using TypeScript, Firebase, and Vite for development mode.

Downloads

34

Readme

Ranking Builder

Ranking Builder is an NPM package that allows you to manage game rankings using Firebase as the database. It was developed using TypeScript, Firebase, and Vite for development mode.

Installation

To install Ranking Builder in your project, simply use the following command:

npm install ranking-builder

Examples of use

Here's an example of how to use the library to add a new user to the ranking:

import { RankingBuilder } from "ranking-builder";

const config = {
  apiKey: "YOUR_apiKey",
  authDomain: "YOUR_authDomain",
  databaseURL: "YOUR_databaseURL",
  projectId: "YOUR_projectId",
  storageBucket: "YOUR_storageBucket",
  messagingSenderId: "YOUR_messagingSenderId",
  appId: "YOUR_appId",
};

const rankingBuilder = new RankingBuilder(
  {
    disableLog: false,
    emailAddress: "[email protected]",
    password: "your_password",
  },
  config
);

rankingBuilder.createUser({
  name: "Player 1",
  score: 1000,
  time: "00:10:00",
});

rankingBuilder.signIn("[email protected]", "your_password");

rankingBuilder.signOut();

rankingBuilder.createUser({
  name: "Player 1",
  score: 1000,
  time: "00:10:00",
});

rankingBuilder.updateUser("a5d6e7f8-g9h0-i1j2-k3l4-m5n6o7p8q9r0", {
  name: "Player 2",
  score: 500,
  time: "00:05:00",
});

rankingBuilder.deleteUser("a5d6e7f8-g9h0-i1j2-k3l4-m5n6o7p8q9r0");

rankingBuilder.getUser("a5d6e7f8-g9h0-i1j2-k3l4-m5n6o7p8q9r0");

rankingBuilder.listData((data) => {
  console.log(data);
});

RankingBuilderRenderer

RankingBuilderRenderer is a class that allows developers to easily render a table with the top users of their game or application. It works by receiving a rankingBuilder instance and a DOM node (e.g., a div element) as inputs, and it automatically generates a table with the top users based on the score. The table can be customized with additional features, such as the ability to delete or edit users. To learn more about RankingBuilderRenderer, check out the RANKING_BUILDER_RENDERER_README.md file.

How to get your firebase config?

  1. Go to the Firebase console page: https://console.firebase.google.com/
  2. Log in with your Google account.
  3. Create a new project or select an existing one.
  4. In the left menu, select the "Project Settings" option (gear icon).
  5. In the "Project account settings" section, click on "Add a service account".
  6. A JSON file with your Firebase account settings will be displayed.
  7. Copy these settings and paste them into your application.

Your Firebase account settings are used to initialize the Firebase instance in your application. You will need to pass these settings as a parameter to the RankingBuilder class when instantiating it.

API

| Method | Description | | ----------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | signIn({emailAddress, password}?: Credentials) | Used to sign in with the user. It is optional on the first instance because when you instantiate the RankingBuilder class, at the first time you sign in, the user is signed as anonymous. | | signOut() | Used to sign out the user, in case you need to sign in with another user. | | createUser(user: RawUser) | Used to add a new user to the database. | | updateUser(userId: string, user: RawUser) | Used to update an existing user in the database. | | deleteUser(userId: string) | Used to delete a user from the database. | | getUser(userId: string) | Used to get a specific user from the database. | | listData(callbackFn: (data: Data) => void; topResults?: number) | Used to get a list of users and total count from the database. Pass an optional param topResults to get count of users, by default the listData returns top 10 users based on their score. | | isAnonymous | Used to know if the logged user is anonymous or not. |

Dependencies and Prerequisites

Ranking Builder depends on the following libraries:

  • uuid
  • firebase

You must have a Firebase account in order to use Ranking Builder.

Contributions

If you want to contribute to Ranking Builder, follow these steps:

  • Fork the repository
  • Create a new branch for your feature
  • Commit your changes
  • Push the branch and create a pull request

License

Ranking Builder is licensed under the MIT License.