n2words 3.1.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 +44 -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/{lib/languages/bn.js → src/bn-BD.js} +110 -6
- package/src/cs-CZ.d.ts +49 -0
- package/{lib/languages/cs.js → src/cs-CZ.js} +240 -14
- package/src/da-DK.d.ts +44 -0
- package/{lib/languages/da.js → src/da-DK.js} +131 -11
- 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/{lib/languages/en.js → src/en-NZ.js} +164 -31
- 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} +228 -18
- 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/{lib/languages/fi.js → src/fi-FI.js} +152 -11
- package/src/fil-PH.d.ts +37 -0
- package/{lib/languages/fil.js → src/fil-PH.js} +144 -8
- package/src/fr-BE.d.ts +49 -0
- package/{lib/languages → src}/fr-BE.js +175 -13
- package/src/fr-FR.d.ts +63 -0
- package/{lib/languages/fr.js → src/fr-FR.js} +182 -16
- package/src/gu-IN.d.ts +35 -0
- package/{lib/languages/gu.js → src/gu-IN.js} +115 -6
- package/src/ha-NG.d.ts +37 -0
- package/{lib/languages/ha.js → src/ha-NG.js} +107 -8
- package/src/hbo-IL.d.ts +39 -0
- package/{lib/languages/hbo.js → src/hbo-IL.js} +211 -19
- package/src/he-IL.d.ts +37 -0
- package/src/he-IL.js +537 -0
- package/src/hi-IN.d.ts +36 -0
- package/{lib/languages/hi.js → src/hi-IN.js} +116 -6
- 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} +99 -8
- package/src/it-IT.d.ts +59 -0
- package/{lib/languages/it.js → src/it-IT.js} +179 -15
- package/src/ja-JP.d.ts +49 -0
- package/{lib/languages/ja.js → src/ja-JP.js} +111 -12
- package/src/ka-GE.d.ts +44 -0
- package/{lib/languages/ka.js → src/ka-GE.js} +113 -11
- package/src/kn-IN.d.ts +35 -0
- package/{lib/languages/kn.js → src/kn-IN.js} +115 -6
- package/src/ko-KR.d.ts +45 -0
- package/{lib/languages/ko.js → src/ko-KR.js} +94 -12
- 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/{lib/languages/mr.js → src/mr-IN.js} +116 -6
- package/src/ms-MY.d.ts +37 -0
- package/{lib/languages/ms.js → src/ms-MY.js} +111 -8
- package/src/nb-NO.d.ts +44 -0
- package/{lib/languages/nb.js → src/nb-NO.js} +153 -11
- package/src/nl-NL.d.ts +54 -0
- package/{lib/languages/nl.js → src/nl-NL.js} +260 -18
- package/src/pa-IN.d.ts +36 -0
- package/{lib/languages/pa.js → src/pa-IN.js} +116 -6
- package/src/pl-PL.d.ts +55 -0
- package/src/pl-PL.js +585 -0
- package/src/pt-PT.d.ts +45 -0
- package/{lib/languages/pt.js → src/pt-PT.js} +234 -12
- 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} +136 -11
- 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} +109 -6
- package/src/te-IN.d.ts +35 -0
- package/{lib/languages/te.js → src/te-IN.js} +115 -6
- 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/{lib/languages/tr.js → src/tr-TR.js} +168 -23
- package/src/uk-UA.d.ts +42 -0
- package/src/uk-UA.js +463 -0
- package/src/ur-PK.d.ts +36 -0
- package/{lib/languages/ur.js → src/ur-PK.js} +116 -6
- 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} +102 -11
- package/src/yo-NG.d.ts +37 -0
- package/{lib/languages/yo.js → src/yo-NG.js} +109 -9
- 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/ka.js +0 -3
- package/dist/languages/ka.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/yo.js +0 -3
- package/dist/languages/yo.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 -159
- package/lib/languages/am.d.ts +0 -7
- package/lib/languages/am.js +0 -159
- package/lib/languages/ar.d.ts +0 -17
- package/lib/languages/az.d.ts +0 -7
- package/lib/languages/az.js +0 -171
- package/lib/languages/bn.d.ts +0 -7
- 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 -320
- package/lib/languages/el.d.ts +0 -14
- package/lib/languages/el.js +0 -236
- package/lib/languages/en.d.ts +0 -17
- 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/fil.d.ts +0 -7
- package/lib/languages/fr-BE.d.ts +0 -11
- package/lib/languages/fr.d.ts +0 -21
- package/lib/languages/gu.d.ts +0 -7
- 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 -265
- package/lib/languages/hi.d.ts +0 -7
- package/lib/languages/hr.d.ts +0 -11
- package/lib/languages/hr.js +0 -224
- 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/ja.d.ts +0 -17
- package/lib/languages/ka.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 -301
- package/lib/languages/lv.d.ts +0 -18
- package/lib/languages/lv.js +0 -312
- package/lib/languages/mr.d.ts +0 -7
- 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/pl.d.ts +0 -22
- package/lib/languages/pl.js +0 -317
- package/lib/languages/pt.d.ts +0 -17
- package/lib/languages/ro.d.ts +0 -18
- package/lib/languages/ru.d.ts +0 -11
- package/lib/languages/ru.js +0 -245
- package/lib/languages/sr-Cyrl.d.ts +0 -11
- package/lib/languages/sr-Cyrl.js +0 -221
- package/lib/languages/sr-Latn.d.ts +0 -11
- package/lib/languages/sr-Latn.js +0 -221
- 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/uk.d.ts +0 -11
- package/lib/languages/uk.js +0 -224
- package/lib/languages/ur.d.ts +0 -7
- package/lib/languages/vi.d.ts +0 -17
- package/lib/languages/yo.d.ts +0 -7
- package/lib/languages/zh-Hans.d.ts +0 -11
- package/lib/languages/zh-Hant.d.ts +0 -11
- package/lib/n2words.d.ts +0 -55
- package/lib/n2words.js +0 -126
- 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/en-US.js
ADDED
|
@@ -0,0 +1,516 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* American English language converter
|
|
3
|
+
*
|
|
4
|
+
* CLDR: en-US | English as used in the United States
|
|
5
|
+
*
|
|
6
|
+
* Exports:
|
|
7
|
+
* - toCardinal(value, options?) - Cardinal numbers: 42 → "forty-two"
|
|
8
|
+
* - toOrdinal(value) - Ordinal numbers: 42 → "forty-second"
|
|
9
|
+
* - toCurrency(value, options?) - Currency: 42.50 → "forty-two dollars and fifty cents"
|
|
10
|
+
*
|
|
11
|
+
* American English conventions:
|
|
12
|
+
* - No "and" after hundreds: "one hundred twenty-three" (default)
|
|
13
|
+
* - No "and" before final segment: "one million one" (default)
|
|
14
|
+
* - Hyphenated tens-ones: "twenty-one", "forty-two"
|
|
15
|
+
* - Western numbering system (short scale: billion = 10^9)
|
|
16
|
+
* - Optional hundred-pairing: 1500 → "fifteen hundred" (colloquial)
|
|
17
|
+
* - Optional "and" insertion: 101 → "one hundred and one" (informal)
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { parseCardinalValue } from './utils/parse-cardinal.js'
|
|
21
|
+
import { parseCurrencyValue } from './utils/parse-currency.js'
|
|
22
|
+
import { parseOrdinalValue } from './utils/parse-ordinal.js'
|
|
23
|
+
import { validateOptions } from './utils/validate-options.js'
|
|
24
|
+
|
|
25
|
+
// ============================================================================
|
|
26
|
+
// VOCABULARY
|
|
27
|
+
// ============================================================================
|
|
28
|
+
|
|
29
|
+
// Cardinal vocabulary
|
|
30
|
+
const ONES = ['', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']
|
|
31
|
+
const TEENS = ['ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen']
|
|
32
|
+
const TENS = ['', '', 'twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety']
|
|
33
|
+
const SCALES = [
|
|
34
|
+
'thousand', 'million', 'billion', 'trillion', 'quadrillion',
|
|
35
|
+
'quintillion', 'sextillion', 'septillion', 'octillion', 'nonillion',
|
|
36
|
+
'decillion', 'undecillion', 'duodecillion', 'tredecillion', 'quattuordecillion',
|
|
37
|
+
'quindecillion', 'sexdecillion', 'septendecillion', 'octodecillion', 'novemdecillion',
|
|
38
|
+
'vigintillion'
|
|
39
|
+
]
|
|
40
|
+
const HUNDRED = 'hundred'
|
|
41
|
+
const ZERO = 'zero'
|
|
42
|
+
const NEGATIVE = 'minus'
|
|
43
|
+
const DECIMAL_SEP = 'point'
|
|
44
|
+
|
|
45
|
+
// Ordinal vocabulary
|
|
46
|
+
const ORDINAL_ONES = ['', 'first', 'second', 'third', 'fourth', 'fifth', 'sixth', 'seventh', 'eighth', 'ninth']
|
|
47
|
+
const ORDINAL_TEENS = ['tenth', 'eleventh', 'twelfth', 'thirteenth', 'fourteenth', 'fifteenth', 'sixteenth', 'seventeenth', 'eighteenth', 'nineteenth']
|
|
48
|
+
const ORDINAL_TENS = ['', '', 'twentieth', 'thirtieth', 'fortieth', 'fiftieth', 'sixtieth', 'seventieth', 'eightieth', 'ninetieth']
|
|
49
|
+
|
|
50
|
+
// Currency vocabulary
|
|
51
|
+
const DOLLAR = 'dollar'
|
|
52
|
+
const DOLLARS = 'dollars'
|
|
53
|
+
const CENT = 'cent'
|
|
54
|
+
const CENTS = 'cents'
|
|
55
|
+
|
|
56
|
+
// ============================================================================
|
|
57
|
+
// SHARED HELPERS
|
|
58
|
+
// ============================================================================
|
|
59
|
+
|
|
60
|
+
// Reusable result object to avoid allocation per call
|
|
61
|
+
const segmentResult = { word: '', hasHundred: false }
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Builds words for a 0-999 segment.
|
|
65
|
+
*
|
|
66
|
+
* @param {number} n - Number 0-999
|
|
67
|
+
* @param {boolean} useAnd - Whether to use "and" after hundreds
|
|
68
|
+
* @returns {{ word: string, hasHundred: boolean }}
|
|
69
|
+
*/
|
|
70
|
+
function buildSegment (n, useAnd) {
|
|
71
|
+
if (n === 0) {
|
|
72
|
+
segmentResult.word = ''
|
|
73
|
+
segmentResult.hasHundred = false
|
|
74
|
+
return segmentResult
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const ones = n % 10
|
|
78
|
+
const tens = Math.trunc(n / 10) % 10
|
|
79
|
+
const hundreds = Math.trunc(n / 100)
|
|
80
|
+
|
|
81
|
+
// Build tens-ones part first
|
|
82
|
+
let tensOnes = ''
|
|
83
|
+
if (tens === 1) {
|
|
84
|
+
tensOnes = TEENS[ones]
|
|
85
|
+
} else if (tens >= 2) {
|
|
86
|
+
tensOnes = ones > 0 ? TENS[tens] + '-' + ONES[ones] : TENS[tens]
|
|
87
|
+
} else if (ones > 0) {
|
|
88
|
+
tensOnes = ONES[ones]
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Hundreds place
|
|
92
|
+
if (hundreds > 0) {
|
|
93
|
+
if (tensOnes) {
|
|
94
|
+
const connector = useAnd ? ' and ' : ' '
|
|
95
|
+
segmentResult.word = ONES[hundreds] + ' ' + HUNDRED + connector + tensOnes
|
|
96
|
+
} else {
|
|
97
|
+
segmentResult.word = ONES[hundreds] + ' ' + HUNDRED
|
|
98
|
+
}
|
|
99
|
+
segmentResult.hasHundred = true
|
|
100
|
+
} else {
|
|
101
|
+
segmentResult.word = tensOnes
|
|
102
|
+
segmentResult.hasHundred = false
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return segmentResult
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// ============================================================================
|
|
109
|
+
// CARDINAL: toCardinal(value, options?)
|
|
110
|
+
// ============================================================================
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Converts a non-negative integer to English words.
|
|
114
|
+
*
|
|
115
|
+
* @param {bigint} n - Non-negative integer to convert
|
|
116
|
+
* @param {boolean} hundredPairing - Use hundred-pairing for 1100-9999
|
|
117
|
+
* @param {boolean} useAnd - Use "and" after hundreds and before final segment
|
|
118
|
+
* @returns {string} English words
|
|
119
|
+
*/
|
|
120
|
+
function integerToWords (n, hundredPairing, useAnd) {
|
|
121
|
+
if (n === 0n) return ZERO
|
|
122
|
+
|
|
123
|
+
// Fast path: numbers < 1000
|
|
124
|
+
if (n < 1000n) {
|
|
125
|
+
return buildSegment(Number(n), useAnd).word
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Hundred-pairing: 1100-9999 → "eleven hundred" to "ninety-nine hundred ninety-nine"
|
|
129
|
+
if (hundredPairing && n >= 1100n && n <= 9999n) {
|
|
130
|
+
const num = Number(n)
|
|
131
|
+
const highPart = Math.trunc(num / 100)
|
|
132
|
+
const lowPart = num % 100
|
|
133
|
+
|
|
134
|
+
const { word: highWord } = buildSegment(highPart, useAnd)
|
|
135
|
+
let result = highWord + ' ' + HUNDRED
|
|
136
|
+
|
|
137
|
+
if (lowPart > 0) {
|
|
138
|
+
const { word: lowWord } = buildSegment(lowPart, useAnd)
|
|
139
|
+
// Add "and" before remainder if useAnd is true
|
|
140
|
+
if (useAnd) {
|
|
141
|
+
result += ' and'
|
|
142
|
+
}
|
|
143
|
+
result += ' ' + lowWord
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return result
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Fast path: numbers < 1,000,000
|
|
150
|
+
if (n < 1_000_000n) {
|
|
151
|
+
const thousands = Number(n / 1000n)
|
|
152
|
+
const remainder = Number(n % 1000n)
|
|
153
|
+
|
|
154
|
+
const { word: thousandsWord } = buildSegment(thousands, useAnd)
|
|
155
|
+
let result = thousandsWord + ' ' + SCALES[0]
|
|
156
|
+
|
|
157
|
+
if (remainder > 0) {
|
|
158
|
+
const { word: remainderWord, hasHundred } = buildSegment(remainder, useAnd)
|
|
159
|
+
// Add "and" before remainder if useAnd is true and remainder has no hundred
|
|
160
|
+
if (useAnd && !hasHundred) {
|
|
161
|
+
result += ' and'
|
|
162
|
+
}
|
|
163
|
+
result += ' ' + remainderWord
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
return result
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// For numbers >= 1,000,000, use scale decomposition
|
|
170
|
+
return buildLargeNumberWords(n, useAnd)
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Builds words for numbers >= 1,000,000.
|
|
175
|
+
* Uses BigInt division for faster segment extraction.
|
|
176
|
+
*
|
|
177
|
+
* @param {bigint} n - Number >= 1,000,000
|
|
178
|
+
* @param {boolean} useAnd - Use "and" after hundreds and before final segment
|
|
179
|
+
* @returns {string} English words
|
|
180
|
+
*/
|
|
181
|
+
function buildLargeNumberWords (n, useAnd) {
|
|
182
|
+
// Extract segments using BigInt division
|
|
183
|
+
// Segments are stored least-significant first (index 0 = ones, 1 = thousands, etc.)
|
|
184
|
+
const segments = []
|
|
185
|
+
let temp = n
|
|
186
|
+
while (temp > 0n) {
|
|
187
|
+
segments.push(Number(temp % 1000n))
|
|
188
|
+
temp = temp / 1000n
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// Find the first (smallest index) non-zero segment - this is processed last
|
|
192
|
+
let firstNonZeroIdx = -1
|
|
193
|
+
if (useAnd) {
|
|
194
|
+
for (let i = 0; i < segments.length; i++) {
|
|
195
|
+
if (segments[i] !== 0) {
|
|
196
|
+
firstNonZeroIdx = i
|
|
197
|
+
break
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// Build result string (process from most-significant to least)
|
|
203
|
+
let result = ''
|
|
204
|
+
let prevWasScale = false
|
|
205
|
+
|
|
206
|
+
for (let i = segments.length - 1; i >= 0; i--) {
|
|
207
|
+
const segment = segments[i]
|
|
208
|
+
if (segment === 0) continue
|
|
209
|
+
|
|
210
|
+
const { word, hasHundred } = buildSegment(segment, useAnd)
|
|
211
|
+
const isLastSegment = (i === firstNonZeroIdx)
|
|
212
|
+
|
|
213
|
+
// Add "and" only before FINAL segment if it follows scale and doesn't have hundred
|
|
214
|
+
if (useAnd && result && isLastSegment && prevWasScale && !hasHundred) {
|
|
215
|
+
result += ' and'
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// Add segment word
|
|
219
|
+
if (result) result += ' '
|
|
220
|
+
result += word
|
|
221
|
+
|
|
222
|
+
// Add scale word (i=0 is units, i=1 is thousands, etc.)
|
|
223
|
+
if (i > 0) {
|
|
224
|
+
result += ' ' + SCALES[i - 1]
|
|
225
|
+
prevWasScale = true
|
|
226
|
+
} else {
|
|
227
|
+
prevWasScale = false
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
return result
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Converts decimal digits to English words.
|
|
236
|
+
*
|
|
237
|
+
* @param {string} decimalPart - Decimal digits (without the point)
|
|
238
|
+
* @param {boolean} useAnd - Use "and" in number conversion
|
|
239
|
+
* @returns {string} English words for decimal part
|
|
240
|
+
*/
|
|
241
|
+
function decimalPartToWords (decimalPart, useAnd) {
|
|
242
|
+
let result = ''
|
|
243
|
+
|
|
244
|
+
// Handle leading zeros
|
|
245
|
+
let i = 0
|
|
246
|
+
while (i < decimalPart.length && decimalPart[i] === '0') {
|
|
247
|
+
if (result) result += ' '
|
|
248
|
+
result += ZERO
|
|
249
|
+
i++
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// Convert remainder as a single number
|
|
253
|
+
const remainder = decimalPart.slice(i)
|
|
254
|
+
if (remainder) {
|
|
255
|
+
if (result) result += ' '
|
|
256
|
+
result += integerToWords(BigInt(remainder), false, useAnd)
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
return result
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Converts a numeric value to American English words.
|
|
264
|
+
*
|
|
265
|
+
* This is the main public API. It accepts any valid numeric input
|
|
266
|
+
* (number, string, or bigint) and handles parsing internally.
|
|
267
|
+
*
|
|
268
|
+
* @param {number | string | bigint} value - The numeric value to convert
|
|
269
|
+
* @param {Object} [options] - Optional configuration
|
|
270
|
+
* @param {boolean} [options.hundredPairing=false] - Use hundred-pairing for 1100-9999 (e.g., "fifteen hundred" instead of "one thousand five hundred")
|
|
271
|
+
* @param {boolean} [options.and=false] - Use "and" after hundreds and before final small numbers (e.g., "one hundred and one" instead of "one hundred one")
|
|
272
|
+
* @returns {string} The number in American English words
|
|
273
|
+
* @throws {TypeError} If value is not a valid numeric type
|
|
274
|
+
* @throws {Error} If value is not a valid number format
|
|
275
|
+
*
|
|
276
|
+
* @example
|
|
277
|
+
* toCardinal(42) // 'forty-two'
|
|
278
|
+
* toCardinal(101) // 'one hundred one'
|
|
279
|
+
* toCardinal(101, { and: true }) // 'one hundred and one'
|
|
280
|
+
* toCardinal(1500) // 'one thousand five hundred'
|
|
281
|
+
* toCardinal(1500, { hundredPairing: true }) // 'fifteen hundred'
|
|
282
|
+
*/
|
|
283
|
+
function toCardinal (value, options) {
|
|
284
|
+
options = validateOptions(options)
|
|
285
|
+
const { isNegative, integerPart, decimalPart } = parseCardinalValue(value)
|
|
286
|
+
|
|
287
|
+
// Extract options with defaults
|
|
288
|
+
const { hundredPairing = false, and: useAnd = false } = options
|
|
289
|
+
|
|
290
|
+
let result = ''
|
|
291
|
+
|
|
292
|
+
if (isNegative) {
|
|
293
|
+
result = NEGATIVE + ' '
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
result += integerToWords(integerPart, hundredPairing, useAnd)
|
|
297
|
+
|
|
298
|
+
if (decimalPart) {
|
|
299
|
+
result += ' ' + DECIMAL_SEP + ' ' + decimalPartToWords(decimalPart, useAnd)
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
return result
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// ============================================================================
|
|
306
|
+
// ORDINAL: toOrdinal(value)
|
|
307
|
+
// ============================================================================
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* Builds ordinal words for a 0-999 segment (final segment only).
|
|
311
|
+
* Returns ordinal form: "first", "twenty-third", "one hundred forty-fifth"
|
|
312
|
+
*
|
|
313
|
+
* @param {number} n - Number 0-999
|
|
314
|
+
* @returns {string} Ordinal words for this segment
|
|
315
|
+
*/
|
|
316
|
+
function buildOrdinalSegment (n) {
|
|
317
|
+
const ones = n % 10
|
|
318
|
+
const tens = Math.trunc(n / 10) % 10
|
|
319
|
+
const hundreds = Math.trunc(n / 100)
|
|
320
|
+
|
|
321
|
+
// Build ordinal for tens-ones portion
|
|
322
|
+
let tensOnesOrdinal = ''
|
|
323
|
+
if (tens === 1) {
|
|
324
|
+
// Teens: 10-19 → "tenth" through "nineteenth"
|
|
325
|
+
tensOnesOrdinal = ORDINAL_TEENS[ones]
|
|
326
|
+
} else if (tens >= 2) {
|
|
327
|
+
if (ones > 0) {
|
|
328
|
+
// Compound: "twenty-first", "thirty-second", etc.
|
|
329
|
+
tensOnesOrdinal = TENS[tens] + '-' + ORDINAL_ONES[ones]
|
|
330
|
+
} else {
|
|
331
|
+
// Round tens: "twentieth", "thirtieth", etc.
|
|
332
|
+
tensOnesOrdinal = ORDINAL_TENS[tens]
|
|
333
|
+
}
|
|
334
|
+
} else if (ones > 0) {
|
|
335
|
+
// Single digit: "first", "second", etc.
|
|
336
|
+
tensOnesOrdinal = ORDINAL_ONES[ones]
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
// Hundreds place
|
|
340
|
+
if (hundreds > 0) {
|
|
341
|
+
if (tensOnesOrdinal) {
|
|
342
|
+
// "one hundred twenty-first"
|
|
343
|
+
return ONES[hundreds] + ' ' + HUNDRED + ' ' + tensOnesOrdinal
|
|
344
|
+
} else {
|
|
345
|
+
// "one hundredth", "two hundredth", etc.
|
|
346
|
+
return ONES[hundreds] + ' hundredth'
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
return tensOnesOrdinal
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* Converts a positive integer to ordinal words.
|
|
355
|
+
* Generates ordinals directly without string manipulation.
|
|
356
|
+
*
|
|
357
|
+
* @param {bigint} n - Positive integer to convert
|
|
358
|
+
* @returns {string} Ordinal English words
|
|
359
|
+
*/
|
|
360
|
+
function integerToOrdinal (n) {
|
|
361
|
+
// Fast path: numbers < 1000
|
|
362
|
+
if (n < 1000n) {
|
|
363
|
+
return buildOrdinalSegment(Number(n))
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
// Fast path: numbers < 1,000,000
|
|
367
|
+
if (n < 1_000_000n) {
|
|
368
|
+
const thousands = Number(n / 1000n)
|
|
369
|
+
const remainder = Number(n % 1000n)
|
|
370
|
+
|
|
371
|
+
if (remainder === 0) {
|
|
372
|
+
// Exact thousands: "one thousandth", "five thousandth"
|
|
373
|
+
return buildSegment(thousands, false).word + ' ' + SCALES[0] + 'th'
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
// Has remainder: cardinal thousands + ordinal remainder
|
|
377
|
+
const { word: thousandsWord } = buildSegment(thousands, false)
|
|
378
|
+
return thousandsWord + ' ' + SCALES[0] + ' ' + buildOrdinalSegment(remainder)
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
// For numbers >= 1,000,000, use scale decomposition
|
|
382
|
+
return buildLargeOrdinal(n)
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* Builds ordinal words for numbers >= 1,000,000.
|
|
387
|
+
* All segments except the final one are cardinal; final segment is ordinal.
|
|
388
|
+
*
|
|
389
|
+
* @param {bigint} n - Number >= 1,000,000
|
|
390
|
+
* @returns {string} Ordinal English words
|
|
391
|
+
*/
|
|
392
|
+
function buildLargeOrdinal (n) {
|
|
393
|
+
// Extract segments (least-significant first)
|
|
394
|
+
const segments = []
|
|
395
|
+
let temp = n
|
|
396
|
+
while (temp > 0n) {
|
|
397
|
+
segments.push(Number(temp % 1000n))
|
|
398
|
+
temp = temp / 1000n
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
// Find the lowest non-zero segment (this gets ordinal treatment)
|
|
402
|
+
let lowestNonZeroIdx = 0
|
|
403
|
+
for (let i = 0; i < segments.length; i++) {
|
|
404
|
+
if (segments[i] !== 0) {
|
|
405
|
+
lowestNonZeroIdx = i
|
|
406
|
+
break
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
// Build result (most-significant to least)
|
|
411
|
+
let result = ''
|
|
412
|
+
|
|
413
|
+
for (let i = segments.length - 1; i >= 0; i--) {
|
|
414
|
+
const segment = segments[i]
|
|
415
|
+
if (segment === 0) continue
|
|
416
|
+
|
|
417
|
+
const isLowestSegment = (i === lowestNonZeroIdx)
|
|
418
|
+
|
|
419
|
+
if (result) result += ' '
|
|
420
|
+
|
|
421
|
+
if (isLowestSegment) {
|
|
422
|
+
// Final non-zero segment gets ordinal treatment
|
|
423
|
+
if (i === 0) {
|
|
424
|
+
// Units position: use ordinal segment
|
|
425
|
+
result += buildOrdinalSegment(segment)
|
|
426
|
+
} else {
|
|
427
|
+
// Scale position with no remainder below: "one millionth"
|
|
428
|
+
result += buildSegment(segment, false).word + ' ' + SCALES[i - 1] + 'th'
|
|
429
|
+
}
|
|
430
|
+
} else {
|
|
431
|
+
// Non-final segments are cardinal
|
|
432
|
+
result += buildSegment(segment, false).word
|
|
433
|
+
if (i > 0) {
|
|
434
|
+
result += ' ' + SCALES[i - 1]
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
return result
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* Converts a numeric value to American English ordinal words.
|
|
444
|
+
*
|
|
445
|
+
* @param {number | string | bigint} value - The numeric value to convert (must be a positive integer)
|
|
446
|
+
* @returns {string} The number as ordinal words (e.g., "first", "forty-second")
|
|
447
|
+
* @throws {TypeError} If value is not a valid numeric type
|
|
448
|
+
* @throws {RangeError} If value is negative, zero, or has a decimal part
|
|
449
|
+
*
|
|
450
|
+
* @example
|
|
451
|
+
* toOrdinal(1) // 'first'
|
|
452
|
+
* toOrdinal(2) // 'second'
|
|
453
|
+
* toOrdinal(3) // 'third'
|
|
454
|
+
* toOrdinal(21) // 'twenty-first'
|
|
455
|
+
* toOrdinal(42) // 'forty-second'
|
|
456
|
+
* toOrdinal(100) // 'one hundredth'
|
|
457
|
+
* toOrdinal(101) // 'one hundred first'
|
|
458
|
+
* toOrdinal(1000) // 'one thousandth'
|
|
459
|
+
*/
|
|
460
|
+
function toOrdinal (value) {
|
|
461
|
+
const integerPart = parseOrdinalValue(value)
|
|
462
|
+
return integerToOrdinal(integerPart)
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
// ============================================================================
|
|
466
|
+
// CURRENCY: toCurrency(value, options?)
|
|
467
|
+
// ============================================================================
|
|
468
|
+
|
|
469
|
+
/**
|
|
470
|
+
* Converts a numeric value to American English currency words.
|
|
471
|
+
*
|
|
472
|
+
* @param {number | string | bigint} value - The currency amount to convert
|
|
473
|
+
* @param {Object} [options] - Optional configuration
|
|
474
|
+
* @param {boolean} [options.and=true] - Use "and" between dollars and cents (e.g., "one dollar and fifty cents")
|
|
475
|
+
* @returns {string} The amount in American English currency words
|
|
476
|
+
* @throws {TypeError} If value is not a valid numeric type
|
|
477
|
+
* @throws {Error} If value is not a valid number format
|
|
478
|
+
*
|
|
479
|
+
* @example
|
|
480
|
+
* toCurrency(42.50) // 'forty-two dollars and fifty cents'
|
|
481
|
+
* toCurrency(1) // 'one dollar'
|
|
482
|
+
* toCurrency(0.99) // 'ninety-nine cents'
|
|
483
|
+
* toCurrency(42.50, { and: false }) // 'forty-two dollars fifty cents'
|
|
484
|
+
*/
|
|
485
|
+
function toCurrency (value, options) {
|
|
486
|
+
options = validateOptions(options)
|
|
487
|
+
const { isNegative, dollars, cents } = parseCurrencyValue(value)
|
|
488
|
+
const { and: useAnd = true } = options
|
|
489
|
+
|
|
490
|
+
// Build result
|
|
491
|
+
let result = ''
|
|
492
|
+
if (isNegative) result = NEGATIVE + ' '
|
|
493
|
+
|
|
494
|
+
// Dollars part (show if non-zero, or if no cents)
|
|
495
|
+
if (dollars > 0n || cents === 0n) {
|
|
496
|
+
result += integerToWords(dollars, false, false)
|
|
497
|
+
result += ' ' + (dollars === 1n ? DOLLAR : DOLLARS)
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
// Cents part
|
|
501
|
+
if (cents > 0n) {
|
|
502
|
+
if (dollars > 0n) {
|
|
503
|
+
result += useAnd ? ' and ' : ' '
|
|
504
|
+
}
|
|
505
|
+
result += integerToWords(cents, false, false)
|
|
506
|
+
result += ' ' + (cents === 1n ? CENT : CENTS)
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
return result
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
// ============================================================================
|
|
513
|
+
// EXPORTS
|
|
514
|
+
// ============================================================================
|
|
515
|
+
|
|
516
|
+
export { toCardinal, toOrdinal, toCurrency }
|
package/src/en-ZA.d.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a numeric value to South African English words.
|
|
3
|
+
*
|
|
4
|
+
* This is the main public API. It accepts any valid numeric input
|
|
5
|
+
* (number, string, or bigint) and handles parsing internally.
|
|
6
|
+
*
|
|
7
|
+
* @param {number | string | bigint} value - The numeric value to convert
|
|
8
|
+
* @returns {string} The number in English words
|
|
9
|
+
* @throws {TypeError} If value is not a valid numeric type
|
|
10
|
+
* @throws {Error} If value is not a valid number format
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* toCardinal(42) // 'forty-two'
|
|
14
|
+
* toCardinal(-3.14) // 'minus three point fourteen'
|
|
15
|
+
* toCardinal('1000000') // 'one million'
|
|
16
|
+
*/
|
|
17
|
+
export function toCardinal(value: number | string | bigint): string;
|
|
18
|
+
/**
|
|
19
|
+
* Converts a numeric value to South African English ordinal words.
|
|
20
|
+
*
|
|
21
|
+
* @param {number | string | bigint} value - The numeric value to convert (must be a positive integer)
|
|
22
|
+
* @returns {string} The number as ordinal words (e.g., "first", "forty-second")
|
|
23
|
+
* @throws {TypeError} If value is not a valid numeric type
|
|
24
|
+
* @throws {RangeError} If value is negative, zero, or has a decimal part
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* toOrdinal(1) // 'first'
|
|
28
|
+
* toOrdinal(2) // 'second'
|
|
29
|
+
* toOrdinal(3) // 'third'
|
|
30
|
+
* toOrdinal(21) // 'twenty-first'
|
|
31
|
+
* toOrdinal(42) // 'forty-second'
|
|
32
|
+
* toOrdinal(100) // 'one hundredth'
|
|
33
|
+
* toOrdinal(101) // 'one hundred first'
|
|
34
|
+
* toOrdinal(1000) // 'one thousandth'
|
|
35
|
+
*/
|
|
36
|
+
export function toOrdinal(value: number | string | bigint): string;
|
|
37
|
+
/**
|
|
38
|
+
* Converts a numeric value to South African English currency words.
|
|
39
|
+
*
|
|
40
|
+
* @param {number | string | bigint} value - The currency amount to convert
|
|
41
|
+
* @param {Object} [options] - Optional configuration
|
|
42
|
+
* @param {boolean} [options.and=true] - Use "and" between rand and cents (e.g., "one rand and fifty cents")
|
|
43
|
+
* @returns {string} The amount in South African English currency words
|
|
44
|
+
* @throws {TypeError} If value is not a valid numeric type
|
|
45
|
+
* @throws {Error} If value is not a valid number format
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* toCurrency(42.50) // 'forty-two rand and fifty cents'
|
|
49
|
+
* toCurrency(1) // 'one rand'
|
|
50
|
+
* toCurrency(0.99) // 'ninety-nine cents'
|
|
51
|
+
* toCurrency(0.01) // 'one cent'
|
|
52
|
+
* toCurrency(42.50, { and: false }) // 'forty-two rand fifty cents'
|
|
53
|
+
*/
|
|
54
|
+
export function toCurrency(value: number | string | bigint, options?: {
|
|
55
|
+
and?: boolean | undefined;
|
|
56
|
+
}): string;
|