@mdgascar/words 0.11.0 → 0.12.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 +7 -1
- package/dist/index.cjs +13 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -5
- package/dist/index.d.ts +3 -5
- package/dist/index.js +13 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Malagasy number words: write numbers in words, ordinals, and read words back into numbers.
|
|
4
4
|
Zero dependencies, ESM + CommonJS + types.
|
|
5
5
|
|
|
6
|
-
Implements spec 0.
|
|
6
|
+
Implements spec 0.11.0.
|
|
7
7
|
|
|
8
8
|
```sh
|
|
9
9
|
npm install @mdgascar/words
|
|
@@ -46,6 +46,12 @@ spell(30_000_000); // 'telopolo tapitrisa'
|
|
|
46
46
|
spell(30_000_000, { system: 'traditional' }); // 'telo safatsiroa'
|
|
47
47
|
```
|
|
48
48
|
|
|
49
|
+
## Requirements
|
|
50
|
+
|
|
51
|
+
Node.js 22.18 or later (tested on 22, 24 and 26), Bun, Deno, or a browser with ES2022 (Chrome
|
|
52
|
+
and Edge 94+, Firefox 93+, Safari 16.4+). ESM and CommonJS. Full list:
|
|
53
|
+
[Supported versions](https://mdgascar.github.io/mdg-utils-docs/docs/supported-versions/).
|
|
54
|
+
|
|
49
55
|
Rules, sources and recorded disagreements: [spec/words](https://github.com/mdgascar/mdg-utils-spec/blob/dev/modules/words/README.md).
|
|
50
56
|
|
|
51
57
|
Docs, API reference and a live playground: [mdgascar.github.io/mdg-utils-docs/docs/words/](https://mdgascar.github.io/mdg-utils-docs/docs/words/).
|
package/dist/index.cjs
CHANGED
|
@@ -75,6 +75,7 @@ var ORDINAL_PREFIX_BEFORE_VOWEL = "fah";
|
|
|
75
75
|
var VOWELS = ["a", "e", "i", "o", "y"];
|
|
76
76
|
var MAX_TEXT_LENGTH = 100;
|
|
77
77
|
var MAX_WORDS_LENGTH = 4096;
|
|
78
|
+
var MAX_READ_DIGITS = 15;
|
|
78
79
|
|
|
79
80
|
// src/cardinal.ts
|
|
80
81
|
var BASE = 10;
|
|
@@ -147,7 +148,7 @@ function countWords(count, system) {
|
|
|
147
148
|
}
|
|
148
149
|
|
|
149
150
|
// src/generated/errors.ts
|
|
150
|
-
var SPEC_VERSION = "0.
|
|
151
|
+
var SPEC_VERSION = "0.11.0";
|
|
151
152
|
var MdgError = class extends Error {
|
|
152
153
|
/** Always `'MdgError'`. */
|
|
153
154
|
name = "MdgError";
|
|
@@ -348,7 +349,7 @@ var CountReader = class {
|
|
|
348
349
|
(count) => SYSTEMS.some((system) => countWords(count, system) === text)
|
|
349
350
|
);
|
|
350
351
|
}
|
|
351
|
-
|
|
352
|
+
/** Every value of tokens[start, end): a phrase, or parts joined by amby ending in a group. */
|
|
352
353
|
values(start, end) {
|
|
353
354
|
const key = `${String(start)}:${String(end)}`;
|
|
354
355
|
const known = this.spans.get(key);
|
|
@@ -358,7 +359,7 @@ var CountReader = class {
|
|
|
358
359
|
this.spans.set(key, found);
|
|
359
360
|
return found;
|
|
360
361
|
}
|
|
361
|
-
|
|
362
|
+
/** "dimy arivo amby roa alina": whatever comes before an amby, plus a count of the last group. */
|
|
362
363
|
grouped(start, end) {
|
|
363
364
|
const group = GROUP_WORDS.get(String(this.tokens[end - 1]));
|
|
364
365
|
if (group === void 0) return [];
|
|
@@ -446,14 +447,20 @@ function spelledReadings(words) {
|
|
|
446
447
|
return SYSTEMS.some((system) => partsWords(whole, decimal, system) === words);
|
|
447
448
|
});
|
|
448
449
|
}
|
|
450
|
+
function isReadable(text) {
|
|
451
|
+
return text.split(".").every((part) => part.length <= MAX_READ_DIGITS);
|
|
452
|
+
}
|
|
449
453
|
function readExact(words) {
|
|
450
454
|
const readings = spelledReadings(words);
|
|
451
|
-
const [only
|
|
455
|
+
const [only] = readings;
|
|
452
456
|
if (only === void 0) {
|
|
453
457
|
return failure("INVALID_FORMAT", "Expected Malagasy number words, as spell writes them.");
|
|
454
458
|
}
|
|
455
|
-
if (
|
|
456
|
-
return failure(
|
|
459
|
+
if (!readings.every(isReadable)) {
|
|
460
|
+
return failure(
|
|
461
|
+
"OUT_OF_RANGE",
|
|
462
|
+
`parseWords reads up to ${String(MAX_READ_DIGITS)} digits before and after faingo.`
|
|
463
|
+
);
|
|
457
464
|
}
|
|
458
465
|
return { success: true, data: only };
|
|
459
466
|
}
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/generated/data.ts","../src/cardinal.ts","../src/generated/errors.ts","../src/decimal-text.ts","../src/system.ts","../src/spell.ts","../src/ordinal.ts","../src/read-words.ts","../src/parse.ts"],"names":["LEADING_ZEROS","ONE","BASE","HUNDRED","TRAILING_ZEROS"],"mappings":";;;AAKO,IAAM,SAAA,GAAY,OAAA;AAGlB,IAAM,UAAA,GAAa;AAAA,EACxB,EAAA;AAAA,EACA,MAAA;AAAA,EACA,KAAA;AAAA,EACA,MAAA;AAAA,EACA,QAAA;AAAA,EACA,MAAA;AAAA,EACA,OAAA;AAAA,EACA,MAAA;AAAA,EACA,MAAA;AAAA,EACA;AACF,CAAA;AAGO,IAAM,oBAAA,GAAuB,QAAA;AAG7B,IAAM,SAAA,GAAY;AAAA,EACvB,EAAA;AAAA,EACA,MAAA;AAAA,EACA,SAAA;AAAA,EACA,UAAA;AAAA,EACA,SAAA;AAAA,EACA,WAAA;AAAA,EACA,UAAA;AAAA,EACA,UAAA;AAAA,EACA,UAAA;AAAA,EACA;AACF,CAAA;AAGO,IAAM,aAAA,GAAgB;AAAA,EAC3B,EAAA;AAAA,EACA,MAAA;AAAA,EACA,UAAA;AAAA,EACA,WAAA;AAAA,EACA,SAAA;AAAA,EACA,WAAA;AAAA,EACA,UAAA;AAAA,EACA,WAAA;AAAA,EACA,WAAA;AAAA,EACA;AACF,CAAA;AAGO,IAAM,MAAA,GAAS;AAAA,EACp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AChB;AACnB,EAAA,MAAM,MAAA,GAAS,cAAA,CAAe,IAAA,EAAM,OAAO,CAAA;AAC3C,EAAA,IAAI,CAAC,MAAA,CAAO,OAAA,EAAS,MAAM,MAAA,CAAO,KAAA;AAClC,EAAA,OAAO,MAAA,CAAO,IAAA;AAChB;AAeO,SAAS,aAAA,CACd,IAAA,EACA,OAAA,GAA6B,EAAC,EACD;AAC7B,EAAA,MAAM,MAAA,GAAS,cAAA,CAAe,IAAA,EAAM,OAAO,CAAA;AAC3C,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/words/data.yaml, spec 0.10.0.\n\n/** @internal */\nexport const ZERO_WORD = 'aotra' as const;\n\n/** @internal Index = digit; index 0 is unused. */\nexport const UNIT_WORDS = [\n '',\n 'iray',\n 'roa',\n 'telo',\n 'efatra',\n 'dimy',\n 'enina',\n 'fito',\n 'valo',\n 'sivy',\n] as const;\n\n/** @internal */\nexport const UNIT_ONE_IN_COMPOUND = 'iraika' as const;\n\n/** @internal Index = tens digit. */\nexport const TEN_WORDS = [\n '',\n 'folo',\n 'roapolo',\n 'telopolo',\n 'efapolo',\n 'dimampolo',\n 'enimpolo',\n 'fitopolo',\n 'valopolo',\n 'sivifolo',\n] as const;\n\n/** @internal Index = hundreds digit. */\nexport const HUNDRED_WORDS = [\n '',\n 'zato',\n 'roanjato',\n 'telonjato',\n 'efajato',\n 'dimanjato',\n 'eninjato',\n 'fitonjato',\n 'valonjato',\n 'sivinjato',\n] as const;\n\n/** @internal Ascending; countDigits null = no limit. */\nexport const SCALES = [\n { word: 'arivo', exponent: 3, countDigits: 1 },\n { word: 'alina', exponent: 4, countDigits: 1 },\n { word: 'hetsy', exponent: 5, countDigits: 1 },\n { word: 'tapitrisa', exponent: 6, countDigits: 3 },\n { word: 'lavitrisa', exponent: 9, countDigits: null },\n] as const;\n\n/** @internal Rule 12: one name per power of ten, ascending, each taking one digit. */\nexport const TRADITIONAL_SCALES = [\n { word: 'arivo', exponent: 3, countDigits: 1 },\n { word: 'alina', exponent: 4, countDigits: 1 },\n { word: 'hetsy', exponent: 5, countDigits: 1 },\n { word: 'tapitrisa', exponent: 6, countDigits: 1 },\n { word: 'safatsiroa', exponent: 7, countDigits: 1 },\n { word: 'tsitamboisa', exponent: 8, countDigits: 1 },\n { word: 'lavitrisa', exponent: 9, countDigits: 1 },\n { word: 'alinkisa', exponent: 10, countDigits: 1 },\n { word: 'tsipesimpesenina', exponent: 11, countDigits: 1 },\n { word: 'tsitokotsiforohana', exponent: 12, countDigits: 1 },\n { word: 'tsihitanoanoa', exponent: 13, countDigits: 1 },\n { word: 'safatsiroafaharoa', exponent: 14, countDigits: 1 },\n { word: 'tsitamboisafaharoa', exponent: 15, countDigits: 1 },\n { word: 'lavitrisafaharoa', exponent: 16, countDigits: 1 },\n { word: 'alinkisafaharoa', exponent: 17, countDigits: 1 },\n { word: 'tsipesimpeseninafaharoa', exponent: 18, countDigits: 1 },\n] as const;\n\n/** @internal */\nexport const DECIMAL_SEPARATOR = 'faingo' as const;\n\n/** @internal */\nexport const JOINER_UNITS_BEFORE_TEN = \"ambin'ny\" as const;\n\n/** @internal */\nexport const JOINER_BELOW_THOUSAND = 'amby' as const;\n\n/** @internal */\nexport const JOINER_BETWEEN_GROUPS = 'sy' as const;\n\n/** @internal */\nexport const MIN_VALUE = 0 as const;\n\n/** @internal Rule 14: the ordinal of 1. */\nexport const ORDINAL_FIRST = 'voalohany' as const;\n\n/** @internal */\nexport const ORDINAL_PREFIX = 'faha' as const;\n\n/** @internal */\nexport const ORDINAL_PREFIX_BEFORE_VOWEL = 'fah' as const;\n\n/** @internal Letters that take the short ordinal prefix. */\nexport const VOWELS = ['a', 'e', 'i', 'o', 'y'] as const;\n\n/** @internal Longest decimal text read (rule 13). */\nexport const MAX_TEXT_LENGTH = 100 as const;\n\n/** @internal Longest words text read by parseWords. */\nexport const MAX_WORDS_LENGTH = 4096 as const;\n","// Whole numbers in words, from their decimal digits, so counts of any length stay exact.\nimport {\n HUNDRED_WORDS,\n JOINER_BELOW_THOUSAND,\n JOINER_BETWEEN_GROUPS,\n JOINER_UNITS_BEFORE_TEN,\n SCALES,\n TEN_WORDS,\n TRADITIONAL_SCALES,\n UNIT_ONE_IN_COMPOUND,\n UNIT_WORDS,\n ZERO_WORD,\n} from './generated/data.ts';\nimport type { NumberSystem } from './system.ts';\n\ntype Digit = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;\ntype Scale = (typeof SCALES)[number] | (typeof TRADITIONAL_SCALES)[number];\ntype ScaleTable = readonly Scale[];\n// A whole number joins its groups with \"sy\" (rule 8); a count before a group word is one\n// phrase, every part joined by \"amby\" (rule 6).\ntype Role = 'number' | 'count';\n\nconst BASE = 10;\nconst HUNDRED = BASE * BASE;\nconst BELOW_THOUSAND_DIGITS = 3;\n// Rule 7: a count of one is bare only for arivo.\nconst BARE_ONE_EXPONENT = SCALES[0].exponent;\nconst LEADING_ZEROS = /^0+/;\nconst ONE = '1';\nconst JOINERS: Readonly<Record<Role, string>> = {\n number: JOINER_BETWEEN_GROUPS,\n count: JOINER_BELOW_THOUSAND,\n};\n\nfunction digitAt(value: number, place: number): Digit {\n return (Math.floor(value / place) % BASE) as Digit;\n}\n\nfunction isNotEmpty(word: string): boolean {\n return word !== '';\n}\n\n// 11–19 join with \"ambin'ny\", other units onto tens with \"amby\".\nfunction belowHundredWords(unitWord: string, units: Digit, tens: Digit): string {\n if (tens === 1 && units > 0) return `${unitWord} ${JOINER_UNITS_BEFORE_TEN} ${TEN_WORDS[1]}`;\n return [unitWord, TEN_WORDS[tens]].filter(isNotEmpty).join(` ${JOINER_BELOW_THOUSAND} `);\n}\n\n// The part below 1000, and the joiner that follows it ('' when nothing does).\ninterface Lowest {\n readonly value: number;\n readonly role: Role;\n readonly nextJoiner: string;\n}\n\n// Rule 4: the part below 100 joins exactly 100 with \"amby\" and 200–900 with \"sy\"; inside a\n// count every join is \"amby\". \"iraika\" replaces \"iray\" right before \"amby\" or \"ambin'ny\".\nfunction belowThousandWords({ value, role, nextJoiner }: Lowest): string {\n const units = digitAt(value, 1);\n const tens = digitAt(value, BASE);\n const hundreds = digitAt(value, HUNDRED);\n const joiner = role === 'count' || hundreds === 1 ? JOINER_BELOW_THOUSAND : JOINER_BETWEEN_GROUPS;\n const afterUnits = tens > 0 || hundreds > 0 ? joiner : nextJoiner;\n const isOneBeforeAmby = units === 1 && (tens > 0 || afterUnits === JOINER_BELOW_THOUSAND);\n const unitWord = isOneBeforeAmby ? UNIT_ONE_IN_COMPOUND : UNIT_WORDS[units];\n const belowHundred = belowHundredWords(unitWord, units, tens);\n return [belowHundred, HUNDRED_WORDS[hundreds]].filter(isNotEmpty).join(` ${joiner} `);\n}\n\n// How many digits the traditional names reach: up to the largest name's single digit.\nconst TRADITIONAL_REACH = TRADITIONAL_SCALES.reduce(\n (most, scale) => Math.max(most, scale.exponent + scale.countDigits),\n 0,\n);\n\n// Rule 12: a number longer than the traditional names reach is read with the standard scales.\nfunction scalesFor(digits: string, system: NumberSystem): ScaleTable {\n return system === 'traditional' && digits.length <= TRADITIONAL_REACH\n ? TRADITIONAL_SCALES\n : SCALES;\n}\n\n// The digits a group counts, without leading zeros: '' when the group is absent.\nfunction scaleCount(digits: string, scale: Scale): string {\n const end = digits.length - scale.exponent;\n if (end <= 0) return '';\n const start = scale.countDigits === null ? 0 : Math.max(0, end - scale.countDigits);\n return digits.slice(start, end).replace(LEADING_ZEROS, '');\n}\n\nfunction scaleWords(digits: string, scale: Scale, scales: ScaleTable): string {\n const count = scaleCount(digits, scale);\n if (count === '') return '';\n if (count === ONE && scale.exponent === BARE_ONE_EXPONENT) return scale.word;\n return `${numberWords(count, scales, 'count')} ${scale.word}`;\n}\n\nfunction numberWords(significant: string, scales: ScaleTable, role: Role): string {\n const upper = scales.map((scale) => scaleWords(significant, scale, scales)).filter(isNotEmpty);\n const joiner = JOINERS[role];\n const lowest = belowThousandWords({\n value: Number(significant.slice(-BELOW_THOUSAND_DIGITS)),\n role,\n nextJoiner: upper.length > 0 ? joiner : '',\n });\n return [lowest, ...upper].filter(isNotEmpty).join(` ${joiner} `);\n}\n\n/**\n * @internal A whole number in words, groups joined by \"sy\", smallest first.\n *\n * @param digits - Decimal digits; leading zeros are ignored.\n * @param system - `standard` or `traditional` (rule 12).\n * @returns The words: `'2586'` → `'enina amby valopolo sy dimanjato sy roa arivo'`.\n */\nexport function wholeWords(digits: string, system: NumberSystem): string {\n const significant = digits.replace(LEADING_ZEROS, '');\n if (significant === '') return ZERO_WORD;\n return numberWords(significant, scalesFor(significant, system), 'number');\n}\n\n/**\n * @internal A count as {@link wholeWords} writes it before a group word.\n *\n * @param count - The count, from 1, as a bigint.\n * @param system - Whether the group word is a standard or a traditional name.\n * @returns The count's words: `25000n` → `'dimy arivo amby roa alina'`.\n */\nexport function countWords(count: bigint, system: NumberSystem): string {\n const scales = system === 'traditional' ? TRADITIONAL_SCALES : SCALES;\n return numberWords(count.toString(), scales, 'count');\n}\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.10.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 an operator.\n * - `PRECISION_LOSS`: The value is exact in the text but the port's number type cannot hold it exactly; ask for the exact text instead.\n * - `AMBIGUOUS`: The text reads as more than one value, so none is chosen.\n */\nexport type ErrorCode =\n | 'INVALID_TYPE'\n | 'OUT_OF_RANGE'\n | 'INVALID_FORMAT'\n | 'UNKNOWN_OPERATOR'\n | 'PRECISION_LOSS'\n | 'AMBIGUOUS';\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 = safeParsePhone(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 * spell(-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","// Numbers and decimal text, turned into their exact decimal digits.\nimport { MAX_TEXT_LENGTH, MIN_VALUE } from './generated/data.ts';\nimport { MdgError } from './generated/errors.ts';\n\n/** @internal The whole digits, and the decimals or `undefined` for a whole number. */\nexport type DecimalParts = readonly [string, string | undefined];\n\nconst TRAILING_ZEROS = /0+$/;\n// Rule 13: ASCII digits, then optionally a point and more digits. Nothing else.\nconst DECIMAL_TEXT = /^([0-9]+)(?:\\.([0-9]+))?$/;\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.${'0'.repeat(Number(exponent) - 1)}${lead}${rest}`;\n}\n\n/**\n * @internal Rule 13: the parts of plain decimal text, trailing decimal zeros dropped.\n *\n * @param text - Text the caller passed.\n * @param caller - Function name for the error message.\n * @returns The whole digits and the decimals.\n */\nexport function decimalTextParts(text: string, caller: string): DecimalParts {\n const match = text.length <= MAX_TEXT_LENGTH ? DECIMAL_TEXT.exec(text) : null;\n if (match === null) {\n throw new MdgError(\n 'INVALID_FORMAT',\n `${caller} reads digits with an optional .decimals, at most ${String(MAX_TEXT_LENGTH)} characters.`,\n );\n }\n const [, whole = '', decimals = ''] = match;\n const significantDecimals = decimals.replace(TRAILING_ZEROS, '');\n return [whole, significantDecimals === '' ? undefined : significantDecimals];\n}\n\n/**\n * @internal Checks a number is finite and between 0 and `Number.MAX_SAFE_INTEGER`.\n *\n * @param value - The value the caller passed.\n * @param caller - Function name for the error message.\n */\nexport function assertSupportedNumber(value: unknown, caller: string): asserts value is number {\n if (typeof value !== 'number' || !Number.isFinite(value)) {\n throw new MdgError('INVALID_TYPE', `${caller} expects a finite number or decimal text.`);\n }\n if (value < MIN_VALUE || value > Number.MAX_SAFE_INTEGER) {\n throw new MdgError(\n 'OUT_OF_RANGE',\n `${caller} supports ${String(MIN_VALUE)} to ${String(Number.MAX_SAFE_INTEGER)}.`,\n );\n }\n}\n\n/**\n * @internal The exact decimal parts of a number or of decimal text.\n *\n * @param value - A number from 0 to `Number.MAX_SAFE_INTEGER`, or plain decimal text.\n * @param caller - Function name for error messages.\n * @returns The whole digits and the decimals.\n */\nexport function decimalParts(value: unknown, caller: string): DecimalParts {\n if (typeof value === 'string') return decimalTextParts(value, caller);\n assertSupportedNumber(value, caller);\n const [whole = '', decimals] = plainDecimal(value).split('.');\n return [whole, decimals];\n}\n","import { MdgError } from './generated/errors.ts';\n\n/**\n * How large numbers are named: `standard` (default; `telopolo tapitrisa` for 30 000 000) or\n * `traditional`, with one name per power of ten (`telo safatsiroa`).\n *\n * @example\n * ```ts\n * const system: NumberSystem = 'traditional';\n * ```\n */\nexport type NumberSystem = 'standard' | 'traditional';\n\n/**\n * Options for {@link spell} and {@link spellOrdinal}.\n *\n * @example\n * ```ts\n * const options: SpellOptions = { system: 'traditional' };\n * ```\n */\nexport interface SpellOptions {\n /** `standard` (default) or `traditional`. */\n readonly system?: NumberSystem;\n}\n\n/** @internal Both systems, standard first. */\nexport const SYSTEMS: readonly NumberSystem[] = ['standard', 'traditional'];\nconst DEFAULT_SYSTEM: NumberSystem = 'standard';\n\n/**\n * @internal The system the options ask for, after checking them.\n *\n * @param options - The options the caller passed.\n * @returns `standard` or `traditional`.\n */\nexport function systemOf(options: unknown): NumberSystem {\n if (typeof options !== 'object' || options === null) {\n throw new MdgError('INVALID_TYPE', 'spell options must be an object.');\n }\n const { system = DEFAULT_SYSTEM } = options as SpellOptions;\n if (!SYSTEMS.includes(system)) {\n throw new MdgError('INVALID_TYPE', 'system is standard or traditional.');\n }\n return system;\n}\n","import { wholeWords } from './cardinal.ts';\nimport { decimalParts } from './decimal-text.ts';\nimport { DECIMAL_SEPARATOR, ZERO_WORD } from './generated/data.ts';\nimport { systemOf, type NumberSystem, type SpellOptions } from './system.ts';\n\nconst LEADING_ZEROS = /^0+/;\n\n// Each leading zero after the point is \"aotra\"; the rest reads as a whole number.\nfunction decimalWords(digits: string, system: NumberSystem): string {\n const significant = digits.replace(LEADING_ZEROS, '');\n const zeros = Array.from({ length: digits.length - significant.length }, () => ZERO_WORD);\n return [...zeros, wholeWords(significant, system)].join(' ');\n}\n\n/**\n * @internal Words for exact decimal parts, as {@link spell} writes them.\n *\n * @param whole - The whole digits.\n * @param decimals - The decimals without trailing zeros, or `undefined`.\n * @param system - `standard` or `traditional`.\n * @returns The words.\n */\nexport function partsWords(\n whole: string,\n decimals: string | undefined,\n system: NumberSystem,\n): string {\n const wholePart = wholeWords(whole, system);\n if (decimals === undefined) return wholePart;\n return `${wholePart} ${DECIMAL_SEPARATOR} ${decimalWords(decimals, system)}`;\n}\n\n/**\n * Writes a number in Malagasy words, smallest part first, with `faingo` before the decimals.\n * {@link parseWords} reads the words back.\n *\n * @param value - A number from 0 to `Number.MAX_SAFE_INTEGER`, whole or decimal, or plain\n * decimal text such as `'2000000000000000.9'`, read exactly (a number that large has already\n * lost its decimals to floating point).\n * @param options - Optional `system`: `standard` (default) or `traditional`, which names every\n * power of ten (`telo safatsiroa` for 30 000 000).\n * @returns The number in Malagasy words.\n * @throws {@link MdgError} `INVALID_TYPE` if `value` is not a finite number or the options are\n * unknown, `INVALID_FORMAT` for text that is not plain decimal (at most 100 characters),\n * `OUT_OF_RANGE` if a number is negative or above `Number.MAX_SAFE_INTEGER`.\n *\n * @example\n * ```ts\n * spell(21); // 'iraika amby roapolo'\n * spell(2026); // 'enina amby roapolo sy roa arivo'\n * spell(3.14); // \"telo faingo efatra ambin'ny folo\"\n * spell(30_000_000, { system: 'traditional' }); // 'telo safatsiroa'\n * spell('2000000000000000.9'); // 'roa tapitrisa lavitrisa faingo sivy'\n * ```\n */\nexport function spell(value: number | string, options: SpellOptions = {}): string {\n const [whole, decimals] = decimalParts(value, 'spell');\n return partsWords(whole, decimals, systemOf(options));\n}\n","import { wholeWords } from './cardinal.ts';\nimport { decimalParts } from './decimal-text.ts';\nimport {\n ORDINAL_FIRST,\n ORDINAL_PREFIX,\n ORDINAL_PREFIX_BEFORE_VOWEL,\n VOWELS,\n} from './generated/data.ts';\nimport { MdgError } from './generated/errors.ts';\nimport { systemOf, type SpellOptions } from './system.ts';\n\nconst STARTS_WITH_VOWEL: ReadonlySet<string> = new Set(VOWELS);\nconst LEADING_ZEROS = /^0+/;\nconst ONE = '1';\nconst POINT = '.';\n\n// Rule 14: whole digits from 1 up; a point in text or decimals in a number are not ordinals.\nfunction ordinalDigits(value: unknown): string {\n if (typeof value === 'string' && value.includes(POINT)) {\n throw new MdgError('INVALID_FORMAT', 'spellOrdinal reads whole digits, with no point.');\n }\n const [whole, decimals] = decimalParts(value, 'spellOrdinal');\n if (decimals !== undefined) {\n throw new MdgError('INVALID_TYPE', 'spellOrdinal expects a whole number.');\n }\n const significant = whole.replace(LEADING_ZEROS, '');\n if (significant === '') {\n throw new MdgError('OUT_OF_RANGE', 'Ordinals start at 1 (voalohany).');\n }\n return significant;\n}\n\n/**\n * Writes the Malagasy ordinal of a whole number: `faha` before the cardinal words, `fah`\n * before a vowel, and `voalohany` for 1.\n *\n * @param value - A whole number from 1 to `Number.MAX_SAFE_INTEGER`, or digit text such as\n * `'1000000000000000000'`, read exactly.\n * @param options - Optional `system`: `standard` (default) or `traditional`.\n * @returns The ordinal: `3` → `'fahatelo'`.\n * @throws {@link MdgError} `INVALID_TYPE` for a number with decimals, a value that is not a\n * number or text, or unknown options; `INVALID_FORMAT` for text that is not digits;\n * `OUT_OF_RANGE` below 1 or above `Number.MAX_SAFE_INTEGER`.\n *\n * @example\n * ```ts\n * spellOrdinal(1); // 'voalohany'\n * spellOrdinal(3); // 'fahatelo'\n * spellOrdinal(4); // 'fahefatra'\n * spellOrdinal(11); // \"fahiraika ambin'ny folo\"\n * spellOrdinal(1000); // 'faharivo'\n * ```\n */\nexport function spellOrdinal(value: number | string, options: SpellOptions = {}): string {\n const digits = ordinalDigits(value);\n const cardinal = wholeWords(digits, systemOf(options));\n if (digits === ONE) return ORDINAL_FIRST;\n const prefix = STARTS_WITH_VOWEL.has(cardinal.charAt(0))\n ? ORDINAL_PREFIX_BEFORE_VOWEL\n : ORDINAL_PREFIX;\n return `${prefix}${cardinal}`;\n}\n","// Malagasy number words → every exact value they can stand for. parse.ts keeps the values that\n// spell back to the same words; more than one left means the words are ambiguous.\nimport { countWords } from './cardinal.ts';\nimport { SYSTEMS } from './system.ts';\nimport {\n DECIMAL_SEPARATOR,\n HUNDRED_WORDS,\n JOINER_BELOW_THOUSAND,\n JOINER_BETWEEN_GROUPS,\n JOINER_UNITS_BEFORE_TEN,\n SCALES,\n TEN_WORDS,\n TRADITIONAL_SCALES,\n UNIT_ONE_IN_COMPOUND,\n UNIT_WORDS,\n ZERO_WORD,\n} from './generated/data.ts';\n\n/** @internal Readings of words: whole parts, and decimal digits (`undefined` if none). */\nexport interface Readings {\n readonly wholes: readonly bigint[];\n readonly decimals: readonly string[] | undefined;\n}\n\nconst BASE = 10;\n// A phrase alternates a word and a joiner: word, joiner, word, ….\nconst TOKENS_PER_STEP = 2;\nconst TEN = BigInt(BASE);\nconst HUNDRED = BASE * BASE;\n// Readings kept per part: real words have one or two; more only in made-up text.\nconst MAX_READINGS = 8;\nconst PHRASE_JOINERS: ReadonlySet<string> = new Set([\n JOINER_BELOW_THOUSAND,\n JOINER_UNITS_BEFORE_TEN,\n]);\n\nfunction wordValues(words: readonly string[], step: number): [string, number][] {\n return words.flatMap((word, digit) => (word === '' ? [] : [[word, digit * step]]));\n}\n\n// Every word a phrase below 1000 is made of, with its value.\nconst PHRASE_VALUES: ReadonlyMap<string, number> = new Map([\n ...wordValues(UNIT_WORDS, 1),\n [UNIT_ONE_IN_COMPOUND, 1],\n ...wordValues(TEN_WORDS, BASE),\n ...wordValues(HUNDRED_WORDS, HUNDRED),\n]);\n\n// The longest phrase below 1000: \"iraika ambin'ny folo amby zato\" style, three words, two joiners.\nconst MAX_PHRASE_TOKENS = 5;\n\ninterface GroupWord {\n readonly factor: bigint;\n readonly hasPhraseCount: boolean;\n // Most words the smaller part before this group can have: the words of factor − 1.\n readonly maxLeftTokens: number;\n}\n\nfunction groupWord(exponent: number, countDigits: number | null): GroupWord {\n const factor = TEN ** BigInt(exponent);\n const maxLeftTokens = countWords(factor - BigInt(1), 'standard').split(' ').length;\n return { factor, hasPhraseCount: countDigits !== null, maxLeftTokens };\n}\n\n// Group words of both systems: their power of ten, and whether their count is a phrase below\n// 1000 (every group but the largest), which bounds where that count can start. Standard comes\n// last so lavitrisa, in both tables, keeps its count of any size.\nconst GROUP_WORDS: ReadonlyMap<string, GroupWord> = new Map(\n [...TRADITIONAL_SCALES, ...SCALES].map((scale) => [\n scale.word,\n groupWord(scale.exponent, scale.countDigits),\n ]),\n);\n\n// \"valo amby efapolo amby telonjato\": words alternate with amby or ambin'ny.\nfunction readPhrase(tokens: readonly string[]): bigint | undefined {\n let total = 0;\n for (const [index, token] of tokens.entries()) {\n const isJoinerPlace = index % TOKENS_PER_STEP === 1;\n if (isJoinerPlace !== PHRASE_JOINERS.has(token)) return undefined;\n if (!isJoinerPlace) total += PHRASE_VALUES.get(token) ?? Number.NaN;\n }\n return tokens.length % TOKENS_PER_STEP === 1 && !Number.isNaN(total) ? BigInt(total) : undefined;\n}\n\nfunction sums(lefts: Iterable<bigint>, rights: Iterable<bigint>, factor: bigint): bigint[] {\n return [...lefts].flatMap((left) => [...rights].map((right) => left + right * factor));\n}\n\n// Smallest part first: what comes before a group is always smaller than one of that group.\nfunction groupSums(lefts: Iterable<bigint>, counts: Iterable<bigint>, factor: bigint): bigint[] {\n return sums(\n [...lefts].filter((left) => left < factor),\n counts,\n factor,\n );\n}\n\nfunction limited(values: Iterable<bigint>): bigint[] {\n return [...new Set(values)].slice(0, MAX_READINGS);\n}\n\n/** Reads the counts in one list of tokens, remembering each span it has read. */\nclass CountReader {\n private readonly spans = new Map<string, bigint[]>();\n private readonly tokens: readonly string[];\n\n constructor(tokens: readonly string[]) {\n this.tokens = tokens;\n }\n\n /**\n * Counts written exactly as spell writes a count before a group word.\n *\n * @param start - First token of the count.\n * @param end - Token after the count.\n * @returns The counts those tokens spell.\n */\n counts(start: number, end: number): bigint[] {\n const text = this.tokens.slice(start, end).join(' ');\n return this.values(start, end).filter((count) =>\n SYSTEMS.some((system) => countWords(count, system) === text),\n );\n }\n\n // Every value of tokens[start, end): a phrase, or parts joined by amby ending in a group.\n private values(start: number, end: number): bigint[] {\n const key = `${String(start)}:${String(end)}`;\n const known = this.spans.get(key);\n if (known !== undefined) return known;\n const phrase = readPhrase(this.tokens.slice(start, end));\n const found = limited([...(phrase === undefined ? [] : [phrase]), ...this.grouped(start, end)]);\n this.spans.set(key, found);\n return found;\n }\n\n // \"dimy arivo amby roa alina\": whatever comes before an amby, plus a count of the last group.\n private grouped(start: number, end: number): bigint[] {\n const group = GROUP_WORDS.get(String(this.tokens[end - 1]));\n if (group === undefined) return [];\n const first = group.hasPhraseCount ? Math.max(start, end - 1 - MAX_PHRASE_TOKENS) : start;\n const last = Math.min(end - 1, start + group.maxLeftTokens + 1);\n const found: bigint[] = [];\n for (let split = first; split <= last; split += 1) {\n if (split > start && this.tokens[split - 1] !== JOINER_BELOW_THOUSAND) continue;\n const lefts = split === start ? [BigInt(0)] : this.values(start, split - 1);\n const counts = split === end - 1 ? [BigInt(1)] : this.counts(split, end - 1);\n found.push(...groupSums(lefts, counts, group.factor));\n }\n return found;\n }\n}\n\nfunction splitOn(tokens: readonly string[], separator: string): string[][] {\n const parts: string[][] = [[]];\n for (const token of tokens) {\n if (token === separator) parts.push([]);\n else parts[parts.length - 1]?.push(token);\n }\n return parts;\n}\n\n// One group of a whole number: a count and a group word (\"roa arivo\"), or a phrase.\nfunction groupValues(tokens: readonly string[]): bigint[] {\n const factor = GROUP_WORDS.get(String(tokens[tokens.length - 1]))?.factor;\n if (factor === undefined) {\n const phrase = readPhrase(tokens);\n return phrase === undefined ? [] : [phrase];\n }\n const counts =\n tokens.length === 1 ? [BigInt(1)] : new CountReader(tokens).counts(0, tokens.length - 1);\n return counts.map((count) => count * factor);\n}\n\n// A whole number: groups joined by \"sy\", or \"aotra\".\nfunction wholeValues(tokens: readonly string[]): bigint[] {\n if (tokens.length === 1 && tokens[0] === ZERO_WORD) return [BigInt(0)];\n return splitOn(tokens, JOINER_BETWEEN_GROUPS).reduce<bigint[]>(\n (totals, group) => limited(sums(totals, groupValues(group), BigInt(1))),\n [BigInt(0)],\n );\n}\n\n// After \"faingo\": one \"aotra\" per leading zero, then a whole number.\nfunction decimalValues(tokens: readonly string[]): string[] {\n const zeros = tokens.findIndex((token) => token !== ZERO_WORD);\n if (zeros < 0) return [];\n const prefix = '0'.repeat(zeros);\n return wholeValues(tokens.slice(zeros)).map((value) => `${prefix}${value.toString()}`);\n}\n\n/**\n * @internal Every value normalised words can stand for, before checking which ones\n * {@link spell} writes as those words.\n *\n * @param words - Lowercase words separated by single spaces.\n * @returns The candidate whole parts and decimals; empty lists when nothing reads.\n */\nexport function readWords(words: string): Readings {\n const [wholeTokens = [], decimalTokens, ...extra] = splitOn(words.split(' '), DECIMAL_SEPARATOR);\n if (extra.length > 0) return { wholes: [], decimals: undefined };\n return {\n wholes: wholeValues(wholeTokens),\n decimals: decimalTokens === undefined ? undefined : decimalValues(decimalTokens),\n };\n}\n","import { plainDecimal } from './decimal-text.ts';\nimport { MAX_WORDS_LENGTH } from './generated/data.ts';\nimport { MdgError, type ErrorCode, type SafeParseResult } from './generated/errors.ts';\nimport { readWords } from './read-words.ts';\nimport { partsWords } from './spell.ts';\nimport { SYSTEMS } from './system.ts';\n\n/**\n * What {@link parseWords} gives back: a `number` (default), or the exact decimal `text`.\n *\n * @example\n * ```ts\n * const exact: ParseResultKind = 'text';\n * ```\n */\nexport type ParseResultKind = 'number' | 'text';\n\n/**\n * Options for {@link parseWords}.\n *\n * @example\n * ```ts\n * const options: ParseWordsOptions = { as: 'text' };\n * ```\n */\nexport interface ParseWordsOptions {\n /** `number` (default), or `text` for the exact decimal digits of any size. */\n readonly as?: ParseResultKind;\n}\n\n/**\n * The value a reader gives back for a {@link ParseResultKind}: `string` for `text`, otherwise\n * `number`.\n *\n * @example\n * ```ts\n * const digits: ParsedValue<'text'> = '2000';\n * ```\n */\nexport type ParsedValue<Kind extends ParseResultKind> = Kind extends 'text' ? string : number;\n\nconst RESULT_KINDS: ReadonlySet<unknown> = new Set<ParseResultKind>(['number', 'text']);\nconst OPTION_KEYS: ReadonlySet<string> = new Set(['as']);\nconst APOSTROPHES = /[‘’ʼ`´]/g;\nconst SPACES = /\\s+/gu;\n// Older spellings of \"ambin'ny\" (dictionary: \"ambin' ny\"; Assimil: \"amby ny\").\nconst SPLIT_AMBINNY = /\\bambin' ny\\b|\\bamby ny\\b/g;\nconst AMBINNY = \"ambin'ny\";\nconst TRAILING_ZEROS = /0+$/;\n\nfunction failure(code: ErrorCode, message: string): SafeParseResult<never> {\n return { success: false, error: new MdgError(code, message) };\n}\n\nfunction resultKind(options: unknown): ParseResultKind | undefined {\n if (typeof options !== 'object' || options === null) return undefined;\n if (Object.keys(options).some((key) => !OPTION_KEYS.has(key))) return undefined;\n const { as = 'number' } = options as ParseWordsOptions;\n return RESULT_KINDS.has(as) ? as : undefined;\n}\n\n// Case, apostrophes, spacing and older spellings do not change the number.\nfunction normalise(text: string): string {\n return text\n .toLowerCase()\n .replace(APOSTROPHES, \"'\")\n .replace(SPACES, ' ')\n .trim()\n .replace(SPLIT_AMBINNY, AMBINNY);\n}\n\n// Every exact value whose spelling is these words: one, none, or (rarely) more.\nfunction spelledReadings(words: string): string[] {\n const { wholes, decimals } = readWords(words);\n const texts = wholes.flatMap((whole) =>\n (decimals ?? ['']).map((digits) => {\n const significant = digits.replace(TRAILING_ZEROS, '');\n return significant === '' ? whole.toString() : `${whole.toString()}.${significant}`;\n }),\n );\n return [...new Set(texts)].filter((text) => {\n const [whole = '', decimal] = text.split('.');\n return SYSTEMS.some((system) => partsWords(whole, decimal, system) === words);\n });\n}\n\nfunction readExact(words: string): SafeParseResult<string> {\n const readings = spelledReadings(words);\n const [only, ...others] = readings;\n if (only === undefined) {\n return failure('INVALID_FORMAT', 'Expected Malagasy number words, as spell writes them.');\n }\n if (others.length > 0) {\n return failure('AMBIGUOUS', `These words read as ${readings.join(' and as ')}.`);\n }\n return { success: true, data: only };\n}\n\n// A number only when it holds the digits exactly: never a silent rounding.\nfunction asNumber(text: string): SafeParseResult<number> {\n const value = Number(text);\n if (value <= Number.MAX_SAFE_INTEGER && plainDecimal(value) === text) {\n return { success: true, data: value };\n }\n return failure(\n 'PRECISION_LOSS',\n `${text} does not fit a number exactly; pass { as: 'text' } for the exact digits.`,\n );\n}\n\n/**\n * Reads Malagasy number words without throwing.\n *\n * @param text - Words as {@link spell} writes them, in either system, in any case and spacing.\n * @param options - Optional `as`: `number` (default) or `text` for the exact digits.\n * @returns `{ success: true, data }` with the number or text, or `{ success: false, error }`.\n *\n * @example\n * ```ts\n * const result = safeParseWords('roa arivo');\n * if (result.success) result.data; // 2000\n * ```\n */\nexport function safeParseWords(\n text: unknown,\n options: ParseWordsOptions = {},\n): SafeParseResult<number | string> {\n if (typeof text !== 'string') return failure('INVALID_TYPE', 'Expected the words as text.');\n const kind = resultKind(options);\n if (kind === undefined) return failure('INVALID_TYPE', \"as is 'number' or 'text'.\");\n if (text.length > MAX_WORDS_LENGTH) {\n return failure('INVALID_FORMAT', `Words are at most ${String(MAX_WORDS_LENGTH)} characters.`);\n }\n const exact = readExact(normalise(text));\n if (!exact.success || kind === 'text') return exact;\n return asNumber(exact.data);\n}\n\n/**\n * Reads Malagasy number words back into a number: the exact inverse of {@link spell}.\n *\n * @param text - Words as {@link spell} writes them, in either system. Case, spacing, curly\n * apostrophes and the older `ambin' ny` and `amby ny` do not matter.\n * @param options - Optional `as`: `number` (default) or `text` for the exact decimal digits.\n * @returns The number, or its digits as text with `{ as: 'text' }`.\n * @throws {@link MdgError} `INVALID_TYPE` for non-strings or bad options, `INVALID_FORMAT` for\n * anything spell does not write, `AMBIGUOUS` for the rare words that two numbers share (from\n * one million billion up), `PRECISION_LOSS` when a number cannot hold the value exactly.\n *\n * @example\n * ```ts\n * parseWords('valo amby efapolo amby telonjato'); // 348\n * parseWords(\"telo faingo efatra ambin'ny folo\"); // 3.14\n * parseWords('telo safatsiroa'); // 30000000\n * parseWords('iray lavitrisa lavitrisa', { as: 'text' }); // '1000000000000000000'\n * ```\n */\nexport function parseWords<Kind extends ParseResultKind = 'number'>(\n text: string,\n options: { readonly as?: Kind } = {},\n): ParsedValue<Kind> {\n const result = safeParseWords(text, options);\n if (!result.success) throw result.error;\n return result.data as ParsedValue<Kind>;\n}\n\n/**\n * Reads Malagasy number words, or gives `undefined` instead of throwing.\n *\n * @param text - Words as {@link spell} writes them.\n * @param options - Optional `as`: `number` (default) or `text`.\n * @returns The value, or `undefined` when {@link parseWords} would throw.\n *\n * @example\n * ```ts\n * tryParseWords('roa arivo'); // 2000\n * tryParseWords('roa sy arivo sy'); // undefined\n * ```\n */\nexport function tryParseWords(\n text: unknown,\n options: ParseWordsOptions = {},\n): number | string | undefined {\n const result = safeParseWords(text, options);\n return result.success ? result.data : undefined;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/generated/data.ts","../src/cardinal.ts","../src/generated/errors.ts","../src/decimal-text.ts","../src/system.ts","../src/spell.ts","../src/ordinal.ts","../src/read-words.ts","../src/parse.ts"],"names":["LEADING_ZEROS","ONE","BASE","HUNDRED","TRAILING_ZEROS"],"mappings":";;;AAKO,IAAM,SAAA,GAAY,OAAA;AAGlB,IAAM,UAAA,GAAa;AAAA,EACxB,EAAA;AAAA,EACA,MAAA;AAAA,EACA,KAAA;AAAA,EACA,MAAA;AAAA,EACA,QAAA;AAAA,EACA,MAAA;AAAA,EACA,OAAA;AAAA,EACA,MAAA;AAAA,EACA,MAAA;AAAA,EACA;AACF,CAAA;AAGO,IAAM,oBAAA,GAAuB,QAAA;AAG7B,IAAM,SAAA,GAAY;AAAA,EACvB,EAAA;AAAA,EACA,MAAA;AAAA,EACA,SAAA;AAAA,EACA,UAAA;AAAA,EACA,SAAA;AAAA,EACA,WAAA;AAAA,EACA,UAAA;AAAA,EACA,UAAA;AAAA,EACA,UAAA;AAAA,EACA;AACF,CAAA;AAGO,IAAM,aAAA,GAAgB;AAAA,EAC3B,EAAA;AAAA,EACA,MAAA;AAAA,EACA,UAAA;AAAA,EACA,WAA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EAAqB,MAAA,CAAO,gBAAgB,CAAC,CAAA,YAAA,CAAc,CAAA;AAAA,EAC9F;AACA,EAAA,MAAM,KAAA,GAAQ,SAAA,CAAU,SAAA,CAAU,IAAI,CAAC,CAAA;AACvC,EAAA,IAAI,CAAC,KAAA,CAAM,OAAA,IAAW,IAAA,KAAS,QAAQ,OAAO,KAAA;AAC9C,EAAA,OAAO,QAAA,CAAS,MAAM,IAAI,CAAA;AAC5B;AAoBO,SAAS,UAAA,CACd,IAAA,EACA,OAAA,GAAkC,EAAC,EAChB;AACnB,EAAA,MAAM,MAAA,GAAS,cAAA,CAAe,IAAA,EAAM,OAAO,CAAA;AAC3C,EAAA,IAAI,CAAC,MAAA,CAAO,OAAA,EAAS,MAAM,MAAA,CAAO,KAAA;AAClC,EAAA,OAAO,MAAA,CAAO,IAAA;AAChB;AAeO,SAAS,aAAA,CACd,IAAA,EACA,OAAA,GAA6B,EAAC,EACD;AAC7B,EAAA,MAAM,MAAA,GAAS,cAAA,CAAe,IAAA,EAAM,OAAO,CAAA;AAC3C,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/words/data.yaml, spec 0.11.0.\n\n/** @internal */\nexport const ZERO_WORD = 'aotra' as const;\n\n/** @internal Index = digit; index 0 is unused. */\nexport const UNIT_WORDS = [\n '',\n 'iray',\n 'roa',\n 'telo',\n 'efatra',\n 'dimy',\n 'enina',\n 'fito',\n 'valo',\n 'sivy',\n] as const;\n\n/** @internal */\nexport const UNIT_ONE_IN_COMPOUND = 'iraika' as const;\n\n/** @internal Index = tens digit. */\nexport const TEN_WORDS = [\n '',\n 'folo',\n 'roapolo',\n 'telopolo',\n 'efapolo',\n 'dimampolo',\n 'enimpolo',\n 'fitopolo',\n 'valopolo',\n 'sivifolo',\n] as const;\n\n/** @internal Index = hundreds digit. */\nexport const HUNDRED_WORDS = [\n '',\n 'zato',\n 'roanjato',\n 'telonjato',\n 'efajato',\n 'dimanjato',\n 'eninjato',\n 'fitonjato',\n 'valonjato',\n 'sivinjato',\n] as const;\n\n/** @internal Ascending; countDigits null = no limit. */\nexport const SCALES = [\n { word: 'arivo', exponent: 3, countDigits: 1 },\n { word: 'alina', exponent: 4, countDigits: 1 },\n { word: 'hetsy', exponent: 5, countDigits: 1 },\n { word: 'tapitrisa', exponent: 6, countDigits: 3 },\n { word: 'lavitrisa', exponent: 9, countDigits: null },\n] as const;\n\n/** @internal Rule 12: one name per power of ten, ascending, each taking one digit. */\nexport const TRADITIONAL_SCALES = [\n { word: 'arivo', exponent: 3, countDigits: 1 },\n { word: 'alina', exponent: 4, countDigits: 1 },\n { word: 'hetsy', exponent: 5, countDigits: 1 },\n { word: 'tapitrisa', exponent: 6, countDigits: 1 },\n { word: 'safatsiroa', exponent: 7, countDigits: 1 },\n { word: 'tsitamboisa', exponent: 8, countDigits: 1 },\n { word: 'lavitrisa', exponent: 9, countDigits: 1 },\n { word: 'alinkisa', exponent: 10, countDigits: 1 },\n { word: 'tsipesimpesenina', exponent: 11, countDigits: 1 },\n { word: 'tsitokotsiforohana', exponent: 12, countDigits: 1 },\n { word: 'tsihitanoanoa', exponent: 13, countDigits: 1 },\n { word: 'safatsiroafaharoa', exponent: 14, countDigits: 1 },\n { word: 'tsitamboisafaharoa', exponent: 15, countDigits: 1 },\n { word: 'lavitrisafaharoa', exponent: 16, countDigits: 1 },\n { word: 'alinkisafaharoa', exponent: 17, countDigits: 1 },\n { word: 'tsipesimpeseninafaharoa', exponent: 18, countDigits: 1 },\n] as const;\n\n/** @internal */\nexport const DECIMAL_SEPARATOR = 'faingo' as const;\n\n/** @internal */\nexport const JOINER_UNITS_BEFORE_TEN = \"ambin'ny\" as const;\n\n/** @internal */\nexport const JOINER_BELOW_THOUSAND = 'amby' as const;\n\n/** @internal */\nexport const JOINER_BETWEEN_GROUPS = 'sy' as const;\n\n/** @internal */\nexport const MIN_VALUE = 0 as const;\n\n/** @internal Rule 14: the ordinal of 1. */\nexport const ORDINAL_FIRST = 'voalohany' as const;\n\n/** @internal */\nexport const ORDINAL_PREFIX = 'faha' as const;\n\n/** @internal */\nexport const ORDINAL_PREFIX_BEFORE_VOWEL = 'fah' as const;\n\n/** @internal Letters that take the short ordinal prefix. */\nexport const VOWELS = ['a', 'e', 'i', 'o', 'y'] as const;\n\n/** @internal Longest decimal text read (rule 13). */\nexport const MAX_TEXT_LENGTH = 100 as const;\n\n/** @internal Longest words text read by parseWords. */\nexport const MAX_WORDS_LENGTH = 4096 as const;\n\n/** @internal Most digits parseWords reads per part. */\nexport const MAX_READ_DIGITS = 15 as const;\n","/** Whole numbers in words, from their decimal digits, so counts of any length stay exact. */\nimport {\n HUNDRED_WORDS,\n JOINER_BELOW_THOUSAND,\n JOINER_BETWEEN_GROUPS,\n JOINER_UNITS_BEFORE_TEN,\n SCALES,\n TEN_WORDS,\n TRADITIONAL_SCALES,\n UNIT_ONE_IN_COMPOUND,\n UNIT_WORDS,\n ZERO_WORD,\n} from './generated/data.ts';\nimport type { NumberSystem } from './system.ts';\n\ntype Digit = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;\ntype Scale = (typeof SCALES)[number] | (typeof TRADITIONAL_SCALES)[number];\ntype ScaleTable = readonly Scale[];\n/**\n * A whole number joins its groups with \"sy\" (rule 8); a count before a group word is one\n * phrase, every part joined by \"amby\" (rule 6).\n */\ntype Role = 'number' | 'count';\n\nconst BASE = 10;\nconst HUNDRED = BASE * BASE;\nconst BELOW_THOUSAND_DIGITS = 3;\n/** Rule 7: a count of one is bare only for arivo. */\nconst BARE_ONE_EXPONENT = SCALES[0].exponent;\nconst LEADING_ZEROS = /^0+/;\nconst ONE = '1';\nconst JOINERS: Readonly<Record<Role, string>> = {\n number: JOINER_BETWEEN_GROUPS,\n count: JOINER_BELOW_THOUSAND,\n};\n\nfunction digitAt(value: number, place: number): Digit {\n return (Math.floor(value / place) % BASE) as Digit;\n}\n\nfunction isNotEmpty(word: string): boolean {\n return word !== '';\n}\n\n/** 11–19 join with \"ambin'ny\", other units onto tens with \"amby\". */\nfunction belowHundredWords(unitWord: string, units: Digit, tens: Digit): string {\n if (tens === 1 && units > 0) return `${unitWord} ${JOINER_UNITS_BEFORE_TEN} ${TEN_WORDS[1]}`;\n return [unitWord, TEN_WORDS[tens]].filter(isNotEmpty).join(` ${JOINER_BELOW_THOUSAND} `);\n}\n\n/** The part below 1000, and the joiner that follows it ('' when nothing does). */\ninterface Lowest {\n readonly value: number;\n readonly role: Role;\n readonly nextJoiner: string;\n}\n\n/**\n * Rule 4: the part below 100 joins exactly 100 with \"amby\" and 200–900 with \"sy\"; inside a\n * count every join is \"amby\". \"iraika\" replaces \"iray\" right before \"amby\" or \"ambin'ny\".\n */\nfunction belowThousandWords({ value, role, nextJoiner }: Lowest): string {\n const units = digitAt(value, 1);\n const tens = digitAt(value, BASE);\n const hundreds = digitAt(value, HUNDRED);\n const joiner = role === 'count' || hundreds === 1 ? JOINER_BELOW_THOUSAND : JOINER_BETWEEN_GROUPS;\n const afterUnits = tens > 0 || hundreds > 0 ? joiner : nextJoiner;\n const isOneBeforeAmby = units === 1 && (tens > 0 || afterUnits === JOINER_BELOW_THOUSAND);\n const unitWord = isOneBeforeAmby ? UNIT_ONE_IN_COMPOUND : UNIT_WORDS[units];\n const belowHundred = belowHundredWords(unitWord, units, tens);\n return [belowHundred, HUNDRED_WORDS[hundreds]].filter(isNotEmpty).join(` ${joiner} `);\n}\n\n/** How many digits the traditional names reach: up to the largest name's single digit. */\nconst TRADITIONAL_REACH = TRADITIONAL_SCALES.reduce(\n (most, scale) => Math.max(most, scale.exponent + scale.countDigits),\n 0,\n);\n\n/** Rule 12: a number longer than the traditional names reach is read with the standard scales. */\nfunction scalesFor(digits: string, system: NumberSystem): ScaleTable {\n return system === 'traditional' && digits.length <= TRADITIONAL_REACH\n ? TRADITIONAL_SCALES\n : SCALES;\n}\n\n/** The digits a group counts, without leading zeros: '' when the group is absent. */\nfunction scaleCount(digits: string, scale: Scale): string {\n const end = digits.length - scale.exponent;\n if (end <= 0) return '';\n const start = scale.countDigits === null ? 0 : Math.max(0, end - scale.countDigits);\n return digits.slice(start, end).replace(LEADING_ZEROS, '');\n}\n\nfunction scaleWords(digits: string, scale: Scale, scales: ScaleTable): string {\n const count = scaleCount(digits, scale);\n if (count === '') return '';\n if (count === ONE && scale.exponent === BARE_ONE_EXPONENT) return scale.word;\n return `${numberWords(count, scales, 'count')} ${scale.word}`;\n}\n\nfunction numberWords(significant: string, scales: ScaleTable, role: Role): string {\n const upper = scales.map((scale) => scaleWords(significant, scale, scales)).filter(isNotEmpty);\n const joiner = JOINERS[role];\n const lowest = belowThousandWords({\n value: Number(significant.slice(-BELOW_THOUSAND_DIGITS)),\n role,\n nextJoiner: upper.length > 0 ? joiner : '',\n });\n return [lowest, ...upper].filter(isNotEmpty).join(` ${joiner} `);\n}\n\n/**\n * @internal A whole number in words, groups joined by \"sy\", smallest first.\n *\n * @param digits - Decimal digits; leading zeros are ignored.\n * @param system - `standard` or `traditional` (rule 12).\n * @returns The words: `'2586'` → `'enina amby valopolo sy dimanjato sy roa arivo'`.\n */\nexport function wholeWords(digits: string, system: NumberSystem): string {\n const significant = digits.replace(LEADING_ZEROS, '');\n if (significant === '') return ZERO_WORD;\n return numberWords(significant, scalesFor(significant, system), 'number');\n}\n\n/**\n * @internal A count as {@link wholeWords} writes it before a group word.\n *\n * @param count - The count, from 1, as a bigint.\n * @param system - Whether the group word is a standard or a traditional name.\n * @returns The count's words: `25000n` → `'dimy arivo amby roa alina'`.\n */\nexport function countWords(count: bigint, system: NumberSystem): string {\n const scales = system === 'traditional' ? TRADITIONAL_SCALES : SCALES;\n return numberWords(count.toString(), scales, 'count');\n}\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.11.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 an operator.\n * - `PRECISION_LOSS`: The value is exact in the text but the port's number type cannot hold it exactly; ask for the exact text instead.\n */\nexport type ErrorCode =\n 'INVALID_TYPE' | 'OUT_OF_RANGE' | 'INVALID_FORMAT' | 'UNKNOWN_OPERATOR' | 'PRECISION_LOSS';\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 = safeParsePhone(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 * spell(-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","/** Numbers and decimal text, turned into their exact decimal digits. */\nimport { MAX_TEXT_LENGTH, MIN_VALUE } from './generated/data.ts';\nimport { MdgError } from './generated/errors.ts';\n\n/** @internal The whole digits, and the decimals or `undefined` for a whole number. */\nexport type DecimalParts = readonly [string, string | undefined];\n\nconst TRAILING_ZEROS = /0+$/;\n/** Rule 13: ASCII digits, then optionally a point and more digits. Nothing else. */\nconst DECIMAL_TEXT = /^([0-9]+)(?:\\.([0-9]+))?$/;\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.${'0'.repeat(Number(exponent) - 1)}${lead}${rest}`;\n}\n\n/**\n * @internal Rule 13: the parts of plain decimal text, trailing decimal zeros dropped.\n *\n * @param text - Text the caller passed.\n * @param caller - Function name for the error message.\n * @returns The whole digits and the decimals.\n */\nexport function decimalTextParts(text: string, caller: string): DecimalParts {\n const match = text.length <= MAX_TEXT_LENGTH ? DECIMAL_TEXT.exec(text) : null;\n if (match === null) {\n throw new MdgError(\n 'INVALID_FORMAT',\n `${caller} reads digits with an optional .decimals, at most ${String(MAX_TEXT_LENGTH)} characters.`,\n );\n }\n const [, whole = '', decimals = ''] = match;\n const significantDecimals = decimals.replace(TRAILING_ZEROS, '');\n return [whole, significantDecimals === '' ? undefined : significantDecimals];\n}\n\n/**\n * @internal Checks a number is finite and between 0 and `Number.MAX_SAFE_INTEGER`.\n *\n * @param value - The value the caller passed.\n * @param caller - Function name for the error message.\n */\nexport function assertSupportedNumber(value: unknown, caller: string): asserts value is number {\n if (typeof value !== 'number' || !Number.isFinite(value)) {\n throw new MdgError('INVALID_TYPE', `${caller} expects a finite number or decimal text.`);\n }\n if (value < MIN_VALUE || value > Number.MAX_SAFE_INTEGER) {\n throw new MdgError(\n 'OUT_OF_RANGE',\n `${caller} supports ${String(MIN_VALUE)} to ${String(Number.MAX_SAFE_INTEGER)}.`,\n );\n }\n}\n\n/**\n * @internal The exact decimal parts of a number or of decimal text.\n *\n * @param value - A number from 0 to `Number.MAX_SAFE_INTEGER`, or plain decimal text.\n * @param caller - Function name for error messages.\n * @returns The whole digits and the decimals.\n */\nexport function decimalParts(value: unknown, caller: string): DecimalParts {\n if (typeof value === 'string') return decimalTextParts(value, caller);\n assertSupportedNumber(value, caller);\n const [whole = '', decimals] = plainDecimal(value).split('.');\n return [whole, decimals];\n}\n","import { MdgError } from './generated/errors.ts';\n\n/**\n * How large numbers are named: `standard` (default; `telopolo tapitrisa` for 30 000 000) or\n * `traditional`, with one name per power of ten (`telo safatsiroa`).\n *\n * @example\n * ```ts\n * const system: NumberSystem = 'traditional';\n * ```\n */\nexport type NumberSystem = 'standard' | 'traditional';\n\n/**\n * Options for {@link spell} and {@link spellOrdinal}.\n *\n * @example\n * ```ts\n * const options: SpellOptions = { system: 'traditional' };\n * ```\n */\nexport interface SpellOptions {\n /** `standard` (default) or `traditional`. */\n readonly system?: NumberSystem;\n}\n\n/** @internal Both systems, standard first. */\nexport const SYSTEMS: readonly NumberSystem[] = ['standard', 'traditional'];\nconst DEFAULT_SYSTEM: NumberSystem = 'standard';\n\n/**\n * @internal The system the options ask for, after checking them.\n *\n * @param options - The options the caller passed.\n * @returns `standard` or `traditional`.\n */\nexport function systemOf(options: unknown): NumberSystem {\n if (typeof options !== 'object' || options === null) {\n throw new MdgError('INVALID_TYPE', 'spell options must be an object.');\n }\n const { system = DEFAULT_SYSTEM } = options as SpellOptions;\n if (!SYSTEMS.includes(system)) {\n throw new MdgError('INVALID_TYPE', 'system is standard or traditional.');\n }\n return system;\n}\n","import { wholeWords } from './cardinal.ts';\nimport { decimalParts } from './decimal-text.ts';\nimport { DECIMAL_SEPARATOR, ZERO_WORD } from './generated/data.ts';\nimport { systemOf, type NumberSystem, type SpellOptions } from './system.ts';\n\nconst LEADING_ZEROS = /^0+/;\n\n/** Each leading zero after the point is \"aotra\"; the rest reads as a whole number. */\nfunction decimalWords(digits: string, system: NumberSystem): string {\n const significant = digits.replace(LEADING_ZEROS, '');\n const zeros = Array.from({ length: digits.length - significant.length }, () => ZERO_WORD);\n return [...zeros, wholeWords(significant, system)].join(' ');\n}\n\n/**\n * @internal Words for exact decimal parts, as {@link spell} writes them.\n *\n * @param whole - The whole digits.\n * @param decimals - The decimals without trailing zeros, or `undefined`.\n * @param system - `standard` or `traditional`.\n * @returns The words.\n */\nexport function partsWords(\n whole: string,\n decimals: string | undefined,\n system: NumberSystem,\n): string {\n const wholePart = wholeWords(whole, system);\n if (decimals === undefined) return wholePart;\n return `${wholePart} ${DECIMAL_SEPARATOR} ${decimalWords(decimals, system)}`;\n}\n\n/**\n * Writes a number in Malagasy words, smallest part first, with `faingo` before the decimals.\n * {@link parseWords} reads the words back.\n *\n * @param value - A number from 0 to `Number.MAX_SAFE_INTEGER`, whole or decimal, or plain\n * decimal text such as `'2000000000000000.9'`, read exactly (a number that large has already\n * lost its decimals to floating point).\n * @param options - Optional `system`: `standard` (default) or `traditional`, which names every\n * power of ten (`telo safatsiroa` for 30 000 000).\n * @returns The number in Malagasy words.\n * @throws {@link MdgError} `INVALID_TYPE` if `value` is not a finite number or the options are\n * unknown, `INVALID_FORMAT` for text that is not plain decimal (at most 100 characters),\n * `OUT_OF_RANGE` if a number is negative or above `Number.MAX_SAFE_INTEGER`.\n *\n * @example\n * ```ts\n * spell(21); // 'iraika amby roapolo'\n * spell(2026); // 'enina amby roapolo sy roa arivo'\n * spell(3.14); // \"telo faingo efatra ambin'ny folo\"\n * spell(30_000_000, { system: 'traditional' }); // 'telo safatsiroa'\n * spell('2000000000000000.9'); // 'roa tapitrisa lavitrisa faingo sivy'\n * ```\n */\nexport function spell(value: number | string, options: SpellOptions = {}): string {\n const [whole, decimals] = decimalParts(value, 'spell');\n return partsWords(whole, decimals, systemOf(options));\n}\n","import { wholeWords } from './cardinal.ts';\nimport { decimalParts } from './decimal-text.ts';\nimport {\n ORDINAL_FIRST,\n ORDINAL_PREFIX,\n ORDINAL_PREFIX_BEFORE_VOWEL,\n VOWELS,\n} from './generated/data.ts';\nimport { MdgError } from './generated/errors.ts';\nimport { systemOf, type SpellOptions } from './system.ts';\n\nconst STARTS_WITH_VOWEL: ReadonlySet<string> = new Set(VOWELS);\nconst LEADING_ZEROS = /^0+/;\nconst ONE = '1';\nconst POINT = '.';\n\n/** Rule 14: whole digits from 1 up; a point in text or decimals in a number are not ordinals. */\nfunction ordinalDigits(value: unknown): string {\n if (typeof value === 'string' && value.includes(POINT)) {\n throw new MdgError('INVALID_FORMAT', 'spellOrdinal reads whole digits, with no point.');\n }\n const [whole, decimals] = decimalParts(value, 'spellOrdinal');\n if (decimals !== undefined) {\n throw new MdgError('INVALID_TYPE', 'spellOrdinal expects a whole number.');\n }\n const significant = whole.replace(LEADING_ZEROS, '');\n if (significant === '') {\n throw new MdgError('OUT_OF_RANGE', 'Ordinals start at 1 (voalohany).');\n }\n return significant;\n}\n\n/**\n * Writes the Malagasy ordinal of a whole number: `faha` before the cardinal words, `fah`\n * before a vowel, and `voalohany` for 1.\n *\n * @param value - A whole number from 1 to `Number.MAX_SAFE_INTEGER`, or digit text such as\n * `'1000000000000000000'`, read exactly.\n * @param options - Optional `system`: `standard` (default) or `traditional`.\n * @returns The ordinal: `3` → `'fahatelo'`.\n * @throws {@link MdgError} `INVALID_TYPE` for a number with decimals, a value that is not a\n * number or text, or unknown options; `INVALID_FORMAT` for text that is not digits;\n * `OUT_OF_RANGE` below 1 or above `Number.MAX_SAFE_INTEGER`.\n *\n * @example\n * ```ts\n * spellOrdinal(1); // 'voalohany'\n * spellOrdinal(3); // 'fahatelo'\n * spellOrdinal(4); // 'fahefatra'\n * spellOrdinal(11); // \"fahiraika ambin'ny folo\"\n * spellOrdinal(1000); // 'faharivo'\n * ```\n */\nexport function spellOrdinal(value: number | string, options: SpellOptions = {}): string {\n const digits = ordinalDigits(value);\n const cardinal = wholeWords(digits, systemOf(options));\n if (digits === ONE) return ORDINAL_FIRST;\n const prefix = STARTS_WITH_VOWEL.has(cardinal.charAt(0))\n ? ORDINAL_PREFIX_BEFORE_VOWEL\n : ORDINAL_PREFIX;\n return `${prefix}${cardinal}`;\n}\n","/**\n * Malagasy number words → every exact value they can stand for. parse.ts keeps the values that\n * spell back to the same words.\n */\nimport { countWords } from './cardinal.ts';\nimport { SYSTEMS } from './system.ts';\nimport {\n DECIMAL_SEPARATOR,\n HUNDRED_WORDS,\n JOINER_BELOW_THOUSAND,\n JOINER_BETWEEN_GROUPS,\n JOINER_UNITS_BEFORE_TEN,\n SCALES,\n TEN_WORDS,\n TRADITIONAL_SCALES,\n UNIT_ONE_IN_COMPOUND,\n UNIT_WORDS,\n ZERO_WORD,\n} from './generated/data.ts';\n\n/** @internal Readings of words: whole parts, and decimal digits (`undefined` if none). */\nexport interface Readings {\n readonly wholes: readonly bigint[];\n readonly decimals: readonly string[] | undefined;\n}\n\nconst BASE = 10;\n/** A phrase alternates a word and a joiner: word, joiner, word, …. */\nconst TOKENS_PER_STEP = 2;\nconst TEN = BigInt(BASE);\nconst HUNDRED = BASE * BASE;\n/** Readings kept per part: real words have one or two; more only in made-up text. */\nconst MAX_READINGS = 8;\nconst PHRASE_JOINERS: ReadonlySet<string> = new Set([\n JOINER_BELOW_THOUSAND,\n JOINER_UNITS_BEFORE_TEN,\n]);\n\nfunction wordValues(words: readonly string[], step: number): [string, number][] {\n return words.flatMap((word, digit) => (word === '' ? [] : [[word, digit * step]]));\n}\n\n/** Every word a phrase below 1000 is made of, with its value. */\nconst PHRASE_VALUES: ReadonlyMap<string, number> = new Map([\n ...wordValues(UNIT_WORDS, 1),\n [UNIT_ONE_IN_COMPOUND, 1],\n ...wordValues(TEN_WORDS, BASE),\n ...wordValues(HUNDRED_WORDS, HUNDRED),\n]);\n\n/**\n * The longest phrase below 1000: \"iraika ambin'ny folo amby zato\" style, three words, two joiners.\n */\nconst MAX_PHRASE_TOKENS = 5;\n\ninterface GroupWord {\n readonly factor: bigint;\n readonly hasPhraseCount: boolean;\n /** Most words the smaller part before this group can have: the words of factor − 1. */\n readonly maxLeftTokens: number;\n}\n\nfunction groupWord(exponent: number, countDigits: number | null): GroupWord {\n const factor = TEN ** BigInt(exponent);\n const maxLeftTokens = countWords(factor - BigInt(1), 'standard').split(' ').length;\n return { factor, hasPhraseCount: countDigits !== null, maxLeftTokens };\n}\n\n/**\n * Group words of both systems: their power of ten, and whether their count is a phrase below\n * 1000 (every group but the largest), which bounds where that count can start. Standard comes\n * last so lavitrisa, in both tables, keeps its count of any size.\n */\nconst GROUP_WORDS: ReadonlyMap<string, GroupWord> = new Map(\n [...TRADITIONAL_SCALES, ...SCALES].map((scale) => [\n scale.word,\n groupWord(scale.exponent, scale.countDigits),\n ]),\n);\n\n/** \"valo amby efapolo amby telonjato\": words alternate with amby or ambin'ny. */\nfunction readPhrase(tokens: readonly string[]): bigint | undefined {\n let total = 0;\n for (const [index, token] of tokens.entries()) {\n const isJoinerPlace = index % TOKENS_PER_STEP === 1;\n if (isJoinerPlace !== PHRASE_JOINERS.has(token)) return undefined;\n if (!isJoinerPlace) total += PHRASE_VALUES.get(token) ?? Number.NaN;\n }\n return tokens.length % TOKENS_PER_STEP === 1 && !Number.isNaN(total) ? BigInt(total) : undefined;\n}\n\nfunction sums(lefts: Iterable<bigint>, rights: Iterable<bigint>, factor: bigint): bigint[] {\n return [...lefts].flatMap((left) => [...rights].map((right) => left + right * factor));\n}\n\n/** Smallest part first: what comes before a group is always smaller than one of that group. */\nfunction groupSums(lefts: Iterable<bigint>, counts: Iterable<bigint>, factor: bigint): bigint[] {\n return sums(\n [...lefts].filter((left) => left < factor),\n counts,\n factor,\n );\n}\n\nfunction limited(values: Iterable<bigint>): bigint[] {\n return [...new Set(values)].slice(0, MAX_READINGS);\n}\n\n/** Reads the counts in one list of tokens, remembering each span it has read. */\nclass CountReader {\n private readonly spans = new Map<string, bigint[]>();\n private readonly tokens: readonly string[];\n\n constructor(tokens: readonly string[]) {\n this.tokens = tokens;\n }\n\n /**\n * Counts written exactly as spell writes a count before a group word.\n *\n * @param start - First token of the count.\n * @param end - Token after the count.\n * @returns The counts those tokens spell.\n */\n counts(start: number, end: number): bigint[] {\n const text = this.tokens.slice(start, end).join(' ');\n return this.values(start, end).filter((count) =>\n SYSTEMS.some((system) => countWords(count, system) === text),\n );\n }\n\n /** Every value of tokens[start, end): a phrase, or parts joined by amby ending in a group. */\n private values(start: number, end: number): bigint[] {\n const key = `${String(start)}:${String(end)}`;\n const known = this.spans.get(key);\n if (known !== undefined) return known;\n const phrase = readPhrase(this.tokens.slice(start, end));\n const found = limited([...(phrase === undefined ? [] : [phrase]), ...this.grouped(start, end)]);\n this.spans.set(key, found);\n return found;\n }\n\n /** \"dimy arivo amby roa alina\": whatever comes before an amby, plus a count of the last group. */\n private grouped(start: number, end: number): bigint[] {\n const group = GROUP_WORDS.get(String(this.tokens[end - 1]));\n if (group === undefined) return [];\n const first = group.hasPhraseCount ? Math.max(start, end - 1 - MAX_PHRASE_TOKENS) : start;\n const last = Math.min(end - 1, start + group.maxLeftTokens + 1);\n const found: bigint[] = [];\n for (let split = first; split <= last; split += 1) {\n if (split > start && this.tokens[split - 1] !== JOINER_BELOW_THOUSAND) continue;\n const lefts = split === start ? [BigInt(0)] : this.values(start, split - 1);\n const counts = split === end - 1 ? [BigInt(1)] : this.counts(split, end - 1);\n found.push(...groupSums(lefts, counts, group.factor));\n }\n return found;\n }\n}\n\nfunction splitOn(tokens: readonly string[], separator: string): string[][] {\n const parts: string[][] = [[]];\n for (const token of tokens) {\n if (token === separator) parts.push([]);\n else parts[parts.length - 1]?.push(token);\n }\n return parts;\n}\n\n/** One group of a whole number: a count and a group word (\"roa arivo\"), or a phrase. */\nfunction groupValues(tokens: readonly string[]): bigint[] {\n const factor = GROUP_WORDS.get(String(tokens[tokens.length - 1]))?.factor;\n if (factor === undefined) {\n const phrase = readPhrase(tokens);\n return phrase === undefined ? [] : [phrase];\n }\n const counts =\n tokens.length === 1 ? [BigInt(1)] : new CountReader(tokens).counts(0, tokens.length - 1);\n return counts.map((count) => count * factor);\n}\n\n/** A whole number: groups joined by \"sy\", or \"aotra\". */\nfunction wholeValues(tokens: readonly string[]): bigint[] {\n if (tokens.length === 1 && tokens[0] === ZERO_WORD) return [BigInt(0)];\n return splitOn(tokens, JOINER_BETWEEN_GROUPS).reduce<bigint[]>(\n (totals, group) => limited(sums(totals, groupValues(group), BigInt(1))),\n [BigInt(0)],\n );\n}\n\n/** After \"faingo\": one \"aotra\" per leading zero, then a whole number. */\nfunction decimalValues(tokens: readonly string[]): string[] {\n const zeros = tokens.findIndex((token) => token !== ZERO_WORD);\n if (zeros < 0) return [];\n const prefix = '0'.repeat(zeros);\n return wholeValues(tokens.slice(zeros)).map((value) => `${prefix}${value.toString()}`);\n}\n\n/**\n * @internal Every value normalised words can stand for, before checking which ones\n * {@link spell} writes as those words.\n *\n * @param words - Lowercase words separated by single spaces.\n * @returns The candidate whole parts and decimals; empty lists when nothing reads.\n */\nexport function readWords(words: string): Readings {\n const [wholeTokens = [], decimalTokens, ...extra] = splitOn(words.split(' '), DECIMAL_SEPARATOR);\n if (extra.length > 0) return { wholes: [], decimals: undefined };\n return {\n wholes: wholeValues(wholeTokens),\n decimals: decimalTokens === undefined ? undefined : decimalValues(decimalTokens),\n };\n}\n","import { plainDecimal } from './decimal-text.ts';\nimport { MAX_READ_DIGITS, MAX_WORDS_LENGTH } from './generated/data.ts';\nimport { MdgError, type ErrorCode, type SafeParseResult } from './generated/errors.ts';\nimport { readWords } from './read-words.ts';\nimport { partsWords } from './spell.ts';\nimport { SYSTEMS } from './system.ts';\n\n/**\n * What {@link parseWords} gives back: a `number` (default), or the exact decimal `text`.\n *\n * @example\n * ```ts\n * const exact: ParseResultKind = 'text';\n * ```\n */\nexport type ParseResultKind = 'number' | 'text';\n\n/**\n * Options for {@link parseWords}.\n *\n * @example\n * ```ts\n * const options: ParseWordsOptions = { as: 'text' };\n * ```\n */\nexport interface ParseWordsOptions {\n /** `number` (default), or `text` for the exact decimal digits of any size. */\n readonly as?: ParseResultKind;\n}\n\n/**\n * The value a reader gives back for a {@link ParseResultKind}: `string` for `text`, otherwise\n * `number`.\n *\n * @example\n * ```ts\n * const digits: ParsedValue<'text'> = '2000';\n * ```\n */\nexport type ParsedValue<Kind extends ParseResultKind> = Kind extends 'text' ? string : number;\n\nconst RESULT_KINDS: ReadonlySet<unknown> = new Set<ParseResultKind>(['number', 'text']);\nconst OPTION_KEYS: ReadonlySet<string> = new Set(['as']);\nconst APOSTROPHES = /[‘’ʼ`´]/g;\nconst SPACES = /\\s+/gu;\n/** Older spellings of \"ambin'ny\" (dictionary: \"ambin' ny\"; Assimil: \"amby ny\"). */\nconst SPLIT_AMBINNY = /\\bambin' ny\\b|\\bamby ny\\b/g;\nconst AMBINNY = \"ambin'ny\";\nconst TRAILING_ZEROS = /0+$/;\n\nfunction failure(code: ErrorCode, message: string): SafeParseResult<never> {\n return { success: false, error: new MdgError(code, message) };\n}\n\nfunction resultKind(options: unknown): ParseResultKind | undefined {\n if (typeof options !== 'object' || options === null) return undefined;\n if (Object.keys(options).some((key) => !OPTION_KEYS.has(key))) return undefined;\n const { as = 'number' } = options as ParseWordsOptions;\n return RESULT_KINDS.has(as) ? as : undefined;\n}\n\n/** Case, apostrophes, spacing and older spellings do not change the number. */\nfunction normalise(text: string): string {\n return text\n .toLowerCase()\n .replace(APOSTROPHES, \"'\")\n .replace(SPACES, ' ')\n .trim()\n .replace(SPLIT_AMBINNY, AMBINNY);\n}\n\n/** Every exact value whose spelling is these words: one, none, or (rarely) more. */\nfunction spelledReadings(words: string): string[] {\n const { wholes, decimals } = readWords(words);\n const texts = wholes.flatMap((whole) =>\n (decimals ?? ['']).map((digits) => {\n const significant = digits.replace(TRAILING_ZEROS, '');\n return significant === '' ? whole.toString() : `${whole.toString()}.${significant}`;\n }),\n );\n return [...new Set(texts)].filter((text) => {\n const [whole = '', decimal] = text.split('.');\n return SYSTEMS.some((system) => partsWords(whole, decimal, system) === words);\n });\n}\n\n/** Rule 15: a whole part or decimals longer than this may be written the same for two numbers. */\nfunction isReadable(text: string): boolean {\n return text.split('.').every((part) => part.length <= MAX_READ_DIGITS);\n}\n\nfunction readExact(words: string): SafeParseResult<string> {\n const readings = spelledReadings(words);\n const [only] = readings;\n if (only === undefined) {\n return failure('INVALID_FORMAT', 'Expected Malagasy number words, as spell writes them.');\n }\n if (!readings.every(isReadable)) {\n return failure(\n 'OUT_OF_RANGE',\n `parseWords reads up to ${String(MAX_READ_DIGITS)} digits before and after faingo.`,\n );\n }\n return { success: true, data: only };\n}\n\n/** A number only when it holds the digits exactly: never a silent rounding. */\nfunction asNumber(text: string): SafeParseResult<number> {\n const value = Number(text);\n if (value <= Number.MAX_SAFE_INTEGER && plainDecimal(value) === text) {\n return { success: true, data: value };\n }\n return failure(\n 'PRECISION_LOSS',\n `${text} does not fit a number exactly; pass { as: 'text' } for the exact digits.`,\n );\n}\n\n/**\n * Reads Malagasy number words without throwing.\n *\n * @param text - Words as {@link spell} writes them, in either system, in any case and spacing.\n * @param options - Optional `as`: `number` (default) or `text` for the exact digits.\n * @returns `{ success: true, data }` with the number or text, or `{ success: false, error }`.\n *\n * @example\n * ```ts\n * const result = safeParseWords('roa arivo');\n * if (result.success) result.data; // 2000\n * ```\n */\nexport function safeParseWords(\n text: unknown,\n options: ParseWordsOptions = {},\n): SafeParseResult<number | string> {\n if (typeof text !== 'string') return failure('INVALID_TYPE', 'Expected the words as text.');\n const kind = resultKind(options);\n if (kind === undefined) return failure('INVALID_TYPE', \"as is 'number' or 'text'.\");\n if (text.length > MAX_WORDS_LENGTH) {\n return failure('INVALID_FORMAT', `Words are at most ${String(MAX_WORDS_LENGTH)} characters.`);\n }\n const exact = readExact(normalise(text));\n if (!exact.success || kind === 'text') return exact;\n return asNumber(exact.data);\n}\n\n/**\n * Reads Malagasy number words back into a number: the exact inverse of {@link spell}.\n *\n * @param text - Words as {@link spell} writes them, in either system. Case, spacing, curly\n * apostrophes and the older `ambin' ny` and `amby ny` do not matter.\n * @param options - Optional `as`: `number` (default) or `text` for the exact decimal digits.\n * @returns The number, or its digits as text with `{ as: 'text' }`.\n * @throws {@link MdgError} `INVALID_TYPE` for non-strings or bad options, `INVALID_FORMAT` for\n * anything spell does not write, `OUT_OF_RANGE` above 15 digits, `PRECISION_LOSS` when a number cannot hold the value exactly.\n *\n * @example\n * ```ts\n * parseWords('valo amby efapolo amby telonjato'); // 348\n * parseWords(\"telo faingo efatra ambin'ny folo\"); // 3.14\n * parseWords('telo safatsiroa'); // 30000000\n * parseWords('iray lavitrisa lavitrisa', { as: 'text' }); // '1000000000000000000'\n * ```\n */\nexport function parseWords<Kind extends ParseResultKind = 'number'>(\n text: string,\n options: { readonly as?: Kind } = {},\n): ParsedValue<Kind> {\n const result = safeParseWords(text, options);\n if (!result.success) throw result.error;\n return result.data as ParsedValue<Kind>;\n}\n\n/**\n * Reads Malagasy number words, or gives `undefined` instead of throwing.\n *\n * @param text - Words as {@link spell} writes them.\n * @param options - Optional `as`: `number` (default) or `text`.\n * @returns The value, or `undefined` when {@link parseWords} would throw.\n *\n * @example\n * ```ts\n * tryParseWords('roa arivo'); // 2000\n * tryParseWords('roa sy arivo sy'); // undefined\n * ```\n */\nexport function tryParseWords(\n text: unknown,\n options: ParseWordsOptions = {},\n): number | string | undefined {\n const result = safeParseWords(text, options);\n return result.success ? result.data : undefined;\n}\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -70,7 +70,7 @@ declare function spell(value: number | string, options?: SpellOptions): string;
|
|
|
70
70
|
declare function spellOrdinal(value: number | string, options?: SpellOptions): string;
|
|
71
71
|
|
|
72
72
|
/** Version of the shared spec this code was generated from. */
|
|
73
|
-
declare const SPEC_VERSION = "0.
|
|
73
|
+
declare const SPEC_VERSION = "0.11.0";
|
|
74
74
|
/**
|
|
75
75
|
* Error code shared by every mdg-utils language port.
|
|
76
76
|
*
|
|
@@ -79,9 +79,8 @@ declare const SPEC_VERSION = "0.10.0";
|
|
|
79
79
|
* - `INVALID_FORMAT`: The input text cannot be read as a value of this module (wrong characters or wrong length).
|
|
80
80
|
* - `UNKNOWN_OPERATOR`: The phone number is well formed but its operator code is not assigned to an operator.
|
|
81
81
|
* - `PRECISION_LOSS`: The value is exact in the text but the port's number type cannot hold it exactly; ask for the exact text instead.
|
|
82
|
-
* - `AMBIGUOUS`: The text reads as more than one value, so none is chosen.
|
|
83
82
|
*/
|
|
84
|
-
type ErrorCode = 'INVALID_TYPE' | 'OUT_OF_RANGE' | 'INVALID_FORMAT' | 'UNKNOWN_OPERATOR' | 'PRECISION_LOSS'
|
|
83
|
+
type ErrorCode = 'INVALID_TYPE' | 'OUT_OF_RANGE' | 'INVALID_FORMAT' | 'UNKNOWN_OPERATOR' | 'PRECISION_LOSS';
|
|
85
84
|
/**
|
|
86
85
|
* Outcome of a `safeParse…` function: the value, or the error that would have been thrown.
|
|
87
86
|
*
|
|
@@ -190,8 +189,7 @@ declare function safeParseWords(text: unknown, options?: ParseWordsOptions): Saf
|
|
|
190
189
|
* @param options - Optional `as`: `number` (default) or `text` for the exact decimal digits.
|
|
191
190
|
* @returns The number, or its digits as text with `{ as: 'text' }`.
|
|
192
191
|
* @throws {@link MdgError} `INVALID_TYPE` for non-strings or bad options, `INVALID_FORMAT` for
|
|
193
|
-
* anything spell does not write, `
|
|
194
|
-
* one million billion up), `PRECISION_LOSS` when a number cannot hold the value exactly.
|
|
192
|
+
* anything spell does not write, `OUT_OF_RANGE` above 15 digits, `PRECISION_LOSS` when a number cannot hold the value exactly.
|
|
195
193
|
*
|
|
196
194
|
* @example
|
|
197
195
|
* ```ts
|
package/dist/index.d.ts
CHANGED
|
@@ -70,7 +70,7 @@ declare function spell(value: number | string, options?: SpellOptions): string;
|
|
|
70
70
|
declare function spellOrdinal(value: number | string, options?: SpellOptions): string;
|
|
71
71
|
|
|
72
72
|
/** Version of the shared spec this code was generated from. */
|
|
73
|
-
declare const SPEC_VERSION = "0.
|
|
73
|
+
declare const SPEC_VERSION = "0.11.0";
|
|
74
74
|
/**
|
|
75
75
|
* Error code shared by every mdg-utils language port.
|
|
76
76
|
*
|
|
@@ -79,9 +79,8 @@ declare const SPEC_VERSION = "0.10.0";
|
|
|
79
79
|
* - `INVALID_FORMAT`: The input text cannot be read as a value of this module (wrong characters or wrong length).
|
|
80
80
|
* - `UNKNOWN_OPERATOR`: The phone number is well formed but its operator code is not assigned to an operator.
|
|
81
81
|
* - `PRECISION_LOSS`: The value is exact in the text but the port's number type cannot hold it exactly; ask for the exact text instead.
|
|
82
|
-
* - `AMBIGUOUS`: The text reads as more than one value, so none is chosen.
|
|
83
82
|
*/
|
|
84
|
-
type ErrorCode = 'INVALID_TYPE' | 'OUT_OF_RANGE' | 'INVALID_FORMAT' | 'UNKNOWN_OPERATOR' | 'PRECISION_LOSS'
|
|
83
|
+
type ErrorCode = 'INVALID_TYPE' | 'OUT_OF_RANGE' | 'INVALID_FORMAT' | 'UNKNOWN_OPERATOR' | 'PRECISION_LOSS';
|
|
85
84
|
/**
|
|
86
85
|
* Outcome of a `safeParse…` function: the value, or the error that would have been thrown.
|
|
87
86
|
*
|
|
@@ -190,8 +189,7 @@ declare function safeParseWords(text: unknown, options?: ParseWordsOptions): Saf
|
|
|
190
189
|
* @param options - Optional `as`: `number` (default) or `text` for the exact decimal digits.
|
|
191
190
|
* @returns The number, or its digits as text with `{ as: 'text' }`.
|
|
192
191
|
* @throws {@link MdgError} `INVALID_TYPE` for non-strings or bad options, `INVALID_FORMAT` for
|
|
193
|
-
* anything spell does not write, `
|
|
194
|
-
* one million billion up), `PRECISION_LOSS` when a number cannot hold the value exactly.
|
|
192
|
+
* anything spell does not write, `OUT_OF_RANGE` above 15 digits, `PRECISION_LOSS` when a number cannot hold the value exactly.
|
|
195
193
|
*
|
|
196
194
|
* @example
|
|
197
195
|
* ```ts
|
package/dist/index.js
CHANGED
|
@@ -73,6 +73,7 @@ var ORDINAL_PREFIX_BEFORE_VOWEL = "fah";
|
|
|
73
73
|
var VOWELS = ["a", "e", "i", "o", "y"];
|
|
74
74
|
var MAX_TEXT_LENGTH = 100;
|
|
75
75
|
var MAX_WORDS_LENGTH = 4096;
|
|
76
|
+
var MAX_READ_DIGITS = 15;
|
|
76
77
|
|
|
77
78
|
// src/cardinal.ts
|
|
78
79
|
var BASE = 10;
|
|
@@ -145,7 +146,7 @@ function countWords(count, system) {
|
|
|
145
146
|
}
|
|
146
147
|
|
|
147
148
|
// src/generated/errors.ts
|
|
148
|
-
var SPEC_VERSION = "0.
|
|
149
|
+
var SPEC_VERSION = "0.11.0";
|
|
149
150
|
var MdgError = class extends Error {
|
|
150
151
|
/** Always `'MdgError'`. */
|
|
151
152
|
name = "MdgError";
|
|
@@ -346,7 +347,7 @@ var CountReader = class {
|
|
|
346
347
|
(count) => SYSTEMS.some((system) => countWords(count, system) === text)
|
|
347
348
|
);
|
|
348
349
|
}
|
|
349
|
-
|
|
350
|
+
/** Every value of tokens[start, end): a phrase, or parts joined by amby ending in a group. */
|
|
350
351
|
values(start, end) {
|
|
351
352
|
const key = `${String(start)}:${String(end)}`;
|
|
352
353
|
const known = this.spans.get(key);
|
|
@@ -356,7 +357,7 @@ var CountReader = class {
|
|
|
356
357
|
this.spans.set(key, found);
|
|
357
358
|
return found;
|
|
358
359
|
}
|
|
359
|
-
|
|
360
|
+
/** "dimy arivo amby roa alina": whatever comes before an amby, plus a count of the last group. */
|
|
360
361
|
grouped(start, end) {
|
|
361
362
|
const group = GROUP_WORDS.get(String(this.tokens[end - 1]));
|
|
362
363
|
if (group === void 0) return [];
|
|
@@ -444,14 +445,20 @@ function spelledReadings(words) {
|
|
|
444
445
|
return SYSTEMS.some((system) => partsWords(whole, decimal, system) === words);
|
|
445
446
|
});
|
|
446
447
|
}
|
|
448
|
+
function isReadable(text) {
|
|
449
|
+
return text.split(".").every((part) => part.length <= MAX_READ_DIGITS);
|
|
450
|
+
}
|
|
447
451
|
function readExact(words) {
|
|
448
452
|
const readings = spelledReadings(words);
|
|
449
|
-
const [only
|
|
453
|
+
const [only] = readings;
|
|
450
454
|
if (only === void 0) {
|
|
451
455
|
return failure("INVALID_FORMAT", "Expected Malagasy number words, as spell writes them.");
|
|
452
456
|
}
|
|
453
|
-
if (
|
|
454
|
-
return failure(
|
|
457
|
+
if (!readings.every(isReadable)) {
|
|
458
|
+
return failure(
|
|
459
|
+
"OUT_OF_RANGE",
|
|
460
|
+
`parseWords reads up to ${String(MAX_READ_DIGITS)} digits before and after faingo.`
|
|
461
|
+
);
|
|
455
462
|
}
|
|
456
463
|
return { success: true, data: only };
|
|
457
464
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/generated/data.ts","../src/cardinal.ts","../src/generated/errors.ts","../src/decimal-text.ts","../src/system.ts","../src/spell.ts","../src/ordinal.ts","../src/read-words.ts","../src/parse.ts"],"names":["LEADING_ZEROS","ONE","BASE","HUNDRED","TRAILING_ZEROS"],"mappings":";AAKO,IAAM,SAAA,GAAY,OAAA;AAGlB,IAAM,UAAA,GAAa;AAAA,EACxB,EAAA;AAAA,EACA,MAAA;AAAA,EACA,KAAA;AAAA,EACA,MAAA;AAAA,EACA,QAAA;AAAA,EACA,MAAA;AAAA,EACA,OAAA;AAAA,EACA,MAAA;AAAA,EACA,MAAA;AAAA,EACA;AACF,CAAA;AAGO,IAAM,oBAAA,GAAuB,QAAA;AAG7B,IAAM,SAAA,GAAY;AAAA,EACvB,EAAA;AAAA,EACA,MAAA;AAAA,EACA,SAAA;AAAA,EACA,UAAA;AAAA,EACA,SAAA;AAAA,EACA,WAAA;AAAA,EACA,UAAA;AAAA,EACA,UAAA;AAAA,EACA,UAAA;AAAA,EACA;AACF,CAAA;AAGO,IAAM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U,SAAA,CAAU,IAAI,CAAC,CAAA;AACvC,EAAA,IAAI,CAAC,KAAA,CAAM,OAAA,IAAW,IAAA,KAAS,QAAQ,OAAO,KAAA;AAC9C,EAAA,OAAO,QAAA,CAAS,MAAM,IAAI,CAAA;AAC5B;AAqBO,SAAS,UAAA,CACd,IAAA,EACA,OAAA,GAAkC,EAAC,EAChB;AACnB,EAAA,MAAM,MAAA,GAAS,cAAA,CAAe,IAAA,EAAM,OAAO,CAAA;AAC3C,EAAA,IAAI,CAAC,MAAA,CAAO,OAAA,EAAS,MAAM,MAAA,CAAO,KAAA;AAClC,EAAA,OAAO,MAAA,CAAO,IAAA;AAChB;AAeO,SAAS,aAAA,CACd,IAAA,EACA,OAAA,GAA6B,EAAC,EACD;AAC7B,EAAA,MAAM,MAAA,GAAS,cAAA,CAAe,IAAA,EAAM,OAAO,CAAA;AAC3C,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/words/data.yaml, spec 0.10.0.\n\n/** @internal */\nexport const ZERO_WORD = 'aotra' as const;\n\n/** @internal Index = digit; index 0 is unused. */\nexport const UNIT_WORDS = [\n '',\n 'iray',\n 'roa',\n 'telo',\n 'efatra',\n 'dimy',\n 'enina',\n 'fito',\n 'valo',\n 'sivy',\n] as const;\n\n/** @internal */\nexport const UNIT_ONE_IN_COMPOUND = 'iraika' as const;\n\n/** @internal Index = tens digit. */\nexport const TEN_WORDS = [\n '',\n 'folo',\n 'roapolo',\n 'telopolo',\n 'efapolo',\n 'dimampolo',\n 'enimpolo',\n 'fitopolo',\n 'valopolo',\n 'sivifolo',\n] as const;\n\n/** @internal Index = hundreds digit. */\nexport const HUNDRED_WORDS = [\n '',\n 'zato',\n 'roanjato',\n 'telonjato',\n 'efajato',\n 'dimanjato',\n 'eninjato',\n 'fitonjato',\n 'valonjato',\n 'sivinjato',\n] as const;\n\n/** @internal Ascending; countDigits null = no limit. */\nexport const SCALES = [\n { word: 'arivo', exponent: 3, countDigits: 1 },\n { word: 'alina', exponent: 4, countDigits: 1 },\n { word: 'hetsy', exponent: 5, countDigits: 1 },\n { word: 'tapitrisa', exponent: 6, countDigits: 3 },\n { word: 'lavitrisa', exponent: 9, countDigits: null },\n] as const;\n\n/** @internal Rule 12: one name per power of ten, ascending, each taking one digit. */\nexport const TRADITIONAL_SCALES = [\n { word: 'arivo', exponent: 3, countDigits: 1 },\n { word: 'alina', exponent: 4, countDigits: 1 },\n { word: 'hetsy', exponent: 5, countDigits: 1 },\n { word: 'tapitrisa', exponent: 6, countDigits: 1 },\n { word: 'safatsiroa', exponent: 7, countDigits: 1 },\n { word: 'tsitamboisa', exponent: 8, countDigits: 1 },\n { word: 'lavitrisa', exponent: 9, countDigits: 1 },\n { word: 'alinkisa', exponent: 10, countDigits: 1 },\n { word: 'tsipesimpesenina', exponent: 11, countDigits: 1 },\n { word: 'tsitokotsiforohana', exponent: 12, countDigits: 1 },\n { word: 'tsihitanoanoa', exponent: 13, countDigits: 1 },\n { word: 'safatsiroafaharoa', exponent: 14, countDigits: 1 },\n { word: 'tsitamboisafaharoa', exponent: 15, countDigits: 1 },\n { word: 'lavitrisafaharoa', exponent: 16, countDigits: 1 },\n { word: 'alinkisafaharoa', exponent: 17, countDigits: 1 },\n { word: 'tsipesimpeseninafaharoa', exponent: 18, countDigits: 1 },\n] as const;\n\n/** @internal */\nexport const DECIMAL_SEPARATOR = 'faingo' as const;\n\n/** @internal */\nexport const JOINER_UNITS_BEFORE_TEN = \"ambin'ny\" as const;\n\n/** @internal */\nexport const JOINER_BELOW_THOUSAND = 'amby' as const;\n\n/** @internal */\nexport const JOINER_BETWEEN_GROUPS = 'sy' as const;\n\n/** @internal */\nexport const MIN_VALUE = 0 as const;\n\n/** @internal Rule 14: the ordinal of 1. */\nexport const ORDINAL_FIRST = 'voalohany' as const;\n\n/** @internal */\nexport const ORDINAL_PREFIX = 'faha' as const;\n\n/** @internal */\nexport const ORDINAL_PREFIX_BEFORE_VOWEL = 'fah' as const;\n\n/** @internal Letters that take the short ordinal prefix. */\nexport const VOWELS = ['a', 'e', 'i', 'o', 'y'] as const;\n\n/** @internal Longest decimal text read (rule 13). */\nexport const MAX_TEXT_LENGTH = 100 as const;\n\n/** @internal Longest words text read by parseWords. */\nexport const MAX_WORDS_LENGTH = 4096 as const;\n","// Whole numbers in words, from their decimal digits, so counts of any length stay exact.\nimport {\n HUNDRED_WORDS,\n JOINER_BELOW_THOUSAND,\n JOINER_BETWEEN_GROUPS,\n JOINER_UNITS_BEFORE_TEN,\n SCALES,\n TEN_WORDS,\n TRADITIONAL_SCALES,\n UNIT_ONE_IN_COMPOUND,\n UNIT_WORDS,\n ZERO_WORD,\n} from './generated/data.ts';\nimport type { NumberSystem } from './system.ts';\n\ntype Digit = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;\ntype Scale = (typeof SCALES)[number] | (typeof TRADITIONAL_SCALES)[number];\ntype ScaleTable = readonly Scale[];\n// A whole number joins its groups with \"sy\" (rule 8); a count before a group word is one\n// phrase, every part joined by \"amby\" (rule 6).\ntype Role = 'number' | 'count';\n\nconst BASE = 10;\nconst HUNDRED = BASE * BASE;\nconst BELOW_THOUSAND_DIGITS = 3;\n// Rule 7: a count of one is bare only for arivo.\nconst BARE_ONE_EXPONENT = SCALES[0].exponent;\nconst LEADING_ZEROS = /^0+/;\nconst ONE = '1';\nconst JOINERS: Readonly<Record<Role, string>> = {\n number: JOINER_BETWEEN_GROUPS,\n count: JOINER_BELOW_THOUSAND,\n};\n\nfunction digitAt(value: number, place: number): Digit {\n return (Math.floor(value / place) % BASE) as Digit;\n}\n\nfunction isNotEmpty(word: string): boolean {\n return word !== '';\n}\n\n// 11–19 join with \"ambin'ny\", other units onto tens with \"amby\".\nfunction belowHundredWords(unitWord: string, units: Digit, tens: Digit): string {\n if (tens === 1 && units > 0) return `${unitWord} ${JOINER_UNITS_BEFORE_TEN} ${TEN_WORDS[1]}`;\n return [unitWord, TEN_WORDS[tens]].filter(isNotEmpty).join(` ${JOINER_BELOW_THOUSAND} `);\n}\n\n// The part below 1000, and the joiner that follows it ('' when nothing does).\ninterface Lowest {\n readonly value: number;\n readonly role: Role;\n readonly nextJoiner: string;\n}\n\n// Rule 4: the part below 100 joins exactly 100 with \"amby\" and 200–900 with \"sy\"; inside a\n// count every join is \"amby\". \"iraika\" replaces \"iray\" right before \"amby\" or \"ambin'ny\".\nfunction belowThousandWords({ value, role, nextJoiner }: Lowest): string {\n const units = digitAt(value, 1);\n const tens = digitAt(value, BASE);\n const hundreds = digitAt(value, HUNDRED);\n const joiner = role === 'count' || hundreds === 1 ? JOINER_BELOW_THOUSAND : JOINER_BETWEEN_GROUPS;\n const afterUnits = tens > 0 || hundreds > 0 ? joiner : nextJoiner;\n const isOneBeforeAmby = units === 1 && (tens > 0 || afterUnits === JOINER_BELOW_THOUSAND);\n const unitWord = isOneBeforeAmby ? UNIT_ONE_IN_COMPOUND : UNIT_WORDS[units];\n const belowHundred = belowHundredWords(unitWord, units, tens);\n return [belowHundred, HUNDRED_WORDS[hundreds]].filter(isNotEmpty).join(` ${joiner} `);\n}\n\n// How many digits the traditional names reach: up to the largest name's single digit.\nconst TRADITIONAL_REACH = TRADITIONAL_SCALES.reduce(\n (most, scale) => Math.max(most, scale.exponent + scale.countDigits),\n 0,\n);\n\n// Rule 12: a number longer than the traditional names reach is read with the standard scales.\nfunction scalesFor(digits: string, system: NumberSystem): ScaleTable {\n return system === 'traditional' && digits.length <= TRADITIONAL_REACH\n ? TRADITIONAL_SCALES\n : SCALES;\n}\n\n// The digits a group counts, without leading zeros: '' when the group is absent.\nfunction scaleCount(digits: string, scale: Scale): string {\n const end = digits.length - scale.exponent;\n if (end <= 0) return '';\n const start = scale.countDigits === null ? 0 : Math.max(0, end - scale.countDigits);\n return digits.slice(start, end).replace(LEADING_ZEROS, '');\n}\n\nfunction scaleWords(digits: string, scale: Scale, scales: ScaleTable): string {\n const count = scaleCount(digits, scale);\n if (count === '') return '';\n if (count === ONE && scale.exponent === BARE_ONE_EXPONENT) return scale.word;\n return `${numberWords(count, scales, 'count')} ${scale.word}`;\n}\n\nfunction numberWords(significant: string, scales: ScaleTable, role: Role): string {\n const upper = scales.map((scale) => scaleWords(significant, scale, scales)).filter(isNotEmpty);\n const joiner = JOINERS[role];\n const lowest = belowThousandWords({\n value: Number(significant.slice(-BELOW_THOUSAND_DIGITS)),\n role,\n nextJoiner: upper.length > 0 ? joiner : '',\n });\n return [lowest, ...upper].filter(isNotEmpty).join(` ${joiner} `);\n}\n\n/**\n * @internal A whole number in words, groups joined by \"sy\", smallest first.\n *\n * @param digits - Decimal digits; leading zeros are ignored.\n * @param system - `standard` or `traditional` (rule 12).\n * @returns The words: `'2586'` → `'enina amby valopolo sy dimanjato sy roa arivo'`.\n */\nexport function wholeWords(digits: string, system: NumberSystem): string {\n const significant = digits.replace(LEADING_ZEROS, '');\n if (significant === '') return ZERO_WORD;\n return numberWords(significant, scalesFor(significant, system), 'number');\n}\n\n/**\n * @internal A count as {@link wholeWords} writes it before a group word.\n *\n * @param count - The count, from 1, as a bigint.\n * @param system - Whether the group word is a standard or a traditional name.\n * @returns The count's words: `25000n` → `'dimy arivo amby roa alina'`.\n */\nexport function countWords(count: bigint, system: NumberSystem): string {\n const scales = system === 'traditional' ? TRADITIONAL_SCALES : SCALES;\n return numberWords(count.toString(), scales, 'count');\n}\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.10.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 an operator.\n * - `PRECISION_LOSS`: The value is exact in the text but the port's number type cannot hold it exactly; ask for the exact text instead.\n * - `AMBIGUOUS`: The text reads as more than one value, so none is chosen.\n */\nexport type ErrorCode =\n | 'INVALID_TYPE'\n | 'OUT_OF_RANGE'\n | 'INVALID_FORMAT'\n | 'UNKNOWN_OPERATOR'\n | 'PRECISION_LOSS'\n | 'AMBIGUOUS';\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 = safeParsePhone(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 * spell(-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","// Numbers and decimal text, turned into their exact decimal digits.\nimport { MAX_TEXT_LENGTH, MIN_VALUE } from './generated/data.ts';\nimport { MdgError } from './generated/errors.ts';\n\n/** @internal The whole digits, and the decimals or `undefined` for a whole number. */\nexport type DecimalParts = readonly [string, string | undefined];\n\nconst TRAILING_ZEROS = /0+$/;\n// Rule 13: ASCII digits, then optionally a point and more digits. Nothing else.\nconst DECIMAL_TEXT = /^([0-9]+)(?:\\.([0-9]+))?$/;\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.${'0'.repeat(Number(exponent) - 1)}${lead}${rest}`;\n}\n\n/**\n * @internal Rule 13: the parts of plain decimal text, trailing decimal zeros dropped.\n *\n * @param text - Text the caller passed.\n * @param caller - Function name for the error message.\n * @returns The whole digits and the decimals.\n */\nexport function decimalTextParts(text: string, caller: string): DecimalParts {\n const match = text.length <= MAX_TEXT_LENGTH ? DECIMAL_TEXT.exec(text) : null;\n if (match === null) {\n throw new MdgError(\n 'INVALID_FORMAT',\n `${caller} reads digits with an optional .decimals, at most ${String(MAX_TEXT_LENGTH)} characters.`,\n );\n }\n const [, whole = '', decimals = ''] = match;\n const significantDecimals = decimals.replace(TRAILING_ZEROS, '');\n return [whole, significantDecimals === '' ? undefined : significantDecimals];\n}\n\n/**\n * @internal Checks a number is finite and between 0 and `Number.MAX_SAFE_INTEGER`.\n *\n * @param value - The value the caller passed.\n * @param caller - Function name for the error message.\n */\nexport function assertSupportedNumber(value: unknown, caller: string): asserts value is number {\n if (typeof value !== 'number' || !Number.isFinite(value)) {\n throw new MdgError('INVALID_TYPE', `${caller} expects a finite number or decimal text.`);\n }\n if (value < MIN_VALUE || value > Number.MAX_SAFE_INTEGER) {\n throw new MdgError(\n 'OUT_OF_RANGE',\n `${caller} supports ${String(MIN_VALUE)} to ${String(Number.MAX_SAFE_INTEGER)}.`,\n );\n }\n}\n\n/**\n * @internal The exact decimal parts of a number or of decimal text.\n *\n * @param value - A number from 0 to `Number.MAX_SAFE_INTEGER`, or plain decimal text.\n * @param caller - Function name for error messages.\n * @returns The whole digits and the decimals.\n */\nexport function decimalParts(value: unknown, caller: string): DecimalParts {\n if (typeof value === 'string') return decimalTextParts(value, caller);\n assertSupportedNumber(value, caller);\n const [whole = '', decimals] = plainDecimal(value).split('.');\n return [whole, decimals];\n}\n","import { MdgError } from './generated/errors.ts';\n\n/**\n * How large numbers are named: `standard` (default; `telopolo tapitrisa` for 30 000 000) or\n * `traditional`, with one name per power of ten (`telo safatsiroa`).\n *\n * @example\n * ```ts\n * const system: NumberSystem = 'traditional';\n * ```\n */\nexport type NumberSystem = 'standard' | 'traditional';\n\n/**\n * Options for {@link spell} and {@link spellOrdinal}.\n *\n * @example\n * ```ts\n * const options: SpellOptions = { system: 'traditional' };\n * ```\n */\nexport interface SpellOptions {\n /** `standard` (default) or `traditional`. */\n readonly system?: NumberSystem;\n}\n\n/** @internal Both systems, standard first. */\nexport const SYSTEMS: readonly NumberSystem[] = ['standard', 'traditional'];\nconst DEFAULT_SYSTEM: NumberSystem = 'standard';\n\n/**\n * @internal The system the options ask for, after checking them.\n *\n * @param options - The options the caller passed.\n * @returns `standard` or `traditional`.\n */\nexport function systemOf(options: unknown): NumberSystem {\n if (typeof options !== 'object' || options === null) {\n throw new MdgError('INVALID_TYPE', 'spell options must be an object.');\n }\n const { system = DEFAULT_SYSTEM } = options as SpellOptions;\n if (!SYSTEMS.includes(system)) {\n throw new MdgError('INVALID_TYPE', 'system is standard or traditional.');\n }\n return system;\n}\n","import { wholeWords } from './cardinal.ts';\nimport { decimalParts } from './decimal-text.ts';\nimport { DECIMAL_SEPARATOR, ZERO_WORD } from './generated/data.ts';\nimport { systemOf, type NumberSystem, type SpellOptions } from './system.ts';\n\nconst LEADING_ZEROS = /^0+/;\n\n// Each leading zero after the point is \"aotra\"; the rest reads as a whole number.\nfunction decimalWords(digits: string, system: NumberSystem): string {\n const significant = digits.replace(LEADING_ZEROS, '');\n const zeros = Array.from({ length: digits.length - significant.length }, () => ZERO_WORD);\n return [...zeros, wholeWords(significant, system)].join(' ');\n}\n\n/**\n * @internal Words for exact decimal parts, as {@link spell} writes them.\n *\n * @param whole - The whole digits.\n * @param decimals - The decimals without trailing zeros, or `undefined`.\n * @param system - `standard` or `traditional`.\n * @returns The words.\n */\nexport function partsWords(\n whole: string,\n decimals: string | undefined,\n system: NumberSystem,\n): string {\n const wholePart = wholeWords(whole, system);\n if (decimals === undefined) return wholePart;\n return `${wholePart} ${DECIMAL_SEPARATOR} ${decimalWords(decimals, system)}`;\n}\n\n/**\n * Writes a number in Malagasy words, smallest part first, with `faingo` before the decimals.\n * {@link parseWords} reads the words back.\n *\n * @param value - A number from 0 to `Number.MAX_SAFE_INTEGER`, whole or decimal, or plain\n * decimal text such as `'2000000000000000.9'`, read exactly (a number that large has already\n * lost its decimals to floating point).\n * @param options - Optional `system`: `standard` (default) or `traditional`, which names every\n * power of ten (`telo safatsiroa` for 30 000 000).\n * @returns The number in Malagasy words.\n * @throws {@link MdgError} `INVALID_TYPE` if `value` is not a finite number or the options are\n * unknown, `INVALID_FORMAT` for text that is not plain decimal (at most 100 characters),\n * `OUT_OF_RANGE` if a number is negative or above `Number.MAX_SAFE_INTEGER`.\n *\n * @example\n * ```ts\n * spell(21); // 'iraika amby roapolo'\n * spell(2026); // 'enina amby roapolo sy roa arivo'\n * spell(3.14); // \"telo faingo efatra ambin'ny folo\"\n * spell(30_000_000, { system: 'traditional' }); // 'telo safatsiroa'\n * spell('2000000000000000.9'); // 'roa tapitrisa lavitrisa faingo sivy'\n * ```\n */\nexport function spell(value: number | string, options: SpellOptions = {}): string {\n const [whole, decimals] = decimalParts(value, 'spell');\n return partsWords(whole, decimals, systemOf(options));\n}\n","import { wholeWords } from './cardinal.ts';\nimport { decimalParts } from './decimal-text.ts';\nimport {\n ORDINAL_FIRST,\n ORDINAL_PREFIX,\n ORDINAL_PREFIX_BEFORE_VOWEL,\n VOWELS,\n} from './generated/data.ts';\nimport { MdgError } from './generated/errors.ts';\nimport { systemOf, type SpellOptions } from './system.ts';\n\nconst STARTS_WITH_VOWEL: ReadonlySet<string> = new Set(VOWELS);\nconst LEADING_ZEROS = /^0+/;\nconst ONE = '1';\nconst POINT = '.';\n\n// Rule 14: whole digits from 1 up; a point in text or decimals in a number are not ordinals.\nfunction ordinalDigits(value: unknown): string {\n if (typeof value === 'string' && value.includes(POINT)) {\n throw new MdgError('INVALID_FORMAT', 'spellOrdinal reads whole digits, with no point.');\n }\n const [whole, decimals] = decimalParts(value, 'spellOrdinal');\n if (decimals !== undefined) {\n throw new MdgError('INVALID_TYPE', 'spellOrdinal expects a whole number.');\n }\n const significant = whole.replace(LEADING_ZEROS, '');\n if (significant === '') {\n throw new MdgError('OUT_OF_RANGE', 'Ordinals start at 1 (voalohany).');\n }\n return significant;\n}\n\n/**\n * Writes the Malagasy ordinal of a whole number: `faha` before the cardinal words, `fah`\n * before a vowel, and `voalohany` for 1.\n *\n * @param value - A whole number from 1 to `Number.MAX_SAFE_INTEGER`, or digit text such as\n * `'1000000000000000000'`, read exactly.\n * @param options - Optional `system`: `standard` (default) or `traditional`.\n * @returns The ordinal: `3` → `'fahatelo'`.\n * @throws {@link MdgError} `INVALID_TYPE` for a number with decimals, a value that is not a\n * number or text, or unknown options; `INVALID_FORMAT` for text that is not digits;\n * `OUT_OF_RANGE` below 1 or above `Number.MAX_SAFE_INTEGER`.\n *\n * @example\n * ```ts\n * spellOrdinal(1); // 'voalohany'\n * spellOrdinal(3); // 'fahatelo'\n * spellOrdinal(4); // 'fahefatra'\n * spellOrdinal(11); // \"fahiraika ambin'ny folo\"\n * spellOrdinal(1000); // 'faharivo'\n * ```\n */\nexport function spellOrdinal(value: number | string, options: SpellOptions = {}): string {\n const digits = ordinalDigits(value);\n const cardinal = wholeWords(digits, systemOf(options));\n if (digits === ONE) return ORDINAL_FIRST;\n const prefix = STARTS_WITH_VOWEL.has(cardinal.charAt(0))\n ? ORDINAL_PREFIX_BEFORE_VOWEL\n : ORDINAL_PREFIX;\n return `${prefix}${cardinal}`;\n}\n","// Malagasy number words → every exact value they can stand for. parse.ts keeps the values that\n// spell back to the same words; more than one left means the words are ambiguous.\nimport { countWords } from './cardinal.ts';\nimport { SYSTEMS } from './system.ts';\nimport {\n DECIMAL_SEPARATOR,\n HUNDRED_WORDS,\n JOINER_BELOW_THOUSAND,\n JOINER_BETWEEN_GROUPS,\n JOINER_UNITS_BEFORE_TEN,\n SCALES,\n TEN_WORDS,\n TRADITIONAL_SCALES,\n UNIT_ONE_IN_COMPOUND,\n UNIT_WORDS,\n ZERO_WORD,\n} from './generated/data.ts';\n\n/** @internal Readings of words: whole parts, and decimal digits (`undefined` if none). */\nexport interface Readings {\n readonly wholes: readonly bigint[];\n readonly decimals: readonly string[] | undefined;\n}\n\nconst BASE = 10;\n// A phrase alternates a word and a joiner: word, joiner, word, ….\nconst TOKENS_PER_STEP = 2;\nconst TEN = BigInt(BASE);\nconst HUNDRED = BASE * BASE;\n// Readings kept per part: real words have one or two; more only in made-up text.\nconst MAX_READINGS = 8;\nconst PHRASE_JOINERS: ReadonlySet<string> = new Set([\n JOINER_BELOW_THOUSAND,\n JOINER_UNITS_BEFORE_TEN,\n]);\n\nfunction wordValues(words: readonly string[], step: number): [string, number][] {\n return words.flatMap((word, digit) => (word === '' ? [] : [[word, digit * step]]));\n}\n\n// Every word a phrase below 1000 is made of, with its value.\nconst PHRASE_VALUES: ReadonlyMap<string, number> = new Map([\n ...wordValues(UNIT_WORDS, 1),\n [UNIT_ONE_IN_COMPOUND, 1],\n ...wordValues(TEN_WORDS, BASE),\n ...wordValues(HUNDRED_WORDS, HUNDRED),\n]);\n\n// The longest phrase below 1000: \"iraika ambin'ny folo amby zato\" style, three words, two joiners.\nconst MAX_PHRASE_TOKENS = 5;\n\ninterface GroupWord {\n readonly factor: bigint;\n readonly hasPhraseCount: boolean;\n // Most words the smaller part before this group can have: the words of factor − 1.\n readonly maxLeftTokens: number;\n}\n\nfunction groupWord(exponent: number, countDigits: number | null): GroupWord {\n const factor = TEN ** BigInt(exponent);\n const maxLeftTokens = countWords(factor - BigInt(1), 'standard').split(' ').length;\n return { factor, hasPhraseCount: countDigits !== null, maxLeftTokens };\n}\n\n// Group words of both systems: their power of ten, and whether their count is a phrase below\n// 1000 (every group but the largest), which bounds where that count can start. Standard comes\n// last so lavitrisa, in both tables, keeps its count of any size.\nconst GROUP_WORDS: ReadonlyMap<string, GroupWord> = new Map(\n [...TRADITIONAL_SCALES, ...SCALES].map((scale) => [\n scale.word,\n groupWord(scale.exponent, scale.countDigits),\n ]),\n);\n\n// \"valo amby efapolo amby telonjato\": words alternate with amby or ambin'ny.\nfunction readPhrase(tokens: readonly string[]): bigint | undefined {\n let total = 0;\n for (const [index, token] of tokens.entries()) {\n const isJoinerPlace = index % TOKENS_PER_STEP === 1;\n if (isJoinerPlace !== PHRASE_JOINERS.has(token)) return undefined;\n if (!isJoinerPlace) total += PHRASE_VALUES.get(token) ?? Number.NaN;\n }\n return tokens.length % TOKENS_PER_STEP === 1 && !Number.isNaN(total) ? BigInt(total) : undefined;\n}\n\nfunction sums(lefts: Iterable<bigint>, rights: Iterable<bigint>, factor: bigint): bigint[] {\n return [...lefts].flatMap((left) => [...rights].map((right) => left + right * factor));\n}\n\n// Smallest part first: what comes before a group is always smaller than one of that group.\nfunction groupSums(lefts: Iterable<bigint>, counts: Iterable<bigint>, factor: bigint): bigint[] {\n return sums(\n [...lefts].filter((left) => left < factor),\n counts,\n factor,\n );\n}\n\nfunction limited(values: Iterable<bigint>): bigint[] {\n return [...new Set(values)].slice(0, MAX_READINGS);\n}\n\n/** Reads the counts in one list of tokens, remembering each span it has read. */\nclass CountReader {\n private readonly spans = new Map<string, bigint[]>();\n private readonly tokens: readonly string[];\n\n constructor(tokens: readonly string[]) {\n this.tokens = tokens;\n }\n\n /**\n * Counts written exactly as spell writes a count before a group word.\n *\n * @param start - First token of the count.\n * @param end - Token after the count.\n * @returns The counts those tokens spell.\n */\n counts(start: number, end: number): bigint[] {\n const text = this.tokens.slice(start, end).join(' ');\n return this.values(start, end).filter((count) =>\n SYSTEMS.some((system) => countWords(count, system) === text),\n );\n }\n\n // Every value of tokens[start, end): a phrase, or parts joined by amby ending in a group.\n private values(start: number, end: number): bigint[] {\n const key = `${String(start)}:${String(end)}`;\n const known = this.spans.get(key);\n if (known !== undefined) return known;\n const phrase = readPhrase(this.tokens.slice(start, end));\n const found = limited([...(phrase === undefined ? [] : [phrase]), ...this.grouped(start, end)]);\n this.spans.set(key, found);\n return found;\n }\n\n // \"dimy arivo amby roa alina\": whatever comes before an amby, plus a count of the last group.\n private grouped(start: number, end: number): bigint[] {\n const group = GROUP_WORDS.get(String(this.tokens[end - 1]));\n if (group === undefined) return [];\n const first = group.hasPhraseCount ? Math.max(start, end - 1 - MAX_PHRASE_TOKENS) : start;\n const last = Math.min(end - 1, start + group.maxLeftTokens + 1);\n const found: bigint[] = [];\n for (let split = first; split <= last; split += 1) {\n if (split > start && this.tokens[split - 1] !== JOINER_BELOW_THOUSAND) continue;\n const lefts = split === start ? [BigInt(0)] : this.values(start, split - 1);\n const counts = split === end - 1 ? [BigInt(1)] : this.counts(split, end - 1);\n found.push(...groupSums(lefts, counts, group.factor));\n }\n return found;\n }\n}\n\nfunction splitOn(tokens: readonly string[], separator: string): string[][] {\n const parts: string[][] = [[]];\n for (const token of tokens) {\n if (token === separator) parts.push([]);\n else parts[parts.length - 1]?.push(token);\n }\n return parts;\n}\n\n// One group of a whole number: a count and a group word (\"roa arivo\"), or a phrase.\nfunction groupValues(tokens: readonly string[]): bigint[] {\n const factor = GROUP_WORDS.get(String(tokens[tokens.length - 1]))?.factor;\n if (factor === undefined) {\n const phrase = readPhrase(tokens);\n return phrase === undefined ? [] : [phrase];\n }\n const counts =\n tokens.length === 1 ? [BigInt(1)] : new CountReader(tokens).counts(0, tokens.length - 1);\n return counts.map((count) => count * factor);\n}\n\n// A whole number: groups joined by \"sy\", or \"aotra\".\nfunction wholeValues(tokens: readonly string[]): bigint[] {\n if (tokens.length === 1 && tokens[0] === ZERO_WORD) return [BigInt(0)];\n return splitOn(tokens, JOINER_BETWEEN_GROUPS).reduce<bigint[]>(\n (totals, group) => limited(sums(totals, groupValues(group), BigInt(1))),\n [BigInt(0)],\n );\n}\n\n// After \"faingo\": one \"aotra\" per leading zero, then a whole number.\nfunction decimalValues(tokens: readonly string[]): string[] {\n const zeros = tokens.findIndex((token) => token !== ZERO_WORD);\n if (zeros < 0) return [];\n const prefix = '0'.repeat(zeros);\n return wholeValues(tokens.slice(zeros)).map((value) => `${prefix}${value.toString()}`);\n}\n\n/**\n * @internal Every value normalised words can stand for, before checking which ones\n * {@link spell} writes as those words.\n *\n * @param words - Lowercase words separated by single spaces.\n * @returns The candidate whole parts and decimals; empty lists when nothing reads.\n */\nexport function readWords(words: string): Readings {\n const [wholeTokens = [], decimalTokens, ...extra] = splitOn(words.split(' '), DECIMAL_SEPARATOR);\n if (extra.length > 0) return { wholes: [], decimals: undefined };\n return {\n wholes: wholeValues(wholeTokens),\n decimals: decimalTokens === undefined ? undefined : decimalValues(decimalTokens),\n };\n}\n","import { plainDecimal } from './decimal-text.ts';\nimport { MAX_WORDS_LENGTH } from './generated/data.ts';\nimport { MdgError, type ErrorCode, type SafeParseResult } from './generated/errors.ts';\nimport { readWords } from './read-words.ts';\nimport { partsWords } from './spell.ts';\nimport { SYSTEMS } from './system.ts';\n\n/**\n * What {@link parseWords} gives back: a `number` (default), or the exact decimal `text`.\n *\n * @example\n * ```ts\n * const exact: ParseResultKind = 'text';\n * ```\n */\nexport type ParseResultKind = 'number' | 'text';\n\n/**\n * Options for {@link parseWords}.\n *\n * @example\n * ```ts\n * const options: ParseWordsOptions = { as: 'text' };\n * ```\n */\nexport interface ParseWordsOptions {\n /** `number` (default), or `text` for the exact decimal digits of any size. */\n readonly as?: ParseResultKind;\n}\n\n/**\n * The value a reader gives back for a {@link ParseResultKind}: `string` for `text`, otherwise\n * `number`.\n *\n * @example\n * ```ts\n * const digits: ParsedValue<'text'> = '2000';\n * ```\n */\nexport type ParsedValue<Kind extends ParseResultKind> = Kind extends 'text' ? string : number;\n\nconst RESULT_KINDS: ReadonlySet<unknown> = new Set<ParseResultKind>(['number', 'text']);\nconst OPTION_KEYS: ReadonlySet<string> = new Set(['as']);\nconst APOSTROPHES = /[‘’ʼ`´]/g;\nconst SPACES = /\\s+/gu;\n// Older spellings of \"ambin'ny\" (dictionary: \"ambin' ny\"; Assimil: \"amby ny\").\nconst SPLIT_AMBINNY = /\\bambin' ny\\b|\\bamby ny\\b/g;\nconst AMBINNY = \"ambin'ny\";\nconst TRAILING_ZEROS = /0+$/;\n\nfunction failure(code: ErrorCode, message: string): SafeParseResult<never> {\n return { success: false, error: new MdgError(code, message) };\n}\n\nfunction resultKind(options: unknown): ParseResultKind | undefined {\n if (typeof options !== 'object' || options === null) return undefined;\n if (Object.keys(options).some((key) => !OPTION_KEYS.has(key))) return undefined;\n const { as = 'number' } = options as ParseWordsOptions;\n return RESULT_KINDS.has(as) ? as : undefined;\n}\n\n// Case, apostrophes, spacing and older spellings do not change the number.\nfunction normalise(text: string): string {\n return text\n .toLowerCase()\n .replace(APOSTROPHES, \"'\")\n .replace(SPACES, ' ')\n .trim()\n .replace(SPLIT_AMBINNY, AMBINNY);\n}\n\n// Every exact value whose spelling is these words: one, none, or (rarely) more.\nfunction spelledReadings(words: string): string[] {\n const { wholes, decimals } = readWords(words);\n const texts = wholes.flatMap((whole) =>\n (decimals ?? ['']).map((digits) => {\n const significant = digits.replace(TRAILING_ZEROS, '');\n return significant === '' ? whole.toString() : `${whole.toString()}.${significant}`;\n }),\n );\n return [...new Set(texts)].filter((text) => {\n const [whole = '', decimal] = text.split('.');\n return SYSTEMS.some((system) => partsWords(whole, decimal, system) === words);\n });\n}\n\nfunction readExact(words: string): SafeParseResult<string> {\n const readings = spelledReadings(words);\n const [only, ...others] = readings;\n if (only === undefined) {\n return failure('INVALID_FORMAT', 'Expected Malagasy number words, as spell writes them.');\n }\n if (others.length > 0) {\n return failure('AMBIGUOUS', `These words read as ${readings.join(' and as ')}.`);\n }\n return { success: true, data: only };\n}\n\n// A number only when it holds the digits exactly: never a silent rounding.\nfunction asNumber(text: string): SafeParseResult<number> {\n const value = Number(text);\n if (value <= Number.MAX_SAFE_INTEGER && plainDecimal(value) === text) {\n return { success: true, data: value };\n }\n return failure(\n 'PRECISION_LOSS',\n `${text} does not fit a number exactly; pass { as: 'text' } for the exact digits.`,\n );\n}\n\n/**\n * Reads Malagasy number words without throwing.\n *\n * @param text - Words as {@link spell} writes them, in either system, in any case and spacing.\n * @param options - Optional `as`: `number` (default) or `text` for the exact digits.\n * @returns `{ success: true, data }` with the number or text, or `{ success: false, error }`.\n *\n * @example\n * ```ts\n * const result = safeParseWords('roa arivo');\n * if (result.success) result.data; // 2000\n * ```\n */\nexport function safeParseWords(\n text: unknown,\n options: ParseWordsOptions = {},\n): SafeParseResult<number | string> {\n if (typeof text !== 'string') return failure('INVALID_TYPE', 'Expected the words as text.');\n const kind = resultKind(options);\n if (kind === undefined) return failure('INVALID_TYPE', \"as is 'number' or 'text'.\");\n if (text.length > MAX_WORDS_LENGTH) {\n return failure('INVALID_FORMAT', `Words are at most ${String(MAX_WORDS_LENGTH)} characters.`);\n }\n const exact = readExact(normalise(text));\n if (!exact.success || kind === 'text') return exact;\n return asNumber(exact.data);\n}\n\n/**\n * Reads Malagasy number words back into a number: the exact inverse of {@link spell}.\n *\n * @param text - Words as {@link spell} writes them, in either system. Case, spacing, curly\n * apostrophes and the older `ambin' ny` and `amby ny` do not matter.\n * @param options - Optional `as`: `number` (default) or `text` for the exact decimal digits.\n * @returns The number, or its digits as text with `{ as: 'text' }`.\n * @throws {@link MdgError} `INVALID_TYPE` for non-strings or bad options, `INVALID_FORMAT` for\n * anything spell does not write, `AMBIGUOUS` for the rare words that two numbers share (from\n * one million billion up), `PRECISION_LOSS` when a number cannot hold the value exactly.\n *\n * @example\n * ```ts\n * parseWords('valo amby efapolo amby telonjato'); // 348\n * parseWords(\"telo faingo efatra ambin'ny folo\"); // 3.14\n * parseWords('telo safatsiroa'); // 30000000\n * parseWords('iray lavitrisa lavitrisa', { as: 'text' }); // '1000000000000000000'\n * ```\n */\nexport function parseWords<Kind extends ParseResultKind = 'number'>(\n text: string,\n options: { readonly as?: Kind } = {},\n): ParsedValue<Kind> {\n const result = safeParseWords(text, options);\n if (!result.success) throw result.error;\n return result.data as ParsedValue<Kind>;\n}\n\n/**\n * Reads Malagasy number words, or gives `undefined` instead of throwing.\n *\n * @param text - Words as {@link spell} writes them.\n * @param options - Optional `as`: `number` (default) or `text`.\n * @returns The value, or `undefined` when {@link parseWords} would throw.\n *\n * @example\n * ```ts\n * tryParseWords('roa arivo'); // 2000\n * tryParseWords('roa sy arivo sy'); // undefined\n * ```\n */\nexport function tryParseWords(\n text: unknown,\n options: ParseWordsOptions = {},\n): number | string | undefined {\n const result = safeParseWords(text, options);\n return result.success ? result.data : undefined;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/generated/data.ts","../src/cardinal.ts","../src/generated/errors.ts","../src/decimal-text.ts","../src/system.ts","../src/spell.ts","../src/ordinal.ts","../src/read-words.ts","../src/parse.ts"],"names":["LEADING_ZEROS","ONE","BASE","HUNDRED","TRAILING_ZEROS"],"mappings":";AAKO,IAAM,SAAA,GAAY,OAAA;AAGlB,IAAM,UAAA,GAAa;AAAA,EACxB,EAAA;AAAA,EACA,MAAA;AAAA,EACA,KAAA;AAAA,EACA,MAAA;AAAA,EACA,QAAA;AAAA,EACA,MAAA;AAAA,EACA,OAAA;AAAA,EACA,MAAA;AAAA,EACA,MAAA;AAAA,EACA;AACF,CAAA;AAGO,IAAM,oBAAA,GAAuB,QAAA;AAG7B,IAAM,SAAA,GAAY;AAAA,EACvB,EAAA;AAAA,EACA,MAAA;AAAA,EACA,SA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IAAA,GAAO,WAAW,OAAO,CAAA;AAC/B,EAAA,IAAI,IAAA,KAAS,MAAA,EAAW,OAAO,OAAA,CAAQ,gBAAgB,2BAA2B,CAAA;AAClF,EAAA,IAAI,IAAA,CAAK,SAAS,gBAAA,EAAkB;AAClC,IAAA,OAAO,QAAQ,gBAAA,EAAkB,CAAA,kBAAA,EAAqB,MAAA,CAAO,gBAAgB,CAAC,CAAA,YAAA,CAAc,CAAA;AAAA,EAC9F;AACA,EAAA,MAAM,KAAA,GAAQ,SAAA,CAAU,SAAA,CAAU,IAAI,CAAC,CAAA;AACvC,EAAA,IAAI,CAAC,KAAA,CAAM,OAAA,IAAW,IAAA,KAAS,QAAQ,OAAO,KAAA;AAC9C,EAAA,OAAO,QAAA,CAAS,MAAM,IAAI,CAAA;AAC5B;AAoBO,SAAS,UAAA,CACd,IAAA,EACA,OAAA,GAAkC,EAAC,EAChB;AACnB,EAAA,MAAM,MAAA,GAAS,cAAA,CAAe,IAAA,EAAM,OAAO,CAAA;AAC3C,EAAA,IAAI,CAAC,MAAA,CAAO,OAAA,EAAS,MAAM,MAAA,CAAO,KAAA;AAClC,EAAA,OAAO,MAAA,CAAO,IAAA;AAChB;AAeO,SAAS,aAAA,CACd,IAAA,EACA,OAAA,GAA6B,EAAC,EACD;AAC7B,EAAA,MAAM,MAAA,GAAS,cAAA,CAAe,IAAA,EAAM,OAAO,CAAA;AAC3C,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/words/data.yaml, spec 0.11.0.\n\n/** @internal */\nexport const ZERO_WORD = 'aotra' as const;\n\n/** @internal Index = digit; index 0 is unused. */\nexport const UNIT_WORDS = [\n '',\n 'iray',\n 'roa',\n 'telo',\n 'efatra',\n 'dimy',\n 'enina',\n 'fito',\n 'valo',\n 'sivy',\n] as const;\n\n/** @internal */\nexport const UNIT_ONE_IN_COMPOUND = 'iraika' as const;\n\n/** @internal Index = tens digit. */\nexport const TEN_WORDS = [\n '',\n 'folo',\n 'roapolo',\n 'telopolo',\n 'efapolo',\n 'dimampolo',\n 'enimpolo',\n 'fitopolo',\n 'valopolo',\n 'sivifolo',\n] as const;\n\n/** @internal Index = hundreds digit. */\nexport const HUNDRED_WORDS = [\n '',\n 'zato',\n 'roanjato',\n 'telonjato',\n 'efajato',\n 'dimanjato',\n 'eninjato',\n 'fitonjato',\n 'valonjato',\n 'sivinjato',\n] as const;\n\n/** @internal Ascending; countDigits null = no limit. */\nexport const SCALES = [\n { word: 'arivo', exponent: 3, countDigits: 1 },\n { word: 'alina', exponent: 4, countDigits: 1 },\n { word: 'hetsy', exponent: 5, countDigits: 1 },\n { word: 'tapitrisa', exponent: 6, countDigits: 3 },\n { word: 'lavitrisa', exponent: 9, countDigits: null },\n] as const;\n\n/** @internal Rule 12: one name per power of ten, ascending, each taking one digit. */\nexport const TRADITIONAL_SCALES = [\n { word: 'arivo', exponent: 3, countDigits: 1 },\n { word: 'alina', exponent: 4, countDigits: 1 },\n { word: 'hetsy', exponent: 5, countDigits: 1 },\n { word: 'tapitrisa', exponent: 6, countDigits: 1 },\n { word: 'safatsiroa', exponent: 7, countDigits: 1 },\n { word: 'tsitamboisa', exponent: 8, countDigits: 1 },\n { word: 'lavitrisa', exponent: 9, countDigits: 1 },\n { word: 'alinkisa', exponent: 10, countDigits: 1 },\n { word: 'tsipesimpesenina', exponent: 11, countDigits: 1 },\n { word: 'tsitokotsiforohana', exponent: 12, countDigits: 1 },\n { word: 'tsihitanoanoa', exponent: 13, countDigits: 1 },\n { word: 'safatsiroafaharoa', exponent: 14, countDigits: 1 },\n { word: 'tsitamboisafaharoa', exponent: 15, countDigits: 1 },\n { word: 'lavitrisafaharoa', exponent: 16, countDigits: 1 },\n { word: 'alinkisafaharoa', exponent: 17, countDigits: 1 },\n { word: 'tsipesimpeseninafaharoa', exponent: 18, countDigits: 1 },\n] as const;\n\n/** @internal */\nexport const DECIMAL_SEPARATOR = 'faingo' as const;\n\n/** @internal */\nexport const JOINER_UNITS_BEFORE_TEN = \"ambin'ny\" as const;\n\n/** @internal */\nexport const JOINER_BELOW_THOUSAND = 'amby' as const;\n\n/** @internal */\nexport const JOINER_BETWEEN_GROUPS = 'sy' as const;\n\n/** @internal */\nexport const MIN_VALUE = 0 as const;\n\n/** @internal Rule 14: the ordinal of 1. */\nexport const ORDINAL_FIRST = 'voalohany' as const;\n\n/** @internal */\nexport const ORDINAL_PREFIX = 'faha' as const;\n\n/** @internal */\nexport const ORDINAL_PREFIX_BEFORE_VOWEL = 'fah' as const;\n\n/** @internal Letters that take the short ordinal prefix. */\nexport const VOWELS = ['a', 'e', 'i', 'o', 'y'] as const;\n\n/** @internal Longest decimal text read (rule 13). */\nexport const MAX_TEXT_LENGTH = 100 as const;\n\n/** @internal Longest words text read by parseWords. */\nexport const MAX_WORDS_LENGTH = 4096 as const;\n\n/** @internal Most digits parseWords reads per part. */\nexport const MAX_READ_DIGITS = 15 as const;\n","/** Whole numbers in words, from their decimal digits, so counts of any length stay exact. */\nimport {\n HUNDRED_WORDS,\n JOINER_BELOW_THOUSAND,\n JOINER_BETWEEN_GROUPS,\n JOINER_UNITS_BEFORE_TEN,\n SCALES,\n TEN_WORDS,\n TRADITIONAL_SCALES,\n UNIT_ONE_IN_COMPOUND,\n UNIT_WORDS,\n ZERO_WORD,\n} from './generated/data.ts';\nimport type { NumberSystem } from './system.ts';\n\ntype Digit = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;\ntype Scale = (typeof SCALES)[number] | (typeof TRADITIONAL_SCALES)[number];\ntype ScaleTable = readonly Scale[];\n/**\n * A whole number joins its groups with \"sy\" (rule 8); a count before a group word is one\n * phrase, every part joined by \"amby\" (rule 6).\n */\ntype Role = 'number' | 'count';\n\nconst BASE = 10;\nconst HUNDRED = BASE * BASE;\nconst BELOW_THOUSAND_DIGITS = 3;\n/** Rule 7: a count of one is bare only for arivo. */\nconst BARE_ONE_EXPONENT = SCALES[0].exponent;\nconst LEADING_ZEROS = /^0+/;\nconst ONE = '1';\nconst JOINERS: Readonly<Record<Role, string>> = {\n number: JOINER_BETWEEN_GROUPS,\n count: JOINER_BELOW_THOUSAND,\n};\n\nfunction digitAt(value: number, place: number): Digit {\n return (Math.floor(value / place) % BASE) as Digit;\n}\n\nfunction isNotEmpty(word: string): boolean {\n return word !== '';\n}\n\n/** 11–19 join with \"ambin'ny\", other units onto tens with \"amby\". */\nfunction belowHundredWords(unitWord: string, units: Digit, tens: Digit): string {\n if (tens === 1 && units > 0) return `${unitWord} ${JOINER_UNITS_BEFORE_TEN} ${TEN_WORDS[1]}`;\n return [unitWord, TEN_WORDS[tens]].filter(isNotEmpty).join(` ${JOINER_BELOW_THOUSAND} `);\n}\n\n/** The part below 1000, and the joiner that follows it ('' when nothing does). */\ninterface Lowest {\n readonly value: number;\n readonly role: Role;\n readonly nextJoiner: string;\n}\n\n/**\n * Rule 4: the part below 100 joins exactly 100 with \"amby\" and 200–900 with \"sy\"; inside a\n * count every join is \"amby\". \"iraika\" replaces \"iray\" right before \"amby\" or \"ambin'ny\".\n */\nfunction belowThousandWords({ value, role, nextJoiner }: Lowest): string {\n const units = digitAt(value, 1);\n const tens = digitAt(value, BASE);\n const hundreds = digitAt(value, HUNDRED);\n const joiner = role === 'count' || hundreds === 1 ? JOINER_BELOW_THOUSAND : JOINER_BETWEEN_GROUPS;\n const afterUnits = tens > 0 || hundreds > 0 ? joiner : nextJoiner;\n const isOneBeforeAmby = units === 1 && (tens > 0 || afterUnits === JOINER_BELOW_THOUSAND);\n const unitWord = isOneBeforeAmby ? UNIT_ONE_IN_COMPOUND : UNIT_WORDS[units];\n const belowHundred = belowHundredWords(unitWord, units, tens);\n return [belowHundred, HUNDRED_WORDS[hundreds]].filter(isNotEmpty).join(` ${joiner} `);\n}\n\n/** How many digits the traditional names reach: up to the largest name's single digit. */\nconst TRADITIONAL_REACH = TRADITIONAL_SCALES.reduce(\n (most, scale) => Math.max(most, scale.exponent + scale.countDigits),\n 0,\n);\n\n/** Rule 12: a number longer than the traditional names reach is read with the standard scales. */\nfunction scalesFor(digits: string, system: NumberSystem): ScaleTable {\n return system === 'traditional' && digits.length <= TRADITIONAL_REACH\n ? TRADITIONAL_SCALES\n : SCALES;\n}\n\n/** The digits a group counts, without leading zeros: '' when the group is absent. */\nfunction scaleCount(digits: string, scale: Scale): string {\n const end = digits.length - scale.exponent;\n if (end <= 0) return '';\n const start = scale.countDigits === null ? 0 : Math.max(0, end - scale.countDigits);\n return digits.slice(start, end).replace(LEADING_ZEROS, '');\n}\n\nfunction scaleWords(digits: string, scale: Scale, scales: ScaleTable): string {\n const count = scaleCount(digits, scale);\n if (count === '') return '';\n if (count === ONE && scale.exponent === BARE_ONE_EXPONENT) return scale.word;\n return `${numberWords(count, scales, 'count')} ${scale.word}`;\n}\n\nfunction numberWords(significant: string, scales: ScaleTable, role: Role): string {\n const upper = scales.map((scale) => scaleWords(significant, scale, scales)).filter(isNotEmpty);\n const joiner = JOINERS[role];\n const lowest = belowThousandWords({\n value: Number(significant.slice(-BELOW_THOUSAND_DIGITS)),\n role,\n nextJoiner: upper.length > 0 ? joiner : '',\n });\n return [lowest, ...upper].filter(isNotEmpty).join(` ${joiner} `);\n}\n\n/**\n * @internal A whole number in words, groups joined by \"sy\", smallest first.\n *\n * @param digits - Decimal digits; leading zeros are ignored.\n * @param system - `standard` or `traditional` (rule 12).\n * @returns The words: `'2586'` → `'enina amby valopolo sy dimanjato sy roa arivo'`.\n */\nexport function wholeWords(digits: string, system: NumberSystem): string {\n const significant = digits.replace(LEADING_ZEROS, '');\n if (significant === '') return ZERO_WORD;\n return numberWords(significant, scalesFor(significant, system), 'number');\n}\n\n/**\n * @internal A count as {@link wholeWords} writes it before a group word.\n *\n * @param count - The count, from 1, as a bigint.\n * @param system - Whether the group word is a standard or a traditional name.\n * @returns The count's words: `25000n` → `'dimy arivo amby roa alina'`.\n */\nexport function countWords(count: bigint, system: NumberSystem): string {\n const scales = system === 'traditional' ? TRADITIONAL_SCALES : SCALES;\n return numberWords(count.toString(), scales, 'count');\n}\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.11.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 an operator.\n * - `PRECISION_LOSS`: The value is exact in the text but the port's number type cannot hold it exactly; ask for the exact text instead.\n */\nexport type ErrorCode =\n 'INVALID_TYPE' | 'OUT_OF_RANGE' | 'INVALID_FORMAT' | 'UNKNOWN_OPERATOR' | 'PRECISION_LOSS';\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 = safeParsePhone(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 * spell(-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","/** Numbers and decimal text, turned into their exact decimal digits. */\nimport { MAX_TEXT_LENGTH, MIN_VALUE } from './generated/data.ts';\nimport { MdgError } from './generated/errors.ts';\n\n/** @internal The whole digits, and the decimals or `undefined` for a whole number. */\nexport type DecimalParts = readonly [string, string | undefined];\n\nconst TRAILING_ZEROS = /0+$/;\n/** Rule 13: ASCII digits, then optionally a point and more digits. Nothing else. */\nconst DECIMAL_TEXT = /^([0-9]+)(?:\\.([0-9]+))?$/;\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.${'0'.repeat(Number(exponent) - 1)}${lead}${rest}`;\n}\n\n/**\n * @internal Rule 13: the parts of plain decimal text, trailing decimal zeros dropped.\n *\n * @param text - Text the caller passed.\n * @param caller - Function name for the error message.\n * @returns The whole digits and the decimals.\n */\nexport function decimalTextParts(text: string, caller: string): DecimalParts {\n const match = text.length <= MAX_TEXT_LENGTH ? DECIMAL_TEXT.exec(text) : null;\n if (match === null) {\n throw new MdgError(\n 'INVALID_FORMAT',\n `${caller} reads digits with an optional .decimals, at most ${String(MAX_TEXT_LENGTH)} characters.`,\n );\n }\n const [, whole = '', decimals = ''] = match;\n const significantDecimals = decimals.replace(TRAILING_ZEROS, '');\n return [whole, significantDecimals === '' ? undefined : significantDecimals];\n}\n\n/**\n * @internal Checks a number is finite and between 0 and `Number.MAX_SAFE_INTEGER`.\n *\n * @param value - The value the caller passed.\n * @param caller - Function name for the error message.\n */\nexport function assertSupportedNumber(value: unknown, caller: string): asserts value is number {\n if (typeof value !== 'number' || !Number.isFinite(value)) {\n throw new MdgError('INVALID_TYPE', `${caller} expects a finite number or decimal text.`);\n }\n if (value < MIN_VALUE || value > Number.MAX_SAFE_INTEGER) {\n throw new MdgError(\n 'OUT_OF_RANGE',\n `${caller} supports ${String(MIN_VALUE)} to ${String(Number.MAX_SAFE_INTEGER)}.`,\n );\n }\n}\n\n/**\n * @internal The exact decimal parts of a number or of decimal text.\n *\n * @param value - A number from 0 to `Number.MAX_SAFE_INTEGER`, or plain decimal text.\n * @param caller - Function name for error messages.\n * @returns The whole digits and the decimals.\n */\nexport function decimalParts(value: unknown, caller: string): DecimalParts {\n if (typeof value === 'string') return decimalTextParts(value, caller);\n assertSupportedNumber(value, caller);\n const [whole = '', decimals] = plainDecimal(value).split('.');\n return [whole, decimals];\n}\n","import { MdgError } from './generated/errors.ts';\n\n/**\n * How large numbers are named: `standard` (default; `telopolo tapitrisa` for 30 000 000) or\n * `traditional`, with one name per power of ten (`telo safatsiroa`).\n *\n * @example\n * ```ts\n * const system: NumberSystem = 'traditional';\n * ```\n */\nexport type NumberSystem = 'standard' | 'traditional';\n\n/**\n * Options for {@link spell} and {@link spellOrdinal}.\n *\n * @example\n * ```ts\n * const options: SpellOptions = { system: 'traditional' };\n * ```\n */\nexport interface SpellOptions {\n /** `standard` (default) or `traditional`. */\n readonly system?: NumberSystem;\n}\n\n/** @internal Both systems, standard first. */\nexport const SYSTEMS: readonly NumberSystem[] = ['standard', 'traditional'];\nconst DEFAULT_SYSTEM: NumberSystem = 'standard';\n\n/**\n * @internal The system the options ask for, after checking them.\n *\n * @param options - The options the caller passed.\n * @returns `standard` or `traditional`.\n */\nexport function systemOf(options: unknown): NumberSystem {\n if (typeof options !== 'object' || options === null) {\n throw new MdgError('INVALID_TYPE', 'spell options must be an object.');\n }\n const { system = DEFAULT_SYSTEM } = options as SpellOptions;\n if (!SYSTEMS.includes(system)) {\n throw new MdgError('INVALID_TYPE', 'system is standard or traditional.');\n }\n return system;\n}\n","import { wholeWords } from './cardinal.ts';\nimport { decimalParts } from './decimal-text.ts';\nimport { DECIMAL_SEPARATOR, ZERO_WORD } from './generated/data.ts';\nimport { systemOf, type NumberSystem, type SpellOptions } from './system.ts';\n\nconst LEADING_ZEROS = /^0+/;\n\n/** Each leading zero after the point is \"aotra\"; the rest reads as a whole number. */\nfunction decimalWords(digits: string, system: NumberSystem): string {\n const significant = digits.replace(LEADING_ZEROS, '');\n const zeros = Array.from({ length: digits.length - significant.length }, () => ZERO_WORD);\n return [...zeros, wholeWords(significant, system)].join(' ');\n}\n\n/**\n * @internal Words for exact decimal parts, as {@link spell} writes them.\n *\n * @param whole - The whole digits.\n * @param decimals - The decimals without trailing zeros, or `undefined`.\n * @param system - `standard` or `traditional`.\n * @returns The words.\n */\nexport function partsWords(\n whole: string,\n decimals: string | undefined,\n system: NumberSystem,\n): string {\n const wholePart = wholeWords(whole, system);\n if (decimals === undefined) return wholePart;\n return `${wholePart} ${DECIMAL_SEPARATOR} ${decimalWords(decimals, system)}`;\n}\n\n/**\n * Writes a number in Malagasy words, smallest part first, with `faingo` before the decimals.\n * {@link parseWords} reads the words back.\n *\n * @param value - A number from 0 to `Number.MAX_SAFE_INTEGER`, whole or decimal, or plain\n * decimal text such as `'2000000000000000.9'`, read exactly (a number that large has already\n * lost its decimals to floating point).\n * @param options - Optional `system`: `standard` (default) or `traditional`, which names every\n * power of ten (`telo safatsiroa` for 30 000 000).\n * @returns The number in Malagasy words.\n * @throws {@link MdgError} `INVALID_TYPE` if `value` is not a finite number or the options are\n * unknown, `INVALID_FORMAT` for text that is not plain decimal (at most 100 characters),\n * `OUT_OF_RANGE` if a number is negative or above `Number.MAX_SAFE_INTEGER`.\n *\n * @example\n * ```ts\n * spell(21); // 'iraika amby roapolo'\n * spell(2026); // 'enina amby roapolo sy roa arivo'\n * spell(3.14); // \"telo faingo efatra ambin'ny folo\"\n * spell(30_000_000, { system: 'traditional' }); // 'telo safatsiroa'\n * spell('2000000000000000.9'); // 'roa tapitrisa lavitrisa faingo sivy'\n * ```\n */\nexport function spell(value: number | string, options: SpellOptions = {}): string {\n const [whole, decimals] = decimalParts(value, 'spell');\n return partsWords(whole, decimals, systemOf(options));\n}\n","import { wholeWords } from './cardinal.ts';\nimport { decimalParts } from './decimal-text.ts';\nimport {\n ORDINAL_FIRST,\n ORDINAL_PREFIX,\n ORDINAL_PREFIX_BEFORE_VOWEL,\n VOWELS,\n} from './generated/data.ts';\nimport { MdgError } from './generated/errors.ts';\nimport { systemOf, type SpellOptions } from './system.ts';\n\nconst STARTS_WITH_VOWEL: ReadonlySet<string> = new Set(VOWELS);\nconst LEADING_ZEROS = /^0+/;\nconst ONE = '1';\nconst POINT = '.';\n\n/** Rule 14: whole digits from 1 up; a point in text or decimals in a number are not ordinals. */\nfunction ordinalDigits(value: unknown): string {\n if (typeof value === 'string' && value.includes(POINT)) {\n throw new MdgError('INVALID_FORMAT', 'spellOrdinal reads whole digits, with no point.');\n }\n const [whole, decimals] = decimalParts(value, 'spellOrdinal');\n if (decimals !== undefined) {\n throw new MdgError('INVALID_TYPE', 'spellOrdinal expects a whole number.');\n }\n const significant = whole.replace(LEADING_ZEROS, '');\n if (significant === '') {\n throw new MdgError('OUT_OF_RANGE', 'Ordinals start at 1 (voalohany).');\n }\n return significant;\n}\n\n/**\n * Writes the Malagasy ordinal of a whole number: `faha` before the cardinal words, `fah`\n * before a vowel, and `voalohany` for 1.\n *\n * @param value - A whole number from 1 to `Number.MAX_SAFE_INTEGER`, or digit text such as\n * `'1000000000000000000'`, read exactly.\n * @param options - Optional `system`: `standard` (default) or `traditional`.\n * @returns The ordinal: `3` → `'fahatelo'`.\n * @throws {@link MdgError} `INVALID_TYPE` for a number with decimals, a value that is not a\n * number or text, or unknown options; `INVALID_FORMAT` for text that is not digits;\n * `OUT_OF_RANGE` below 1 or above `Number.MAX_SAFE_INTEGER`.\n *\n * @example\n * ```ts\n * spellOrdinal(1); // 'voalohany'\n * spellOrdinal(3); // 'fahatelo'\n * spellOrdinal(4); // 'fahefatra'\n * spellOrdinal(11); // \"fahiraika ambin'ny folo\"\n * spellOrdinal(1000); // 'faharivo'\n * ```\n */\nexport function spellOrdinal(value: number | string, options: SpellOptions = {}): string {\n const digits = ordinalDigits(value);\n const cardinal = wholeWords(digits, systemOf(options));\n if (digits === ONE) return ORDINAL_FIRST;\n const prefix = STARTS_WITH_VOWEL.has(cardinal.charAt(0))\n ? ORDINAL_PREFIX_BEFORE_VOWEL\n : ORDINAL_PREFIX;\n return `${prefix}${cardinal}`;\n}\n","/**\n * Malagasy number words → every exact value they can stand for. parse.ts keeps the values that\n * spell back to the same words.\n */\nimport { countWords } from './cardinal.ts';\nimport { SYSTEMS } from './system.ts';\nimport {\n DECIMAL_SEPARATOR,\n HUNDRED_WORDS,\n JOINER_BELOW_THOUSAND,\n JOINER_BETWEEN_GROUPS,\n JOINER_UNITS_BEFORE_TEN,\n SCALES,\n TEN_WORDS,\n TRADITIONAL_SCALES,\n UNIT_ONE_IN_COMPOUND,\n UNIT_WORDS,\n ZERO_WORD,\n} from './generated/data.ts';\n\n/** @internal Readings of words: whole parts, and decimal digits (`undefined` if none). */\nexport interface Readings {\n readonly wholes: readonly bigint[];\n readonly decimals: readonly string[] | undefined;\n}\n\nconst BASE = 10;\n/** A phrase alternates a word and a joiner: word, joiner, word, …. */\nconst TOKENS_PER_STEP = 2;\nconst TEN = BigInt(BASE);\nconst HUNDRED = BASE * BASE;\n/** Readings kept per part: real words have one or two; more only in made-up text. */\nconst MAX_READINGS = 8;\nconst PHRASE_JOINERS: ReadonlySet<string> = new Set([\n JOINER_BELOW_THOUSAND,\n JOINER_UNITS_BEFORE_TEN,\n]);\n\nfunction wordValues(words: readonly string[], step: number): [string, number][] {\n return words.flatMap((word, digit) => (word === '' ? [] : [[word, digit * step]]));\n}\n\n/** Every word a phrase below 1000 is made of, with its value. */\nconst PHRASE_VALUES: ReadonlyMap<string, number> = new Map([\n ...wordValues(UNIT_WORDS, 1),\n [UNIT_ONE_IN_COMPOUND, 1],\n ...wordValues(TEN_WORDS, BASE),\n ...wordValues(HUNDRED_WORDS, HUNDRED),\n]);\n\n/**\n * The longest phrase below 1000: \"iraika ambin'ny folo amby zato\" style, three words, two joiners.\n */\nconst MAX_PHRASE_TOKENS = 5;\n\ninterface GroupWord {\n readonly factor: bigint;\n readonly hasPhraseCount: boolean;\n /** Most words the smaller part before this group can have: the words of factor − 1. */\n readonly maxLeftTokens: number;\n}\n\nfunction groupWord(exponent: number, countDigits: number | null): GroupWord {\n const factor = TEN ** BigInt(exponent);\n const maxLeftTokens = countWords(factor - BigInt(1), 'standard').split(' ').length;\n return { factor, hasPhraseCount: countDigits !== null, maxLeftTokens };\n}\n\n/**\n * Group words of both systems: their power of ten, and whether their count is a phrase below\n * 1000 (every group but the largest), which bounds where that count can start. Standard comes\n * last so lavitrisa, in both tables, keeps its count of any size.\n */\nconst GROUP_WORDS: ReadonlyMap<string, GroupWord> = new Map(\n [...TRADITIONAL_SCALES, ...SCALES].map((scale) => [\n scale.word,\n groupWord(scale.exponent, scale.countDigits),\n ]),\n);\n\n/** \"valo amby efapolo amby telonjato\": words alternate with amby or ambin'ny. */\nfunction readPhrase(tokens: readonly string[]): bigint | undefined {\n let total = 0;\n for (const [index, token] of tokens.entries()) {\n const isJoinerPlace = index % TOKENS_PER_STEP === 1;\n if (isJoinerPlace !== PHRASE_JOINERS.has(token)) return undefined;\n if (!isJoinerPlace) total += PHRASE_VALUES.get(token) ?? Number.NaN;\n }\n return tokens.length % TOKENS_PER_STEP === 1 && !Number.isNaN(total) ? BigInt(total) : undefined;\n}\n\nfunction sums(lefts: Iterable<bigint>, rights: Iterable<bigint>, factor: bigint): bigint[] {\n return [...lefts].flatMap((left) => [...rights].map((right) => left + right * factor));\n}\n\n/** Smallest part first: what comes before a group is always smaller than one of that group. */\nfunction groupSums(lefts: Iterable<bigint>, counts: Iterable<bigint>, factor: bigint): bigint[] {\n return sums(\n [...lefts].filter((left) => left < factor),\n counts,\n factor,\n );\n}\n\nfunction limited(values: Iterable<bigint>): bigint[] {\n return [...new Set(values)].slice(0, MAX_READINGS);\n}\n\n/** Reads the counts in one list of tokens, remembering each span it has read. */\nclass CountReader {\n private readonly spans = new Map<string, bigint[]>();\n private readonly tokens: readonly string[];\n\n constructor(tokens: readonly string[]) {\n this.tokens = tokens;\n }\n\n /**\n * Counts written exactly as spell writes a count before a group word.\n *\n * @param start - First token of the count.\n * @param end - Token after the count.\n * @returns The counts those tokens spell.\n */\n counts(start: number, end: number): bigint[] {\n const text = this.tokens.slice(start, end).join(' ');\n return this.values(start, end).filter((count) =>\n SYSTEMS.some((system) => countWords(count, system) === text),\n );\n }\n\n /** Every value of tokens[start, end): a phrase, or parts joined by amby ending in a group. */\n private values(start: number, end: number): bigint[] {\n const key = `${String(start)}:${String(end)}`;\n const known = this.spans.get(key);\n if (known !== undefined) return known;\n const phrase = readPhrase(this.tokens.slice(start, end));\n const found = limited([...(phrase === undefined ? [] : [phrase]), ...this.grouped(start, end)]);\n this.spans.set(key, found);\n return found;\n }\n\n /** \"dimy arivo amby roa alina\": whatever comes before an amby, plus a count of the last group. */\n private grouped(start: number, end: number): bigint[] {\n const group = GROUP_WORDS.get(String(this.tokens[end - 1]));\n if (group === undefined) return [];\n const first = group.hasPhraseCount ? Math.max(start, end - 1 - MAX_PHRASE_TOKENS) : start;\n const last = Math.min(end - 1, start + group.maxLeftTokens + 1);\n const found: bigint[] = [];\n for (let split = first; split <= last; split += 1) {\n if (split > start && this.tokens[split - 1] !== JOINER_BELOW_THOUSAND) continue;\n const lefts = split === start ? [BigInt(0)] : this.values(start, split - 1);\n const counts = split === end - 1 ? [BigInt(1)] : this.counts(split, end - 1);\n found.push(...groupSums(lefts, counts, group.factor));\n }\n return found;\n }\n}\n\nfunction splitOn(tokens: readonly string[], separator: string): string[][] {\n const parts: string[][] = [[]];\n for (const token of tokens) {\n if (token === separator) parts.push([]);\n else parts[parts.length - 1]?.push(token);\n }\n return parts;\n}\n\n/** One group of a whole number: a count and a group word (\"roa arivo\"), or a phrase. */\nfunction groupValues(tokens: readonly string[]): bigint[] {\n const factor = GROUP_WORDS.get(String(tokens[tokens.length - 1]))?.factor;\n if (factor === undefined) {\n const phrase = readPhrase(tokens);\n return phrase === undefined ? [] : [phrase];\n }\n const counts =\n tokens.length === 1 ? [BigInt(1)] : new CountReader(tokens).counts(0, tokens.length - 1);\n return counts.map((count) => count * factor);\n}\n\n/** A whole number: groups joined by \"sy\", or \"aotra\". */\nfunction wholeValues(tokens: readonly string[]): bigint[] {\n if (tokens.length === 1 && tokens[0] === ZERO_WORD) return [BigInt(0)];\n return splitOn(tokens, JOINER_BETWEEN_GROUPS).reduce<bigint[]>(\n (totals, group) => limited(sums(totals, groupValues(group), BigInt(1))),\n [BigInt(0)],\n );\n}\n\n/** After \"faingo\": one \"aotra\" per leading zero, then a whole number. */\nfunction decimalValues(tokens: readonly string[]): string[] {\n const zeros = tokens.findIndex((token) => token !== ZERO_WORD);\n if (zeros < 0) return [];\n const prefix = '0'.repeat(zeros);\n return wholeValues(tokens.slice(zeros)).map((value) => `${prefix}${value.toString()}`);\n}\n\n/**\n * @internal Every value normalised words can stand for, before checking which ones\n * {@link spell} writes as those words.\n *\n * @param words - Lowercase words separated by single spaces.\n * @returns The candidate whole parts and decimals; empty lists when nothing reads.\n */\nexport function readWords(words: string): Readings {\n const [wholeTokens = [], decimalTokens, ...extra] = splitOn(words.split(' '), DECIMAL_SEPARATOR);\n if (extra.length > 0) return { wholes: [], decimals: undefined };\n return {\n wholes: wholeValues(wholeTokens),\n decimals: decimalTokens === undefined ? undefined : decimalValues(decimalTokens),\n };\n}\n","import { plainDecimal } from './decimal-text.ts';\nimport { MAX_READ_DIGITS, MAX_WORDS_LENGTH } from './generated/data.ts';\nimport { MdgError, type ErrorCode, type SafeParseResult } from './generated/errors.ts';\nimport { readWords } from './read-words.ts';\nimport { partsWords } from './spell.ts';\nimport { SYSTEMS } from './system.ts';\n\n/**\n * What {@link parseWords} gives back: a `number` (default), or the exact decimal `text`.\n *\n * @example\n * ```ts\n * const exact: ParseResultKind = 'text';\n * ```\n */\nexport type ParseResultKind = 'number' | 'text';\n\n/**\n * Options for {@link parseWords}.\n *\n * @example\n * ```ts\n * const options: ParseWordsOptions = { as: 'text' };\n * ```\n */\nexport interface ParseWordsOptions {\n /** `number` (default), or `text` for the exact decimal digits of any size. */\n readonly as?: ParseResultKind;\n}\n\n/**\n * The value a reader gives back for a {@link ParseResultKind}: `string` for `text`, otherwise\n * `number`.\n *\n * @example\n * ```ts\n * const digits: ParsedValue<'text'> = '2000';\n * ```\n */\nexport type ParsedValue<Kind extends ParseResultKind> = Kind extends 'text' ? string : number;\n\nconst RESULT_KINDS: ReadonlySet<unknown> = new Set<ParseResultKind>(['number', 'text']);\nconst OPTION_KEYS: ReadonlySet<string> = new Set(['as']);\nconst APOSTROPHES = /[‘’ʼ`´]/g;\nconst SPACES = /\\s+/gu;\n/** Older spellings of \"ambin'ny\" (dictionary: \"ambin' ny\"; Assimil: \"amby ny\"). */\nconst SPLIT_AMBINNY = /\\bambin' ny\\b|\\bamby ny\\b/g;\nconst AMBINNY = \"ambin'ny\";\nconst TRAILING_ZEROS = /0+$/;\n\nfunction failure(code: ErrorCode, message: string): SafeParseResult<never> {\n return { success: false, error: new MdgError(code, message) };\n}\n\nfunction resultKind(options: unknown): ParseResultKind | undefined {\n if (typeof options !== 'object' || options === null) return undefined;\n if (Object.keys(options).some((key) => !OPTION_KEYS.has(key))) return undefined;\n const { as = 'number' } = options as ParseWordsOptions;\n return RESULT_KINDS.has(as) ? as : undefined;\n}\n\n/** Case, apostrophes, spacing and older spellings do not change the number. */\nfunction normalise(text: string): string {\n return text\n .toLowerCase()\n .replace(APOSTROPHES, \"'\")\n .replace(SPACES, ' ')\n .trim()\n .replace(SPLIT_AMBINNY, AMBINNY);\n}\n\n/** Every exact value whose spelling is these words: one, none, or (rarely) more. */\nfunction spelledReadings(words: string): string[] {\n const { wholes, decimals } = readWords(words);\n const texts = wholes.flatMap((whole) =>\n (decimals ?? ['']).map((digits) => {\n const significant = digits.replace(TRAILING_ZEROS, '');\n return significant === '' ? whole.toString() : `${whole.toString()}.${significant}`;\n }),\n );\n return [...new Set(texts)].filter((text) => {\n const [whole = '', decimal] = text.split('.');\n return SYSTEMS.some((system) => partsWords(whole, decimal, system) === words);\n });\n}\n\n/** Rule 15: a whole part or decimals longer than this may be written the same for two numbers. */\nfunction isReadable(text: string): boolean {\n return text.split('.').every((part) => part.length <= MAX_READ_DIGITS);\n}\n\nfunction readExact(words: string): SafeParseResult<string> {\n const readings = spelledReadings(words);\n const [only] = readings;\n if (only === undefined) {\n return failure('INVALID_FORMAT', 'Expected Malagasy number words, as spell writes them.');\n }\n if (!readings.every(isReadable)) {\n return failure(\n 'OUT_OF_RANGE',\n `parseWords reads up to ${String(MAX_READ_DIGITS)} digits before and after faingo.`,\n );\n }\n return { success: true, data: only };\n}\n\n/** A number only when it holds the digits exactly: never a silent rounding. */\nfunction asNumber(text: string): SafeParseResult<number> {\n const value = Number(text);\n if (value <= Number.MAX_SAFE_INTEGER && plainDecimal(value) === text) {\n return { success: true, data: value };\n }\n return failure(\n 'PRECISION_LOSS',\n `${text} does not fit a number exactly; pass { as: 'text' } for the exact digits.`,\n );\n}\n\n/**\n * Reads Malagasy number words without throwing.\n *\n * @param text - Words as {@link spell} writes them, in either system, in any case and spacing.\n * @param options - Optional `as`: `number` (default) or `text` for the exact digits.\n * @returns `{ success: true, data }` with the number or text, or `{ success: false, error }`.\n *\n * @example\n * ```ts\n * const result = safeParseWords('roa arivo');\n * if (result.success) result.data; // 2000\n * ```\n */\nexport function safeParseWords(\n text: unknown,\n options: ParseWordsOptions = {},\n): SafeParseResult<number | string> {\n if (typeof text !== 'string') return failure('INVALID_TYPE', 'Expected the words as text.');\n const kind = resultKind(options);\n if (kind === undefined) return failure('INVALID_TYPE', \"as is 'number' or 'text'.\");\n if (text.length > MAX_WORDS_LENGTH) {\n return failure('INVALID_FORMAT', `Words are at most ${String(MAX_WORDS_LENGTH)} characters.`);\n }\n const exact = readExact(normalise(text));\n if (!exact.success || kind === 'text') return exact;\n return asNumber(exact.data);\n}\n\n/**\n * Reads Malagasy number words back into a number: the exact inverse of {@link spell}.\n *\n * @param text - Words as {@link spell} writes them, in either system. Case, spacing, curly\n * apostrophes and the older `ambin' ny` and `amby ny` do not matter.\n * @param options - Optional `as`: `number` (default) or `text` for the exact decimal digits.\n * @returns The number, or its digits as text with `{ as: 'text' }`.\n * @throws {@link MdgError} `INVALID_TYPE` for non-strings or bad options, `INVALID_FORMAT` for\n * anything spell does not write, `OUT_OF_RANGE` above 15 digits, `PRECISION_LOSS` when a number cannot hold the value exactly.\n *\n * @example\n * ```ts\n * parseWords('valo amby efapolo amby telonjato'); // 348\n * parseWords(\"telo faingo efatra ambin'ny folo\"); // 3.14\n * parseWords('telo safatsiroa'); // 30000000\n * parseWords('iray lavitrisa lavitrisa', { as: 'text' }); // '1000000000000000000'\n * ```\n */\nexport function parseWords<Kind extends ParseResultKind = 'number'>(\n text: string,\n options: { readonly as?: Kind } = {},\n): ParsedValue<Kind> {\n const result = safeParseWords(text, options);\n if (!result.success) throw result.error;\n return result.data as ParsedValue<Kind>;\n}\n\n/**\n * Reads Malagasy number words, or gives `undefined` instead of throwing.\n *\n * @param text - Words as {@link spell} writes them.\n * @param options - Optional `as`: `number` (default) or `text`.\n * @returns The value, or `undefined` when {@link parseWords} would throw.\n *\n * @example\n * ```ts\n * tryParseWords('roa arivo'); // 2000\n * tryParseWords('roa sy arivo sy'); // undefined\n * ```\n */\nexport function tryParseWords(\n text: unknown,\n options: ParseWordsOptions = {},\n): number | string | undefined {\n const result = safeParseWords(text, options);\n return result.success ? result.data : undefined;\n}\n"]}
|