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

@birtalanrobert/money

v1.0.0

Published

Integer minor-unit money, arithmetic, allocation and formatting

Readme

@birtalanrobert/money

Integer minor-unit money. No floats, ever, at any point in the chain.

This requirement comes up in every financial system — "money in integer minor units, never floats" — which is why this package exists and why it has no dependencies.

Core ideas

  • Money is { amount, currency }, where amount is a safe integer count of minor units (cents, bani, fillér). It is frozen on construction.
  • Currency is never implicit. Mixing currencies throws rather than coercing; quietly coercing is how money goes missing.
  • Floats enter in exactly one placefromMajor() — because user input and third-party payloads arrive that way. They never leave except through toMajor() for display.

Usage

import { money, fromMajor, add, allocate, fromNet, format } from '@birtalanrobert/money';

const price = fromMajor(12.34, 'EUR'); // 1234 minor units
const total = add(price, money(500, 'EUR')); // 1734

// VAT, with net and gross always distinguishable
const line = fromNet(total, 19);
line.net.amount; // 1734
line.tax.amount; // 329
line.gross.amount; // 2063

// Splitting without losing a cent
allocate(money(1000, 'EUR'), [1, 1, 1]); // 334, 333, 333 — sums to exactly 1000

format(price, { locale: 'ro-RO' });

Currencies

EUR, RON, HUF and the surrounding regional currencies are registered by default with their ISO 4217 exponents. Note that ISO gives HUF an exponent of 2 even though Hungarian everyday practice uses whole forints. If a project wants integer forints it must say so explicitly at boot, rather than relying on a surprising default:

registerCurrency({ code: 'HUF', exponent: 0, name: 'Hungarian forint' });

Rounding

RoundingMode.HalfUp is the default, deliberately: these are commercial applications issuing invoices, and HalfUp is what the surrounding paperwork and the customer's own arithmetic use. HalfEven is available for statistical work.

Allocation

allocate() is the algorithm behind every bill split, fee distribution, discount apportionment and commission calculation. Shares are handed out by integer division and the remaining units distributed to the largest fractional remainders — so the parts always sum exactly back to the whole, for any input, including negatives.

The naive alternative (multiply by ratio, round each) either loses money or invents it, and the discrepancy surfaces later as an unexplainable one-cent difference on a reconciliation report.

Tax

fromGross() derives the net from the gross rather than recomputing it, so net + tax === gross exactly. The gross is what the customer actually paid and it must not move. Verified across every rate in use in both target markets.