Functional Weave
Code in TypeScript

money.amount

A currency-tagged monetary amount held in integer minor units.

1.0.0 (not the latest) · published 2026-10-03 by charlie · Anterra

Pinned by 6 tests, run in TypeScript, Python and Rust · fewer than the registry now requires. 1.0.2 adds them.

What it does

Money is never a float. 0.1 + 0.2 is not 0.3 in binary floating point, and an invoice that is a penny out is a support ticket.

Amounts are integers in the currency's minor unit, tagged with the currency so that adding GBP to EUR fails loudly rather than silently producing a number.

For example

  • money(12,000, GBP) → £120.00 pounds and pence
  • money(0, GBP) → £0.00 zero
  • money(-2,599, GBP) → -£25.99 negative amounts are allowed (credit notes)

The function

The same function in TypeScript, Python and Rust, pinned by the same tests. Pick your language; the choice follows you around the registry.

export function money(minor: number, currency: string): Money
minorintamount in minor units: pence, cents, yen
currencystringISO 4217 alphabetic code, uppercase
returnsMoney

The type it declares, generated into your project

/** A monetary amount in integer minor units, tagged with its currency. */
export interface Money {
  /** pence, cents, yen; never a float */
  readonly minor: number;
  /** ISO 4217 alphabetic code, uppercase */
  readonly currency: string;
}

Your code names it in one line, in the file that uses it

import { money } from "#fune/money.amount@^1";
impl/typescript.ts · 35 lines · open · raw
import { type Money } from "./money_amount_types.ts";

// Money is declared in function.fune: integer minor units, never a float.

const CURRENCY = /^[A-Z]{3}$/;

export function money(minor: number, currency: string): Money {
  if (!Number.isInteger(minor)) {
    throw new TypeError(`money() takes integer minor units, received ${minor}`);
  }
  if (typeof currency !== "string" || !CURRENCY.test(currency)) {
    throw new RangeError(`"${currency}" is not an uppercase ISO 4217 currency code`);
  }
  return { minor, currency };
}

export function isMoney(value: unknown): value is Money {
  return (
    typeof value === "object" &&
    value !== null &&
    Number.isInteger((value as Money).minor) &&
    CURRENCY.test((value as Money).currency ?? "")
  );
}

/** Guard against the silent nonsense of adding GBP to EUR. */
export function assertSameCurrency(a: Money, b: Money): void {
  if (a.currency !== b.currency) {
    throw new RangeError(`currency mismatch: ${a.currency} and ${b.currency}`);
  }
}

export function zero(currency: string): Money {
  return money(0, currency);
}

Install

fune build

With that line in your source, in a TypeScript project (language typescript in fune.project), fune build resolves it and nothing else, pins them in fune.lock, downloads only the TypeScript package of each, and builds the code above into your project’s .fune/build, one readable file per capability with a header linking back here. Or pin a range in fune.project and build in one step:

fune add money.amount
Download for TypeScript money.amount-1.0.0-typescript.fune · 3,881 bytes sha256 a23635c044e9dc0a1ccf942ffa04b04b64f3f4bca5f347f15f3a90a70946910b

The manifest, vectors and README with only the TypeScript implementation. Install it without the registry with fune add ./money.amount-1.0.0-typescript.fune, or fetch it from a terminal with fune pull money.amount@1.0.0:typescript.

The whole function, every language, is one file too: money.amount-1.0.0.fune, 6,566 bytes, sha256 0cbec6e22e228a57a285a6cfd8ad1a99992e1b1622d5c04234e85a78766cdfea. It installs into a project of any language.

Customise it in your app

The seams this capability offers. Put a marker directly above a function of your own and fune build wires it into the built code; the package on the registry is not changed, the built file’s header lists it under CUSTOMISED, and fune hooks lists every hook in the project. How hooks work.

before — your function gets the arguments and returns them, changed or not, or throws to refuse the call.

// fune: before money.amount

after — your function gets the result and the arguments, and returns the final result.

// fune: after money.amount

replace — it requires no other capability, so there is no dependency to replace.

step — your function runs at a numbered point inside the function’s body, receives the in-scope values it names as parameters, and may return replacements. List the points with fune show money.amount --steps.

// fune: step money.amount after <n|label>

Tests

A version published now needs at least 8 tests for every function, and one that expects the error for each function that throws; the registry refuses it otherwise. fune verify --all runs each case in TypeScript, Python and Rust, and a project runs them again with fune verify. This page lists the cases; it does not run them. The exact JSON is vectors.json.

This version has fewer tests than the registry now requires. It was published before every function had to have 8. 1.0.2 meets it, and a project on ^1.0.0 installs that or newer.

  • money has 6 tests; every function needs at least 8. Add 2 more to vectors.json: the ordinary case, the boundaries (zero, negative, the largest values), the rounding edge and every error it documents
CaseArgumentsExpected
pounds and pence 12,000, GBP → £120.00
zero 0, GBP → £0.00
negative amounts are allowed (credit notes) -2,599, GBP → -£25.99
zero-decimal currency 1,500, JPY → ¥1,500
lowercase currency is rejected 100, gbp → error: ISO 4217
non-integer minor units are rejected 10.5, GBP → error: integer minor units

Files

PathBytes
README.md300
impl/python.py947
impl/rust.rs1,599
impl/typescript.ts1,093
vectors.json653