← All packages

@lacspace/money

v1.2.0App & Utils Kit0 deps

Money done right — integer minor units (no floating-point cent bugs), currency-safe arithmetic, remainder-preserving allocation/split, explicit rounding modes (incl. banker's), Intl and Intl-free formatting, string parsing, and injected-rate conversion. Zero-dependency, isomorphic.

npm i @lacspace/money

Usage

money.ts
import { money, Money } from "@lacspace/money";

const price = money(19.99, "USD");   // 1999 minor units, exact
price.multiply(3).format();          // "$59.97"
price.add(money(5, "USD"));          // $24.99
money(9.99, "USD").add(money(1, "EUR")); // ❌ throws: currency mismatch

// Split a bill three ways — the cent doesn't vanish
money(10, "USD").allocate([1, 1, 1]).map((m) => m.format());
// ["$3.34", "$3.33", "$3.33"]   (sum is exactly $10.00)

// Zero-decimal & 3-decimal currencies handled automatically
money(1000, "JPY").format("ja-JP"); // "¥1,000"
money(1.5, "BHD").toMinor();        // 1500  (BHD has 3 decimals)

Exports 4

MoneydecimalsFormoneysumMoney

Keywords

moneycurrencydinero-alternativeminor-unitscentsdecimal

More in App & Utils Kit

@lacspace/cache

A tiny in-memory cache — LRU/LFU eviction, per-entry TTL, stale-while-revalidate, tag invalidation and hit/miss stats, plus wrap()/getOrSet()/memoize() to cache any async function with single-flight de-duplication. Zero-dependency, isomorphic.

@lacspace/case

Convert strings between cases — camelCase, PascalCase, snake_case, kebab-case, CONSTANT_CASE, Title/Sentence/Header/Capital Case and more, with a unicode-aware word splitter, an opt-in acronym registry, and is<Case> detectors. Zero-dependency, isomorphic.

@lacspace/color

Parse, convert, manipulate and check colours — hex/rgb/hsl/hsv/oklch plus 148 CSS names, lighten/darken/mix/invert/complement, tints/shades & colour-wheel harmonies, and WCAG contrast for accessible UIs. Zero-dependency, isomorphic.

@lacspace/env

Typed, validated environment variables — declare a schema, validate at boot, get a typed frozen object or one clear aggregated error. Coercers for ports, URLs, durations, byte sizes, lists & enums, ${VAR} expansion, secret-redacted errors and non-throwing safe-parse. A zero-dependency t3-env / envalid alternative.

@lacspace/flags

Feature flags & A/B experiments with no SaaS and no infrastructure — deterministic percentage rollouts, targeting segments, weighted variants, kill switches and per-user QA overrides, with an explain() that tells you why each flag resolved. Synchronous, zero-dependency, isomorphic.

@lacspace/form

End-to-end form handling — turn FormData into typed, validated, spam-guarded data on the server (Next.js Server Actions), and manage interactive form state on the client (values/errors/touched/dirty, sync+async validation, nested paths, field arrays). One framework-free, zero-dependency package.