n2words 3.0.0 → 4.0.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/CHANGELOG.md +59 -0
- package/LICENSE +1 -1
- package/README.md +64 -184
- package/dist/am-ET.js +2 -0
- package/dist/am-ET.umd.js +2 -0
- package/dist/am-Latn-ET.js +2 -0
- package/dist/am-Latn-ET.umd.js +2 -0
- package/dist/ar-SA.js +2 -0
- package/dist/ar-SA.umd.js +2 -0
- package/dist/az-AZ.js +2 -0
- package/dist/az-AZ.umd.js +2 -0
- package/dist/bn-BD.js +2 -0
- package/dist/bn-BD.umd.js +2 -0
- package/dist/cs-CZ.js +2 -0
- package/dist/cs-CZ.umd.js +2 -0
- package/dist/da-DK.js +2 -0
- package/dist/da-DK.umd.js +2 -0
- package/dist/de-DE.js +2 -0
- package/dist/de-DE.umd.js +2 -0
- package/dist/el-GR.js +2 -0
- package/dist/el-GR.umd.js +2 -0
- package/dist/en-AU.js +2 -0
- package/dist/en-AU.umd.js +2 -0
- package/dist/en-BD.js +2 -0
- package/dist/en-BD.umd.js +2 -0
- package/dist/en-CA.js +2 -0
- package/dist/en-CA.umd.js +2 -0
- package/dist/en-GB.js +2 -0
- package/dist/en-GB.umd.js +2 -0
- package/dist/en-GH.js +2 -0
- package/dist/en-GH.umd.js +2 -0
- package/dist/en-IE.js +2 -0
- package/dist/en-IE.umd.js +2 -0
- package/dist/en-IN.js +2 -0
- package/dist/en-IN.umd.js +2 -0
- package/dist/en-KE.js +2 -0
- package/dist/en-KE.umd.js +2 -0
- package/dist/en-MY.js +2 -0
- package/dist/en-MY.umd.js +2 -0
- package/dist/en-NG.js +2 -0
- package/dist/en-NG.umd.js +2 -0
- package/dist/en-NZ.js +2 -0
- package/dist/en-NZ.umd.js +2 -0
- package/dist/en-PH.js +2 -0
- package/dist/en-PH.umd.js +2 -0
- package/dist/en-PK.js +2 -0
- package/dist/en-PK.umd.js +2 -0
- package/dist/en-SG.js +2 -0
- package/dist/en-SG.umd.js +2 -0
- package/dist/en-US.js +2 -0
- package/dist/en-US.umd.js +2 -0
- package/dist/en-ZA.js +2 -0
- package/dist/en-ZA.umd.js +2 -0
- package/dist/es-ES.js +2 -0
- package/dist/es-ES.umd.js +2 -0
- package/dist/es-MX.js +2 -0
- package/dist/es-MX.umd.js +2 -0
- package/dist/es-US.js +2 -0
- package/dist/es-US.umd.js +2 -0
- package/dist/fa-IR.js +2 -0
- package/dist/fa-IR.umd.js +2 -0
- package/dist/fi-FI.js +2 -0
- package/dist/fi-FI.umd.js +2 -0
- package/dist/fil-PH.js +2 -0
- package/dist/fil-PH.umd.js +2 -0
- package/dist/fr-BE.js +2 -0
- package/dist/fr-BE.umd.js +2 -0
- package/dist/fr-FR.js +2 -0
- package/dist/fr-FR.umd.js +2 -0
- package/dist/gu-IN.js +2 -0
- package/dist/gu-IN.umd.js +2 -0
- package/dist/ha-NG.js +2 -0
- package/dist/ha-NG.umd.js +2 -0
- package/dist/hbo-IL.js +2 -0
- package/dist/hbo-IL.umd.js +2 -0
- package/dist/he-IL.js +2 -0
- package/dist/he-IL.umd.js +2 -0
- package/dist/hi-IN.js +2 -0
- package/dist/hi-IN.umd.js +2 -0
- package/dist/hr-HR.js +2 -0
- package/dist/hr-HR.umd.js +2 -0
- package/dist/hu-HU.js +2 -0
- package/dist/hu-HU.umd.js +2 -0
- package/dist/id-ID.js +2 -0
- package/dist/id-ID.umd.js +2 -0
- package/dist/it-IT.js +2 -0
- package/dist/it-IT.umd.js +2 -0
- package/dist/ja-JP.js +2 -0
- package/dist/ja-JP.umd.js +2 -0
- package/dist/ka-GE.js +2 -0
- package/dist/ka-GE.umd.js +2 -0
- package/dist/kn-IN.js +2 -0
- package/dist/kn-IN.umd.js +2 -0
- package/dist/ko-KR.js +2 -0
- package/dist/ko-KR.umd.js +2 -0
- package/dist/lt-LT.js +2 -0
- package/dist/lt-LT.umd.js +2 -0
- package/dist/lv-LV.js +2 -0
- package/dist/lv-LV.umd.js +2 -0
- package/dist/mr-IN.js +2 -0
- package/dist/mr-IN.umd.js +2 -0
- package/dist/ms-MY.js +2 -0
- package/dist/ms-MY.umd.js +2 -0
- package/dist/nb-NO.js +2 -0
- package/dist/nb-NO.umd.js +2 -0
- package/dist/nl-NL.js +2 -0
- package/dist/nl-NL.umd.js +2 -0
- package/dist/pa-IN.js +2 -0
- package/dist/pa-IN.umd.js +2 -0
- package/dist/pl-PL.js +2 -0
- package/dist/pl-PL.umd.js +2 -0
- package/dist/pt-PT.js +2 -0
- package/dist/pt-PT.umd.js +2 -0
- package/dist/ro-RO.js +2 -0
- package/dist/ro-RO.umd.js +2 -0
- package/dist/ru-RU.js +2 -0
- package/dist/ru-RU.umd.js +2 -0
- package/dist/sr-Cyrl-RS.js +2 -0
- package/dist/sr-Cyrl-RS.umd.js +2 -0
- package/dist/sr-Latn-RS.js +2 -0
- package/dist/sr-Latn-RS.umd.js +2 -0
- package/dist/sv-SE.js +2 -0
- package/dist/sv-SE.umd.js +2 -0
- package/dist/sw-KE.js +2 -0
- package/dist/sw-KE.umd.js +2 -0
- package/dist/ta-IN.js +2 -0
- package/dist/ta-IN.umd.js +2 -0
- package/dist/te-IN.js +2 -0
- package/dist/te-IN.umd.js +2 -0
- package/dist/th-TH.js +2 -0
- package/dist/th-TH.umd.js +2 -0
- package/dist/tr-TR.js +2 -0
- package/dist/tr-TR.umd.js +2 -0
- package/dist/uk-UA.js +2 -0
- package/dist/uk-UA.umd.js +2 -0
- package/dist/ur-PK.js +2 -0
- package/dist/ur-PK.umd.js +2 -0
- package/dist/vi-VN.js +2 -0
- package/dist/vi-VN.umd.js +2 -0
- package/dist/yo-NG.js +2 -0
- package/dist/yo-NG.umd.js +2 -0
- package/dist/zh-Hans-CN.js +2 -0
- package/dist/zh-Hans-CN.umd.js +2 -0
- package/dist/zh-Hant-TW.js +2 -0
- package/dist/zh-Hant-TW.umd.js +2 -0
- package/package.json +47 -82
- package/src/am-ET.d.ts +40 -0
- package/src/am-ET.js +269 -0
- package/src/am-Latn-ET.d.ts +35 -0
- package/src/am-Latn-ET.js +264 -0
- package/src/ar-SA.d.ts +49 -0
- package/{lib/languages/ar.js → src/ar-SA.js} +177 -15
- package/src/az-AZ.d.ts +37 -0
- package/src/az-AZ.js +312 -0
- package/src/bn-BD.d.ts +36 -0
- package/src/bn-BD.js +270 -0
- package/src/cs-CZ.d.ts +49 -0
- package/{lib/languages/cs.js → src/cs-CZ.js} +249 -40
- package/src/da-DK.d.ts +44 -0
- package/{lib/languages/da.js → src/da-DK.js} +136 -23
- package/src/de-DE.d.ts +57 -0
- package/src/de-DE.js +603 -0
- package/src/el-GR.d.ts +40 -0
- package/src/el-GR.js +418 -0
- package/src/en-AU.d.ts +47 -0
- package/src/en-AU.js +423 -0
- package/src/en-BD.d.ts +49 -0
- package/src/en-BD.js +415 -0
- package/src/en-CA.d.ts +63 -0
- package/src/en-CA.js +518 -0
- package/src/en-GB.d.ts +56 -0
- package/src/en-GB.js +469 -0
- package/src/en-GH.d.ts +11 -0
- package/src/en-GH.js +345 -0
- package/src/en-IE.d.ts +56 -0
- package/src/en-IE.js +479 -0
- package/src/en-IN.d.ts +49 -0
- package/src/en-IN.js +415 -0
- package/src/en-KE.d.ts +11 -0
- package/src/en-KE.js +345 -0
- package/src/en-MY.d.ts +11 -0
- package/src/en-MY.js +347 -0
- package/src/en-NG.d.ts +56 -0
- package/src/en-NG.js +479 -0
- package/src/en-NZ.d.ts +11 -0
- package/src/en-NZ.js +375 -0
- package/src/en-PH.d.ts +11 -0
- package/src/en-PH.js +345 -0
- package/src/en-PK.d.ts +49 -0
- package/src/en-PK.js +415 -0
- package/src/en-SG.d.ts +11 -0
- package/src/en-SG.js +345 -0
- package/src/en-US.d.ts +63 -0
- package/src/en-US.js +516 -0
- package/src/en-ZA.d.ts +56 -0
- package/src/en-ZA.js +478 -0
- package/src/es-ES.d.ts +65 -0
- package/src/es-ES.js +541 -0
- package/src/es-MX.d.ts +58 -0
- package/{lib/languages/es.js → src/es-MX.js} +237 -47
- package/src/es-US.d.ts +58 -0
- package/src/es-US.js +446 -0
- package/src/fa-IR.d.ts +38 -0
- package/src/fa-IR.js +246 -0
- package/src/fi-FI.d.ts +46 -0
- package/src/fi-FI.js +379 -0
- package/src/fil-PH.d.ts +37 -0
- package/{lib/languages/fil.js → src/fil-PH.js} +149 -24
- package/src/fr-BE.d.ts +49 -0
- package/src/fr-BE.js +453 -0
- package/src/fr-FR.d.ts +63 -0
- package/{lib/languages/fr.js → src/fr-FR.js} +200 -47
- package/src/gu-IN.d.ts +35 -0
- package/src/gu-IN.js +259 -0
- package/src/ha-NG.d.ts +37 -0
- package/{lib/languages/ha.js → src/ha-NG.js} +110 -16
- package/src/hbo-IL.d.ts +39 -0
- package/{lib/languages/hbo.js → src/hbo-IL.js} +217 -43
- package/src/he-IL.d.ts +37 -0
- package/src/he-IL.js +537 -0
- package/src/hi-IN.d.ts +36 -0
- package/src/hi-IN.js +280 -0
- package/src/hr-HR.d.ts +42 -0
- package/src/hr-HR.js +463 -0
- package/src/hu-HU.d.ts +38 -0
- package/{lib/languages/hu.js → src/hu-HU.js} +164 -6
- package/src/id-ID.d.ts +38 -0
- package/{lib/languages/id.js → src/id-ID.js} +106 -20
- package/src/it-IT.d.ts +59 -0
- package/src/it-IT.js +506 -0
- package/src/ja-JP.d.ts +49 -0
- package/{lib/languages/ja.js → src/ja-JP.js} +119 -32
- package/src/ka-GE.d.ts +44 -0
- package/src/ka-GE.js +393 -0
- package/src/kn-IN.d.ts +35 -0
- package/{lib/languages/kn.js → src/kn-IN.js} +156 -34
- package/src/ko-KR.d.ts +45 -0
- package/{lib/languages/ko.js → src/ko-KR.js} +99 -24
- package/src/lt-LT.d.ts +49 -0
- package/src/lt-LT.js +543 -0
- package/src/lv-LV.d.ts +49 -0
- package/src/lv-LV.js +595 -0
- package/src/mr-IN.d.ts +36 -0
- package/src/mr-IN.js +260 -0
- package/src/ms-MY.d.ts +37 -0
- package/{lib/languages/ms.js → src/ms-MY.js} +118 -20
- package/src/nb-NO.d.ts +44 -0
- package/{lib/languages/nb.js → src/nb-NO.js} +165 -33
- package/src/nl-NL.d.ts +54 -0
- package/{lib/languages/nl.js → src/nl-NL.js} +271 -47
- package/src/pa-IN.d.ts +36 -0
- package/src/pa-IN.js +268 -0
- package/src/pl-PL.d.ts +55 -0
- package/src/pl-PL.js +585 -0
- package/src/pt-PT.d.ts +45 -0
- package/src/pt-PT.js +514 -0
- package/src/ro-RO.d.ts +44 -0
- package/{lib/languages/ro.js → src/ro-RO.js} +212 -18
- package/src/ru-RU.d.ts +50 -0
- package/src/ru-RU.js +535 -0
- package/src/sr-Cyrl-RS.d.ts +49 -0
- package/src/sr-Cyrl-RS.js +503 -0
- package/src/sr-Latn-RS.d.ts +49 -0
- package/src/sr-Latn-RS.js +503 -0
- package/src/sv-SE.d.ts +44 -0
- package/{lib/languages/sv.js → src/sv-SE.js} +149 -34
- package/src/sw-KE.d.ts +37 -0
- package/{lib/languages/sw.js → src/sw-KE.js} +117 -6
- package/src/ta-IN.d.ts +35 -0
- package/{lib/languages/ta.js → src/ta-IN.js} +163 -47
- package/src/te-IN.d.ts +35 -0
- package/{lib/languages/te.js → src/te-IN.js} +147 -46
- package/src/th-TH.d.ts +38 -0
- package/{lib/languages/th.js → src/th-TH.js} +99 -6
- package/src/tr-TR.d.ts +48 -0
- package/src/tr-TR.js +397 -0
- package/src/uk-UA.d.ts +42 -0
- package/src/uk-UA.js +463 -0
- package/src/ur-PK.d.ts +36 -0
- package/src/ur-PK.js +268 -0
- package/src/utils/expand-scientific.d.ts +32 -0
- package/src/utils/expand-scientific.js +65 -0
- package/src/utils/parse-cardinal.d.ts +14 -0
- package/{lib/utils/parse-numeric.js → src/utils/parse-cardinal.js} +14 -44
- package/src/utils/parse-currency.d.ts +14 -0
- package/src/utils/parse-currency.js +91 -0
- package/src/utils/parse-ordinal.d.ts +10 -0
- package/src/utils/parse-ordinal.js +103 -0
- package/src/vi-VN.d.ts +48 -0
- package/{lib/languages/vi.js → src/vi-VN.js} +124 -53
- package/src/yo-NG.d.ts +37 -0
- package/src/yo-NG.js +403 -0
- package/src/zh-Hans-CN.d.ts +48 -0
- package/{lib/languages/zh-Hans.js → src/zh-Hans-CN.js} +140 -8
- package/src/zh-Hant-TW.d.ts +50 -0
- package/{lib/languages/zh-Hant.js → src/zh-Hant-TW.js} +139 -8
- package/dist/languages/am-Latn.js +0 -3
- package/dist/languages/am-Latn.js.map +0 -1
- package/dist/languages/am.js +0 -3
- package/dist/languages/am.js.map +0 -1
- package/dist/languages/ar.js +0 -3
- package/dist/languages/ar.js.map +0 -1
- package/dist/languages/az.js +0 -3
- package/dist/languages/az.js.map +0 -1
- package/dist/languages/bn.js +0 -3
- package/dist/languages/bn.js.map +0 -1
- package/dist/languages/cs.js +0 -3
- package/dist/languages/cs.js.map +0 -1
- package/dist/languages/da.js +0 -3
- package/dist/languages/da.js.map +0 -1
- package/dist/languages/de.js +0 -3
- package/dist/languages/de.js.map +0 -1
- package/dist/languages/el.js +0 -3
- package/dist/languages/el.js.map +0 -1
- package/dist/languages/en.js +0 -3
- package/dist/languages/en.js.map +0 -1
- package/dist/languages/es.js +0 -3
- package/dist/languages/es.js.map +0 -1
- package/dist/languages/fa.js +0 -3
- package/dist/languages/fa.js.map +0 -1
- package/dist/languages/fi.js +0 -3
- package/dist/languages/fi.js.map +0 -1
- package/dist/languages/fil.js +0 -3
- package/dist/languages/fil.js.map +0 -1
- package/dist/languages/fr-BE.js +0 -3
- package/dist/languages/fr-BE.js.map +0 -1
- package/dist/languages/fr.js +0 -3
- package/dist/languages/fr.js.map +0 -1
- package/dist/languages/gu.js +0 -3
- package/dist/languages/gu.js.map +0 -1
- package/dist/languages/ha.js +0 -3
- package/dist/languages/ha.js.map +0 -1
- package/dist/languages/hbo.js +0 -3
- package/dist/languages/hbo.js.map +0 -1
- package/dist/languages/he.js +0 -3
- package/dist/languages/he.js.map +0 -1
- package/dist/languages/hi.js +0 -3
- package/dist/languages/hi.js.map +0 -1
- package/dist/languages/hr.js +0 -3
- package/dist/languages/hr.js.map +0 -1
- package/dist/languages/hu.js +0 -3
- package/dist/languages/hu.js.map +0 -1
- package/dist/languages/id.js +0 -3
- package/dist/languages/id.js.map +0 -1
- package/dist/languages/it.js +0 -3
- package/dist/languages/it.js.map +0 -1
- package/dist/languages/ja.js +0 -3
- package/dist/languages/ja.js.map +0 -1
- package/dist/languages/kn.js +0 -3
- package/dist/languages/kn.js.map +0 -1
- package/dist/languages/ko.js +0 -3
- package/dist/languages/ko.js.map +0 -1
- package/dist/languages/lt.js +0 -3
- package/dist/languages/lt.js.map +0 -1
- package/dist/languages/lv.js +0 -3
- package/dist/languages/lv.js.map +0 -1
- package/dist/languages/mr.js +0 -3
- package/dist/languages/mr.js.map +0 -1
- package/dist/languages/ms.js +0 -3
- package/dist/languages/ms.js.map +0 -1
- package/dist/languages/nb.js +0 -3
- package/dist/languages/nb.js.map +0 -1
- package/dist/languages/nl.js +0 -3
- package/dist/languages/nl.js.map +0 -1
- package/dist/languages/pa.js +0 -3
- package/dist/languages/pa.js.map +0 -1
- package/dist/languages/pl.js +0 -3
- package/dist/languages/pl.js.map +0 -1
- package/dist/languages/pt.js +0 -3
- package/dist/languages/pt.js.map +0 -1
- package/dist/languages/ro.js +0 -3
- package/dist/languages/ro.js.map +0 -1
- package/dist/languages/ru.js +0 -3
- package/dist/languages/ru.js.map +0 -1
- package/dist/languages/sr-Cyrl.js +0 -3
- package/dist/languages/sr-Cyrl.js.map +0 -1
- package/dist/languages/sr-Latn.js +0 -3
- package/dist/languages/sr-Latn.js.map +0 -1
- package/dist/languages/sv.js +0 -3
- package/dist/languages/sv.js.map +0 -1
- package/dist/languages/sw.js +0 -3
- package/dist/languages/sw.js.map +0 -1
- package/dist/languages/ta.js +0 -3
- package/dist/languages/ta.js.map +0 -1
- package/dist/languages/te.js +0 -3
- package/dist/languages/te.js.map +0 -1
- package/dist/languages/th.js +0 -3
- package/dist/languages/th.js.map +0 -1
- package/dist/languages/tr.js +0 -3
- package/dist/languages/tr.js.map +0 -1
- package/dist/languages/uk.js +0 -3
- package/dist/languages/uk.js.map +0 -1
- package/dist/languages/ur.js +0 -3
- package/dist/languages/ur.js.map +0 -1
- package/dist/languages/vi.js +0 -3
- package/dist/languages/vi.js.map +0 -1
- package/dist/languages/zh-Hans.js +0 -3
- package/dist/languages/zh-Hans.js.map +0 -1
- package/dist/languages/zh-Hant.js +0 -3
- package/dist/languages/zh-Hant.js.map +0 -1
- package/dist/n2words.js +0 -3
- package/dist/n2words.js.map +0 -1
- package/lib/languages/am-Latn.d.ts +0 -7
- package/lib/languages/am-Latn.js +0 -164
- package/lib/languages/am.d.ts +0 -7
- package/lib/languages/am.js +0 -164
- package/lib/languages/ar.d.ts +0 -17
- package/lib/languages/az.d.ts +0 -7
- package/lib/languages/az.js +0 -176
- package/lib/languages/bn.d.ts +0 -7
- package/lib/languages/bn.js +0 -145
- package/lib/languages/cs.d.ts +0 -18
- package/lib/languages/da.d.ts +0 -14
- package/lib/languages/de.d.ts +0 -17
- package/lib/languages/de.js +0 -332
- package/lib/languages/el.d.ts +0 -14
- package/lib/languages/el.js +0 -243
- package/lib/languages/en.d.ts +0 -17
- package/lib/languages/en.js +0 -256
- package/lib/languages/es.d.ts +0 -21
- package/lib/languages/fa.d.ts +0 -7
- package/lib/languages/fa.js +0 -134
- package/lib/languages/fi.d.ts +0 -14
- package/lib/languages/fi.js +0 -245
- package/lib/languages/fil.d.ts +0 -7
- package/lib/languages/fr-BE.d.ts +0 -11
- package/lib/languages/fr-BE.js +0 -300
- package/lib/languages/fr.d.ts +0 -21
- package/lib/languages/gu.d.ts +0 -7
- package/lib/languages/gu.js +0 -137
- package/lib/languages/ha.d.ts +0 -7
- package/lib/languages/hbo.d.ts +0 -13
- package/lib/languages/he.d.ts +0 -13
- package/lib/languages/he.js +0 -276
- package/lib/languages/hi.d.ts +0 -7
- package/lib/languages/hi.js +0 -145
- package/lib/languages/hr.d.ts +0 -11
- package/lib/languages/hr.js +0 -218
- package/lib/languages/hu.d.ts +0 -7
- package/lib/languages/id.d.ts +0 -7
- package/lib/languages/it.d.ts +0 -19
- package/lib/languages/it.js +0 -377
- package/lib/languages/ja.d.ts +0 -17
- package/lib/languages/kn.d.ts +0 -7
- package/lib/languages/ko.d.ts +0 -14
- package/lib/languages/lt.d.ts +0 -18
- package/lib/languages/lt.js +0 -310
- package/lib/languages/lv.d.ts +0 -18
- package/lib/languages/lv.js +0 -321
- package/lib/languages/mr.d.ts +0 -7
- package/lib/languages/mr.js +0 -137
- package/lib/languages/ms.d.ts +0 -7
- package/lib/languages/nb.d.ts +0 -14
- package/lib/languages/nl.d.ts +0 -26
- package/lib/languages/pa.d.ts +0 -7
- package/lib/languages/pa.js +0 -163
- package/lib/languages/pl.d.ts +0 -22
- package/lib/languages/pl.js +0 -330
- package/lib/languages/pt.d.ts +0 -17
- package/lib/languages/pt.js +0 -306
- package/lib/languages/ro.d.ts +0 -18
- package/lib/languages/ru.d.ts +0 -11
- package/lib/languages/ru.js +0 -240
- package/lib/languages/sr-Cyrl.d.ts +0 -11
- package/lib/languages/sr-Cyrl.js +0 -215
- package/lib/languages/sr-Latn.d.ts +0 -11
- package/lib/languages/sr-Latn.js +0 -215
- package/lib/languages/sv.d.ts +0 -14
- package/lib/languages/sw.d.ts +0 -7
- package/lib/languages/ta.d.ts +0 -7
- package/lib/languages/te.d.ts +0 -7
- package/lib/languages/th.d.ts +0 -7
- package/lib/languages/tr.d.ts +0 -18
- package/lib/languages/tr.js +0 -263
- package/lib/languages/uk.d.ts +0 -11
- package/lib/languages/uk.js +0 -218
- package/lib/languages/ur.d.ts +0 -7
- package/lib/languages/ur.js +0 -163
- package/lib/languages/vi.d.ts +0 -17
- package/lib/languages/zh-Hans.d.ts +0 -11
- package/lib/languages/zh-Hant.d.ts +0 -11
- package/lib/n2words.d.ts +0 -53
- package/lib/n2words.js +0 -122
- package/lib/utils/parse-numeric.d.ts +0 -17
- /package/{lib → src}/utils/is-plain-object.d.ts +0 -0
- /package/{lib → src}/utils/is-plain-object.js +0 -0
- /package/{lib → src}/utils/validate-options.d.ts +0 -0
- /package/{lib → src}/utils/validate-options.js +0 -0
package/src/ur-PK.js
ADDED
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Urdu (Pakistan) language converter
|
|
3
|
+
*
|
|
4
|
+
* CLDR: ur-PK | Urdu as used in Pakistan
|
|
5
|
+
*
|
|
6
|
+
* Key features:
|
|
7
|
+
* - Indian numbering system (ہزار, لاکھ, کروڑ)
|
|
8
|
+
* - Urdu script (right-to-left)
|
|
9
|
+
* - 3-2-2 grouping pattern (last 3 digits, then groups of 2)
|
|
10
|
+
* - Complete word forms for 0-99
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { parseCardinalValue } from './utils/parse-cardinal.js'
|
|
14
|
+
import { parseCurrencyValue } from './utils/parse-currency.js'
|
|
15
|
+
import { parseOrdinalValue } from './utils/parse-ordinal.js'
|
|
16
|
+
|
|
17
|
+
// ============================================================================
|
|
18
|
+
// Vocabulary
|
|
19
|
+
// ============================================================================
|
|
20
|
+
|
|
21
|
+
const ZERO = 'صفر'
|
|
22
|
+
const NEGATIVE = 'منفی'
|
|
23
|
+
const DECIMAL_SEP = 'اعشاریہ'
|
|
24
|
+
const HUNDRED = 'سو'
|
|
25
|
+
|
|
26
|
+
// ============================================================================
|
|
27
|
+
// Ordinal Vocabulary
|
|
28
|
+
// ============================================================================
|
|
29
|
+
|
|
30
|
+
// Ordinal suffix (adds to cardinal)
|
|
31
|
+
const ORDINAL_SUFFIX = 'واں'
|
|
32
|
+
|
|
33
|
+
// Special ordinals for first few numbers
|
|
34
|
+
const ORDINAL_SPECIAL = ['', 'پہلا', 'دوسرا', 'تیسرا', 'چوتھا', 'پانچواں', 'چھٹا']
|
|
35
|
+
|
|
36
|
+
// ============================================================================
|
|
37
|
+
// Currency Vocabulary (Pakistani Rupee)
|
|
38
|
+
// ============================================================================
|
|
39
|
+
|
|
40
|
+
// Rupee: singular/plural (same form used)
|
|
41
|
+
const RUPEE = 'روپیہ'
|
|
42
|
+
const RUPEES = 'روپے'
|
|
43
|
+
|
|
44
|
+
// Paisa: singular/plural
|
|
45
|
+
const PAISA = 'پیسہ'
|
|
46
|
+
const PAISE = 'پیسے'
|
|
47
|
+
|
|
48
|
+
const BELOW_HUNDRED = [
|
|
49
|
+
'صفر', 'ایک', 'دو', 'تین', 'چار', 'پانچ', 'چھ', 'سات', 'آٹھ', 'نو',
|
|
50
|
+
'دس', 'گیارہ', 'بارہ', 'تیرہ', 'چودہ', 'پندرہ', 'سولہ', 'سترہ', 'اٹھارہ', 'انیس',
|
|
51
|
+
'بیس', 'اکیس', 'بائیس', 'تیئیس', 'چوبیس', 'پچیس', 'چھبیس', 'ستائیس', 'اٹھائیس', 'انتیس',
|
|
52
|
+
'تیس', 'اکتیس', 'بتیس', 'تینتیس', 'چونتیس', 'پینتیس', 'چھتیس', 'سینتیس', 'اڑتیس', 'انتالیس',
|
|
53
|
+
'چالیس', 'اکتالیس', 'بیالیس', 'تینتالیس', 'چوالیس', 'پینتالیس', 'چھالیس', 'سینتالیس', 'اڑتالیس', 'انچاس',
|
|
54
|
+
'پچاس', 'اکاون', 'باون', 'ترپن', 'چون', 'پچپن', 'چھپن', 'ستاون', 'اٹھاون', 'انسٹھ',
|
|
55
|
+
'ساٹھ', 'اکسٹھ', 'باسٹھ', 'ترسٹھ', 'چونسٹھ', 'پینسٹھ', 'چھیاسٹھ', 'سڑسٹھ', 'اڑسٹھ', 'انہتر',
|
|
56
|
+
'ستر', 'اکہتر', 'بہتر', 'تہتر', 'چوہتر', 'پچھتر', 'چھہتر', 'ستتر', 'اٹھہتر', 'اناسی',
|
|
57
|
+
'اسی', 'اکیاسی', 'بیاسی', 'تریاسی', 'چوراسی', 'پچاسی', 'چھیاسی', 'ستاسی', 'اٹھاسی', 'نواسی',
|
|
58
|
+
'نوے', 'اکانوے', 'بانوے', 'ترانوے', 'چورانوے', 'پچانوے', 'چھیانوے', 'ستانوے', 'اٹھانوے', 'ننانوے'
|
|
59
|
+
]
|
|
60
|
+
|
|
61
|
+
// Scale words: index 0 = units (empty), 1 = thousand, 2 = lakh, 3 = crore, etc.
|
|
62
|
+
const SCALE_WORDS = ['', 'ہزار', 'لاکھ', 'کروڑ', 'ارب', 'کھرب', 'نیل', 'پدم', 'شنکھ']
|
|
63
|
+
|
|
64
|
+
// ============================================================================
|
|
65
|
+
// Segment Building
|
|
66
|
+
// ============================================================================
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Builds words for a 0-999 segment.
|
|
70
|
+
*/
|
|
71
|
+
function buildSegment (n) {
|
|
72
|
+
if (n === 0) return ''
|
|
73
|
+
if (n < 100) return BELOW_HUNDRED[n]
|
|
74
|
+
|
|
75
|
+
const hundreds = Math.trunc(n / 100)
|
|
76
|
+
const remainder = n % 100
|
|
77
|
+
|
|
78
|
+
if (remainder === 0) {
|
|
79
|
+
return BELOW_HUNDRED[hundreds] + ' ' + HUNDRED
|
|
80
|
+
}
|
|
81
|
+
return BELOW_HUNDRED[hundreds] + ' ' + HUNDRED + ' ' + BELOW_HUNDRED[remainder]
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// ============================================================================
|
|
85
|
+
// Conversion Functions
|
|
86
|
+
// ============================================================================
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Converts a non-negative integer to Urdu words.
|
|
90
|
+
*
|
|
91
|
+
* Uses BigInt modulo for segment extraction (faster than string slicing).
|
|
92
|
+
* South Asian 3-2-2 grouping: first 3 digits, then groups of 2.
|
|
93
|
+
*
|
|
94
|
+
* @param {bigint} n - Non-negative integer to convert
|
|
95
|
+
* @returns {string} Urdu words
|
|
96
|
+
*/
|
|
97
|
+
function integerToWords (n) {
|
|
98
|
+
if (n === 0n) return ZERO
|
|
99
|
+
|
|
100
|
+
// Fast path: numbers < 1000 (direct lookup)
|
|
101
|
+
if (n < 1000n) {
|
|
102
|
+
return buildSegment(Number(n))
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Extract segments using BigInt modulo
|
|
106
|
+
const segments = []
|
|
107
|
+
segments.push(Number(n % 1000n))
|
|
108
|
+
let temp = n / 1000n
|
|
109
|
+
|
|
110
|
+
while (temp > 0n) {
|
|
111
|
+
segments.push(Number(temp % 100n))
|
|
112
|
+
temp = temp / 100n
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Build result string (process from most-significant to least)
|
|
116
|
+
const words = []
|
|
117
|
+
for (let i = segments.length - 1; i >= 0; i--) {
|
|
118
|
+
const segment = segments[i]
|
|
119
|
+
if (segment === 0) continue
|
|
120
|
+
|
|
121
|
+
if (i === 0) {
|
|
122
|
+
words.push(buildSegment(segment))
|
|
123
|
+
} else {
|
|
124
|
+
words.push(BELOW_HUNDRED[segment])
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (i > 0 && SCALE_WORDS[i]) {
|
|
128
|
+
words.push(SCALE_WORDS[i])
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return words.join(' ')
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function decimalPartToWords (decimalPart) {
|
|
136
|
+
let result = ''
|
|
137
|
+
let i = 0
|
|
138
|
+
|
|
139
|
+
while (i < decimalPart.length && decimalPart[i] === '0') {
|
|
140
|
+
if (result) result += ' '
|
|
141
|
+
result += ZERO
|
|
142
|
+
i++
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const remainder = decimalPart.slice(i)
|
|
146
|
+
if (remainder) {
|
|
147
|
+
if (result) result += ' '
|
|
148
|
+
result += integerToWords(BigInt(remainder))
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return result
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Converts a numeric value to Urdu words.
|
|
156
|
+
*
|
|
157
|
+
* @param {number | string | bigint} value - The numeric value to convert
|
|
158
|
+
* @returns {string} The number in Urdu words
|
|
159
|
+
*/
|
|
160
|
+
function toCardinal (value) {
|
|
161
|
+
const { isNegative, integerPart, decimalPart } = parseCardinalValue(value)
|
|
162
|
+
|
|
163
|
+
let result = ''
|
|
164
|
+
|
|
165
|
+
if (isNegative) {
|
|
166
|
+
result = NEGATIVE + ' '
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
result += integerToWords(integerPart)
|
|
170
|
+
|
|
171
|
+
if (decimalPart) {
|
|
172
|
+
result += ' ' + DECIMAL_SEP + ' ' + decimalPartToWords(decimalPart)
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return result
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// ============================================================================
|
|
179
|
+
// ORDINAL: toOrdinal(value)
|
|
180
|
+
// ============================================================================
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Converts a positive integer to Urdu ordinal words.
|
|
184
|
+
*
|
|
185
|
+
* Urdu ordinals: First 6 are irregular, then add -واں suffix.
|
|
186
|
+
*
|
|
187
|
+
* @param {bigint} n - Positive integer to convert
|
|
188
|
+
* @returns {string} Urdu ordinal words
|
|
189
|
+
*/
|
|
190
|
+
function integerToOrdinal (n) {
|
|
191
|
+
// Special ordinals for 1-6
|
|
192
|
+
if (n >= 1n && n <= 6n) {
|
|
193
|
+
return ORDINAL_SPECIAL[Number(n)]
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// For 7 and above, add suffix to cardinal
|
|
197
|
+
const cardinal = integerToWords(n)
|
|
198
|
+
return cardinal + ORDINAL_SUFFIX
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Converts a numeric value to Urdu ordinal words.
|
|
203
|
+
*
|
|
204
|
+
* @param {number | string | bigint} value - The numeric value to convert (positive integer)
|
|
205
|
+
* @returns {string} The number as ordinal words
|
|
206
|
+
* @throws {TypeError} If value is not a valid numeric type
|
|
207
|
+
* @throws {RangeError} If value is negative, zero, or has a decimal part
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* toOrdinal(1) // 'پہلا'
|
|
211
|
+
* toOrdinal(2) // 'دوسرا'
|
|
212
|
+
* toOrdinal(3) // 'تیسرا'
|
|
213
|
+
* toOrdinal(10) // 'دسواں'
|
|
214
|
+
*/
|
|
215
|
+
function toOrdinal (value) {
|
|
216
|
+
const integerPart = parseOrdinalValue(value)
|
|
217
|
+
return integerToOrdinal(integerPart)
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// ============================================================================
|
|
221
|
+
// CURRENCY: toCurrency(value, options?)
|
|
222
|
+
// ============================================================================
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Converts a numeric value to Urdu currency words (Pakistani Rupee).
|
|
226
|
+
*
|
|
227
|
+
* @param {number | string | bigint} value - The currency amount to convert
|
|
228
|
+
* @returns {string} The amount in Urdu currency words
|
|
229
|
+
* @throws {TypeError} If value is not a valid numeric type
|
|
230
|
+
* @throws {Error} If value is not a valid number format
|
|
231
|
+
*
|
|
232
|
+
* @example
|
|
233
|
+
* toCurrency(42.50) // 'بیالیس روپے پچاس پیسے'
|
|
234
|
+
* toCurrency(1) // 'ایک روپیہ'
|
|
235
|
+
* toCurrency(0.01) // 'ایک پیسہ'
|
|
236
|
+
*/
|
|
237
|
+
function toCurrency (value) {
|
|
238
|
+
const { isNegative, dollars: rupees, cents: paise } = parseCurrencyValue(value)
|
|
239
|
+
|
|
240
|
+
// Build result
|
|
241
|
+
let result = ''
|
|
242
|
+
if (isNegative) result = NEGATIVE + ' '
|
|
243
|
+
|
|
244
|
+
// Rupees part - show if non-zero, or if no paise
|
|
245
|
+
if (rupees > 0n || paise === 0n) {
|
|
246
|
+
result += integerToWords(rupees)
|
|
247
|
+
// Singular for 1 rupee, plural otherwise
|
|
248
|
+
result += ' ' + (rupees === 1n ? RUPEE : RUPEES)
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// Paise part
|
|
252
|
+
if (paise > 0n) {
|
|
253
|
+
if (rupees > 0n) {
|
|
254
|
+
result += ' '
|
|
255
|
+
}
|
|
256
|
+
result += integerToWords(paise)
|
|
257
|
+
// Singular for 1 paisa, plural otherwise
|
|
258
|
+
result += ' ' + (paise === 1n ? PAISA : PAISE)
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
return result
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// ============================================================================
|
|
265
|
+
// Exports
|
|
266
|
+
// ============================================================================
|
|
267
|
+
|
|
268
|
+
export { toCardinal, toOrdinal, toCurrency }
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scientific notation expansion utility.
|
|
3
|
+
* Converts scientific notation strings to full decimal form.
|
|
4
|
+
* @module expand-scientific
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Expands scientific notation to full decimal form.
|
|
8
|
+
* Handles arbitrarily large exponents without precision loss.
|
|
9
|
+
*
|
|
10
|
+
* @param {string} str - String in scientific notation (e.g., "1e21", "1.5e-3")
|
|
11
|
+
* @returns {string} Full decimal representation (e.g., "1000000000000000000000", "0.0015")
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* expandScientificNotation("1e21") // "1000000000000000000000"
|
|
15
|
+
* expandScientificNotation("1.5e3") // "1500"
|
|
16
|
+
* expandScientificNotation("1e-3") // "0.001"
|
|
17
|
+
*/
|
|
18
|
+
export function expandScientificNotation(str: string): string;
|
|
19
|
+
/**
|
|
20
|
+
* Converts a number to decimal string, expanding scientific notation if needed.
|
|
21
|
+
*
|
|
22
|
+
* @param {number} value - The number to convert
|
|
23
|
+
* @returns {string} Decimal string representation
|
|
24
|
+
*/
|
|
25
|
+
export function numberToString(value: number): string;
|
|
26
|
+
/**
|
|
27
|
+
* Checks if a string contains scientific notation.
|
|
28
|
+
*
|
|
29
|
+
* @param {string} str - String to check
|
|
30
|
+
* @returns {boolean} True if string contains 'e' or 'E'
|
|
31
|
+
*/
|
|
32
|
+
export function hasScientificNotation(str: string): boolean;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scientific notation expansion utility.
|
|
3
|
+
* Converts scientific notation strings to full decimal form.
|
|
4
|
+
* @module expand-scientific
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Expands scientific notation to full decimal form.
|
|
9
|
+
* Handles arbitrarily large exponents without precision loss.
|
|
10
|
+
*
|
|
11
|
+
* @param {string} str - String in scientific notation (e.g., "1e21", "1.5e-3")
|
|
12
|
+
* @returns {string} Full decimal representation (e.g., "1000000000000000000000", "0.0015")
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* expandScientificNotation("1e21") // "1000000000000000000000"
|
|
16
|
+
* expandScientificNotation("1.5e3") // "1500"
|
|
17
|
+
* expandScientificNotation("1e-3") // "0.001"
|
|
18
|
+
*/
|
|
19
|
+
export function expandScientificNotation (str) {
|
|
20
|
+
let [mantissa, expStr] = str.toLowerCase().split('e')
|
|
21
|
+
const exp = parseInt(expStr, 10)
|
|
22
|
+
|
|
23
|
+
// Strip sign before processing digits
|
|
24
|
+
let sign = ''
|
|
25
|
+
if (mantissa[0] === '-') {
|
|
26
|
+
sign = '-'
|
|
27
|
+
mantissa = mantissa.slice(1)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const dotIndex = mantissa.indexOf('.')
|
|
31
|
+
const digits = dotIndex === -1
|
|
32
|
+
? mantissa
|
|
33
|
+
: mantissa.slice(0, dotIndex) + mantissa.slice(dotIndex + 1)
|
|
34
|
+
const integerLength = dotIndex === -1 ? mantissa.length : dotIndex
|
|
35
|
+
const newDotPosition = integerLength + exp
|
|
36
|
+
|
|
37
|
+
if (newDotPosition >= digits.length) {
|
|
38
|
+
return sign + digits + '0'.repeat(newDotPosition - digits.length)
|
|
39
|
+
} else if (newDotPosition <= 0) {
|
|
40
|
+
return sign + '0.' + '0'.repeat(-newDotPosition) + digits
|
|
41
|
+
} else {
|
|
42
|
+
return sign + digits.slice(0, newDotPosition) + '.' + digits.slice(newDotPosition)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Converts a number to decimal string, expanding scientific notation if needed.
|
|
48
|
+
*
|
|
49
|
+
* @param {number} value - The number to convert
|
|
50
|
+
* @returns {string} Decimal string representation
|
|
51
|
+
*/
|
|
52
|
+
export function numberToString (value) {
|
|
53
|
+
const str = value.toString()
|
|
54
|
+
return hasScientificNotation(str) ? expandScientificNotation(str) : str
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Checks if a string contains scientific notation.
|
|
59
|
+
*
|
|
60
|
+
* @param {string} str - String to check
|
|
61
|
+
* @returns {boolean} True if string contains 'e' or 'E'
|
|
62
|
+
*/
|
|
63
|
+
export function hasScientificNotation (str) {
|
|
64
|
+
return str.includes('e') || str.includes('E')
|
|
65
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parses a value for cardinal conversion.
|
|
3
|
+
* Cardinals accept any numeric value: integers, decimals, negatives.
|
|
4
|
+
*
|
|
5
|
+
* @param {number|string|bigint} value - The value to parse
|
|
6
|
+
* @returns {{isNegative: boolean, integerPart: bigint, decimalPart?: string}}
|
|
7
|
+
* @throws {TypeError} If value is not number, string, or bigint
|
|
8
|
+
* @throws {RangeError} If value is not finite
|
|
9
|
+
*/
|
|
10
|
+
export function parseCardinalValue(value: number | string | bigint): {
|
|
11
|
+
isNegative: boolean;
|
|
12
|
+
integerPart: bigint;
|
|
13
|
+
decimalPart?: string;
|
|
14
|
+
};
|
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Cardinal value parsing utility.
|
|
3
3
|
* Transforms user input (number, string, or bigint) into normalized components.
|
|
4
|
-
*
|
|
4
|
+
* Handles negatives, decimals, and scientific notation.
|
|
5
|
+
* @module parse-cardinal
|
|
5
6
|
*/
|
|
6
7
|
|
|
8
|
+
import { expandScientificNotation, hasScientificNotation, numberToString } from './expand-scientific.js'
|
|
9
|
+
|
|
7
10
|
/**
|
|
8
|
-
* Parses a
|
|
9
|
-
*
|
|
11
|
+
* Parses a value for cardinal conversion.
|
|
12
|
+
* Cardinals accept any numeric value: integers, decimals, negatives.
|
|
13
|
+
*
|
|
14
|
+
* @param {number|string|bigint} value - The value to parse
|
|
10
15
|
* @returns {{isNegative: boolean, integerPart: bigint, decimalPart?: string}}
|
|
11
16
|
* @throws {TypeError} If value is not number, string, or bigint
|
|
12
|
-
* @throws {
|
|
17
|
+
* @throws {RangeError} If value is not finite
|
|
13
18
|
*/
|
|
14
|
-
export function
|
|
19
|
+
export function parseCardinalValue (value) {
|
|
15
20
|
const type = typeof value
|
|
16
21
|
|
|
17
22
|
// BigInt: simplest case
|
|
@@ -24,7 +29,7 @@ export function parseNumericValue (value) {
|
|
|
24
29
|
// Number: fast path for safe integers
|
|
25
30
|
if (type === 'number') {
|
|
26
31
|
if (!Number.isFinite(value)) {
|
|
27
|
-
throw new
|
|
32
|
+
throw new RangeError('Number must be finite (NaN and Infinity are not supported)')
|
|
28
33
|
}
|
|
29
34
|
if (Number.isSafeInteger(value)) {
|
|
30
35
|
return value < 0
|
|
@@ -44,27 +49,15 @@ export function parseNumericValue (value) {
|
|
|
44
49
|
)
|
|
45
50
|
}
|
|
46
51
|
|
|
47
|
-
/**
|
|
48
|
-
* Converts a number to decimal string, expanding scientific notation if needed.
|
|
49
|
-
*/
|
|
50
|
-
function numberToString (value) {
|
|
51
|
-
const str = value.toString()
|
|
52
|
-
return (str.includes('e') || str.includes('E'))
|
|
53
|
-
? expandScientificNotation(str)
|
|
54
|
-
: str
|
|
55
|
-
}
|
|
56
|
-
|
|
57
52
|
/**
|
|
58
53
|
* Validates and normalizes a string numeric input.
|
|
59
54
|
*/
|
|
60
55
|
function normalizeString (value) {
|
|
61
56
|
const trimmed = value.trim()
|
|
62
57
|
if (trimmed.length === 0 || Number.isNaN(Number(trimmed))) {
|
|
63
|
-
throw new
|
|
58
|
+
throw new RangeError(`Invalid number format: "${value}"`)
|
|
64
59
|
}
|
|
65
|
-
return (trimmed
|
|
66
|
-
? expandScientificNotation(trimmed)
|
|
67
|
-
: trimmed
|
|
60
|
+
return hasScientificNotation(trimmed) ? expandScientificNotation(trimmed) : trimmed
|
|
68
61
|
}
|
|
69
62
|
|
|
70
63
|
/**
|
|
@@ -83,26 +76,3 @@ function parseNumericString (str) {
|
|
|
83
76
|
const decimalPart = str.slice(dotIndex + 1)
|
|
84
77
|
return { isNegative, integerPart: BigInt(integerStr), decimalPart }
|
|
85
78
|
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Expands scientific notation to decimal form (e.g., "1e21" → "1000...").
|
|
89
|
-
*/
|
|
90
|
-
function expandScientificNotation (str) {
|
|
91
|
-
const [mantissa, expStr] = str.toLowerCase().split('e')
|
|
92
|
-
const exp = parseInt(expStr, 10)
|
|
93
|
-
|
|
94
|
-
const dotIndex = mantissa.indexOf('.')
|
|
95
|
-
const digits = dotIndex === -1
|
|
96
|
-
? mantissa
|
|
97
|
-
: mantissa.slice(0, dotIndex) + mantissa.slice(dotIndex + 1)
|
|
98
|
-
const integerLength = dotIndex === -1 ? mantissa.length : dotIndex
|
|
99
|
-
const newDotPosition = integerLength + exp
|
|
100
|
-
|
|
101
|
-
if (newDotPosition >= digits.length) {
|
|
102
|
-
return digits + '0'.repeat(newDotPosition - digits.length)
|
|
103
|
-
}
|
|
104
|
-
if (newDotPosition <= 0) {
|
|
105
|
-
return '0.' + '0'.repeat(-newDotPosition) + digits
|
|
106
|
-
}
|
|
107
|
-
return digits.slice(0, newDotPosition) + '.' + digits.slice(newDotPosition)
|
|
108
|
-
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parses a value for currency conversion.
|
|
3
|
+
* Returns dollars and cents as separate bigints, plus negative flag.
|
|
4
|
+
*
|
|
5
|
+
* @param {number|string|bigint} value - The value to parse
|
|
6
|
+
* @returns {{isNegative: boolean, dollars: bigint, cents: bigint}}
|
|
7
|
+
* @throws {TypeError} If value is not number, string, or bigint
|
|
8
|
+
* @throws {RangeError} If value is not finite
|
|
9
|
+
*/
|
|
10
|
+
export function parseCurrencyValue(value: number | string | bigint): {
|
|
11
|
+
isNegative: boolean;
|
|
12
|
+
dollars: bigint;
|
|
13
|
+
cents: bigint;
|
|
14
|
+
};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Currency value parsing utility.
|
|
3
|
+
* Optimized parser for currency conversion - extracts dollars and cents.
|
|
4
|
+
* @module parse-currency
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { expandScientificNotation, hasScientificNotation, numberToString } from './expand-scientific.js'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Parses a value for currency conversion.
|
|
11
|
+
* Returns dollars and cents as separate bigints, plus negative flag.
|
|
12
|
+
*
|
|
13
|
+
* @param {number|string|bigint} value - The value to parse
|
|
14
|
+
* @returns {{isNegative: boolean, dollars: bigint, cents: bigint}}
|
|
15
|
+
* @throws {TypeError} If value is not number, string, or bigint
|
|
16
|
+
* @throws {RangeError} If value is not finite
|
|
17
|
+
*/
|
|
18
|
+
export function parseCurrencyValue (value) {
|
|
19
|
+
const type = typeof value
|
|
20
|
+
|
|
21
|
+
// BigInt: whole dollars only
|
|
22
|
+
if (type === 'bigint') {
|
|
23
|
+
return value < 0n
|
|
24
|
+
? { isNegative: true, dollars: -value, cents: 0n }
|
|
25
|
+
: { isNegative: false, dollars: value, cents: 0n }
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Number: fast path for safe integers
|
|
29
|
+
if (type === 'number') {
|
|
30
|
+
if (!Number.isFinite(value)) {
|
|
31
|
+
throw new RangeError('Currency must be a finite number')
|
|
32
|
+
}
|
|
33
|
+
if (Number.isSafeInteger(value)) {
|
|
34
|
+
return value < 0
|
|
35
|
+
? { isNegative: true, dollars: BigInt(-value), cents: 0n }
|
|
36
|
+
: { isNegative: false, dollars: BigInt(value), cents: 0n }
|
|
37
|
+
}
|
|
38
|
+
// Non-integer or unsafe: convert to string
|
|
39
|
+
return parseCurrencyString(numberToString(value))
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// String input
|
|
43
|
+
if (type === 'string') {
|
|
44
|
+
return parseCurrencyString(value)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
throw new TypeError(
|
|
48
|
+
`Invalid value type: expected number, string, or bigint, received ${type}`
|
|
49
|
+
)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Parses a string for currency conversion.
|
|
54
|
+
*
|
|
55
|
+
* @param {string} value - The string to parse
|
|
56
|
+
* @returns {{isNegative: boolean, dollars: bigint, cents: bigint}}
|
|
57
|
+
*/
|
|
58
|
+
function parseCurrencyString (value) {
|
|
59
|
+
let str = value.trim()
|
|
60
|
+
|
|
61
|
+
if (str.length === 0 || Number.isNaN(Number(str))) {
|
|
62
|
+
throw new RangeError(`Invalid currency format: "${value}"`)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Expand scientific notation
|
|
66
|
+
if (hasScientificNotation(str)) {
|
|
67
|
+
str = expandScientificNotation(str)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Handle negative
|
|
71
|
+
const isNegative = str[0] === '-'
|
|
72
|
+
if (isNegative) str = str.slice(1)
|
|
73
|
+
|
|
74
|
+
// Split on decimal
|
|
75
|
+
const dotIndex = str.indexOf('.')
|
|
76
|
+
if (dotIndex === -1) {
|
|
77
|
+
return { isNegative, dollars: BigInt(str), cents: 0n }
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const dollarStr = str.slice(0, dotIndex) || '0'
|
|
81
|
+
const decimalPart = str.slice(dotIndex + 1)
|
|
82
|
+
|
|
83
|
+
// Truncate to 2 decimal places and pad if needed
|
|
84
|
+
const centStr = (decimalPart + '00').slice(0, 2)
|
|
85
|
+
|
|
86
|
+
return {
|
|
87
|
+
isNegative,
|
|
88
|
+
dollars: BigInt(dollarStr),
|
|
89
|
+
cents: BigInt(centStr)
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parses a value for ordinal conversion.
|
|
3
|
+
* Ordinals require positive integers only (no zero, negatives, or decimals).
|
|
4
|
+
*
|
|
5
|
+
* @param {number|string|bigint} value - The value to parse
|
|
6
|
+
* @returns {bigint} The positive integer value
|
|
7
|
+
* @throws {TypeError} If value is not number, string, or bigint
|
|
8
|
+
* @throws {RangeError} If value is zero, negative, or has a decimal part
|
|
9
|
+
*/
|
|
10
|
+
export function parseOrdinalValue(value: number | string | bigint): bigint;
|