@factorn/money
v0.1.0
Published
Class-first money utilities powered by Dinero.js (number and bigint)
Readme
@factorn/money
Class-first money utilities for Node.js and the browser, built on Dinero.js v2.
Install
pnpm add @factorn/money
# or: npm install @factorn/moneyChoose a calculator
| Import | Amount type | Use when |
| ----------------------- | ----------- | ------------------------------------ |
| @factorn/money | number | Typical retail / app amounts |
| @factorn/money/bigint | bigint | Large ledgers, high-precision totals |
Both entries expose the same Money API.
import { Money, USD, EUR } from "@factorn/money";
const price = Money.fromMinor(1999, USD); // $19.99
const tax = price.percentage(15);
const total = Money.sum([price, tax]);
price.format("en-US"); // "$19.99"
JSON.stringify(price); // {"amount":1999,"currency":"USD","scale":2}import { Money, USD } from "@factorn/money/bigint";
const price = Money.fromMinor(1999n, USD);
JSON.stringify(price); // {"amount":"1999","currency":"USD","scale":2}Common operations
import { Money, USD, EUR, halfEven } from "@factorn/money";
const a = Money.fromMajor("10.00", USD);
const b = Money.fromMajor(2.5, USD);
a.add(b);
a.subtract(b);
a.multiply(3);
a.multiply({ amount: 21, scale: 1 }); // × 2.1
a.allocate([1, 2]);
a.percentage(15); // integer percent
a.percentage("12.5"); // fractional percent as string
a.convert(EUR, { EUR: { amount: 89, scale: 2 } });
a.transformScale(3, halfEven);
a.trimScale();Scripts
| Command | Description |
| ---------------- | ----------------- |
| pnpm build | Build with tsdown |
| pnpm typecheck | Type-check |
| pnpm test | Run tests |
| pnpm lint | Lint with oxlint |
| pnpm format | Format with oxfmt |
