n2words
Version:
Convert numbers to words in 70+ languages with zero dependencies. Supports BigInt, decimals, and browser/Node.js environments.
27 lines (26 loc) • 1.44 kB
TypeScript
/**
* Range guard — the throwing counterpart of the scale-range producers.
*
* A precondition validator in the same family as `parseCardinalValue` /
* `resolveOptions`: the language calls it and it throws on a value past the
* form's ceiling, e.g. `checkMax(integerPart, cardinalMax, decimalPart)`. The
* `*Max` it consumes is produced by the pure helpers in `scale.js`.
* @module check-max
*/
/**
* Throws a `RangeError` when `value` — or its integer-spelled fraction —
* reaches a form's ceiling (`max`, the smallest value the form refuses).
*
* Runs at the entry point: an O(1) short-circuit before any spelling is built —
* the in-range path is just the bigint comparison, plus a single
* `BigInt(fraction)` parse when an integer-spelled fraction is supplied. The
* message renders `10^N - 1` when the ceiling is an exact power of ten,
* otherwise the raw maximum.
* @param {bigint} value The integer magnitude to test (integer part, dollars, …)
* @param {bigint | null} max The form's ceiling, or `null` for no limit (never throws)
* @param {string} [fraction] The decimal digit string — pass it **only** when the
* fraction is spelled via the scale builder; digit-by-digit and ordinal /
* currency forms omit it so long fractions stay valid.
* @throws {RangeError} when the value is out of range
*/
export declare function checkMax(value: bigint, max: bigint | null, fraction?: string): void;