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

@zenuinebit/loyalty-points

v0.1.0

Published

Loyalty points: earn rules, tiers, redemption limits and an expiring-points ledger.

Readme

@zenuinebit/loyalty-points

Loyalty programme maths: earning, tiers, redemption limits, and a points ledger where points expire. Money is in minor units (see @zenuinebit/money); dates are "YYYY-MM-DD" strings. No dependencies.

import { earn, tierFor, maxRedeemable, pointsValue, earnedEntry, balance, expiringSoon } from "@zenuinebit/loyalty-points";

// 1 point per 100.00 spent, with a Gold bonus of 1.5x
earn(250_000, { points: 1, per: 10_000, multiplier: 1.5 });   // 37

const tiers = [{ name: "Silver", min: 0 }, { name: "Gold", min: 1000, multiplier: 1.5 }];
tierFor(1200, tiers)?.name;                                    // "Gold"

// How many points can pay for this bill? (1 point = 1.00, at most half the bill, in steps of 10)
maxRedeemable(480, 20_000, { minorPerPoint: 100, maxPercentOfBill: 50, step: 10 });  // 100

// A ledger: earned points expire after 90 days; redeemed points are negative entries
const entries = [
  earnedEntry("2025-01-01", 100, 90),
  earnedEntry("2025-02-01", 200, 365),
  { date: "2025-03-01", points: -150 },
];
balance(entries, "2025-03-15");                   // 150
expiringSoon(entries, "2025-03-15", 30);          // points expiring in the next 30 days

How it works

  • earn rounds down and is safe against floating-point noise (3.3000000000000003 is 3, not 4).
  • expiresOn is the first day the points are no longer valid.
  • Redemptions use up the soonest-expiring points first, so customers lose as little as possible. A redemption bigger than the points valid that day throws, which usually means a bug or a double spend in your data.
  • The ledger is derived from entries each time. Store the entries, not the balance.

Not included: storage, fraud checks, refunds (add a negative entry for earned points taken back), and a points-to-currency tax treatment.