Cashu-TS - v4.5.1
    Preparing search index...

    Class AmountWithUnit

    Immutable Amount paired with a currency unit.

    Binary ops require matching units (throw AmountWithUnitError otherwise); scalar ops preserve the unit.

    Lift via Amount.withUnit / AmountWithUnit.from, drop via AmountWithUnit.toAmount.

    AmountWithUnit.from(100, 'sat');
    Amount.from(21).withUnit('sat');
    Index

    Constructors

    Properties

    unit: string

    Methods

    • Internal

      Coercion hook: returns the unit-bearing string for "string" hints (String(x), template literals), throws otherwise. Prevents +, -, *, ==, Number(x), etc. from silently stripping the unit — use AmountWithUnit.toAmount for explicit numeric access.

      Parameters

      • hint: "string" | "number" | "default"

      Returns string

    • Returns { amount: string; unit: string }

    • Unit-bearing canonical form, e.g. "[sat]: 100". Used by String(x), template literals, console.log, and any other string-coercion context.

      Leads with [ (never a digit, sign, or decimal point) so that parseInt(String(x)) / parseFloat(String(x)) return NaN even if the unit itself starts with digits — otherwise a unit like "9999sat" would let parseInt silently extract 9999 from the unit and drop the real amount.

      Returns string

    • Sum a unit-tagged iterable.

      • If unit is provided, every element must match it; the result has that unit. An empty iterable returns AmountWithUnit.zero(unit).
      • If unit is omitted, the iterable must be non-empty; the unit is inferred from the first element and every subsequent element must match. An empty iterable throws.

      Parameters

      Returns AmountWithUnit

      On unit mismatch, or on empty iterable when unit is omitted.