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/pricing-rules

v0.1.0

Published

Promotions for a cart: buy X get Y, quantity tiers, bundles, percent off and spend thresholds.

Readme

@zenuinebit/pricing-rules

Promotions for a @zenuinebit/cart: buy X get Y, quantity tiers, bundles, percent off and spend thresholds. Amounts are integers in minor units.

import { createCart, addItem, computeTotals } from "@zenuinebit/cart";
import { applyPromotions } from "@zenuinebit/pricing-rules";

let cart = createCart({ currency: "INR" });
cart = addItem(cart, { sku: "TEA", name: "Tea 250g", unitPrice: 12000, quantity: 3 });

const { cart: priced, applied } = applyPromotions(cart, [
  { id: "tea-b2g1", name: "Buy 2 get 1 free", type: "buy-x-get-y", sku: "TEA", buy: 2, get: 1 },
  { id: "big-basket", name: "10% off above 500", type: "spend-threshold", minSpend: 50000, percent: 10 },
]);

applied;                       // [{ ruleId, name, amount, skus }] - show these on the receipt
computeTotals(priced);         // normal cart totals, with the promotions included

Rules | type | What it does | |---|---| | buy-x-get-y | Every buy + get units of a SKU, get are free | | quantity-tier | tiers: [{minQty, percent}], the highest tier reached applies to the line | | percent-off | Percent off listed skus, or every line if omitted | | bundle | items sold together for price; each complete set is discounted, and the saving is split exactly across lines | | spend-threshold | Cart-level percent or amount off once the cart (after line promotions) reaches minSpend |

How rules combine

  • Line rules run in the order given and a line gets at most one promotion: the first rule that discounts it wins. Put your best deals first.
  • Lines that already have a manual discount are left alone.
  • Spend-threshold rules run last, on what is left after line promotions.
  • Calling applyPromotions again starts from scratch, so it is safe to re-run after the cart changes. The input cart is never changed.
  • Promotions are stored as discounts with a promo:<id> code, so they show up in the normal cart totals.

Not included: coupon codes and usage limits, date ranges, customer groups, and stacking several promotions on one line. Check those in your app before passing the rules in.