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

@azghr/specie

v0.1.2

Published

Tiny integer-cents money type — safe arithmetic, currency-aware rounding, Intl formatting. No bignum, no dependencies.

Readme

specie

npm MIT License

Tiny integer-cents money type — safe arithmetic, currency-aware rounding, Intl formatting. No bignum, no dependencies.

The Problem

0.1 + 0.2 !== 0.3. Storing money as floats produces rounding errors and audit nightmares. Correct money is integer minor units + a currency + explicit rounding + locale formatting.

This is competitive space: dinero.js, big.js, and decimal.js cover arbitrary decimals. specie is worth building only because it stays radically smaller: integer minor units only, currency-aware default fractions via Intl, and a few explicit operations.

Install

npm install @azghr/specie
# or
pnpm add @azghr/specie
# or
yarn add @azghr/specie

Use

import { money, fromDecimal } from "@azghr/specie";

// 10-second copy-paste
const price = money(1999, "USD");           // $19.99 as 1999 cents
price.add(money(100, "USD")).format();    // "$20.99"

// Realistic usage
const subtotal = fromDecimal("19.99", "USD");
const tax = subtotal.multiply(0.0825);     // 8.25% tax
const total = subtotal.add(tax);
total.format();                          // "$21.64"

API

money(amount: number, currency: string): Money

Create Money from integer minor units. amount must be a safe integer.

money(1999, "USD")  // $19.99
money(500, "JPY")   // ¥500

fromDecimal(value: string, currency: string): Money

Parse decimal string to Money. Never uses float parsing to avoid rounding errors.

fromDecimal("19.99", "USD")  // 1999 cents
fromDecimal("-10.50", "USD") // -1050 cents

Money.add(other: Money): Money

Add another Money value (same currency only). Throws CurrencyMismatch on currency mismatch.

Money.subtract(other: Money): Money

Subtract another Money value (same currency only).

Money.multiply(factor: number, rounding?: Rounding): Money

Multiply by a factor with rounding. Default: "half-even" (banker's rounding).

money(1000, "USD").multiply(1.0825)              // Apply 8.25% tax
money(100, "USD").multiply(1.5, "half-up")       // Force ties up

Money.allocate(ratios: readonly number[]): Money[]

Distribute by ratios using largest-remainder method. Parts sum exactly to the original amount.

money(100, "USD").allocate([3, 2])  // [$60, $40] (not $59.99/$40.01)

Money.format(locale?: string): string

Format using Intl.NumberFormat.

money(1999, "USD").format()        // "$19.99"
money(123456, "JPY").format("ja-JP") // "¥123,456" (no decimals)

Money.compare(other: Money): -1 | 0 | 1

Compare with another Money. Throws CurrencyMismatch on currency mismatch.

Money.equals(other: Money): boolean

Check equality.

Money.isZero(), Money.isNegative(), Money.isPositive()

Check amount sign.

Money.toJSON(): { amount: number; currency: string }

Serialize to plain object.

Type: Rounding

"half-up" | "half-even" | "down" | "up"

Class: CurrencyMismatch

Error thrown when operations mix different currencies.

Non-Goals

Use dinero.js or decimal.js for:

  • Arbitrary precision / values beyond Number.MAX_SAFE_INTEGER
  • Multi-currency conversion / forex
  • Historical rates
  • Crypto amounts with 18 decimals

TypeScript Note

import { money, fromDecimal } from "@azghr/specie";

// Full type safety
const price: Money = money(1999, "USD");
const total: Money = price.add(money(500, "USD"));

// Currency mismatch caught at compile time
const usd = money(100, "USD");
const eur = money(100, "EUR");
// usd.add(eur) // TypeScript: this works, runtime throws CurrencyMismatch

Related Packages

Caching & Concurrency:

Text Processing:

  • @azghr/shorn — Truncate strings by byte budget without breaking graphemes
  • seriatim — Sequential processing utilities

HTTP & Network:

  • forbear — Read server rate-limit instructions from HTTP responses
  • forestall — Delay execution until a condition is met
  • obviate — Render operations unnecessary through caching

System & Process:

  • quiesce — Ordered, timeboxed graceful shutdown for Node
  • sortition — Deterministic percentage rollouts and A/B bucketing
  • stanch — Stop flows or operations based on conditions

Utilities:

  • expunge — Remove or exclude items from collections
  • occlude — Hide or mask data and functionality
  • placemark — Geographic location and mapping utilities

License

MIT