diff --git a/TODO.md b/TODO.md new file mode 100644 index 0000000..9ddde2d --- /dev/null +++ b/TODO.md @@ -0,0 +1,11 @@ +- [ ] Improve test case organization +- [ ] Implement stream support (not tested) +- [X] Implement `BigInt` support +- [X] Fully localizable number systems (e.g. custom rules for combining fragments of number words) + - [ ] Reimplement tl-PH +- [ ] Exponential syntax support +- [ ] Optimizations for fractions +- [ ] Check invalid string inputs +- [ ] Ordinals (e.g. `twentieth`, `first`, `two millionth`) + - [ ] Implement other `fractionType`s, implement `lazy` fractions, e.g. `0.05` => `zero point zero five`, + will implement `ratio` (`zero and five over one hundred`) and `part` (`zero and five hundredths`) diff --git a/packages/core/package.json b/packages/core/package.json index bfcf4b9..806d23d 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -16,7 +16,7 @@ "license": "MIT", "keywords": [ "pridepack", - "number" + "number", "name" ], "name": "@theoryofnekomata/numerica", diff --git a/packages/core/src/locales/en-PH/chongo.test.ts b/packages/core/src/locales/en-PH/chongo.test.ts index e6e6905..ac91191 100644 --- a/packages/core/src/locales/en-PH/chongo.test.ts +++ b/packages/core/src/locales/en-PH/chongo.test.ts @@ -119,9 +119,26 @@ describe('Landon\'s original test cases', () => { }) }) - describe('Titanic size numbers (< 1e+3000003', () => { + describe('Titanic size numbers (< 1e+3000003)', () => { it('converts 123456789246801357000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 to one hundred twenty three milliaduoseptuagintillion four hundred fifty six milliaunseptuagintillion seven hundred eighty nine milliaseptuagintillion two hundred forty six millianovemsexagintillion eight hundred one milliaoctosexagintillion three hundred fifty seven milliaseptensexagintillion', () => { expect(getNumberName('123456789246801357000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000')).toBe('one hundred twenty three milliaduoseptuagintillion four hundred fifty six milliaunseptuagintillion seven hundred eighty nine milliaseptuagintillion two hundred forty six millianovemsexagintillion eight hundred one milliaoctosexagintillion three hundred fifty seven milliaseptensexagintillion') }) + + it.each` + value | americanName + ${'1.23456789246801357e+6221'} | ${'one hundred twenty three duomilliaduoseptuagintillion four hundred fifty six duomilliaunseptuagintillion seven hundred eighty nine duomilliaseptuagintillion two hundred forty six duomillianovemsexagintillion eight hundred one duomilliaoctosexagintillion three hundred fifty seven duomilliaseptensexagintillion'} + ${'1.23456789246801357e+2961221'} | ${'one hundred twenty three nongenseptenoctoginmilliaduoseptuagintillion four hundred fifty six nongenseptenoctoginmilliaunseptuagintillion seven hundred eighty nine nongenseptenoctoginmilliaseptuagintillion two hundred forty six nongenseptenoctoginmillianovemsexagintillion eight hundred one nongenseptenoctoginmilliaoctosexagintillion three hundred fifty seven nongenseptenoctoginmilliaseptensexagintillion'} + ${'123.456789246801357e+2961000000219'} | ${'one hundred twenty three nongenseptenoctoginmilliamilliamilliaduoseptuagintillion four hundred fifty six nongenseptenoctoginmilliamilliamilliaunseptuagintillion seven hundred eighty nine nongenseptenoctoginmilliamilliamilliaseptuagintillion two hundred forty six nongenseptenoctoginmilliamilliamillianovemsexagintillion eight hundred one nongenseptenoctoginmilliamilliamilliaoctosexagintillion three hundred fifty seven nongenseptenoctoginmilliamilliamilliaseptensexagintillion'} + ${'1e+3003'} | ${'one milliatillion'} + ${'1e+98025'} | ${'one duotriginmilliasescenquattuorseptuagintillion'} + ${'1e+3000003'} | ${'one milliamilliatillion'} + ${'1e+2570329536'} | ${'one octingensexquinquaginmilliamilliaseptingensexseptuaginmilliaquingenundecillion'} + ${'1e+3000000003'} | ${'one milliamilliamilliatillion'} + ${'1e+1174743648579'} | ${'one trecenunnonaginmilliamilliamilliaquingenunoctoginmilliamilliaduocensexdecmilliacenduononagintillion'} + ${'1e+3000000000003'} | ${'one milliamilliamilliamilliatillion'} + ${'1e+696276510359811'} | ${'one duocenduotriginmilliamilliamilliamilliaduononaginmilliamilliamilliacenseptuaginmilliamilliacennovemdecmillianongensextrigintillion'} + `('converts $value to $americanName', ({ value, americanName }) => { + expect(getNumberName(value)).toBe(americanName) + }) }) }) \ No newline at end of file diff --git a/packages/core/src/utils/numeric.ts b/packages/core/src/utils/numeric.ts index a7db85d..194dd35 100644 --- a/packages/core/src/utils/numeric.ts +++ b/packages/core/src/utils/numeric.ts @@ -19,7 +19,9 @@ export const normalizeNumeric = (x: Numeric): string => { case 'bigint': return x.toString(10) case 'string': - return new BigNumber(x).toString(10) + // TODO assume not all strings follow a correct format + return x + // return new BigNumber(x).toString(10) case 'object': return x.toString(10) default: @@ -40,8 +42,9 @@ export const deconstructNumeric = (x: string) => { } } const [significandStrExp, exponentStr] = absolute.split(EXPONENT_SEPARATOR) + const [integral] = significandStrExp.split(SIGNIFICAND_DECIMAL_POINT) return { - exponent: new BigNumber(exponentStr), + exponent: new BigNumber(exponentStr).plus(integral.length - 1), significandDigits: significandStrExp.replaceAll(SIGNIFICAND_DECIMAL_POINT, '') } }