From 7a890bbeeff447b337b44782c3a39dad53f96220 Mon Sep 17 00:00:00 2001 From: TheoryOfNekomata Date: Thu, 29 Jul 2021 13:45:29 +0800 Subject: [PATCH] Trim input, update TODO The inputs are now trimmed before conversion. The TODO items are updated for possible correct formats. --- TODO.md | 13 +++++++++++++ packages/core/src/utils/numeric.ts | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/TODO.md b/TODO.md index 8ec7a7a..cde2412 100644 --- a/TODO.md +++ b/TODO.md @@ -9,3 +9,16 @@ - [X] 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`) +- [ ] Special names? (e.g. `googol` for `1e+100`) + +Some inputs to consider: + +1. `1/2` converts to `one half`. When only `lazy` is enabled, it converts to `one over two`. +2. `5/10` or `0.5` or `.5` (on en-US or en-PH) converts to `five tenths`. When `simplify` is `true`, it converts to + `one half`. When only `lazy` is enabled, it converts to `five over ten`. +3. `1e-2` converts to `one hundredth`. It follows by `one thousandth`, `one millionth`, `one billionth`, `one trillionth` etc. +4. `2/1e+2` converts to `two hundredths`. `2/2e+2` converts to `two two-hundredths`. +5. Should we enable `1e+(1e+100)` inputs? "googolplex" + 1. Should we enable `1e+1/10`? + 2. Should we enable `1e+1/1e+2`? + 3. Should we enable `1e+(1e+1)/10`? diff --git a/packages/core/src/utils/numeric.ts b/packages/core/src/utils/numeric.ts index 869cf62..27f34f5 100644 --- a/packages/core/src/utils/numeric.ts +++ b/packages/core/src/utils/numeric.ts @@ -20,7 +20,7 @@ export const normalizeNumeric = (x: Numeric): string => { return x.toString(10); case 'string': // TODO assume not all strings follow a correct format - return x; + return x.trim(); // return new BigNumber(x).toString(10) case 'object': return x.toString(10);