@mdgascar/ariary 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/dist/index.cjs +3 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -2
- package/dist/index.d.ts +7 -2
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@ comma for decimals; other conventions opt-in), read amounts
|
|
|
5
5
|
typed by users, write them in words, and convert old francs (FMG). Zero third-party
|
|
6
6
|
dependencies, ESM + CommonJS + types.
|
|
7
7
|
|
|
8
|
-
Implements spec 0.
|
|
8
|
+
Implements spec 0.7.0.
|
|
9
9
|
|
|
10
10
|
```sh
|
|
11
11
|
npm install @mdgascar/ariary
|
|
@@ -38,6 +38,7 @@ safeParseAriary('1.5'); // { success: false, error: MdgError INVALID_FORMAT }
|
|
|
38
38
|
|
|
39
39
|
ariaryToWords(1500); // 'dimanjato sy arivo ariary'
|
|
40
40
|
ariaryToWords(1500.5); // 'dimanjato sy arivo faingo dimy ariary'
|
|
41
|
+
ariaryToWords(30_000_000, { system: 'traditional' }); // 'telo safatsiroa ariary'
|
|
41
42
|
fmgToAriary(7500); // 1500
|
|
42
43
|
fmgToAriary(7501); // 1500.2
|
|
43
44
|
ariaryToFmg(0.07); // 0.35 (exact, never 0.35000000000000003)
|
package/dist/index.cjs
CHANGED
|
@@ -28,7 +28,7 @@ var FRANC_DIVISION_FACTOR = 2;
|
|
|
28
28
|
var MIN_AMOUNT = 0;
|
|
29
29
|
|
|
30
30
|
// src/generated/errors.ts
|
|
31
|
-
var SPEC_VERSION = "0.
|
|
31
|
+
var SPEC_VERSION = "0.7.0";
|
|
32
32
|
var MdgError = class extends Error {
|
|
33
33
|
/** Always `'MdgError'`. */
|
|
34
34
|
name = "MdgError";
|
|
@@ -105,9 +105,9 @@ function divideExact(value, divisionFactor) {
|
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
// src/convert.ts
|
|
108
|
-
function ariaryToWords(amount) {
|
|
108
|
+
function ariaryToWords(amount, options = {}) {
|
|
109
109
|
assertAmount(amount);
|
|
110
|
-
return `${words.numberToWords(amount)} ${CURRENCY_WORD}`;
|
|
110
|
+
return `${words.numberToWords(amount, options)} ${CURRENCY_WORD}`;
|
|
111
111
|
}
|
|
112
112
|
function fmgToAriary(francs) {
|
|
113
113
|
assertAmount(francs);
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/generated/data.ts","../src/generated/errors.ts","../src/amount.ts","../src/decimal.ts","../src/convert.ts","../src/separators.ts","../src/format.ts","../src/read-digits.ts","../src/parse.ts"],"names":["numberToWords","DECIMAL_POINT"],"mappings":";;;;;;;AAKO,IAAM,eAAA,GAAkB,IAAA;AAGxB,IAAM,aAAA,GAAgB,QAAA;AAGtB,IAAM,gBAAA,GAAmB,MAAA;AAGzB,IAAM,UAAA,GAAa,CAAA;AAMnB,IAAM,gBAAA,uBAA4D,GAAA,CAGvE;AAAA,EACA,CAAC,SAAS,MAAQ,CAAA;AAAA,EAClB,CAAC,OAAO,GAAG,CAAA;AAAA,EACX,CAAC,SAAS,GAAG;AACf,CAAC,CAAA;AAGM,IAAM,gBAAA,GAAmB,OAAA;AAMzB,IAAM,kBAAA,uBAA6D,GAAA,CAGxE;AAAA,EACA,CAAC,SAAS,GAAG,CAAA;AAAA,EACb,CAAC,OAAO,GAAG;AACb,CAAC,CAAA;AAGM,IAAM,eAAA,GAAkB,OAAA;AAGxB,IAAM,mBAAA,GAAsB,CAAC,GAAA,EAAK,MAAA,EAAU,UAAU,GAAG,CAAA;AAGzD,IAAM,eAAA,GAAkB,CAAC,QAAA,EAAU,KAAA,EAAO,IAAI,CAAA;AAG9C,IAAM,YAAA,GAAe,KAAA;AAGrB,IAAM,iBAAA,GAAoB,CAAA;AAG1B,IAAM,qBAAA,GA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,gBAAgB,CAAC,CAAA,YAAA,CAAc,CAAA;AAAA,EAChG;AACA,EAAA,MAAM,MAAA,GAAS,UAAA,CAAW,IAAA,EAAM,UAAU,CAAA;AAC1C,EAAA,IAAI,WAAW,MAAA,EAAW;AACxB,IAAA,OAAO,OAAA,CAAQ,kBAAkB,qDAAqD,CAAA;AAAA,EACxF;AACA,EAAA,MAAM,MAAA,GAAS,OAAO,MAAM,CAAA;AAC5B,EAAA,IAAI,SAAS,UAAA,EAAY;AACvB,IAAA,OAAO,QAAQ,cAAA,EAAgB,CAAA,iBAAA,EAAoB,MAAA,CAAO,UAAU,CAAC,CAAA,CAAA,CAAG,CAAA;AAAA,EAC1E;AACA,EAAA,OAAO,EAAE,OAAA,EAAS,IAAA,EAAM,IAAA,EAAM,MAAA,EAAO;AACvC;AAoBO,SAAS,WAAA,CAAY,IAAA,EAAc,OAAA,GAA8B,EAAC,EAAW;AAClF,EAAA,MAAM,MAAA,GAAS,eAAA,CAAgB,IAAA,EAAM,OAAO,CAAA;AAC5C,EAAA,IAAI,CAAC,MAAA,CAAO,OAAA,EAAS,MAAM,MAAA,CAAO,KAAA;AAClC,EAAA,OAAO,MAAA,CAAO,IAAA;AAChB;AAiBO,SAAS,cAAA,CACd,IAAA,EACA,OAAA,GAA8B,EAAC,EACX;AACpB,EAAA,MAAM,MAAA,GAAS,eAAA,CAAgB,IAAA,EAAM,OAAO,CAAA;AAC5C,EAAA,OAAO,MAAA,CAAO,OAAA,GAAU,MAAA,CAAO,IAAA,GAAO,MAAA;AACxC","file":"index.cjs","sourcesContent":["// GENERATED — edit spec/ instead. Run `just codegen` to refresh.\n\n// From spec/modules/ariary/data.yaml, spec 0.6.0.\n\n/** @internal */\nexport const CURRENCY_SYMBOL = 'Ar' as const;\n\n/** @internal */\nexport const CURRENCY_WORD = 'ariary' as const;\n\n/** @internal */\nexport const SYMBOL_SEPARATOR = '\\u00a0' as const;\n\n/** @internal */\nexport const GROUP_SIZE = 3 as const;\n\n/** Thousand separator used by {@link formatAriary}: `space` (default) or `dot`. */\nexport type AriaryGrouping = 'space' | 'dot' | 'comma';\n\n/** @internal Grouping option → separator character; the first entry is the default. */\nexport const GROUP_SEPARATORS: ReadonlyMap<AriaryGrouping, string> = new Map<\n AriaryGrouping,\n string\n>([\n ['space', '\\u00a0'],\n ['dot', '.'],\n ['comma', ','],\n]);\n\n/** @internal */\nexport const DEFAULT_GROUPING = 'space' as const;\n\n/** Decimal separator used by {@link formatAriary} and the parsers: `comma` (default) or `dot`. */\nexport type AriaryDecimal = 'comma' | 'dot';\n\n/** @internal Decimal option → separator character; the first entry is the default. */\nexport const DECIMAL_SEPARATORS: ReadonlyMap<AriaryDecimal, string> = new Map<\n AriaryDecimal,\n string\n>([\n ['comma', ','],\n ['dot', '.'],\n]);\n\n/** @internal */\nexport const DEFAULT_DECIMAL = 'comma' as const;\n\n/** @internal */\nexport const READABLE_SEPARATORS = [' ', '\\u00a0', '\\u202f', '.'] as const;\n\n/** @internal Lower-cased, longest first. */\nexport const CURRENCY_TOKENS = ['ariary', 'mga', 'ar'] as const;\n\n/** @internal */\nexport const FRANC_SYMBOL = 'Fmg' as const;\n\n/** @internal */\nexport const FRANCS_PER_ARIARY = 5 as const;\n\n/** @internal 10 ÷ FRANCS_PER_ARIARY. */\nexport const FRANC_DIVISION_FACTOR = 2 as const;\n\n/** @internal */\nexport const MIN_AMOUNT = 0 as const;\n","// GENERATED — edit spec/ instead. Run `just codegen` to refresh.\n\n/** Version of the shared spec this code was generated from. */\nexport const SPEC_VERSION = '0.6.0';\n\n/**\n * Error code shared by every mdg-utils language port.\n *\n * - `INVALID_TYPE`: The input is not of the accepted type (for example a string or a non-integer where an integer is expected).\n * - `OUT_OF_RANGE`: The input has the right type but lies outside the supported range.\n * - `INVALID_FORMAT`: The input text cannot be read as a value of this module (wrong characters or wrong length).\n * - `UNKNOWN_OPERATOR`: The phone number is well formed but its operator code is not assigned to a mobile operator.\n */\nexport type ErrorCode = 'INVALID_TYPE' | 'OUT_OF_RANGE' | 'INVALID_FORMAT' | 'UNKNOWN_OPERATOR';\n\n/**\n * Outcome of a `safeParse…` function: the value, or the error that would have been thrown.\n *\n * @example\n * ```ts\n * const result = safeParsePhoneNumber(input);\n * if (result.success) console.log(result.data);\n * else console.log(result.error.code);\n * ```\n */\nexport type SafeParseResult<T> =\n | { readonly success: true; readonly data: T }\n | { readonly success: false; readonly error: MdgError };\n\n/**\n * Error thrown by mdg-utils functions. Check `code`, which is the same in every language.\n *\n * @example\n * ```ts\n * try {\n * numberToWords(-1);\n * } catch (error) {\n * if (error instanceof MdgError && error.code === 'OUT_OF_RANGE') {\n * // handle it\n * }\n * }\n * ```\n */\nexport class MdgError extends Error {\n /** Always `'MdgError'`. */\n override readonly name = 'MdgError';\n /** Why the call failed; the same code in every language. */\n readonly code: ErrorCode;\n\n /**\n * Creates an error with a shared spec code.\n *\n * @param code - Shared spec error code.\n * @param message - Human-readable explanation, in English.\n */\n constructor(code: ErrorCode, message: string) {\n super(message);\n this.code = code;\n }\n\n /**\n * Makes `instanceof MdgError` true for errors from any mdg-utils package or build.\n *\n * @remarks Each package, and its ESM and CommonJS builds, has its own copy of this class,\n * so the check looks at the error's shape instead of its prototype chain.\n *\n * @param value - Any value, usually a caught error.\n * @returns `true` when `value` is an mdg-utils error.\n */\n static override [Symbol.hasInstance](value: unknown): boolean {\n return value instanceof Error && value.name === 'MdgError' && 'code' in value;\n }\n}\n","import { MIN_AMOUNT } from './generated/data.ts';\nimport { MdgError } from './generated/errors.ts';\n\n/** @internal The spec sets no maximum: amounts stop where a number stops being exact. */\nexport const MAX_AMOUNT = Number.MAX_SAFE_INTEGER;\n\n/**\n * @internal Validates an amount, whole or decimal, at the public boundary.\n *\n * @param value - The amount the caller passed.\n */\nexport function assertAmount(value: unknown): asserts value is number {\n if (typeof value !== 'number' || !Number.isFinite(value)) {\n throw new MdgError('INVALID_TYPE', 'Amounts are finite numbers.');\n }\n assertInRange(value);\n}\n\n/**\n * @internal Throws OUT_OF_RANGE for a number below 0 or above {@link MAX_AMOUNT}.\n *\n * @param value - A finite number.\n */\nexport function assertInRange(value: number): void {\n if (value < MIN_AMOUNT || value > MAX_AMOUNT) {\n throw new MdgError(\n 'OUT_OF_RANGE',\n `Amounts go from ${String(MIN_AMOUNT)} to ${String(MAX_AMOUNT)}.`,\n );\n }\n}\n","// Exact decimal helpers. Amounts are number values, but money must never show binary rounding\n// artefacts (0.07 × 5 is 0.35000000000000003 in floating point), so these work on the decimal\n// digits of the value's shortest exact form.\n\nconst DECIMAL_POINT = '.';\nconst ZERO = '0';\n// String(value) of a small number, e.g. '1e-7' or '1.5e-10'.\nconst NEGATIVE_EXPONENT = /^(\\d)(?:\\.(\\d+))?e-(\\d+)$/;\n\n/**\n * @internal The shortest exact decimal form of a number, never in exponent notation.\n *\n * @param value - A non-negative finite number.\n * @returns Its digits: `1500.5` → `'1500.5'`, `1e-7` → `'0.0000001'`.\n */\nexport function plainDecimal(value: number): string {\n const text = String(value);\n const match = NEGATIVE_EXPONENT.exec(text);\n if (match === null) return text;\n const [, lead = '', rest = '', exponent = ''] = match;\n return `0${DECIMAL_POINT}${ZERO.repeat(Number(exponent) - 1)}${lead}${rest}`;\n}\n\ninterface Scaled {\n /** All the digits, as one integer. */\n readonly units: bigint;\n /** How many of them come after the point. */\n readonly places: number;\n}\n\nfunction toScaled(value: number): Scaled {\n const [whole = '', decimals = ''] = plainDecimal(value).split(DECIMAL_POINT);\n return { units: BigInt(`${whole}${decimals}`), places: decimals.length };\n}\n\nfunction toNumber({ units, places }: Scaled): number {\n const digits = units.toString().padStart(places + 1, ZERO);\n const point = digits.length - places;\n return Number(`${digits.slice(0, point)}${DECIMAL_POINT}${digits.slice(point)}`);\n}\n\n/**\n * @internal Multiplies exactly in decimal, then reads the result as the nearest number.\n *\n * @param value - A non-negative finite number.\n * @param factor - A whole multiplier.\n * @returns `value × factor`: `0.07 × 5` → `0.35`.\n */\nexport function multiplyExact(value: number, factor: number): number {\n const { units, places } = toScaled(value);\n return toNumber({ units: units * BigInt(factor), places });\n}\n\n/**\n * @internal Divides exactly by a divisor of 10: multiplies by `10 ÷ divisor`, then moves the\n * point one place left.\n *\n * @param value - A non-negative finite number.\n * @param divisionFactor - `10 ÷ divisor` (2 to divide by 5).\n * @returns `value ÷ divisor`: `7501 ÷ 5` → `1500.2`.\n */\nexport function divideExact(value: number, divisionFactor: number): number {\n const { units, places } = toScaled(value);\n return toNumber({ units: units * BigInt(divisionFactor), places: places + 1 });\n}\n","import { numberToWords } from '@mdgascar/words';\nimport { CURRENCY_WORD, FRANC_DIVISION_FACTOR, FRANCS_PER_ARIARY } from './generated/data.ts';\nimport { assertAmount, assertInRange } from './amount.ts';\nimport { divideExact, multiplyExact } from './decimal.ts';\n\n/**\n * Writes an Ariary amount in Malagasy words.\n *\n * @param amount - Ariary from 0 to `Number.MAX_SAFE_INTEGER`, whole or decimal.\n * @returns The amount in words followed by `ariary`; decimals follow `faingo`.\n * @throws {@link MdgError} `INVALID_TYPE` or `OUT_OF_RANGE`.\n *\n * @example\n * ```ts\n * ariaryToWords(1500); // 'dimanjato sy arivo ariary'\n * ariaryToWords(1500.5); // 'dimanjato sy arivo faingo dimy ariary'\n * ```\n */\nexport function ariaryToWords(amount: number): string {\n assertAmount(amount);\n return `${numberToWords(amount)} ${CURRENCY_WORD}`;\n}\n\n/**\n * Converts old Malagasy francs (FMG) to ariary: 5 FMG = 1 Ar, exactly in decimal.\n *\n * @param francs - Francs from 0 to `Number.MAX_SAFE_INTEGER`, whole or decimal.\n * @returns The amount in ariary: `7501` → `1500.2`.\n * @throws {@link MdgError} `INVALID_TYPE` if `francs` is not a finite number, `OUT_OF_RANGE` when\n * it is negative or above `Number.MAX_SAFE_INTEGER`.\n *\n * @example\n * ```ts\n * fmgToAriary(7500); // 1500\n * fmgToAriary(7501); // 1500.2\n * ```\n */\nexport function fmgToAriary(francs: number): number {\n assertAmount(francs);\n return divideExact(francs, FRANC_DIVISION_FACTOR);\n}\n\n/**\n * Converts ariary to old Malagasy francs (FMG): 1 Ar = 5 FMG, exactly in decimal.\n *\n * @param amount - Ariary from 0 up, whole or decimal.\n * @returns The amount in francs: `0.07` → `0.35`, never `0.35000000000000003`.\n * @throws {@link MdgError} `INVALID_TYPE` if `amount` is not a finite number, `OUT_OF_RANGE` when\n * it is negative or the francs would exceed `Number.MAX_SAFE_INTEGER`.\n *\n * @example\n * ```ts\n * ariaryToFmg(1500); // 7500\n * ariaryToFmg(0.07); // 0.35\n * ```\n */\nexport function ariaryToFmg(amount: number): number {\n assertAmount(amount);\n const francs = multiplyExact(amount, FRANCS_PER_ARIARY);\n assertInRange(francs);\n return francs;\n}\n","// Grouping and decimal options shared by formatting and reading. Every default is the Malagasy\n// way; the comma grouping and the decimal dot are opt-in for text in another convention.\nimport {\n DECIMAL_SEPARATORS,\n DEFAULT_DECIMAL,\n DEFAULT_GROUPING,\n GROUP_SEPARATORS,\n type AriaryDecimal,\n type AriaryGrouping,\n} from './generated/data.ts';\nimport { MdgError } from './generated/errors.ts';\n\n/**\n * Separator options for formatting and reading amounts.\n *\n * @example\n * ```ts\n * const english: AriarySeparatorOptions = { grouping: 'comma', decimal: 'dot' };\n * ```\n */\nexport interface AriarySeparatorOptions {\n /** Thousand separator: `space` (default), `dot`, or `comma` for another convention. */\n readonly grouping?: AriaryGrouping;\n /** Decimal separator: `comma` (default), or `dot` for another convention. */\n readonly decimal?: AriaryDecimal;\n}\n\n/**\n * @internal Throws INVALID_TYPE unless `options` is an object.\n *\n * @param options - What the caller passed as options.\n */\nexport function assertOptionsObject(options: unknown): asserts options is Record<string, unknown> {\n if (typeof options !== 'object' || options === null) {\n throw new MdgError('INVALID_TYPE', 'Options must be an object.');\n }\n}\n\n/**\n * @internal Reads the `decimal` option.\n *\n * @param options - The caller's options.\n * @returns The decimal character, a comma by default.\n */\nexport function decimalFor(options: AriarySeparatorOptions): string {\n const decimal = DECIMAL_SEPARATORS.get(options.decimal ?? DEFAULT_DECIMAL);\n if (decimal === undefined) throw new MdgError('INVALID_TYPE', 'decimal is comma or dot.');\n return decimal;\n}\n\n/**\n * @internal Reads a `grouping` option and checks it against the decimal character.\n *\n * @param id - The grouping option.\n * @param decimal - The decimal character in use.\n * @returns The grouping character.\n */\nexport function groupingFor(id: AriaryGrouping, decimal: string): string {\n const grouping = GROUP_SEPARATORS.get(id);\n if (grouping === undefined)\n throw new MdgError('INVALID_TYPE', 'grouping is space, dot or comma.');\n if (grouping === decimal) {\n throw new MdgError('INVALID_TYPE', 'grouping and decimal must be different characters.');\n }\n return grouping;\n}\n\n/**\n * @internal The grouping option for formatting.\n *\n * @param options - The caller's options.\n * @returns The one given, or the Malagasy default.\n */\nexport function formatGroupingId(options: AriarySeparatorOptions): AriaryGrouping {\n return options.grouping ?? DEFAULT_GROUPING;\n}\n","import { CURRENCY_SYMBOL, FRANC_SYMBOL, GROUP_SIZE, SYMBOL_SEPARATOR } from './generated/data.ts';\nimport { MdgError } from './generated/errors.ts';\nimport { assertAmount } from './amount.ts';\nimport { plainDecimal } from './decimal.ts';\nimport {\n assertOptionsObject,\n decimalFor,\n formatGroupingId,\n groupingFor,\n type AriarySeparatorOptions,\n} from './separators.ts';\n\n/**\n * Where the currency symbol goes: `before` (default, `Ar 1 500`) or `after` (`1 500 Ar`).\n *\n * @example\n * ```ts\n * const position: AriarySymbolPosition = 'after';\n * ```\n */\nexport type AriarySymbolPosition = 'before' | 'after';\n\n/**\n * Layout options for {@link formatAriary} and {@link formatFmg}.\n *\n * @example\n * ```ts\n * const options: AriaryFormatOptions = { grouping: 'dot', symbolPosition: 'after' };\n * ```\n */\nexport interface AriaryFormatOptions extends AriarySeparatorOptions {\n /** Symbol `before` (default) or `after` the amount. */\n readonly symbolPosition?: AriarySymbolPosition;\n}\n\nconst SYMBOL_POSITIONS: ReadonlySet<unknown> = new Set<AriarySymbolPosition>(['before', 'after']);\nconst DECIMAL_POINT = '.';\nconst DIGIT_GROUP_BOUNDARY = new RegExp(`\\\\B(?=(\\\\d{${String(GROUP_SIZE)}})+(?!\\\\d))`, 'g');\n\ninterface Layout {\n readonly grouping: string;\n readonly decimal: string;\n readonly symbolAfter: boolean;\n}\n\nfunction layoutFor(options: unknown): Layout {\n assertOptionsObject(options);\n const { symbolPosition = 'before' } = options as AriaryFormatOptions;\n if (!SYMBOL_POSITIONS.has(symbolPosition)) {\n throw new MdgError('INVALID_TYPE', 'symbolPosition is before or after.');\n }\n const decimal = decimalFor(options);\n const grouping = groupingFor(formatGroupingId(options), decimal);\n return { grouping, decimal, symbolAfter: symbolPosition === 'after' };\n}\n\n// Groups the whole part only; decimals follow a comma as they are, never grouped or rounded.\nfunction layOut(amount: number, symbol: string, options: AriaryFormatOptions): string {\n const layout = layoutFor(options);\n const [whole = '', decimals] = plainDecimal(amount).split(DECIMAL_POINT);\n const grouped = whole.replace(DIGIT_GROUP_BOUNDARY, layout.grouping);\n const digits = decimals === undefined ? grouped : `${grouped}${layout.decimal}${decimals}`;\n return layout.symbolAfter\n ? `${digits}${SYMBOL_SEPARATOR}${symbol}`\n : `${symbol}${SYMBOL_SEPARATOR}${digits}`;\n}\n\n/**\n * Writes an Ariary amount the Malagasy way: symbol `Ar`, digits grouped by no-break spaces.\n *\n * @param amount - Ariary from 0 to `Number.MAX_SAFE_INTEGER`, whole or decimal.\n * @param options - Optional `grouping` (`space`, `dot` or `comma`), `decimal` (`comma` or `dot`)\n * and `symbolPosition` (`before` or `after`). The defaults are the Malagasy way.\n * @returns The formatted amount, e.g. `Ar 1 500` or `Ar 1 500,5` (the spaces are U+00A0).\n * @throws {@link MdgError} `INVALID_TYPE` for a value that is not a finite number or unknown options,\n * `OUT_OF_RANGE` outside 0 to `Number.MAX_SAFE_INTEGER`.\n *\n * @example\n * ```ts\n * formatAriary(1500); // 'Ar 1 500'\n * formatAriary(1500, { grouping: 'dot', symbolPosition: 'after' }); // '1.500 Ar'\n * formatAriary(1500.5); // 'Ar 1 500,5'\n * ```\n */\nexport function formatAriary(amount: number, options: AriaryFormatOptions = {}): string {\n assertAmount(amount);\n return layOut(amount, CURRENCY_SYMBOL, options);\n}\n\n/**\n * Writes an amount in old Malagasy francs, with the same layout as {@link formatAriary}.\n *\n * @param francs - Francs from 0 to `Number.MAX_SAFE_INTEGER`, whole or decimal.\n * @param options - Same options as {@link formatAriary}.\n * @returns The formatted amount, e.g. `Fmg 7 500`.\n * @throws {@link MdgError} `INVALID_TYPE` or `OUT_OF_RANGE`, as {@link formatAriary}.\n *\n * @example\n * ```ts\n * formatFmg(7500); // 'Fmg 7 500'\n * ```\n */\nexport function formatFmg(francs: number, options: AriaryFormatOptions = {}): string {\n assertAmount(francs);\n return layOut(francs, FRANC_SYMBOL, options);\n}\n","// Reads the digits of an amount typed by a user: an optional currency token, then plain or\n// grouped digits, then optionally a decimal separator and the decimals.\nimport { CURRENCY_TOKENS, GROUP_SIZE, READABLE_SEPARATORS } from './generated/data.ts';\n\nconst SPACE = ' ';\nconst WHITESPACE = /\\s/;\nconst PLAIN_AMOUNT = /^(?:0|[1-9]\\d*)$/;\nconst DECIMALS = /^\\d+$/;\nconst NON_DIGITS = /\\D/g;\nconst REGEX_SPECIAL = /[\\\\^$.*+?()[\\]{}|-]/g;\nconst DECIMAL_POINT = '.';\n\n/** @internal What a reader accepts: grouping characters between digit groups, and the decimal one. */\nexport interface ReadSeparators {\n readonly grouping: readonly string[];\n readonly decimal: string;\n}\n\ntype Reader = (amount: string) => string | undefined;\n\nconst readers = new Map<string, Reader>();\n\nfunction isWhitespace(character: string): boolean {\n return WHITESPACE.test(character);\n}\n\nfunction escapeForClass(character: string): string {\n return character.replace(REGEX_SPECIAL, '\\\\$&');\n}\n\n// One digit group of three after the first, repeating the same separator: '1 500 000'.\nfunction groupedPattern(separatorClass: string): RegExp {\n const group = `\\\\d{${String(GROUP_SIZE)}}`;\n return new RegExp(\n `^[1-9]\\\\d{0,${String(GROUP_SIZE - 1)}}([${separatorClass}])${group}(?:\\\\1${group})*$`,\n );\n}\n\n// Spaces of every kind count as one separator: they are turned into a plain space first.\nfunction wholeReader(grouping: readonly string[]): Reader {\n const spaces = grouping.filter(isWhitespace);\n const normalizeSpaces = new RegExp(`[${spaces.map(escapeForClass).join('')}]`, 'g');\n const others = grouping.filter((character) => !isWhitespace(character));\n const separators = [...(spaces.length > 0 ? [SPACE] : []), ...others];\n const grouped = groupedPattern(separators.map(escapeForClass).join(''));\n return (whole) => {\n const normalized = spaces.length > 0 ? whole.replace(normalizeSpaces, SPACE) : whole;\n const isAmount = PLAIN_AMOUNT.test(normalized) || grouped.test(normalized);\n return isAmount ? normalized.replace(NON_DIGITS, '') : undefined;\n };\n}\n\nfunction makeReader({ grouping, decimal }: ReadSeparators): Reader {\n const wholeDigits = wholeReader(grouping);\n return (amount) => {\n const [whole = '', decimals, extra] = amount.split(decimal);\n if (extra !== undefined) return undefined;\n const digits = wholeDigits(whole);\n if (digits === undefined || decimals === undefined) return digits;\n return DECIMALS.test(decimals) ? `${digits}${DECIMAL_POINT}${decimals}` : undefined;\n };\n}\n\nfunction readerFor(separators: ReadSeparators): Reader {\n const key = `${separators.grouping.join('')}|${separators.decimal}`;\n const cached = readers.get(key);\n if (cached !== undefined) return cached;\n const reader = makeReader(separators);\n readers.set(key, reader);\n return reader;\n}\n\nfunction stripCurrency(text: string): string | undefined {\n const lower = text.toLowerCase();\n const prefix = CURRENCY_TOKENS.find((token) => lower.startsWith(token)) ?? '';\n const suffix = CURRENCY_TOKENS.find((token) => lower.endsWith(token)) ?? '';\n if (prefix !== '' && suffix !== '') return undefined;\n return text.slice(prefix.length, text.length - suffix.length).trim();\n}\n\n/**\n * @internal The grouping characters a reader accepts.\n *\n * @param grouping - The chosen grouping character, or undefined for every Malagasy one.\n * @param decimal - The decimal character, which never counts as grouping.\n * @returns Every Malagasy separator (spaces and dot) when none is chosen; else the chosen one,\n * a space standing for every kind of space.\n */\nexport function readableGrouping(grouping: string | undefined, decimal: string): string[] {\n if (grouping === undefined) return READABLE_SEPARATORS.filter((value) => value !== decimal);\n return isWhitespace(grouping) ? READABLE_SEPARATORS.filter(isWhitespace) : [grouping];\n}\n\n/**\n * Extracts the digits of an amount such as `Ar 1 500`, `1.500 Ar`, `MGA 1500` or `1 500,50`.\n *\n * @param text - An amount as typed by a user.\n * @param separators - The grouping and decimal characters to accept.\n * @returns The digits with a `.` before any decimals (`'1500'`, `'1500.50'`), or `undefined`\n * when the text is not an amount.\n *\n * @example\n * ```ts\n * readDigits('1 500,50', { grouping: [' ', '.'], decimal: ',' }); // '1500.50'\n * ```\n */\nexport function readDigits(text: string, separators: ReadSeparators): string | undefined {\n const amount = stripCurrency(text.trim());\n if (amount === undefined) return undefined;\n return readerFor(separators)(amount);\n}\n","import { MAX_AMOUNT } from './amount.ts';\nimport { MdgError, type ErrorCode, type SafeParseResult } from './generated/errors.ts';\nimport { readableGrouping, readDigits, type ReadSeparators } from './read-digits.ts';\nimport {\n assertOptionsObject,\n decimalFor,\n groupingFor,\n type AriarySeparatorOptions,\n} from './separators.ts';\n\n/**\n * Options for reading amounts: which `grouping` and `decimal` separators the text uses.\n * Without `grouping`, every Malagasy one is accepted (spaces or dot); `decimal` defaults to a\n * comma. Say so for text in another convention: `{ grouping: 'comma', decimal: 'dot' }`.\n *\n * @example\n * ```ts\n * const english: AriaryParseOptions = { grouping: 'comma', decimal: 'dot' };\n * ```\n */\nexport type AriaryParseOptions = AriarySeparatorOptions;\n\nconst PARSE_OPTION_KEYS: ReadonlySet<string> = new Set(['grouping', 'decimal']);\n\n// Bounded so a parser that reads user input never scans unbounded text.\nconst MAX_INPUT_LENGTH = 32;\n\nfunction failure(code: ErrorCode, message: string): SafeParseResult<never> {\n return { success: false, error: new MdgError(code, message) };\n}\n\n// The parsers never throw for bad options either: the error comes back as a value.\nfunction safeReadSeparators(options: unknown): ReadSeparators | MdgError {\n try {\n return readSeparatorsFor(options);\n } catch (error) {\n return error as MdgError;\n }\n}\n\nfunction readSeparatorsFor(options: unknown): ReadSeparators {\n assertOptionsObject(options);\n if (Object.keys(options).some((key) => !PARSE_OPTION_KEYS.has(key))) {\n throw new MdgError('INVALID_TYPE', 'Reading takes only the grouping and decimal options.');\n }\n const separators = options as AriaryParseOptions;\n const decimal = decimalFor(separators);\n const grouping =\n separators.grouping === undefined ? undefined : groupingFor(separators.grouping, decimal);\n return { grouping: readableGrouping(grouping, decimal), decimal };\n}\n\n/**\n * Reads an Ariary amount without throwing.\n *\n * @param text - An amount such as `Ar 1 500`, `1.500 Ar`, `MGA 1500` or `1 500,50`.\n * @param options - Optional `grouping` and `decimal`; see {@link AriaryParseOptions}.\n * @returns `{ success: true, data }` with the amount, or `{ success: false, error }`.\n *\n * @example\n * ```ts\n * const result = safeParseAriary('1 500 Ar');\n * if (result.success) result.data; // 1500\n * ```\n */\nexport function safeParseAriary(\n text: unknown,\n options: AriaryParseOptions = {},\n): SafeParseResult<number> {\n if (typeof text !== 'string') return failure('INVALID_TYPE', 'Expected the amount as text.');\n const separators = safeReadSeparators(options);\n if (separators instanceof MdgError) return { success: false, error: separators };\n if (text.length > MAX_INPUT_LENGTH) {\n return failure('INVALID_FORMAT', `Amounts are at most ${String(MAX_INPUT_LENGTH)} characters.`);\n }\n const digits = readDigits(text, separators);\n if (digits === undefined) {\n return failure('INVALID_FORMAT', 'Expected an amount such as Ar 1 500 or Ar 1 500,50.');\n }\n const amount = Number(digits);\n if (amount > MAX_AMOUNT) {\n return failure('OUT_OF_RANGE', `Amounts go up to ${String(MAX_AMOUNT)}.`);\n }\n return { success: true, data: amount };\n}\n\n/**\n * Reads an Ariary amount written in any common way.\n *\n * @param text - An amount such as `Ar 1 500`, `1.500 Ar`, `MGA 1500` or `1 500,50`.\n * @param options - Optional `grouping` and `decimal`; see {@link AriaryParseOptions}.\n * @returns The amount, whole or decimal.\n * @throws {@link MdgError} `INVALID_TYPE` for non-strings or bad options, `INVALID_FORMAT` for text\n * that is not an amount (signs, a dot as decimal point by default), `OUT_OF_RANGE` above\n * `Number.MAX_SAFE_INTEGER`.\n *\n * @example\n * ```ts\n * parseAriary('Ar 1 500'); // 1500\n * parseAriary('1.500 Ar'); // 1500\n * parseAriary('1 500,50 Ar'); // 1500.5\n * parseAriary('1,500.50', { grouping: 'comma', decimal: 'dot' }); // 1500.5\n * ```\n */\nexport function parseAriary(text: string, options: AriaryParseOptions = {}): number {\n const result = safeParseAriary(text, options);\n if (!result.success) throw result.error;\n return result.data;\n}\n\n/**\n * Reads an Ariary amount, or gives `undefined` instead of throwing.\n *\n * Use {@link safeParseAriary} when you need to know why the text was rejected.\n *\n * @param text - An amount such as `Ar 1 500`, `1.500 Ar`, `MGA 1500` or `1 500,50`.\n * @param options - Optional `grouping` and `decimal`; see {@link AriaryParseOptions}.\n * @returns The amount, or `undefined` when {@link parseAriary} would throw.\n *\n * @example\n * ```ts\n * tryParseAriary('1.500 Ar'); // 1500\n * tryParseAriary('1.5'); // undefined\n * ```\n */\nexport function tryParseAriary(\n text: unknown,\n options: AriaryParseOptions = {},\n): number | undefined {\n const result = safeParseAriary(text, options);\n return result.success ? result.data : undefined;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/generated/data.ts","../src/generated/errors.ts","../src/amount.ts","../src/decimal.ts","../src/convert.ts","../src/separators.ts","../src/format.ts","../src/read-digits.ts","../src/parse.ts"],"names":["numberToWords","DECIMAL_POINT"],"mappings":";;;;;;;AAKO,IAAM,eAAA,GAAkB,IAAA;AAGxB,IAAM,aAAA,GAAgB,QAAA;AAGtB,IAAM,gBAAA,GAAmB,MAAA;AAGzB,IAAM,UAAA,GAAa,CAAA;AAMnB,IAAM,gBAAA,uBAA4D,GAAA,CAGvE;AAAA,EACA,CAAC,SAAS,MAAQ,CAAA;AAAA,EAClB,CAAC,OAAO,GAAG,CAAA;AAAA,EACX,CAAC,SAAS,GAAG;AACf,CAAC,CAAA;AAGM,IAAM,gBAAA,GAAmB,OAAA;AAMzB,IAAM,kBAAA,uBAA6D,GAAA,CAGxE;AAAA,EACA,CAAC,SAAS,GAAG,CAAA;AAAA,EACb,CAAC,OAAO,GAAG;AACb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,MAAA,CAAO,IAAA,GAAO,MAAA;AACxC","file":"index.cjs","sourcesContent":["// GENERATED — edit spec/ instead. Run `just codegen` to refresh.\n\n// From spec/modules/ariary/data.yaml, spec 0.7.0.\n\n/** @internal */\nexport const CURRENCY_SYMBOL = 'Ar' as const;\n\n/** @internal */\nexport const CURRENCY_WORD = 'ariary' as const;\n\n/** @internal */\nexport const SYMBOL_SEPARATOR = '\\u00a0' as const;\n\n/** @internal */\nexport const GROUP_SIZE = 3 as const;\n\n/** Thousand separator used by {@link formatAriary}: `space` (default) or `dot`. */\nexport type AriaryGrouping = 'space' | 'dot' | 'comma';\n\n/** @internal Grouping option → separator character; the first entry is the default. */\nexport const GROUP_SEPARATORS: ReadonlyMap<AriaryGrouping, string> = new Map<\n AriaryGrouping,\n string\n>([\n ['space', '\\u00a0'],\n ['dot', '.'],\n ['comma', ','],\n]);\n\n/** @internal */\nexport const DEFAULT_GROUPING = 'space' as const;\n\n/** Decimal separator used by {@link formatAriary} and the parsers: `comma` (default) or `dot`. */\nexport type AriaryDecimal = 'comma' | 'dot';\n\n/** @internal Decimal option → separator character; the first entry is the default. */\nexport const DECIMAL_SEPARATORS: ReadonlyMap<AriaryDecimal, string> = new Map<\n AriaryDecimal,\n string\n>([\n ['comma', ','],\n ['dot', '.'],\n]);\n\n/** @internal */\nexport const DEFAULT_DECIMAL = 'comma' as const;\n\n/** @internal */\nexport const READABLE_SEPARATORS = [' ', '\\u00a0', '\\u202f', '.'] as const;\n\n/** @internal Lower-cased, longest first. */\nexport const CURRENCY_TOKENS = ['ariary', 'mga', 'ar'] as const;\n\n/** @internal */\nexport const FRANC_SYMBOL = 'Fmg' as const;\n\n/** @internal */\nexport const FRANCS_PER_ARIARY = 5 as const;\n\n/** @internal 10 ÷ FRANCS_PER_ARIARY. */\nexport const FRANC_DIVISION_FACTOR = 2 as const;\n\n/** @internal */\nexport const MIN_AMOUNT = 0 as const;\n","// GENERATED — edit spec/ instead. Run `just codegen` to refresh.\n\n/** Version of the shared spec this code was generated from. */\nexport const SPEC_VERSION = '0.7.0';\n\n/**\n * Error code shared by every mdg-utils language port.\n *\n * - `INVALID_TYPE`: The input is not of the accepted type (for example a string or a non-integer where an integer is expected).\n * - `OUT_OF_RANGE`: The input has the right type but lies outside the supported range.\n * - `INVALID_FORMAT`: The input text cannot be read as a value of this module (wrong characters or wrong length).\n * - `UNKNOWN_OPERATOR`: The phone number is well formed but its operator code is not assigned to a mobile operator.\n */\nexport type ErrorCode = 'INVALID_TYPE' | 'OUT_OF_RANGE' | 'INVALID_FORMAT' | 'UNKNOWN_OPERATOR';\n\n/**\n * Outcome of a `safeParse…` function: the value, or the error that would have been thrown.\n *\n * @example\n * ```ts\n * const result = safeParsePhoneNumber(input);\n * if (result.success) console.log(result.data);\n * else console.log(result.error.code);\n * ```\n */\nexport type SafeParseResult<T> =\n | { readonly success: true; readonly data: T }\n | { readonly success: false; readonly error: MdgError };\n\n/**\n * Error thrown by mdg-utils functions. Check `code`, which is the same in every language.\n *\n * @example\n * ```ts\n * try {\n * numberToWords(-1);\n * } catch (error) {\n * if (error instanceof MdgError && error.code === 'OUT_OF_RANGE') {\n * // handle it\n * }\n * }\n * ```\n */\nexport class MdgError extends Error {\n /** Always `'MdgError'`. */\n override readonly name = 'MdgError';\n /** Why the call failed; the same code in every language. */\n readonly code: ErrorCode;\n\n /**\n * Creates an error with a shared spec code.\n *\n * @param code - Shared spec error code.\n * @param message - Human-readable explanation, in English.\n */\n constructor(code: ErrorCode, message: string) {\n super(message);\n this.code = code;\n }\n\n /**\n * Makes `instanceof MdgError` true for errors from any mdg-utils package or build.\n *\n * @remarks Each package, and its ESM and CommonJS builds, has its own copy of this class,\n * so the check looks at the error's shape instead of its prototype chain.\n *\n * @param value - Any value, usually a caught error.\n * @returns `true` when `value` is an mdg-utils error.\n */\n static override [Symbol.hasInstance](value: unknown): boolean {\n return value instanceof Error && value.name === 'MdgError' && 'code' in value;\n }\n}\n","import { MIN_AMOUNT } from './generated/data.ts';\nimport { MdgError } from './generated/errors.ts';\n\n/** @internal The spec sets no maximum: amounts stop where a number stops being exact. */\nexport const MAX_AMOUNT = Number.MAX_SAFE_INTEGER;\n\n/**\n * @internal Validates an amount, whole or decimal, at the public boundary.\n *\n * @param value - The amount the caller passed.\n */\nexport function assertAmount(value: unknown): asserts value is number {\n if (typeof value !== 'number' || !Number.isFinite(value)) {\n throw new MdgError('INVALID_TYPE', 'Amounts are finite numbers.');\n }\n assertInRange(value);\n}\n\n/**\n * @internal Throws OUT_OF_RANGE for a number below 0 or above {@link MAX_AMOUNT}.\n *\n * @param value - A finite number.\n */\nexport function assertInRange(value: number): void {\n if (value < MIN_AMOUNT || value > MAX_AMOUNT) {\n throw new MdgError(\n 'OUT_OF_RANGE',\n `Amounts go from ${String(MIN_AMOUNT)} to ${String(MAX_AMOUNT)}.`,\n );\n }\n}\n","// Exact decimal helpers. Amounts are number values, but money must never show binary rounding\n// artefacts (0.07 × 5 is 0.35000000000000003 in floating point), so these work on the decimal\n// digits of the value's shortest exact form.\n\nconst DECIMAL_POINT = '.';\nconst ZERO = '0';\n// String(value) of a small number, e.g. '1e-7' or '1.5e-10'.\nconst NEGATIVE_EXPONENT = /^(\\d)(?:\\.(\\d+))?e-(\\d+)$/;\n\n/**\n * @internal The shortest exact decimal form of a number, never in exponent notation.\n *\n * @param value - A non-negative finite number.\n * @returns Its digits: `1500.5` → `'1500.5'`, `1e-7` → `'0.0000001'`.\n */\nexport function plainDecimal(value: number): string {\n const text = String(value);\n const match = NEGATIVE_EXPONENT.exec(text);\n if (match === null) return text;\n const [, lead = '', rest = '', exponent = ''] = match;\n return `0${DECIMAL_POINT}${ZERO.repeat(Number(exponent) - 1)}${lead}${rest}`;\n}\n\ninterface Scaled {\n /** All the digits, as one integer. */\n readonly units: bigint;\n /** How many of them come after the point. */\n readonly places: number;\n}\n\nfunction toScaled(value: number): Scaled {\n const [whole = '', decimals = ''] = plainDecimal(value).split(DECIMAL_POINT);\n return { units: BigInt(`${whole}${decimals}`), places: decimals.length };\n}\n\nfunction toNumber({ units, places }: Scaled): number {\n const digits = units.toString().padStart(places + 1, ZERO);\n const point = digits.length - places;\n return Number(`${digits.slice(0, point)}${DECIMAL_POINT}${digits.slice(point)}`);\n}\n\n/**\n * @internal Multiplies exactly in decimal, then reads the result as the nearest number.\n *\n * @param value - A non-negative finite number.\n * @param factor - A whole multiplier.\n * @returns `value × factor`: `0.07 × 5` → `0.35`.\n */\nexport function multiplyExact(value: number, factor: number): number {\n const { units, places } = toScaled(value);\n return toNumber({ units: units * BigInt(factor), places });\n}\n\n/**\n * @internal Divides exactly by a divisor of 10: multiplies by `10 ÷ divisor`, then moves the\n * point one place left.\n *\n * @param value - A non-negative finite number.\n * @param divisionFactor - `10 ÷ divisor` (2 to divide by 5).\n * @returns `value ÷ divisor`: `7501 ÷ 5` → `1500.2`.\n */\nexport function divideExact(value: number, divisionFactor: number): number {\n const { units, places } = toScaled(value);\n return toNumber({ units: units * BigInt(divisionFactor), places: places + 1 });\n}\n","import { numberToWords, type NumberToWordsOptions } from '@mdgascar/words';\nimport { CURRENCY_WORD, FRANC_DIVISION_FACTOR, FRANCS_PER_ARIARY } from './generated/data.ts';\nimport { assertAmount, assertInRange } from './amount.ts';\nimport { divideExact, multiplyExact } from './decimal.ts';\n\n/**\n * Writes an Ariary amount in Malagasy words.\n *\n * @param amount - Ariary from 0 to `Number.MAX_SAFE_INTEGER`, whole or decimal.\n * @param options - The words `system`: `standard` (default) or `traditional`.\n * @returns The amount in words followed by `ariary`; decimals follow `faingo`.\n * @throws {@link MdgError} `INVALID_TYPE` or `OUT_OF_RANGE`.\n *\n * @example\n * ```ts\n * ariaryToWords(1500); // 'dimanjato sy arivo ariary'\n * ariaryToWords(1500.5); // 'dimanjato sy arivo faingo dimy ariary'\n * ariaryToWords(30_000_000, { system: 'traditional' }); // 'telo safatsiroa ariary'\n * ```\n */\nexport function ariaryToWords(amount: number, options: NumberToWordsOptions = {}): string {\n assertAmount(amount);\n return `${numberToWords(amount, options)} ${CURRENCY_WORD}`;\n}\n\n/**\n * Converts old Malagasy francs (FMG) to ariary: 5 FMG = 1 Ar, exactly in decimal.\n *\n * @param francs - Francs from 0 to `Number.MAX_SAFE_INTEGER`, whole or decimal.\n * @returns The amount in ariary: `7501` → `1500.2`.\n * @throws {@link MdgError} `INVALID_TYPE` if `francs` is not a finite number, `OUT_OF_RANGE` when\n * it is negative or above `Number.MAX_SAFE_INTEGER`.\n *\n * @example\n * ```ts\n * fmgToAriary(7500); // 1500\n * fmgToAriary(7501); // 1500.2\n * ```\n */\nexport function fmgToAriary(francs: number): number {\n assertAmount(francs);\n return divideExact(francs, FRANC_DIVISION_FACTOR);\n}\n\n/**\n * Converts ariary to old Malagasy francs (FMG): 1 Ar = 5 FMG, exactly in decimal.\n *\n * @param amount - Ariary from 0 up, whole or decimal.\n * @returns The amount in francs: `0.07` → `0.35`, never `0.35000000000000003`.\n * @throws {@link MdgError} `INVALID_TYPE` if `amount` is not a finite number, `OUT_OF_RANGE` when\n * it is negative or the francs would exceed `Number.MAX_SAFE_INTEGER`.\n *\n * @example\n * ```ts\n * ariaryToFmg(1500); // 7500\n * ariaryToFmg(0.07); // 0.35\n * ```\n */\nexport function ariaryToFmg(amount: number): number {\n assertAmount(amount);\n const francs = multiplyExact(amount, FRANCS_PER_ARIARY);\n assertInRange(francs);\n return francs;\n}\n","// Grouping and decimal options shared by formatting and reading. Every default is the Malagasy\n// way; the comma grouping and the decimal dot are opt-in for text in another convention.\nimport {\n DECIMAL_SEPARATORS,\n DEFAULT_DECIMAL,\n DEFAULT_GROUPING,\n GROUP_SEPARATORS,\n type AriaryDecimal,\n type AriaryGrouping,\n} from './generated/data.ts';\nimport { MdgError } from './generated/errors.ts';\n\n/**\n * Separator options for formatting and reading amounts.\n *\n * @example\n * ```ts\n * const english: AriarySeparatorOptions = { grouping: 'comma', decimal: 'dot' };\n * ```\n */\nexport interface AriarySeparatorOptions {\n /** Thousand separator: `space` (default), `dot`, or `comma` for another convention. */\n readonly grouping?: AriaryGrouping;\n /** Decimal separator: `comma` (default), or `dot` for another convention. */\n readonly decimal?: AriaryDecimal;\n}\n\n/**\n * @internal Throws INVALID_TYPE unless `options` is an object.\n *\n * @param options - What the caller passed as options.\n */\nexport function assertOptionsObject(options: unknown): asserts options is Record<string, unknown> {\n if (typeof options !== 'object' || options === null) {\n throw new MdgError('INVALID_TYPE', 'Options must be an object.');\n }\n}\n\n/**\n * @internal Reads the `decimal` option.\n *\n * @param options - The caller's options.\n * @returns The decimal character, a comma by default.\n */\nexport function decimalFor(options: AriarySeparatorOptions): string {\n const decimal = DECIMAL_SEPARATORS.get(options.decimal ?? DEFAULT_DECIMAL);\n if (decimal === undefined) throw new MdgError('INVALID_TYPE', 'decimal is comma or dot.');\n return decimal;\n}\n\n/**\n * @internal Reads a `grouping` option and checks it against the decimal character.\n *\n * @param id - The grouping option.\n * @param decimal - The decimal character in use.\n * @returns The grouping character.\n */\nexport function groupingFor(id: AriaryGrouping, decimal: string): string {\n const grouping = GROUP_SEPARATORS.get(id);\n if (grouping === undefined)\n throw new MdgError('INVALID_TYPE', 'grouping is space, dot or comma.');\n if (grouping === decimal) {\n throw new MdgError('INVALID_TYPE', 'grouping and decimal must be different characters.');\n }\n return grouping;\n}\n\n/**\n * @internal The grouping option for formatting.\n *\n * @param options - The caller's options.\n * @returns The one given, or the Malagasy default.\n */\nexport function formatGroupingId(options: AriarySeparatorOptions): AriaryGrouping {\n return options.grouping ?? DEFAULT_GROUPING;\n}\n","import { CURRENCY_SYMBOL, FRANC_SYMBOL, GROUP_SIZE, SYMBOL_SEPARATOR } from './generated/data.ts';\nimport { MdgError } from './generated/errors.ts';\nimport { assertAmount } from './amount.ts';\nimport { plainDecimal } from './decimal.ts';\nimport {\n assertOptionsObject,\n decimalFor,\n formatGroupingId,\n groupingFor,\n type AriarySeparatorOptions,\n} from './separators.ts';\n\n/**\n * Where the currency symbol goes: `before` (default, `Ar 1 500`) or `after` (`1 500 Ar`).\n *\n * @example\n * ```ts\n * const position: AriarySymbolPosition = 'after';\n * ```\n */\nexport type AriarySymbolPosition = 'before' | 'after';\n\n/**\n * Layout options for {@link formatAriary} and {@link formatFmg}.\n *\n * @example\n * ```ts\n * const options: AriaryFormatOptions = { grouping: 'dot', symbolPosition: 'after' };\n * ```\n */\nexport interface AriaryFormatOptions extends AriarySeparatorOptions {\n /** Symbol `before` (default) or `after` the amount. */\n readonly symbolPosition?: AriarySymbolPosition;\n}\n\nconst SYMBOL_POSITIONS: ReadonlySet<unknown> = new Set<AriarySymbolPosition>(['before', 'after']);\nconst DECIMAL_POINT = '.';\nconst DIGIT_GROUP_BOUNDARY = new RegExp(`\\\\B(?=(\\\\d{${String(GROUP_SIZE)}})+(?!\\\\d))`, 'g');\n\ninterface Layout {\n readonly grouping: string;\n readonly decimal: string;\n readonly symbolAfter: boolean;\n}\n\nfunction layoutFor(options: unknown): Layout {\n assertOptionsObject(options);\n const { symbolPosition = 'before' } = options as AriaryFormatOptions;\n if (!SYMBOL_POSITIONS.has(symbolPosition)) {\n throw new MdgError('INVALID_TYPE', 'symbolPosition is before or after.');\n }\n const decimal = decimalFor(options);\n const grouping = groupingFor(formatGroupingId(options), decimal);\n return { grouping, decimal, symbolAfter: symbolPosition === 'after' };\n}\n\n// Groups the whole part only; decimals follow a comma as they are, never grouped or rounded.\nfunction layOut(amount: number, symbol: string, options: AriaryFormatOptions): string {\n const layout = layoutFor(options);\n const [whole = '', decimals] = plainDecimal(amount).split(DECIMAL_POINT);\n const grouped = whole.replace(DIGIT_GROUP_BOUNDARY, layout.grouping);\n const digits = decimals === undefined ? grouped : `${grouped}${layout.decimal}${decimals}`;\n return layout.symbolAfter\n ? `${digits}${SYMBOL_SEPARATOR}${symbol}`\n : `${symbol}${SYMBOL_SEPARATOR}${digits}`;\n}\n\n/**\n * Writes an Ariary amount the Malagasy way: symbol `Ar`, digits grouped by no-break spaces.\n *\n * @param amount - Ariary from 0 to `Number.MAX_SAFE_INTEGER`, whole or decimal.\n * @param options - Optional `grouping` (`space`, `dot` or `comma`), `decimal` (`comma` or `dot`)\n * and `symbolPosition` (`before` or `after`). The defaults are the Malagasy way.\n * @returns The formatted amount, e.g. `Ar 1 500` or `Ar 1 500,5` (the spaces are U+00A0).\n * @throws {@link MdgError} `INVALID_TYPE` for a value that is not a finite number or unknown options,\n * `OUT_OF_RANGE` outside 0 to `Number.MAX_SAFE_INTEGER`.\n *\n * @example\n * ```ts\n * formatAriary(1500); // 'Ar 1 500'\n * formatAriary(1500, { grouping: 'dot', symbolPosition: 'after' }); // '1.500 Ar'\n * formatAriary(1500.5); // 'Ar 1 500,5'\n * ```\n */\nexport function formatAriary(amount: number, options: AriaryFormatOptions = {}): string {\n assertAmount(amount);\n return layOut(amount, CURRENCY_SYMBOL, options);\n}\n\n/**\n * Writes an amount in old Malagasy francs, with the same layout as {@link formatAriary}.\n *\n * @param francs - Francs from 0 to `Number.MAX_SAFE_INTEGER`, whole or decimal.\n * @param options - Same options as {@link formatAriary}.\n * @returns The formatted amount, e.g. `Fmg 7 500`.\n * @throws {@link MdgError} `INVALID_TYPE` or `OUT_OF_RANGE`, as {@link formatAriary}.\n *\n * @example\n * ```ts\n * formatFmg(7500); // 'Fmg 7 500'\n * ```\n */\nexport function formatFmg(francs: number, options: AriaryFormatOptions = {}): string {\n assertAmount(francs);\n return layOut(francs, FRANC_SYMBOL, options);\n}\n","// Reads the digits of an amount typed by a user: an optional currency token, then plain or\n// grouped digits, then optionally a decimal separator and the decimals.\nimport { CURRENCY_TOKENS, GROUP_SIZE, READABLE_SEPARATORS } from './generated/data.ts';\n\nconst SPACE = ' ';\nconst WHITESPACE = /\\s/;\nconst PLAIN_AMOUNT = /^(?:0|[1-9]\\d*)$/;\nconst DECIMALS = /^\\d+$/;\nconst NON_DIGITS = /\\D/g;\nconst REGEX_SPECIAL = /[\\\\^$.*+?()[\\]{}|-]/g;\nconst DECIMAL_POINT = '.';\n\n/** @internal What a reader accepts: grouping characters between digit groups, and the decimal one. */\nexport interface ReadSeparators {\n readonly grouping: readonly string[];\n readonly decimal: string;\n}\n\ntype Reader = (amount: string) => string | undefined;\n\nconst readers = new Map<string, Reader>();\n\nfunction isWhitespace(character: string): boolean {\n return WHITESPACE.test(character);\n}\n\nfunction escapeForClass(character: string): string {\n return character.replace(REGEX_SPECIAL, '\\\\$&');\n}\n\n// One digit group of three after the first, repeating the same separator: '1 500 000'.\nfunction groupedPattern(separatorClass: string): RegExp {\n const group = `\\\\d{${String(GROUP_SIZE)}}`;\n return new RegExp(\n `^[1-9]\\\\d{0,${String(GROUP_SIZE - 1)}}([${separatorClass}])${group}(?:\\\\1${group})*$`,\n );\n}\n\n// Spaces of every kind count as one separator: they are turned into a plain space first.\nfunction wholeReader(grouping: readonly string[]): Reader {\n const spaces = grouping.filter(isWhitespace);\n const normalizeSpaces = new RegExp(`[${spaces.map(escapeForClass).join('')}]`, 'g');\n const others = grouping.filter((character) => !isWhitespace(character));\n const separators = [...(spaces.length > 0 ? [SPACE] : []), ...others];\n const grouped = groupedPattern(separators.map(escapeForClass).join(''));\n return (whole) => {\n const normalized = spaces.length > 0 ? whole.replace(normalizeSpaces, SPACE) : whole;\n const isAmount = PLAIN_AMOUNT.test(normalized) || grouped.test(normalized);\n return isAmount ? normalized.replace(NON_DIGITS, '') : undefined;\n };\n}\n\nfunction makeReader({ grouping, decimal }: ReadSeparators): Reader {\n const wholeDigits = wholeReader(grouping);\n return (amount) => {\n const [whole = '', decimals, extra] = amount.split(decimal);\n if (extra !== undefined) return undefined;\n const digits = wholeDigits(whole);\n if (digits === undefined || decimals === undefined) return digits;\n return DECIMALS.test(decimals) ? `${digits}${DECIMAL_POINT}${decimals}` : undefined;\n };\n}\n\nfunction readerFor(separators: ReadSeparators): Reader {\n const key = `${separators.grouping.join('')}|${separators.decimal}`;\n const cached = readers.get(key);\n if (cached !== undefined) return cached;\n const reader = makeReader(separators);\n readers.set(key, reader);\n return reader;\n}\n\nfunction stripCurrency(text: string): string | undefined {\n const lower = text.toLowerCase();\n const prefix = CURRENCY_TOKENS.find((token) => lower.startsWith(token)) ?? '';\n const suffix = CURRENCY_TOKENS.find((token) => lower.endsWith(token)) ?? '';\n if (prefix !== '' && suffix !== '') return undefined;\n return text.slice(prefix.length, text.length - suffix.length).trim();\n}\n\n/**\n * @internal The grouping characters a reader accepts.\n *\n * @param grouping - The chosen grouping character, or undefined for every Malagasy one.\n * @param decimal - The decimal character, which never counts as grouping.\n * @returns Every Malagasy separator (spaces and dot) when none is chosen; else the chosen one,\n * a space standing for every kind of space.\n */\nexport function readableGrouping(grouping: string | undefined, decimal: string): string[] {\n if (grouping === undefined) return READABLE_SEPARATORS.filter((value) => value !== decimal);\n return isWhitespace(grouping) ? READABLE_SEPARATORS.filter(isWhitespace) : [grouping];\n}\n\n/**\n * Extracts the digits of an amount such as `Ar 1 500`, `1.500 Ar`, `MGA 1500` or `1 500,50`.\n *\n * @param text - An amount as typed by a user.\n * @param separators - The grouping and decimal characters to accept.\n * @returns The digits with a `.` before any decimals (`'1500'`, `'1500.50'`), or `undefined`\n * when the text is not an amount.\n *\n * @example\n * ```ts\n * readDigits('1 500,50', { grouping: [' ', '.'], decimal: ',' }); // '1500.50'\n * ```\n */\nexport function readDigits(text: string, separators: ReadSeparators): string | undefined {\n const amount = stripCurrency(text.trim());\n if (amount === undefined) return undefined;\n return readerFor(separators)(amount);\n}\n","import { MAX_AMOUNT } from './amount.ts';\nimport { MdgError, type ErrorCode, type SafeParseResult } from './generated/errors.ts';\nimport { readableGrouping, readDigits, type ReadSeparators } from './read-digits.ts';\nimport {\n assertOptionsObject,\n decimalFor,\n groupingFor,\n type AriarySeparatorOptions,\n} from './separators.ts';\n\n/**\n * Options for reading amounts: which `grouping` and `decimal` separators the text uses.\n * Without `grouping`, every Malagasy one is accepted (spaces or dot); `decimal` defaults to a\n * comma. Say so for text in another convention: `{ grouping: 'comma', decimal: 'dot' }`.\n *\n * @example\n * ```ts\n * const english: AriaryParseOptions = { grouping: 'comma', decimal: 'dot' };\n * ```\n */\nexport type AriaryParseOptions = AriarySeparatorOptions;\n\nconst PARSE_OPTION_KEYS: ReadonlySet<string> = new Set(['grouping', 'decimal']);\n\n// Bounded so a parser that reads user input never scans unbounded text.\nconst MAX_INPUT_LENGTH = 32;\n\nfunction failure(code: ErrorCode, message: string): SafeParseResult<never> {\n return { success: false, error: new MdgError(code, message) };\n}\n\n// The parsers never throw for bad options either: the error comes back as a value.\nfunction safeReadSeparators(options: unknown): ReadSeparators | MdgError {\n try {\n return readSeparatorsFor(options);\n } catch (error) {\n return error as MdgError;\n }\n}\n\nfunction readSeparatorsFor(options: unknown): ReadSeparators {\n assertOptionsObject(options);\n if (Object.keys(options).some((key) => !PARSE_OPTION_KEYS.has(key))) {\n throw new MdgError('INVALID_TYPE', 'Reading takes only the grouping and decimal options.');\n }\n const separators = options as AriaryParseOptions;\n const decimal = decimalFor(separators);\n const grouping =\n separators.grouping === undefined ? undefined : groupingFor(separators.grouping, decimal);\n return { grouping: readableGrouping(grouping, decimal), decimal };\n}\n\n/**\n * Reads an Ariary amount without throwing.\n *\n * @param text - An amount such as `Ar 1 500`, `1.500 Ar`, `MGA 1500` or `1 500,50`.\n * @param options - Optional `grouping` and `decimal`; see {@link AriaryParseOptions}.\n * @returns `{ success: true, data }` with the amount, or `{ success: false, error }`.\n *\n * @example\n * ```ts\n * const result = safeParseAriary('1 500 Ar');\n * if (result.success) result.data; // 1500\n * ```\n */\nexport function safeParseAriary(\n text: unknown,\n options: AriaryParseOptions = {},\n): SafeParseResult<number> {\n if (typeof text !== 'string') return failure('INVALID_TYPE', 'Expected the amount as text.');\n const separators = safeReadSeparators(options);\n if (separators instanceof MdgError) return { success: false, error: separators };\n if (text.length > MAX_INPUT_LENGTH) {\n return failure('INVALID_FORMAT', `Amounts are at most ${String(MAX_INPUT_LENGTH)} characters.`);\n }\n const digits = readDigits(text, separators);\n if (digits === undefined) {\n return failure('INVALID_FORMAT', 'Expected an amount such as Ar 1 500 or Ar 1 500,50.');\n }\n const amount = Number(digits);\n if (amount > MAX_AMOUNT) {\n return failure('OUT_OF_RANGE', `Amounts go up to ${String(MAX_AMOUNT)}.`);\n }\n return { success: true, data: amount };\n}\n\n/**\n * Reads an Ariary amount written in any common way.\n *\n * @param text - An amount such as `Ar 1 500`, `1.500 Ar`, `MGA 1500` or `1 500,50`.\n * @param options - Optional `grouping` and `decimal`; see {@link AriaryParseOptions}.\n * @returns The amount, whole or decimal.\n * @throws {@link MdgError} `INVALID_TYPE` for non-strings or bad options, `INVALID_FORMAT` for text\n * that is not an amount (signs, a dot as decimal point by default), `OUT_OF_RANGE` above\n * `Number.MAX_SAFE_INTEGER`.\n *\n * @example\n * ```ts\n * parseAriary('Ar 1 500'); // 1500\n * parseAriary('1.500 Ar'); // 1500\n * parseAriary('1 500,50 Ar'); // 1500.5\n * parseAriary('1,500.50', { grouping: 'comma', decimal: 'dot' }); // 1500.5\n * ```\n */\nexport function parseAriary(text: string, options: AriaryParseOptions = {}): number {\n const result = safeParseAriary(text, options);\n if (!result.success) throw result.error;\n return result.data;\n}\n\n/**\n * Reads an Ariary amount, or gives `undefined` instead of throwing.\n *\n * Use {@link safeParseAriary} when you need to know why the text was rejected.\n *\n * @param text - An amount such as `Ar 1 500`, `1.500 Ar`, `MGA 1500` or `1 500,50`.\n * @param options - Optional `grouping` and `decimal`; see {@link AriaryParseOptions}.\n * @returns The amount, or `undefined` when {@link parseAriary} would throw.\n *\n * @example\n * ```ts\n * tryParseAriary('1.500 Ar'); // 1500\n * tryParseAriary('1.5'); // undefined\n * ```\n */\nexport function tryParseAriary(\n text: unknown,\n options: AriaryParseOptions = {},\n): number | undefined {\n const result = safeParseAriary(text, options);\n return result.success ? result.data : undefined;\n}\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
import { NumberToWordsOptions } from '@mdgascar/words';
|
|
2
|
+
export { NumberSystem, NumberToWordsOptions } from '@mdgascar/words';
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
5
|
* Writes an Ariary amount in Malagasy words.
|
|
3
6
|
*
|
|
4
7
|
* @param amount - Ariary from 0 to `Number.MAX_SAFE_INTEGER`, whole or decimal.
|
|
8
|
+
* @param options - The words `system`: `standard` (default) or `traditional`.
|
|
5
9
|
* @returns The amount in words followed by `ariary`; decimals follow `faingo`.
|
|
6
10
|
* @throws {@link MdgError} `INVALID_TYPE` or `OUT_OF_RANGE`.
|
|
7
11
|
*
|
|
@@ -9,9 +13,10 @@
|
|
|
9
13
|
* ```ts
|
|
10
14
|
* ariaryToWords(1500); // 'dimanjato sy arivo ariary'
|
|
11
15
|
* ariaryToWords(1500.5); // 'dimanjato sy arivo faingo dimy ariary'
|
|
16
|
+
* ariaryToWords(30_000_000, { system: 'traditional' }); // 'telo safatsiroa ariary'
|
|
12
17
|
* ```
|
|
13
18
|
*/
|
|
14
|
-
declare function ariaryToWords(amount: number): string;
|
|
19
|
+
declare function ariaryToWords(amount: number, options?: NumberToWordsOptions): string;
|
|
15
20
|
/**
|
|
16
21
|
* Converts old Malagasy francs (FMG) to ariary: 5 FMG = 1 Ar, exactly in decimal.
|
|
17
22
|
*
|
|
@@ -118,7 +123,7 @@ declare function formatAriary(amount: number, options?: AriaryFormatOptions): st
|
|
|
118
123
|
declare function formatFmg(francs: number, options?: AriaryFormatOptions): string;
|
|
119
124
|
|
|
120
125
|
/** Version of the shared spec this code was generated from. */
|
|
121
|
-
declare const SPEC_VERSION = "0.
|
|
126
|
+
declare const SPEC_VERSION = "0.7.0";
|
|
122
127
|
/**
|
|
123
128
|
* Error code shared by every mdg-utils language port.
|
|
124
129
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
import { NumberToWordsOptions } from '@mdgascar/words';
|
|
2
|
+
export { NumberSystem, NumberToWordsOptions } from '@mdgascar/words';
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
5
|
* Writes an Ariary amount in Malagasy words.
|
|
3
6
|
*
|
|
4
7
|
* @param amount - Ariary from 0 to `Number.MAX_SAFE_INTEGER`, whole or decimal.
|
|
8
|
+
* @param options - The words `system`: `standard` (default) or `traditional`.
|
|
5
9
|
* @returns The amount in words followed by `ariary`; decimals follow `faingo`.
|
|
6
10
|
* @throws {@link MdgError} `INVALID_TYPE` or `OUT_OF_RANGE`.
|
|
7
11
|
*
|
|
@@ -9,9 +13,10 @@
|
|
|
9
13
|
* ```ts
|
|
10
14
|
* ariaryToWords(1500); // 'dimanjato sy arivo ariary'
|
|
11
15
|
* ariaryToWords(1500.5); // 'dimanjato sy arivo faingo dimy ariary'
|
|
16
|
+
* ariaryToWords(30_000_000, { system: 'traditional' }); // 'telo safatsiroa ariary'
|
|
12
17
|
* ```
|
|
13
18
|
*/
|
|
14
|
-
declare function ariaryToWords(amount: number): string;
|
|
19
|
+
declare function ariaryToWords(amount: number, options?: NumberToWordsOptions): string;
|
|
15
20
|
/**
|
|
16
21
|
* Converts old Malagasy francs (FMG) to ariary: 5 FMG = 1 Ar, exactly in decimal.
|
|
17
22
|
*
|
|
@@ -118,7 +123,7 @@ declare function formatAriary(amount: number, options?: AriaryFormatOptions): st
|
|
|
118
123
|
declare function formatFmg(francs: number, options?: AriaryFormatOptions): string;
|
|
119
124
|
|
|
120
125
|
/** Version of the shared spec this code was generated from. */
|
|
121
|
-
declare const SPEC_VERSION = "0.
|
|
126
|
+
declare const SPEC_VERSION = "0.7.0";
|
|
122
127
|
/**
|
|
123
128
|
* Error code shared by every mdg-utils language port.
|
|
124
129
|
*
|
package/dist/index.js
CHANGED
|
@@ -26,7 +26,7 @@ var FRANC_DIVISION_FACTOR = 2;
|
|
|
26
26
|
var MIN_AMOUNT = 0;
|
|
27
27
|
|
|
28
28
|
// src/generated/errors.ts
|
|
29
|
-
var SPEC_VERSION = "0.
|
|
29
|
+
var SPEC_VERSION = "0.7.0";
|
|
30
30
|
var MdgError = class extends Error {
|
|
31
31
|
/** Always `'MdgError'`. */
|
|
32
32
|
name = "MdgError";
|
|
@@ -103,9 +103,9 @@ function divideExact(value, divisionFactor) {
|
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
// src/convert.ts
|
|
106
|
-
function ariaryToWords(amount) {
|
|
106
|
+
function ariaryToWords(amount, options = {}) {
|
|
107
107
|
assertAmount(amount);
|
|
108
|
-
return `${numberToWords(amount)} ${CURRENCY_WORD}`;
|
|
108
|
+
return `${numberToWords(amount, options)} ${CURRENCY_WORD}`;
|
|
109
109
|
}
|
|
110
110
|
function fmgToAriary(francs) {
|
|
111
111
|
assertAmount(francs);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/generated/data.ts","../src/generated/errors.ts","../src/amount.ts","../src/decimal.ts","../src/convert.ts","../src/separators.ts","../src/format.ts","../src/read-digits.ts","../src/parse.ts"],"names":["DECIMAL_POINT"],"mappings":";;;;;AAKO,IAAM,eAAA,GAAkB,IAAA;AAGxB,IAAM,aAAA,GAAgB,QAAA;AAGtB,IAAM,gBAAA,GAAmB,MAAA;AAGzB,IAAM,UAAA,GAAa,CAAA;AAMnB,IAAM,gBAAA,uBAA4D,GAAA,CAGvE;AAAA,EACA,CAAC,SAAS,MAAQ,CAAA;AAAA,EAClB,CAAC,OAAO,GAAG,CAAA;AAAA,EACX,CAAC,SAAS,GAAG;AACf,CAAC,CAAA;AAGM,IAAM,gBAAA,GAAmB,OAAA;AAMzB,IAAM,kBAAA,uBAA6D,GAAA,CAGxE;AAAA,EACA,CAAC,SAAS,GAAG,CAAA;AAAA,EACb,CAAC,OAAO,GAAG;AACb,CAAC,CAAA;AAGM,IAAM,eAAA,GAAkB,OAAA;AAGxB,IAAM,mBAAA,GAAsB,CAAC,GAAA,EAAK,MAAA,EAAU,UAAU,GAAG,CAAA;AAGzD,IAAM,eAAA,GAAkB,CAAC,QAAA,EAAU,KAAA,EAAO,IAAI,CAAA;AAG9C,IAAM,YAAA,GAAe,KAAA;AAGrB,IAAM,iBAAA,GAAoB,CAAA;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A,EAAuB,MAAA,CAAO,gBAAgB,CAAC,CAAA,YAAA,CAAc,CAAA;AAAA,EAChG;AACA,EAAA,MAAM,MAAA,GAAS,UAAA,CAAW,IAAA,EAAM,UAAU,CAAA;AAC1C,EAAA,IAAI,WAAW,MAAA,EAAW;AACxB,IAAA,OAAO,OAAA,CAAQ,kBAAkB,qDAAqD,CAAA;AAAA,EACxF;AACA,EAAA,MAAM,MAAA,GAAS,OAAO,MAAM,CAAA;AAC5B,EAAA,IAAI,SAAS,UAAA,EAAY;AACvB,IAAA,OAAO,QAAQ,cAAA,EAAgB,CAAA,iBAAA,EAAoB,MAAA,CAAO,UAAU,CAAC,CAAA,CAAA,CAAG,CAAA;AAAA,EAC1E;AACA,EAAA,OAAO,EAAE,OAAA,EAAS,IAAA,EAAM,IAAA,EAAM,MAAA,EAAO;AACvC;AAoBO,SAAS,WAAA,CAAY,IAAA,EAAc,OAAA,GAA8B,EAAC,EAAW;AAClF,EAAA,MAAM,MAAA,GAAS,eAAA,CAAgB,IAAA,EAAM,OAAO,CAAA;AAC5C,EAAA,IAAI,CAAC,MAAA,CAAO,OAAA,EAAS,MAAM,MAAA,CAAO,KAAA;AAClC,EAAA,OAAO,MAAA,CAAO,IAAA;AAChB;AAiBO,SAAS,cAAA,CACd,IAAA,EACA,OAAA,GAA8B,EAAC,EACX;AACpB,EAAA,MAAM,MAAA,GAAS,eAAA,CAAgB,IAAA,EAAM,OAAO,CAAA;AAC5C,EAAA,OAAO,MAAA,CAAO,OAAA,GAAU,MAAA,CAAO,IAAA,GAAO,MAAA;AACxC","file":"index.js","sourcesContent":["// GENERATED — edit spec/ instead. Run `just codegen` to refresh.\n\n// From spec/modules/ariary/data.yaml, spec 0.6.0.\n\n/** @internal */\nexport const CURRENCY_SYMBOL = 'Ar' as const;\n\n/** @internal */\nexport const CURRENCY_WORD = 'ariary' as const;\n\n/** @internal */\nexport const SYMBOL_SEPARATOR = '\\u00a0' as const;\n\n/** @internal */\nexport const GROUP_SIZE = 3 as const;\n\n/** Thousand separator used by {@link formatAriary}: `space` (default) or `dot`. */\nexport type AriaryGrouping = 'space' | 'dot' | 'comma';\n\n/** @internal Grouping option → separator character; the first entry is the default. */\nexport const GROUP_SEPARATORS: ReadonlyMap<AriaryGrouping, string> = new Map<\n AriaryGrouping,\n string\n>([\n ['space', '\\u00a0'],\n ['dot', '.'],\n ['comma', ','],\n]);\n\n/** @internal */\nexport const DEFAULT_GROUPING = 'space' as const;\n\n/** Decimal separator used by {@link formatAriary} and the parsers: `comma` (default) or `dot`. */\nexport type AriaryDecimal = 'comma' | 'dot';\n\n/** @internal Decimal option → separator character; the first entry is the default. */\nexport const DECIMAL_SEPARATORS: ReadonlyMap<AriaryDecimal, string> = new Map<\n AriaryDecimal,\n string\n>([\n ['comma', ','],\n ['dot', '.'],\n]);\n\n/** @internal */\nexport const DEFAULT_DECIMAL = 'comma' as const;\n\n/** @internal */\nexport const READABLE_SEPARATORS = [' ', '\\u00a0', '\\u202f', '.'] as const;\n\n/** @internal Lower-cased, longest first. */\nexport const CURRENCY_TOKENS = ['ariary', 'mga', 'ar'] as const;\n\n/** @internal */\nexport const FRANC_SYMBOL = 'Fmg' as const;\n\n/** @internal */\nexport const FRANCS_PER_ARIARY = 5 as const;\n\n/** @internal 10 ÷ FRANCS_PER_ARIARY. */\nexport const FRANC_DIVISION_FACTOR = 2 as const;\n\n/** @internal */\nexport const MIN_AMOUNT = 0 as const;\n","// GENERATED — edit spec/ instead. Run `just codegen` to refresh.\n\n/** Version of the shared spec this code was generated from. */\nexport const SPEC_VERSION = '0.6.0';\n\n/**\n * Error code shared by every mdg-utils language port.\n *\n * - `INVALID_TYPE`: The input is not of the accepted type (for example a string or a non-integer where an integer is expected).\n * - `OUT_OF_RANGE`: The input has the right type but lies outside the supported range.\n * - `INVALID_FORMAT`: The input text cannot be read as a value of this module (wrong characters or wrong length).\n * - `UNKNOWN_OPERATOR`: The phone number is well formed but its operator code is not assigned to a mobile operator.\n */\nexport type ErrorCode = 'INVALID_TYPE' | 'OUT_OF_RANGE' | 'INVALID_FORMAT' | 'UNKNOWN_OPERATOR';\n\n/**\n * Outcome of a `safeParse…` function: the value, or the error that would have been thrown.\n *\n * @example\n * ```ts\n * const result = safeParsePhoneNumber(input);\n * if (result.success) console.log(result.data);\n * else console.log(result.error.code);\n * ```\n */\nexport type SafeParseResult<T> =\n | { readonly success: true; readonly data: T }\n | { readonly success: false; readonly error: MdgError };\n\n/**\n * Error thrown by mdg-utils functions. Check `code`, which is the same in every language.\n *\n * @example\n * ```ts\n * try {\n * numberToWords(-1);\n * } catch (error) {\n * if (error instanceof MdgError && error.code === 'OUT_OF_RANGE') {\n * // handle it\n * }\n * }\n * ```\n */\nexport class MdgError extends Error {\n /** Always `'MdgError'`. */\n override readonly name = 'MdgError';\n /** Why the call failed; the same code in every language. */\n readonly code: ErrorCode;\n\n /**\n * Creates an error with a shared spec code.\n *\n * @param code - Shared spec error code.\n * @param message - Human-readable explanation, in English.\n */\n constructor(code: ErrorCode, message: string) {\n super(message);\n this.code = code;\n }\n\n /**\n * Makes `instanceof MdgError` true for errors from any mdg-utils package or build.\n *\n * @remarks Each package, and its ESM and CommonJS builds, has its own copy of this class,\n * so the check looks at the error's shape instead of its prototype chain.\n *\n * @param value - Any value, usually a caught error.\n * @returns `true` when `value` is an mdg-utils error.\n */\n static override [Symbol.hasInstance](value: unknown): boolean {\n return value instanceof Error && value.name === 'MdgError' && 'code' in value;\n }\n}\n","import { MIN_AMOUNT } from './generated/data.ts';\nimport { MdgError } from './generated/errors.ts';\n\n/** @internal The spec sets no maximum: amounts stop where a number stops being exact. */\nexport const MAX_AMOUNT = Number.MAX_SAFE_INTEGER;\n\n/**\n * @internal Validates an amount, whole or decimal, at the public boundary.\n *\n * @param value - The amount the caller passed.\n */\nexport function assertAmount(value: unknown): asserts value is number {\n if (typeof value !== 'number' || !Number.isFinite(value)) {\n throw new MdgError('INVALID_TYPE', 'Amounts are finite numbers.');\n }\n assertInRange(value);\n}\n\n/**\n * @internal Throws OUT_OF_RANGE for a number below 0 or above {@link MAX_AMOUNT}.\n *\n * @param value - A finite number.\n */\nexport function assertInRange(value: number): void {\n if (value < MIN_AMOUNT || value > MAX_AMOUNT) {\n throw new MdgError(\n 'OUT_OF_RANGE',\n `Amounts go from ${String(MIN_AMOUNT)} to ${String(MAX_AMOUNT)}.`,\n );\n }\n}\n","// Exact decimal helpers. Amounts are number values, but money must never show binary rounding\n// artefacts (0.07 × 5 is 0.35000000000000003 in floating point), so these work on the decimal\n// digits of the value's shortest exact form.\n\nconst DECIMAL_POINT = '.';\nconst ZERO = '0';\n// String(value) of a small number, e.g. '1e-7' or '1.5e-10'.\nconst NEGATIVE_EXPONENT = /^(\\d)(?:\\.(\\d+))?e-(\\d+)$/;\n\n/**\n * @internal The shortest exact decimal form of a number, never in exponent notation.\n *\n * @param value - A non-negative finite number.\n * @returns Its digits: `1500.5` → `'1500.5'`, `1e-7` → `'0.0000001'`.\n */\nexport function plainDecimal(value: number): string {\n const text = String(value);\n const match = NEGATIVE_EXPONENT.exec(text);\n if (match === null) return text;\n const [, lead = '', rest = '', exponent = ''] = match;\n return `0${DECIMAL_POINT}${ZERO.repeat(Number(exponent) - 1)}${lead}${rest}`;\n}\n\ninterface Scaled {\n /** All the digits, as one integer. */\n readonly units: bigint;\n /** How many of them come after the point. */\n readonly places: number;\n}\n\nfunction toScaled(value: number): Scaled {\n const [whole = '', decimals = ''] = plainDecimal(value).split(DECIMAL_POINT);\n return { units: BigInt(`${whole}${decimals}`), places: decimals.length };\n}\n\nfunction toNumber({ units, places }: Scaled): number {\n const digits = units.toString().padStart(places + 1, ZERO);\n const point = digits.length - places;\n return Number(`${digits.slice(0, point)}${DECIMAL_POINT}${digits.slice(point)}`);\n}\n\n/**\n * @internal Multiplies exactly in decimal, then reads the result as the nearest number.\n *\n * @param value - A non-negative finite number.\n * @param factor - A whole multiplier.\n * @returns `value × factor`: `0.07 × 5` → `0.35`.\n */\nexport function multiplyExact(value: number, factor: number): number {\n const { units, places } = toScaled(value);\n return toNumber({ units: units * BigInt(factor), places });\n}\n\n/**\n * @internal Divides exactly by a divisor of 10: multiplies by `10 ÷ divisor`, then moves the\n * point one place left.\n *\n * @param value - A non-negative finite number.\n * @param divisionFactor - `10 ÷ divisor` (2 to divide by 5).\n * @returns `value ÷ divisor`: `7501 ÷ 5` → `1500.2`.\n */\nexport function divideExact(value: number, divisionFactor: number): number {\n const { units, places } = toScaled(value);\n return toNumber({ units: units * BigInt(divisionFactor), places: places + 1 });\n}\n","import { numberToWords } from '@mdgascar/words';\nimport { CURRENCY_WORD, FRANC_DIVISION_FACTOR, FRANCS_PER_ARIARY } from './generated/data.ts';\nimport { assertAmount, assertInRange } from './amount.ts';\nimport { divideExact, multiplyExact } from './decimal.ts';\n\n/**\n * Writes an Ariary amount in Malagasy words.\n *\n * @param amount - Ariary from 0 to `Number.MAX_SAFE_INTEGER`, whole or decimal.\n * @returns The amount in words followed by `ariary`; decimals follow `faingo`.\n * @throws {@link MdgError} `INVALID_TYPE` or `OUT_OF_RANGE`.\n *\n * @example\n * ```ts\n * ariaryToWords(1500); // 'dimanjato sy arivo ariary'\n * ariaryToWords(1500.5); // 'dimanjato sy arivo faingo dimy ariary'\n * ```\n */\nexport function ariaryToWords(amount: number): string {\n assertAmount(amount);\n return `${numberToWords(amount)} ${CURRENCY_WORD}`;\n}\n\n/**\n * Converts old Malagasy francs (FMG) to ariary: 5 FMG = 1 Ar, exactly in decimal.\n *\n * @param francs - Francs from 0 to `Number.MAX_SAFE_INTEGER`, whole or decimal.\n * @returns The amount in ariary: `7501` → `1500.2`.\n * @throws {@link MdgError} `INVALID_TYPE` if `francs` is not a finite number, `OUT_OF_RANGE` when\n * it is negative or above `Number.MAX_SAFE_INTEGER`.\n *\n * @example\n * ```ts\n * fmgToAriary(7500); // 1500\n * fmgToAriary(7501); // 1500.2\n * ```\n */\nexport function fmgToAriary(francs: number): number {\n assertAmount(francs);\n return divideExact(francs, FRANC_DIVISION_FACTOR);\n}\n\n/**\n * Converts ariary to old Malagasy francs (FMG): 1 Ar = 5 FMG, exactly in decimal.\n *\n * @param amount - Ariary from 0 up, whole or decimal.\n * @returns The amount in francs: `0.07` → `0.35`, never `0.35000000000000003`.\n * @throws {@link MdgError} `INVALID_TYPE` if `amount` is not a finite number, `OUT_OF_RANGE` when\n * it is negative or the francs would exceed `Number.MAX_SAFE_INTEGER`.\n *\n * @example\n * ```ts\n * ariaryToFmg(1500); // 7500\n * ariaryToFmg(0.07); // 0.35\n * ```\n */\nexport function ariaryToFmg(amount: number): number {\n assertAmount(amount);\n const francs = multiplyExact(amount, FRANCS_PER_ARIARY);\n assertInRange(francs);\n return francs;\n}\n","// Grouping and decimal options shared by formatting and reading. Every default is the Malagasy\n// way; the comma grouping and the decimal dot are opt-in for text in another convention.\nimport {\n DECIMAL_SEPARATORS,\n DEFAULT_DECIMAL,\n DEFAULT_GROUPING,\n GROUP_SEPARATORS,\n type AriaryDecimal,\n type AriaryGrouping,\n} from './generated/data.ts';\nimport { MdgError } from './generated/errors.ts';\n\n/**\n * Separator options for formatting and reading amounts.\n *\n * @example\n * ```ts\n * const english: AriarySeparatorOptions = { grouping: 'comma', decimal: 'dot' };\n * ```\n */\nexport interface AriarySeparatorOptions {\n /** Thousand separator: `space` (default), `dot`, or `comma` for another convention. */\n readonly grouping?: AriaryGrouping;\n /** Decimal separator: `comma` (default), or `dot` for another convention. */\n readonly decimal?: AriaryDecimal;\n}\n\n/**\n * @internal Throws INVALID_TYPE unless `options` is an object.\n *\n * @param options - What the caller passed as options.\n */\nexport function assertOptionsObject(options: unknown): asserts options is Record<string, unknown> {\n if (typeof options !== 'object' || options === null) {\n throw new MdgError('INVALID_TYPE', 'Options must be an object.');\n }\n}\n\n/**\n * @internal Reads the `decimal` option.\n *\n * @param options - The caller's options.\n * @returns The decimal character, a comma by default.\n */\nexport function decimalFor(options: AriarySeparatorOptions): string {\n const decimal = DECIMAL_SEPARATORS.get(options.decimal ?? DEFAULT_DECIMAL);\n if (decimal === undefined) throw new MdgError('INVALID_TYPE', 'decimal is comma or dot.');\n return decimal;\n}\n\n/**\n * @internal Reads a `grouping` option and checks it against the decimal character.\n *\n * @param id - The grouping option.\n * @param decimal - The decimal character in use.\n * @returns The grouping character.\n */\nexport function groupingFor(id: AriaryGrouping, decimal: string): string {\n const grouping = GROUP_SEPARATORS.get(id);\n if (grouping === undefined)\n throw new MdgError('INVALID_TYPE', 'grouping is space, dot or comma.');\n if (grouping === decimal) {\n throw new MdgError('INVALID_TYPE', 'grouping and decimal must be different characters.');\n }\n return grouping;\n}\n\n/**\n * @internal The grouping option for formatting.\n *\n * @param options - The caller's options.\n * @returns The one given, or the Malagasy default.\n */\nexport function formatGroupingId(options: AriarySeparatorOptions): AriaryGrouping {\n return options.grouping ?? DEFAULT_GROUPING;\n}\n","import { CURRENCY_SYMBOL, FRANC_SYMBOL, GROUP_SIZE, SYMBOL_SEPARATOR } from './generated/data.ts';\nimport { MdgError } from './generated/errors.ts';\nimport { assertAmount } from './amount.ts';\nimport { plainDecimal } from './decimal.ts';\nimport {\n assertOptionsObject,\n decimalFor,\n formatGroupingId,\n groupingFor,\n type AriarySeparatorOptions,\n} from './separators.ts';\n\n/**\n * Where the currency symbol goes: `before` (default, `Ar 1 500`) or `after` (`1 500 Ar`).\n *\n * @example\n * ```ts\n * const position: AriarySymbolPosition = 'after';\n * ```\n */\nexport type AriarySymbolPosition = 'before' | 'after';\n\n/**\n * Layout options for {@link formatAriary} and {@link formatFmg}.\n *\n * @example\n * ```ts\n * const options: AriaryFormatOptions = { grouping: 'dot', symbolPosition: 'after' };\n * ```\n */\nexport interface AriaryFormatOptions extends AriarySeparatorOptions {\n /** Symbol `before` (default) or `after` the amount. */\n readonly symbolPosition?: AriarySymbolPosition;\n}\n\nconst SYMBOL_POSITIONS: ReadonlySet<unknown> = new Set<AriarySymbolPosition>(['before', 'after']);\nconst DECIMAL_POINT = '.';\nconst DIGIT_GROUP_BOUNDARY = new RegExp(`\\\\B(?=(\\\\d{${String(GROUP_SIZE)}})+(?!\\\\d))`, 'g');\n\ninterface Layout {\n readonly grouping: string;\n readonly decimal: string;\n readonly symbolAfter: boolean;\n}\n\nfunction layoutFor(options: unknown): Layout {\n assertOptionsObject(options);\n const { symbolPosition = 'before' } = options as AriaryFormatOptions;\n if (!SYMBOL_POSITIONS.has(symbolPosition)) {\n throw new MdgError('INVALID_TYPE', 'symbolPosition is before or after.');\n }\n const decimal = decimalFor(options);\n const grouping = groupingFor(formatGroupingId(options), decimal);\n return { grouping, decimal, symbolAfter: symbolPosition === 'after' };\n}\n\n// Groups the whole part only; decimals follow a comma as they are, never grouped or rounded.\nfunction layOut(amount: number, symbol: string, options: AriaryFormatOptions): string {\n const layout = layoutFor(options);\n const [whole = '', decimals] = plainDecimal(amount).split(DECIMAL_POINT);\n const grouped = whole.replace(DIGIT_GROUP_BOUNDARY, layout.grouping);\n const digits = decimals === undefined ? grouped : `${grouped}${layout.decimal}${decimals}`;\n return layout.symbolAfter\n ? `${digits}${SYMBOL_SEPARATOR}${symbol}`\n : `${symbol}${SYMBOL_SEPARATOR}${digits}`;\n}\n\n/**\n * Writes an Ariary amount the Malagasy way: symbol `Ar`, digits grouped by no-break spaces.\n *\n * @param amount - Ariary from 0 to `Number.MAX_SAFE_INTEGER`, whole or decimal.\n * @param options - Optional `grouping` (`space`, `dot` or `comma`), `decimal` (`comma` or `dot`)\n * and `symbolPosition` (`before` or `after`). The defaults are the Malagasy way.\n * @returns The formatted amount, e.g. `Ar 1 500` or `Ar 1 500,5` (the spaces are U+00A0).\n * @throws {@link MdgError} `INVALID_TYPE` for a value that is not a finite number or unknown options,\n * `OUT_OF_RANGE` outside 0 to `Number.MAX_SAFE_INTEGER`.\n *\n * @example\n * ```ts\n * formatAriary(1500); // 'Ar 1 500'\n * formatAriary(1500, { grouping: 'dot', symbolPosition: 'after' }); // '1.500 Ar'\n * formatAriary(1500.5); // 'Ar 1 500,5'\n * ```\n */\nexport function formatAriary(amount: number, options: AriaryFormatOptions = {}): string {\n assertAmount(amount);\n return layOut(amount, CURRENCY_SYMBOL, options);\n}\n\n/**\n * Writes an amount in old Malagasy francs, with the same layout as {@link formatAriary}.\n *\n * @param francs - Francs from 0 to `Number.MAX_SAFE_INTEGER`, whole or decimal.\n * @param options - Same options as {@link formatAriary}.\n * @returns The formatted amount, e.g. `Fmg 7 500`.\n * @throws {@link MdgError} `INVALID_TYPE` or `OUT_OF_RANGE`, as {@link formatAriary}.\n *\n * @example\n * ```ts\n * formatFmg(7500); // 'Fmg 7 500'\n * ```\n */\nexport function formatFmg(francs: number, options: AriaryFormatOptions = {}): string {\n assertAmount(francs);\n return layOut(francs, FRANC_SYMBOL, options);\n}\n","// Reads the digits of an amount typed by a user: an optional currency token, then plain or\n// grouped digits, then optionally a decimal separator and the decimals.\nimport { CURRENCY_TOKENS, GROUP_SIZE, READABLE_SEPARATORS } from './generated/data.ts';\n\nconst SPACE = ' ';\nconst WHITESPACE = /\\s/;\nconst PLAIN_AMOUNT = /^(?:0|[1-9]\\d*)$/;\nconst DECIMALS = /^\\d+$/;\nconst NON_DIGITS = /\\D/g;\nconst REGEX_SPECIAL = /[\\\\^$.*+?()[\\]{}|-]/g;\nconst DECIMAL_POINT = '.';\n\n/** @internal What a reader accepts: grouping characters between digit groups, and the decimal one. */\nexport interface ReadSeparators {\n readonly grouping: readonly string[];\n readonly decimal: string;\n}\n\ntype Reader = (amount: string) => string | undefined;\n\nconst readers = new Map<string, Reader>();\n\nfunction isWhitespace(character: string): boolean {\n return WHITESPACE.test(character);\n}\n\nfunction escapeForClass(character: string): string {\n return character.replace(REGEX_SPECIAL, '\\\\$&');\n}\n\n// One digit group of three after the first, repeating the same separator: '1 500 000'.\nfunction groupedPattern(separatorClass: string): RegExp {\n const group = `\\\\d{${String(GROUP_SIZE)}}`;\n return new RegExp(\n `^[1-9]\\\\d{0,${String(GROUP_SIZE - 1)}}([${separatorClass}])${group}(?:\\\\1${group})*$`,\n );\n}\n\n// Spaces of every kind count as one separator: they are turned into a plain space first.\nfunction wholeReader(grouping: readonly string[]): Reader {\n const spaces = grouping.filter(isWhitespace);\n const normalizeSpaces = new RegExp(`[${spaces.map(escapeForClass).join('')}]`, 'g');\n const others = grouping.filter((character) => !isWhitespace(character));\n const separators = [...(spaces.length > 0 ? [SPACE] : []), ...others];\n const grouped = groupedPattern(separators.map(escapeForClass).join(''));\n return (whole) => {\n const normalized = spaces.length > 0 ? whole.replace(normalizeSpaces, SPACE) : whole;\n const isAmount = PLAIN_AMOUNT.test(normalized) || grouped.test(normalized);\n return isAmount ? normalized.replace(NON_DIGITS, '') : undefined;\n };\n}\n\nfunction makeReader({ grouping, decimal }: ReadSeparators): Reader {\n const wholeDigits = wholeReader(grouping);\n return (amount) => {\n const [whole = '', decimals, extra] = amount.split(decimal);\n if (extra !== undefined) return undefined;\n const digits = wholeDigits(whole);\n if (digits === undefined || decimals === undefined) return digits;\n return DECIMALS.test(decimals) ? `${digits}${DECIMAL_POINT}${decimals}` : undefined;\n };\n}\n\nfunction readerFor(separators: ReadSeparators): Reader {\n const key = `${separators.grouping.join('')}|${separators.decimal}`;\n const cached = readers.get(key);\n if (cached !== undefined) return cached;\n const reader = makeReader(separators);\n readers.set(key, reader);\n return reader;\n}\n\nfunction stripCurrency(text: string): string | undefined {\n const lower = text.toLowerCase();\n const prefix = CURRENCY_TOKENS.find((token) => lower.startsWith(token)) ?? '';\n const suffix = CURRENCY_TOKENS.find((token) => lower.endsWith(token)) ?? '';\n if (prefix !== '' && suffix !== '') return undefined;\n return text.slice(prefix.length, text.length - suffix.length).trim();\n}\n\n/**\n * @internal The grouping characters a reader accepts.\n *\n * @param grouping - The chosen grouping character, or undefined for every Malagasy one.\n * @param decimal - The decimal character, which never counts as grouping.\n * @returns Every Malagasy separator (spaces and dot) when none is chosen; else the chosen one,\n * a space standing for every kind of space.\n */\nexport function readableGrouping(grouping: string | undefined, decimal: string): string[] {\n if (grouping === undefined) return READABLE_SEPARATORS.filter((value) => value !== decimal);\n return isWhitespace(grouping) ? READABLE_SEPARATORS.filter(isWhitespace) : [grouping];\n}\n\n/**\n * Extracts the digits of an amount such as `Ar 1 500`, `1.500 Ar`, `MGA 1500` or `1 500,50`.\n *\n * @param text - An amount as typed by a user.\n * @param separators - The grouping and decimal characters to accept.\n * @returns The digits with a `.` before any decimals (`'1500'`, `'1500.50'`), or `undefined`\n * when the text is not an amount.\n *\n * @example\n * ```ts\n * readDigits('1 500,50', { grouping: [' ', '.'], decimal: ',' }); // '1500.50'\n * ```\n */\nexport function readDigits(text: string, separators: ReadSeparators): string | undefined {\n const amount = stripCurrency(text.trim());\n if (amount === undefined) return undefined;\n return readerFor(separators)(amount);\n}\n","import { MAX_AMOUNT } from './amount.ts';\nimport { MdgError, type ErrorCode, type SafeParseResult } from './generated/errors.ts';\nimport { readableGrouping, readDigits, type ReadSeparators } from './read-digits.ts';\nimport {\n assertOptionsObject,\n decimalFor,\n groupingFor,\n type AriarySeparatorOptions,\n} from './separators.ts';\n\n/**\n * Options for reading amounts: which `grouping` and `decimal` separators the text uses.\n * Without `grouping`, every Malagasy one is accepted (spaces or dot); `decimal` defaults to a\n * comma. Say so for text in another convention: `{ grouping: 'comma', decimal: 'dot' }`.\n *\n * @example\n * ```ts\n * const english: AriaryParseOptions = { grouping: 'comma', decimal: 'dot' };\n * ```\n */\nexport type AriaryParseOptions = AriarySeparatorOptions;\n\nconst PARSE_OPTION_KEYS: ReadonlySet<string> = new Set(['grouping', 'decimal']);\n\n// Bounded so a parser that reads user input never scans unbounded text.\nconst MAX_INPUT_LENGTH = 32;\n\nfunction failure(code: ErrorCode, message: string): SafeParseResult<never> {\n return { success: false, error: new MdgError(code, message) };\n}\n\n// The parsers never throw for bad options either: the error comes back as a value.\nfunction safeReadSeparators(options: unknown): ReadSeparators | MdgError {\n try {\n return readSeparatorsFor(options);\n } catch (error) {\n return error as MdgError;\n }\n}\n\nfunction readSeparatorsFor(options: unknown): ReadSeparators {\n assertOptionsObject(options);\n if (Object.keys(options).some((key) => !PARSE_OPTION_KEYS.has(key))) {\n throw new MdgError('INVALID_TYPE', 'Reading takes only the grouping and decimal options.');\n }\n const separators = options as AriaryParseOptions;\n const decimal = decimalFor(separators);\n const grouping =\n separators.grouping === undefined ? undefined : groupingFor(separators.grouping, decimal);\n return { grouping: readableGrouping(grouping, decimal), decimal };\n}\n\n/**\n * Reads an Ariary amount without throwing.\n *\n * @param text - An amount such as `Ar 1 500`, `1.500 Ar`, `MGA 1500` or `1 500,50`.\n * @param options - Optional `grouping` and `decimal`; see {@link AriaryParseOptions}.\n * @returns `{ success: true, data }` with the amount, or `{ success: false, error }`.\n *\n * @example\n * ```ts\n * const result = safeParseAriary('1 500 Ar');\n * if (result.success) result.data; // 1500\n * ```\n */\nexport function safeParseAriary(\n text: unknown,\n options: AriaryParseOptions = {},\n): SafeParseResult<number> {\n if (typeof text !== 'string') return failure('INVALID_TYPE', 'Expected the amount as text.');\n const separators = safeReadSeparators(options);\n if (separators instanceof MdgError) return { success: false, error: separators };\n if (text.length > MAX_INPUT_LENGTH) {\n return failure('INVALID_FORMAT', `Amounts are at most ${String(MAX_INPUT_LENGTH)} characters.`);\n }\n const digits = readDigits(text, separators);\n if (digits === undefined) {\n return failure('INVALID_FORMAT', 'Expected an amount such as Ar 1 500 or Ar 1 500,50.');\n }\n const amount = Number(digits);\n if (amount > MAX_AMOUNT) {\n return failure('OUT_OF_RANGE', `Amounts go up to ${String(MAX_AMOUNT)}.`);\n }\n return { success: true, data: amount };\n}\n\n/**\n * Reads an Ariary amount written in any common way.\n *\n * @param text - An amount such as `Ar 1 500`, `1.500 Ar`, `MGA 1500` or `1 500,50`.\n * @param options - Optional `grouping` and `decimal`; see {@link AriaryParseOptions}.\n * @returns The amount, whole or decimal.\n * @throws {@link MdgError} `INVALID_TYPE` for non-strings or bad options, `INVALID_FORMAT` for text\n * that is not an amount (signs, a dot as decimal point by default), `OUT_OF_RANGE` above\n * `Number.MAX_SAFE_INTEGER`.\n *\n * @example\n * ```ts\n * parseAriary('Ar 1 500'); // 1500\n * parseAriary('1.500 Ar'); // 1500\n * parseAriary('1 500,50 Ar'); // 1500.5\n * parseAriary('1,500.50', { grouping: 'comma', decimal: 'dot' }); // 1500.5\n * ```\n */\nexport function parseAriary(text: string, options: AriaryParseOptions = {}): number {\n const result = safeParseAriary(text, options);\n if (!result.success) throw result.error;\n return result.data;\n}\n\n/**\n * Reads an Ariary amount, or gives `undefined` instead of throwing.\n *\n * Use {@link safeParseAriary} when you need to know why the text was rejected.\n *\n * @param text - An amount such as `Ar 1 500`, `1.500 Ar`, `MGA 1500` or `1 500,50`.\n * @param options - Optional `grouping` and `decimal`; see {@link AriaryParseOptions}.\n * @returns The amount, or `undefined` when {@link parseAriary} would throw.\n *\n * @example\n * ```ts\n * tryParseAriary('1.500 Ar'); // 1500\n * tryParseAriary('1.5'); // undefined\n * ```\n */\nexport function tryParseAriary(\n text: unknown,\n options: AriaryParseOptions = {},\n): number | undefined {\n const result = safeParseAriary(text, options);\n return result.success ? result.data : undefined;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/generated/data.ts","../src/generated/errors.ts","../src/amount.ts","../src/decimal.ts","../src/convert.ts","../src/separators.ts","../src/format.ts","../src/read-digits.ts","../src/parse.ts"],"names":["DECIMAL_POINT"],"mappings":";;;;;AAKO,IAAM,eAAA,GAAkB,IAAA;AAGxB,IAAM,aAAA,GAAgB,QAAA;AAGtB,IAAM,gBAAA,GAAmB,MAAA;AAGzB,IAAM,UAAA,GAAa,CAAA;AAMnB,IAAM,gBAAA,uBAA4D,GAAA,CAGvE;AAAA,EACA,CAAC,SAAS,MAAQ,CAAA;AAAA,EAClB,CAAC,OAAO,GAAG,CAAA;AAAA,EACX,CAAC,SAAS,GAAG;AACf,CAAC,CAAA;AAGM,IAAM,gBAAA,GAAmB,OAAA;AAMzB,IAAM,kBAAA,uBAA6D,GAAA,CAGxE;AAAA,EACA,CAAC,SAAS,GAAG,CAAA;AAAA,EACb,CAAC,OAAO,G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,GAAU,MAAA,CAAO,IAAA,GAAO,MAAA;AACxC","file":"index.js","sourcesContent":["// GENERATED — edit spec/ instead. Run `just codegen` to refresh.\n\n// From spec/modules/ariary/data.yaml, spec 0.7.0.\n\n/** @internal */\nexport const CURRENCY_SYMBOL = 'Ar' as const;\n\n/** @internal */\nexport const CURRENCY_WORD = 'ariary' as const;\n\n/** @internal */\nexport const SYMBOL_SEPARATOR = '\\u00a0' as const;\n\n/** @internal */\nexport const GROUP_SIZE = 3 as const;\n\n/** Thousand separator used by {@link formatAriary}: `space` (default) or `dot`. */\nexport type AriaryGrouping = 'space' | 'dot' | 'comma';\n\n/** @internal Grouping option → separator character; the first entry is the default. */\nexport const GROUP_SEPARATORS: ReadonlyMap<AriaryGrouping, string> = new Map<\n AriaryGrouping,\n string\n>([\n ['space', '\\u00a0'],\n ['dot', '.'],\n ['comma', ','],\n]);\n\n/** @internal */\nexport const DEFAULT_GROUPING = 'space' as const;\n\n/** Decimal separator used by {@link formatAriary} and the parsers: `comma` (default) or `dot`. */\nexport type AriaryDecimal = 'comma' | 'dot';\n\n/** @internal Decimal option → separator character; the first entry is the default. */\nexport const DECIMAL_SEPARATORS: ReadonlyMap<AriaryDecimal, string> = new Map<\n AriaryDecimal,\n string\n>([\n ['comma', ','],\n ['dot', '.'],\n]);\n\n/** @internal */\nexport const DEFAULT_DECIMAL = 'comma' as const;\n\n/** @internal */\nexport const READABLE_SEPARATORS = [' ', '\\u00a0', '\\u202f', '.'] as const;\n\n/** @internal Lower-cased, longest first. */\nexport const CURRENCY_TOKENS = ['ariary', 'mga', 'ar'] as const;\n\n/** @internal */\nexport const FRANC_SYMBOL = 'Fmg' as const;\n\n/** @internal */\nexport const FRANCS_PER_ARIARY = 5 as const;\n\n/** @internal 10 ÷ FRANCS_PER_ARIARY. */\nexport const FRANC_DIVISION_FACTOR = 2 as const;\n\n/** @internal */\nexport const MIN_AMOUNT = 0 as const;\n","// GENERATED — edit spec/ instead. Run `just codegen` to refresh.\n\n/** Version of the shared spec this code was generated from. */\nexport const SPEC_VERSION = '0.7.0';\n\n/**\n * Error code shared by every mdg-utils language port.\n *\n * - `INVALID_TYPE`: The input is not of the accepted type (for example a string or a non-integer where an integer is expected).\n * - `OUT_OF_RANGE`: The input has the right type but lies outside the supported range.\n * - `INVALID_FORMAT`: The input text cannot be read as a value of this module (wrong characters or wrong length).\n * - `UNKNOWN_OPERATOR`: The phone number is well formed but its operator code is not assigned to a mobile operator.\n */\nexport type ErrorCode = 'INVALID_TYPE' | 'OUT_OF_RANGE' | 'INVALID_FORMAT' | 'UNKNOWN_OPERATOR';\n\n/**\n * Outcome of a `safeParse…` function: the value, or the error that would have been thrown.\n *\n * @example\n * ```ts\n * const result = safeParsePhoneNumber(input);\n * if (result.success) console.log(result.data);\n * else console.log(result.error.code);\n * ```\n */\nexport type SafeParseResult<T> =\n | { readonly success: true; readonly data: T }\n | { readonly success: false; readonly error: MdgError };\n\n/**\n * Error thrown by mdg-utils functions. Check `code`, which is the same in every language.\n *\n * @example\n * ```ts\n * try {\n * numberToWords(-1);\n * } catch (error) {\n * if (error instanceof MdgError && error.code === 'OUT_OF_RANGE') {\n * // handle it\n * }\n * }\n * ```\n */\nexport class MdgError extends Error {\n /** Always `'MdgError'`. */\n override readonly name = 'MdgError';\n /** Why the call failed; the same code in every language. */\n readonly code: ErrorCode;\n\n /**\n * Creates an error with a shared spec code.\n *\n * @param code - Shared spec error code.\n * @param message - Human-readable explanation, in English.\n */\n constructor(code: ErrorCode, message: string) {\n super(message);\n this.code = code;\n }\n\n /**\n * Makes `instanceof MdgError` true for errors from any mdg-utils package or build.\n *\n * @remarks Each package, and its ESM and CommonJS builds, has its own copy of this class,\n * so the check looks at the error's shape instead of its prototype chain.\n *\n * @param value - Any value, usually a caught error.\n * @returns `true` when `value` is an mdg-utils error.\n */\n static override [Symbol.hasInstance](value: unknown): boolean {\n return value instanceof Error && value.name === 'MdgError' && 'code' in value;\n }\n}\n","import { MIN_AMOUNT } from './generated/data.ts';\nimport { MdgError } from './generated/errors.ts';\n\n/** @internal The spec sets no maximum: amounts stop where a number stops being exact. */\nexport const MAX_AMOUNT = Number.MAX_SAFE_INTEGER;\n\n/**\n * @internal Validates an amount, whole or decimal, at the public boundary.\n *\n * @param value - The amount the caller passed.\n */\nexport function assertAmount(value: unknown): asserts value is number {\n if (typeof value !== 'number' || !Number.isFinite(value)) {\n throw new MdgError('INVALID_TYPE', 'Amounts are finite numbers.');\n }\n assertInRange(value);\n}\n\n/**\n * @internal Throws OUT_OF_RANGE for a number below 0 or above {@link MAX_AMOUNT}.\n *\n * @param value - A finite number.\n */\nexport function assertInRange(value: number): void {\n if (value < MIN_AMOUNT || value > MAX_AMOUNT) {\n throw new MdgError(\n 'OUT_OF_RANGE',\n `Amounts go from ${String(MIN_AMOUNT)} to ${String(MAX_AMOUNT)}.`,\n );\n }\n}\n","// Exact decimal helpers. Amounts are number values, but money must never show binary rounding\n// artefacts (0.07 × 5 is 0.35000000000000003 in floating point), so these work on the decimal\n// digits of the value's shortest exact form.\n\nconst DECIMAL_POINT = '.';\nconst ZERO = '0';\n// String(value) of a small number, e.g. '1e-7' or '1.5e-10'.\nconst NEGATIVE_EXPONENT = /^(\\d)(?:\\.(\\d+))?e-(\\d+)$/;\n\n/**\n * @internal The shortest exact decimal form of a number, never in exponent notation.\n *\n * @param value - A non-negative finite number.\n * @returns Its digits: `1500.5` → `'1500.5'`, `1e-7` → `'0.0000001'`.\n */\nexport function plainDecimal(value: number): string {\n const text = String(value);\n const match = NEGATIVE_EXPONENT.exec(text);\n if (match === null) return text;\n const [, lead = '', rest = '', exponent = ''] = match;\n return `0${DECIMAL_POINT}${ZERO.repeat(Number(exponent) - 1)}${lead}${rest}`;\n}\n\ninterface Scaled {\n /** All the digits, as one integer. */\n readonly units: bigint;\n /** How many of them come after the point. */\n readonly places: number;\n}\n\nfunction toScaled(value: number): Scaled {\n const [whole = '', decimals = ''] = plainDecimal(value).split(DECIMAL_POINT);\n return { units: BigInt(`${whole}${decimals}`), places: decimals.length };\n}\n\nfunction toNumber({ units, places }: Scaled): number {\n const digits = units.toString().padStart(places + 1, ZERO);\n const point = digits.length - places;\n return Number(`${digits.slice(0, point)}${DECIMAL_POINT}${digits.slice(point)}`);\n}\n\n/**\n * @internal Multiplies exactly in decimal, then reads the result as the nearest number.\n *\n * @param value - A non-negative finite number.\n * @param factor - A whole multiplier.\n * @returns `value × factor`: `0.07 × 5` → `0.35`.\n */\nexport function multiplyExact(value: number, factor: number): number {\n const { units, places } = toScaled(value);\n return toNumber({ units: units * BigInt(factor), places });\n}\n\n/**\n * @internal Divides exactly by a divisor of 10: multiplies by `10 ÷ divisor`, then moves the\n * point one place left.\n *\n * @param value - A non-negative finite number.\n * @param divisionFactor - `10 ÷ divisor` (2 to divide by 5).\n * @returns `value ÷ divisor`: `7501 ÷ 5` → `1500.2`.\n */\nexport function divideExact(value: number, divisionFactor: number): number {\n const { units, places } = toScaled(value);\n return toNumber({ units: units * BigInt(divisionFactor), places: places + 1 });\n}\n","import { numberToWords, type NumberToWordsOptions } from '@mdgascar/words';\nimport { CURRENCY_WORD, FRANC_DIVISION_FACTOR, FRANCS_PER_ARIARY } from './generated/data.ts';\nimport { assertAmount, assertInRange } from './amount.ts';\nimport { divideExact, multiplyExact } from './decimal.ts';\n\n/**\n * Writes an Ariary amount in Malagasy words.\n *\n * @param amount - Ariary from 0 to `Number.MAX_SAFE_INTEGER`, whole or decimal.\n * @param options - The words `system`: `standard` (default) or `traditional`.\n * @returns The amount in words followed by `ariary`; decimals follow `faingo`.\n * @throws {@link MdgError} `INVALID_TYPE` or `OUT_OF_RANGE`.\n *\n * @example\n * ```ts\n * ariaryToWords(1500); // 'dimanjato sy arivo ariary'\n * ariaryToWords(1500.5); // 'dimanjato sy arivo faingo dimy ariary'\n * ariaryToWords(30_000_000, { system: 'traditional' }); // 'telo safatsiroa ariary'\n * ```\n */\nexport function ariaryToWords(amount: number, options: NumberToWordsOptions = {}): string {\n assertAmount(amount);\n return `${numberToWords(amount, options)} ${CURRENCY_WORD}`;\n}\n\n/**\n * Converts old Malagasy francs (FMG) to ariary: 5 FMG = 1 Ar, exactly in decimal.\n *\n * @param francs - Francs from 0 to `Number.MAX_SAFE_INTEGER`, whole or decimal.\n * @returns The amount in ariary: `7501` → `1500.2`.\n * @throws {@link MdgError} `INVALID_TYPE` if `francs` is not a finite number, `OUT_OF_RANGE` when\n * it is negative or above `Number.MAX_SAFE_INTEGER`.\n *\n * @example\n * ```ts\n * fmgToAriary(7500); // 1500\n * fmgToAriary(7501); // 1500.2\n * ```\n */\nexport function fmgToAriary(francs: number): number {\n assertAmount(francs);\n return divideExact(francs, FRANC_DIVISION_FACTOR);\n}\n\n/**\n * Converts ariary to old Malagasy francs (FMG): 1 Ar = 5 FMG, exactly in decimal.\n *\n * @param amount - Ariary from 0 up, whole or decimal.\n * @returns The amount in francs: `0.07` → `0.35`, never `0.35000000000000003`.\n * @throws {@link MdgError} `INVALID_TYPE` if `amount` is not a finite number, `OUT_OF_RANGE` when\n * it is negative or the francs would exceed `Number.MAX_SAFE_INTEGER`.\n *\n * @example\n * ```ts\n * ariaryToFmg(1500); // 7500\n * ariaryToFmg(0.07); // 0.35\n * ```\n */\nexport function ariaryToFmg(amount: number): number {\n assertAmount(amount);\n const francs = multiplyExact(amount, FRANCS_PER_ARIARY);\n assertInRange(francs);\n return francs;\n}\n","// Grouping and decimal options shared by formatting and reading. Every default is the Malagasy\n// way; the comma grouping and the decimal dot are opt-in for text in another convention.\nimport {\n DECIMAL_SEPARATORS,\n DEFAULT_DECIMAL,\n DEFAULT_GROUPING,\n GROUP_SEPARATORS,\n type AriaryDecimal,\n type AriaryGrouping,\n} from './generated/data.ts';\nimport { MdgError } from './generated/errors.ts';\n\n/**\n * Separator options for formatting and reading amounts.\n *\n * @example\n * ```ts\n * const english: AriarySeparatorOptions = { grouping: 'comma', decimal: 'dot' };\n * ```\n */\nexport interface AriarySeparatorOptions {\n /** Thousand separator: `space` (default), `dot`, or `comma` for another convention. */\n readonly grouping?: AriaryGrouping;\n /** Decimal separator: `comma` (default), or `dot` for another convention. */\n readonly decimal?: AriaryDecimal;\n}\n\n/**\n * @internal Throws INVALID_TYPE unless `options` is an object.\n *\n * @param options - What the caller passed as options.\n */\nexport function assertOptionsObject(options: unknown): asserts options is Record<string, unknown> {\n if (typeof options !== 'object' || options === null) {\n throw new MdgError('INVALID_TYPE', 'Options must be an object.');\n }\n}\n\n/**\n * @internal Reads the `decimal` option.\n *\n * @param options - The caller's options.\n * @returns The decimal character, a comma by default.\n */\nexport function decimalFor(options: AriarySeparatorOptions): string {\n const decimal = DECIMAL_SEPARATORS.get(options.decimal ?? DEFAULT_DECIMAL);\n if (decimal === undefined) throw new MdgError('INVALID_TYPE', 'decimal is comma or dot.');\n return decimal;\n}\n\n/**\n * @internal Reads a `grouping` option and checks it against the decimal character.\n *\n * @param id - The grouping option.\n * @param decimal - The decimal character in use.\n * @returns The grouping character.\n */\nexport function groupingFor(id: AriaryGrouping, decimal: string): string {\n const grouping = GROUP_SEPARATORS.get(id);\n if (grouping === undefined)\n throw new MdgError('INVALID_TYPE', 'grouping is space, dot or comma.');\n if (grouping === decimal) {\n throw new MdgError('INVALID_TYPE', 'grouping and decimal must be different characters.');\n }\n return grouping;\n}\n\n/**\n * @internal The grouping option for formatting.\n *\n * @param options - The caller's options.\n * @returns The one given, or the Malagasy default.\n */\nexport function formatGroupingId(options: AriarySeparatorOptions): AriaryGrouping {\n return options.grouping ?? DEFAULT_GROUPING;\n}\n","import { CURRENCY_SYMBOL, FRANC_SYMBOL, GROUP_SIZE, SYMBOL_SEPARATOR } from './generated/data.ts';\nimport { MdgError } from './generated/errors.ts';\nimport { assertAmount } from './amount.ts';\nimport { plainDecimal } from './decimal.ts';\nimport {\n assertOptionsObject,\n decimalFor,\n formatGroupingId,\n groupingFor,\n type AriarySeparatorOptions,\n} from './separators.ts';\n\n/**\n * Where the currency symbol goes: `before` (default, `Ar 1 500`) or `after` (`1 500 Ar`).\n *\n * @example\n * ```ts\n * const position: AriarySymbolPosition = 'after';\n * ```\n */\nexport type AriarySymbolPosition = 'before' | 'after';\n\n/**\n * Layout options for {@link formatAriary} and {@link formatFmg}.\n *\n * @example\n * ```ts\n * const options: AriaryFormatOptions = { grouping: 'dot', symbolPosition: 'after' };\n * ```\n */\nexport interface AriaryFormatOptions extends AriarySeparatorOptions {\n /** Symbol `before` (default) or `after` the amount. */\n readonly symbolPosition?: AriarySymbolPosition;\n}\n\nconst SYMBOL_POSITIONS: ReadonlySet<unknown> = new Set<AriarySymbolPosition>(['before', 'after']);\nconst DECIMAL_POINT = '.';\nconst DIGIT_GROUP_BOUNDARY = new RegExp(`\\\\B(?=(\\\\d{${String(GROUP_SIZE)}})+(?!\\\\d))`, 'g');\n\ninterface Layout {\n readonly grouping: string;\n readonly decimal: string;\n readonly symbolAfter: boolean;\n}\n\nfunction layoutFor(options: unknown): Layout {\n assertOptionsObject(options);\n const { symbolPosition = 'before' } = options as AriaryFormatOptions;\n if (!SYMBOL_POSITIONS.has(symbolPosition)) {\n throw new MdgError('INVALID_TYPE', 'symbolPosition is before or after.');\n }\n const decimal = decimalFor(options);\n const grouping = groupingFor(formatGroupingId(options), decimal);\n return { grouping, decimal, symbolAfter: symbolPosition === 'after' };\n}\n\n// Groups the whole part only; decimals follow a comma as they are, never grouped or rounded.\nfunction layOut(amount: number, symbol: string, options: AriaryFormatOptions): string {\n const layout = layoutFor(options);\n const [whole = '', decimals] = plainDecimal(amount).split(DECIMAL_POINT);\n const grouped = whole.replace(DIGIT_GROUP_BOUNDARY, layout.grouping);\n const digits = decimals === undefined ? grouped : `${grouped}${layout.decimal}${decimals}`;\n return layout.symbolAfter\n ? `${digits}${SYMBOL_SEPARATOR}${symbol}`\n : `${symbol}${SYMBOL_SEPARATOR}${digits}`;\n}\n\n/**\n * Writes an Ariary amount the Malagasy way: symbol `Ar`, digits grouped by no-break spaces.\n *\n * @param amount - Ariary from 0 to `Number.MAX_SAFE_INTEGER`, whole or decimal.\n * @param options - Optional `grouping` (`space`, `dot` or `comma`), `decimal` (`comma` or `dot`)\n * and `symbolPosition` (`before` or `after`). The defaults are the Malagasy way.\n * @returns The formatted amount, e.g. `Ar 1 500` or `Ar 1 500,5` (the spaces are U+00A0).\n * @throws {@link MdgError} `INVALID_TYPE` for a value that is not a finite number or unknown options,\n * `OUT_OF_RANGE` outside 0 to `Number.MAX_SAFE_INTEGER`.\n *\n * @example\n * ```ts\n * formatAriary(1500); // 'Ar 1 500'\n * formatAriary(1500, { grouping: 'dot', symbolPosition: 'after' }); // '1.500 Ar'\n * formatAriary(1500.5); // 'Ar 1 500,5'\n * ```\n */\nexport function formatAriary(amount: number, options: AriaryFormatOptions = {}): string {\n assertAmount(amount);\n return layOut(amount, CURRENCY_SYMBOL, options);\n}\n\n/**\n * Writes an amount in old Malagasy francs, with the same layout as {@link formatAriary}.\n *\n * @param francs - Francs from 0 to `Number.MAX_SAFE_INTEGER`, whole or decimal.\n * @param options - Same options as {@link formatAriary}.\n * @returns The formatted amount, e.g. `Fmg 7 500`.\n * @throws {@link MdgError} `INVALID_TYPE` or `OUT_OF_RANGE`, as {@link formatAriary}.\n *\n * @example\n * ```ts\n * formatFmg(7500); // 'Fmg 7 500'\n * ```\n */\nexport function formatFmg(francs: number, options: AriaryFormatOptions = {}): string {\n assertAmount(francs);\n return layOut(francs, FRANC_SYMBOL, options);\n}\n","// Reads the digits of an amount typed by a user: an optional currency token, then plain or\n// grouped digits, then optionally a decimal separator and the decimals.\nimport { CURRENCY_TOKENS, GROUP_SIZE, READABLE_SEPARATORS } from './generated/data.ts';\n\nconst SPACE = ' ';\nconst WHITESPACE = /\\s/;\nconst PLAIN_AMOUNT = /^(?:0|[1-9]\\d*)$/;\nconst DECIMALS = /^\\d+$/;\nconst NON_DIGITS = /\\D/g;\nconst REGEX_SPECIAL = /[\\\\^$.*+?()[\\]{}|-]/g;\nconst DECIMAL_POINT = '.';\n\n/** @internal What a reader accepts: grouping characters between digit groups, and the decimal one. */\nexport interface ReadSeparators {\n readonly grouping: readonly string[];\n readonly decimal: string;\n}\n\ntype Reader = (amount: string) => string | undefined;\n\nconst readers = new Map<string, Reader>();\n\nfunction isWhitespace(character: string): boolean {\n return WHITESPACE.test(character);\n}\n\nfunction escapeForClass(character: string): string {\n return character.replace(REGEX_SPECIAL, '\\\\$&');\n}\n\n// One digit group of three after the first, repeating the same separator: '1 500 000'.\nfunction groupedPattern(separatorClass: string): RegExp {\n const group = `\\\\d{${String(GROUP_SIZE)}}`;\n return new RegExp(\n `^[1-9]\\\\d{0,${String(GROUP_SIZE - 1)}}([${separatorClass}])${group}(?:\\\\1${group})*$`,\n );\n}\n\n// Spaces of every kind count as one separator: they are turned into a plain space first.\nfunction wholeReader(grouping: readonly string[]): Reader {\n const spaces = grouping.filter(isWhitespace);\n const normalizeSpaces = new RegExp(`[${spaces.map(escapeForClass).join('')}]`, 'g');\n const others = grouping.filter((character) => !isWhitespace(character));\n const separators = [...(spaces.length > 0 ? [SPACE] : []), ...others];\n const grouped = groupedPattern(separators.map(escapeForClass).join(''));\n return (whole) => {\n const normalized = spaces.length > 0 ? whole.replace(normalizeSpaces, SPACE) : whole;\n const isAmount = PLAIN_AMOUNT.test(normalized) || grouped.test(normalized);\n return isAmount ? normalized.replace(NON_DIGITS, '') : undefined;\n };\n}\n\nfunction makeReader({ grouping, decimal }: ReadSeparators): Reader {\n const wholeDigits = wholeReader(grouping);\n return (amount) => {\n const [whole = '', decimals, extra] = amount.split(decimal);\n if (extra !== undefined) return undefined;\n const digits = wholeDigits(whole);\n if (digits === undefined || decimals === undefined) return digits;\n return DECIMALS.test(decimals) ? `${digits}${DECIMAL_POINT}${decimals}` : undefined;\n };\n}\n\nfunction readerFor(separators: ReadSeparators): Reader {\n const key = `${separators.grouping.join('')}|${separators.decimal}`;\n const cached = readers.get(key);\n if (cached !== undefined) return cached;\n const reader = makeReader(separators);\n readers.set(key, reader);\n return reader;\n}\n\nfunction stripCurrency(text: string): string | undefined {\n const lower = text.toLowerCase();\n const prefix = CURRENCY_TOKENS.find((token) => lower.startsWith(token)) ?? '';\n const suffix = CURRENCY_TOKENS.find((token) => lower.endsWith(token)) ?? '';\n if (prefix !== '' && suffix !== '') return undefined;\n return text.slice(prefix.length, text.length - suffix.length).trim();\n}\n\n/**\n * @internal The grouping characters a reader accepts.\n *\n * @param grouping - The chosen grouping character, or undefined for every Malagasy one.\n * @param decimal - The decimal character, which never counts as grouping.\n * @returns Every Malagasy separator (spaces and dot) when none is chosen; else the chosen one,\n * a space standing for every kind of space.\n */\nexport function readableGrouping(grouping: string | undefined, decimal: string): string[] {\n if (grouping === undefined) return READABLE_SEPARATORS.filter((value) => value !== decimal);\n return isWhitespace(grouping) ? READABLE_SEPARATORS.filter(isWhitespace) : [grouping];\n}\n\n/**\n * Extracts the digits of an amount such as `Ar 1 500`, `1.500 Ar`, `MGA 1500` or `1 500,50`.\n *\n * @param text - An amount as typed by a user.\n * @param separators - The grouping and decimal characters to accept.\n * @returns The digits with a `.` before any decimals (`'1500'`, `'1500.50'`), or `undefined`\n * when the text is not an amount.\n *\n * @example\n * ```ts\n * readDigits('1 500,50', { grouping: [' ', '.'], decimal: ',' }); // '1500.50'\n * ```\n */\nexport function readDigits(text: string, separators: ReadSeparators): string | undefined {\n const amount = stripCurrency(text.trim());\n if (amount === undefined) return undefined;\n return readerFor(separators)(amount);\n}\n","import { MAX_AMOUNT } from './amount.ts';\nimport { MdgError, type ErrorCode, type SafeParseResult } from './generated/errors.ts';\nimport { readableGrouping, readDigits, type ReadSeparators } from './read-digits.ts';\nimport {\n assertOptionsObject,\n decimalFor,\n groupingFor,\n type AriarySeparatorOptions,\n} from './separators.ts';\n\n/**\n * Options for reading amounts: which `grouping` and `decimal` separators the text uses.\n * Without `grouping`, every Malagasy one is accepted (spaces or dot); `decimal` defaults to a\n * comma. Say so for text in another convention: `{ grouping: 'comma', decimal: 'dot' }`.\n *\n * @example\n * ```ts\n * const english: AriaryParseOptions = { grouping: 'comma', decimal: 'dot' };\n * ```\n */\nexport type AriaryParseOptions = AriarySeparatorOptions;\n\nconst PARSE_OPTION_KEYS: ReadonlySet<string> = new Set(['grouping', 'decimal']);\n\n// Bounded so a parser that reads user input never scans unbounded text.\nconst MAX_INPUT_LENGTH = 32;\n\nfunction failure(code: ErrorCode, message: string): SafeParseResult<never> {\n return { success: false, error: new MdgError(code, message) };\n}\n\n// The parsers never throw for bad options either: the error comes back as a value.\nfunction safeReadSeparators(options: unknown): ReadSeparators | MdgError {\n try {\n return readSeparatorsFor(options);\n } catch (error) {\n return error as MdgError;\n }\n}\n\nfunction readSeparatorsFor(options: unknown): ReadSeparators {\n assertOptionsObject(options);\n if (Object.keys(options).some((key) => !PARSE_OPTION_KEYS.has(key))) {\n throw new MdgError('INVALID_TYPE', 'Reading takes only the grouping and decimal options.');\n }\n const separators = options as AriaryParseOptions;\n const decimal = decimalFor(separators);\n const grouping =\n separators.grouping === undefined ? undefined : groupingFor(separators.grouping, decimal);\n return { grouping: readableGrouping(grouping, decimal), decimal };\n}\n\n/**\n * Reads an Ariary amount without throwing.\n *\n * @param text - An amount such as `Ar 1 500`, `1.500 Ar`, `MGA 1500` or `1 500,50`.\n * @param options - Optional `grouping` and `decimal`; see {@link AriaryParseOptions}.\n * @returns `{ success: true, data }` with the amount, or `{ success: false, error }`.\n *\n * @example\n * ```ts\n * const result = safeParseAriary('1 500 Ar');\n * if (result.success) result.data; // 1500\n * ```\n */\nexport function safeParseAriary(\n text: unknown,\n options: AriaryParseOptions = {},\n): SafeParseResult<number> {\n if (typeof text !== 'string') return failure('INVALID_TYPE', 'Expected the amount as text.');\n const separators = safeReadSeparators(options);\n if (separators instanceof MdgError) return { success: false, error: separators };\n if (text.length > MAX_INPUT_LENGTH) {\n return failure('INVALID_FORMAT', `Amounts are at most ${String(MAX_INPUT_LENGTH)} characters.`);\n }\n const digits = readDigits(text, separators);\n if (digits === undefined) {\n return failure('INVALID_FORMAT', 'Expected an amount such as Ar 1 500 or Ar 1 500,50.');\n }\n const amount = Number(digits);\n if (amount > MAX_AMOUNT) {\n return failure('OUT_OF_RANGE', `Amounts go up to ${String(MAX_AMOUNT)}.`);\n }\n return { success: true, data: amount };\n}\n\n/**\n * Reads an Ariary amount written in any common way.\n *\n * @param text - An amount such as `Ar 1 500`, `1.500 Ar`, `MGA 1500` or `1 500,50`.\n * @param options - Optional `grouping` and `decimal`; see {@link AriaryParseOptions}.\n * @returns The amount, whole or decimal.\n * @throws {@link MdgError} `INVALID_TYPE` for non-strings or bad options, `INVALID_FORMAT` for text\n * that is not an amount (signs, a dot as decimal point by default), `OUT_OF_RANGE` above\n * `Number.MAX_SAFE_INTEGER`.\n *\n * @example\n * ```ts\n * parseAriary('Ar 1 500'); // 1500\n * parseAriary('1.500 Ar'); // 1500\n * parseAriary('1 500,50 Ar'); // 1500.5\n * parseAriary('1,500.50', { grouping: 'comma', decimal: 'dot' }); // 1500.5\n * ```\n */\nexport function parseAriary(text: string, options: AriaryParseOptions = {}): number {\n const result = safeParseAriary(text, options);\n if (!result.success) throw result.error;\n return result.data;\n}\n\n/**\n * Reads an Ariary amount, or gives `undefined` instead of throwing.\n *\n * Use {@link safeParseAriary} when you need to know why the text was rejected.\n *\n * @param text - An amount such as `Ar 1 500`, `1.500 Ar`, `MGA 1500` or `1 500,50`.\n * @param options - Optional `grouping` and `decimal`; see {@link AriaryParseOptions}.\n * @returns The amount, or `undefined` when {@link parseAriary} would throw.\n *\n * @example\n * ```ts\n * tryParseAriary('1.500 Ar'); // 1500\n * tryParseAriary('1.5'); // undefined\n * ```\n */\nexport function tryParseAriary(\n text: unknown,\n options: AriaryParseOptions = {},\n): number | undefined {\n const result = safeParseAriary(text, options);\n return result.success ? result.data : undefined;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mdgascar/ariary",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Malagasy Ariary amounts: format (Ar 1 500), parse, words and franc (FMG) conversion.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Mdgascar contributors",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"provenance": true
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@mdgascar/words": "^0.
|
|
52
|
+
"@mdgascar/words": "^0.8.0"
|
|
53
53
|
},
|
|
54
54
|
"scripts": {
|
|
55
55
|
"build": "tsup",
|