n2words 3.1.0 → 5.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 +51 -40
- 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-BR.js +2 -0
- package/dist/pt-BR.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 +61 -88
- 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-BR.d.ts +31 -0
- package/src/pt-BR.js +534 -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-ZA.js
ADDED
|
@@ -0,0 +1,478 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* South African English language converter
|
|
3
|
+
*
|
|
4
|
+
* CLDR: en-ZA | English as used in South Africa
|
|
5
|
+
*
|
|
6
|
+
* Exports:
|
|
7
|
+
* - toCardinal(value) - Cardinal numbers: 42 → "forty-two"
|
|
8
|
+
* - toOrdinal(value) - Ordinal numbers: 42 → "forty-second"
|
|
9
|
+
* - toCurrency(value, options?) - Currency: 42.50 → "forty-two rand and fifty cents"
|
|
10
|
+
*
|
|
11
|
+
* South African English conventions:
|
|
12
|
+
* - Follows British English style
|
|
13
|
+
* - "and" after hundreds: "one hundred and twenty-three"
|
|
14
|
+
* - "and" before final segment: "one million and one"
|
|
15
|
+
* - Hyphenated tens-ones: "twenty-one", "forty-two"
|
|
16
|
+
* - Western numbering system (short scale: billion = 10^9)
|
|
17
|
+
* - Currency: South African Rand (ZAR) - rand (singular/plural), cent/cents
|
|
18
|
+
*
|
|
19
|
+
* Note: "Rand" is invariable (same for singular and plural).
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import { parseCardinalValue } from './utils/parse-cardinal.js'
|
|
23
|
+
import { parseCurrencyValue } from './utils/parse-currency.js'
|
|
24
|
+
import { parseOrdinalValue } from './utils/parse-ordinal.js'
|
|
25
|
+
import { validateOptions } from './utils/validate-options.js'
|
|
26
|
+
|
|
27
|
+
// ============================================================================
|
|
28
|
+
// Vocabulary (module-level constants)
|
|
29
|
+
// ============================================================================
|
|
30
|
+
|
|
31
|
+
const ONES = ['', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']
|
|
32
|
+
const TEENS = ['ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen']
|
|
33
|
+
const TENS = ['', '', 'twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety']
|
|
34
|
+
|
|
35
|
+
const SCALES = [
|
|
36
|
+
'thousand', 'million', 'billion', 'trillion', 'quadrillion',
|
|
37
|
+
'quintillion', 'sextillion', 'septillion', 'octillion', 'nonillion',
|
|
38
|
+
'decillion', 'undecillion', 'duodecillion', 'tredecillion', 'quattuordecillion',
|
|
39
|
+
'quindecillion', 'sexdecillion', 'septendecillion', 'octodecillion', 'novemdecillion',
|
|
40
|
+
'vigintillion'
|
|
41
|
+
]
|
|
42
|
+
|
|
43
|
+
const HUNDRED = 'hundred'
|
|
44
|
+
const ZERO = 'zero'
|
|
45
|
+
const NEGATIVE = 'minus'
|
|
46
|
+
const DECIMAL_SEP = 'point'
|
|
47
|
+
|
|
48
|
+
// Ordinal vocabulary
|
|
49
|
+
const ORDINAL_ONES = ['', 'first', 'second', 'third', 'fourth', 'fifth', 'sixth', 'seventh', 'eighth', 'ninth']
|
|
50
|
+
const ORDINAL_TEENS = ['tenth', 'eleventh', 'twelfth', 'thirteenth', 'fourteenth', 'fifteenth', 'sixteenth', 'seventeenth', 'eighteenth', 'nineteenth']
|
|
51
|
+
const ORDINAL_TENS = ['', '', 'twentieth', 'thirtieth', 'fortieth', 'fiftieth', 'sixtieth', 'seventieth', 'eightieth', 'ninetieth']
|
|
52
|
+
|
|
53
|
+
// Currency vocabulary (South African Rand - invariable)
|
|
54
|
+
const RAND = 'rand'
|
|
55
|
+
const CENT = 'cent'
|
|
56
|
+
const CENTS = 'cents'
|
|
57
|
+
|
|
58
|
+
// ============================================================================
|
|
59
|
+
// Segment Building
|
|
60
|
+
// ============================================================================
|
|
61
|
+
|
|
62
|
+
// Reusable result object to avoid allocation per call
|
|
63
|
+
const segmentResult = { word: '', hasHundred: false }
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Builds words for a 0-999 segment.
|
|
67
|
+
*
|
|
68
|
+
* @param {number} n - Number 0-999
|
|
69
|
+
* @returns {{ word: string, hasHundred: boolean }}
|
|
70
|
+
*/
|
|
71
|
+
function buildSegment (n) {
|
|
72
|
+
if (n === 0) {
|
|
73
|
+
segmentResult.word = ''
|
|
74
|
+
segmentResult.hasHundred = false
|
|
75
|
+
return segmentResult
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const ones = n % 10
|
|
79
|
+
const tens = Math.trunc(n / 10) % 10
|
|
80
|
+
const hundreds = Math.trunc(n / 100)
|
|
81
|
+
|
|
82
|
+
// Build tens-ones part first
|
|
83
|
+
let tensOnes = ''
|
|
84
|
+
if (tens === 1) {
|
|
85
|
+
tensOnes = TEENS[ones]
|
|
86
|
+
} else if (tens >= 2) {
|
|
87
|
+
tensOnes = ones > 0 ? TENS[tens] + '-' + ONES[ones] : TENS[tens]
|
|
88
|
+
} else if (ones > 0) {
|
|
89
|
+
tensOnes = ONES[ones]
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Hundreds place
|
|
93
|
+
if (hundreds > 0) {
|
|
94
|
+
if (tensOnes) {
|
|
95
|
+
segmentResult.word = ONES[hundreds] + ' ' + HUNDRED + ' and ' + 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
|
+
// Conversion Functions
|
|
110
|
+
// ============================================================================
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Converts a non-negative integer to English words.
|
|
114
|
+
*
|
|
115
|
+
* @param {bigint} n - Non-negative integer to convert
|
|
116
|
+
* @returns {string} English words
|
|
117
|
+
*/
|
|
118
|
+
function integerToWords (n) {
|
|
119
|
+
if (n === 0n) return ZERO
|
|
120
|
+
|
|
121
|
+
// Fast path: numbers < 1000
|
|
122
|
+
if (n < 1000n) {
|
|
123
|
+
return buildSegment(Number(n)).word
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Fast path: numbers < 1,000,000
|
|
127
|
+
if (n < 1_000_000n) {
|
|
128
|
+
const thousands = Number(n / 1000n)
|
|
129
|
+
const remainder = Number(n % 1000n)
|
|
130
|
+
|
|
131
|
+
const { word: thousandsWord } = buildSegment(thousands)
|
|
132
|
+
let result = thousandsWord + ' ' + SCALES[0]
|
|
133
|
+
|
|
134
|
+
if (remainder > 0) {
|
|
135
|
+
const { word: remainderWord, hasHundred } = buildSegment(remainder)
|
|
136
|
+
result += hasHundred ? ' ' + remainderWord : ' and ' + remainderWord
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return result
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// For numbers >= 1,000,000, use scale decomposition
|
|
143
|
+
return buildLargeNumberWords(n)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Builds words for numbers >= 1,000,000.
|
|
148
|
+
* Uses BigInt division for faster segment extraction.
|
|
149
|
+
*
|
|
150
|
+
* @param {bigint} n - Number >= 1,000,000
|
|
151
|
+
* @returns {string} English words
|
|
152
|
+
*/
|
|
153
|
+
function buildLargeNumberWords (n) {
|
|
154
|
+
// Extract segments using BigInt division
|
|
155
|
+
// Segments are stored least-significant first (index 0 = ones, 1 = thousands, etc.)
|
|
156
|
+
const segments = []
|
|
157
|
+
let temp = n
|
|
158
|
+
while (temp > 0n) {
|
|
159
|
+
segments.push(Number(temp % 1000n))
|
|
160
|
+
temp = temp / 1000n
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Find the first (smallest index) non-zero segment - this is processed last
|
|
164
|
+
let firstNonZeroIdx = -1
|
|
165
|
+
for (let i = 0; i < segments.length; i++) {
|
|
166
|
+
if (segments[i] !== 0) {
|
|
167
|
+
firstNonZeroIdx = i
|
|
168
|
+
break
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// Build result string (process from most-significant to least)
|
|
173
|
+
let result = ''
|
|
174
|
+
let prevWasScale = false
|
|
175
|
+
|
|
176
|
+
for (let i = segments.length - 1; i >= 0; i--) {
|
|
177
|
+
const segment = segments[i]
|
|
178
|
+
if (segment === 0) continue
|
|
179
|
+
|
|
180
|
+
const { word, hasHundred } = buildSegment(segment)
|
|
181
|
+
const isLastSegment = (i === firstNonZeroIdx)
|
|
182
|
+
|
|
183
|
+
// Add "and" only before FINAL segment if it follows scale and doesn't have hundred
|
|
184
|
+
if (result && isLastSegment && prevWasScale && !hasHundred) {
|
|
185
|
+
result += ' and'
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// Add segment word
|
|
189
|
+
if (result) result += ' '
|
|
190
|
+
result += word
|
|
191
|
+
|
|
192
|
+
// Add scale word (i=0 is units, i=1 is thousands, etc.)
|
|
193
|
+
if (i > 0) {
|
|
194
|
+
result += ' ' + SCALES[i - 1]
|
|
195
|
+
prevWasScale = true
|
|
196
|
+
} else {
|
|
197
|
+
prevWasScale = false
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return result
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Converts decimal digits to English words.
|
|
206
|
+
*
|
|
207
|
+
* @param {string} decimalPart - Decimal digits (without the point)
|
|
208
|
+
* @returns {string} English words for decimal part
|
|
209
|
+
*/
|
|
210
|
+
function decimalPartToWords (decimalPart) {
|
|
211
|
+
let result = ''
|
|
212
|
+
|
|
213
|
+
// Handle leading zeros
|
|
214
|
+
let i = 0
|
|
215
|
+
while (i < decimalPart.length && decimalPart[i] === '0') {
|
|
216
|
+
if (result) result += ' '
|
|
217
|
+
result += ZERO
|
|
218
|
+
i++
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// Convert remainder as a single number
|
|
222
|
+
const remainder = decimalPart.slice(i)
|
|
223
|
+
if (remainder) {
|
|
224
|
+
if (result) result += ' '
|
|
225
|
+
result += integerToWords(BigInt(remainder))
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
return result
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Converts a numeric value to South African English words.
|
|
233
|
+
*
|
|
234
|
+
* This is the main public API. It accepts any valid numeric input
|
|
235
|
+
* (number, string, or bigint) and handles parsing internally.
|
|
236
|
+
*
|
|
237
|
+
* @param {number | string | bigint} value - The numeric value to convert
|
|
238
|
+
* @returns {string} The number in English words
|
|
239
|
+
* @throws {TypeError} If value is not a valid numeric type
|
|
240
|
+
* @throws {Error} If value is not a valid number format
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* toCardinal(42) // 'forty-two'
|
|
244
|
+
* toCardinal(-3.14) // 'minus three point fourteen'
|
|
245
|
+
* toCardinal('1000000') // 'one million'
|
|
246
|
+
*/
|
|
247
|
+
function toCardinal (value) {
|
|
248
|
+
const { isNegative, integerPart, decimalPart } = parseCardinalValue(value)
|
|
249
|
+
|
|
250
|
+
let result = ''
|
|
251
|
+
|
|
252
|
+
if (isNegative) {
|
|
253
|
+
result = NEGATIVE + ' '
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
result += integerToWords(integerPart)
|
|
257
|
+
|
|
258
|
+
if (decimalPart) {
|
|
259
|
+
result += ' ' + DECIMAL_SEP + ' ' + decimalPartToWords(decimalPart)
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
return result
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// ============================================================================
|
|
266
|
+
// ORDINAL: toOrdinal(value)
|
|
267
|
+
// ============================================================================
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Builds ordinal words for a 0-999 segment (final segment only).
|
|
271
|
+
* Returns ordinal form: "first", "twenty-third", "one hundred forty-fifth"
|
|
272
|
+
*
|
|
273
|
+
* @param {number} n - Number 0-999
|
|
274
|
+
* @returns {string} Ordinal words for this segment
|
|
275
|
+
*/
|
|
276
|
+
function buildOrdinalSegment (n) {
|
|
277
|
+
const ones = n % 10
|
|
278
|
+
const tens = Math.trunc(n / 10) % 10
|
|
279
|
+
const hundreds = Math.trunc(n / 100)
|
|
280
|
+
|
|
281
|
+
// Build ordinal for tens-ones portion
|
|
282
|
+
let tensOnesOrdinal = ''
|
|
283
|
+
if (tens === 1) {
|
|
284
|
+
// Teens: 10-19 → "tenth" through "nineteenth"
|
|
285
|
+
tensOnesOrdinal = ORDINAL_TEENS[ones]
|
|
286
|
+
} else if (tens >= 2) {
|
|
287
|
+
if (ones > 0) {
|
|
288
|
+
// Compound: "twenty-first", "thirty-second", etc.
|
|
289
|
+
tensOnesOrdinal = TENS[tens] + '-' + ORDINAL_ONES[ones]
|
|
290
|
+
} else {
|
|
291
|
+
// Round tens: "twentieth", "thirtieth", etc.
|
|
292
|
+
tensOnesOrdinal = ORDINAL_TENS[tens]
|
|
293
|
+
}
|
|
294
|
+
} else if (ones > 0) {
|
|
295
|
+
// Single digit: "first", "second", etc.
|
|
296
|
+
tensOnesOrdinal = ORDINAL_ONES[ones]
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// Hundreds place
|
|
300
|
+
if (hundreds > 0) {
|
|
301
|
+
if (tensOnesOrdinal) {
|
|
302
|
+
// "one hundred twenty-first"
|
|
303
|
+
return ONES[hundreds] + ' ' + HUNDRED + ' ' + tensOnesOrdinal
|
|
304
|
+
} else {
|
|
305
|
+
// "one hundredth", "two hundredth", etc.
|
|
306
|
+
return ONES[hundreds] + ' hundredth'
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
return tensOnesOrdinal
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Converts a positive integer to ordinal words.
|
|
315
|
+
* Generates ordinals directly without string manipulation.
|
|
316
|
+
*
|
|
317
|
+
* @param {bigint} n - Positive integer to convert
|
|
318
|
+
* @returns {string} Ordinal English words
|
|
319
|
+
*/
|
|
320
|
+
function integerToOrdinal (n) {
|
|
321
|
+
// Fast path: numbers < 1000
|
|
322
|
+
if (n < 1000n) {
|
|
323
|
+
return buildOrdinalSegment(Number(n))
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
// Fast path: numbers < 1,000,000
|
|
327
|
+
if (n < 1_000_000n) {
|
|
328
|
+
const thousands = Number(n / 1000n)
|
|
329
|
+
const remainder = Number(n % 1000n)
|
|
330
|
+
|
|
331
|
+
if (remainder === 0) {
|
|
332
|
+
// Exact thousands: "one thousandth", "five thousandth"
|
|
333
|
+
return buildSegment(thousands).word + ' ' + SCALES[0] + 'th'
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
// Has remainder: cardinal thousands + ordinal remainder
|
|
337
|
+
const { word: thousandsWord } = buildSegment(thousands)
|
|
338
|
+
return thousandsWord + ' ' + SCALES[0] + ' ' + buildOrdinalSegment(remainder)
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
// For numbers >= 1,000,000, use scale decomposition
|
|
342
|
+
return buildLargeOrdinal(n)
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Builds ordinal words for numbers >= 1,000,000.
|
|
347
|
+
* All segments except the final one are cardinal; final segment is ordinal.
|
|
348
|
+
*
|
|
349
|
+
* @param {bigint} n - Number >= 1,000,000
|
|
350
|
+
* @returns {string} Ordinal English words
|
|
351
|
+
*/
|
|
352
|
+
function buildLargeOrdinal (n) {
|
|
353
|
+
// Extract segments (least-significant first)
|
|
354
|
+
const segments = []
|
|
355
|
+
let temp = n
|
|
356
|
+
while (temp > 0n) {
|
|
357
|
+
segments.push(Number(temp % 1000n))
|
|
358
|
+
temp = temp / 1000n
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
// Find the lowest non-zero segment (this gets ordinal treatment)
|
|
362
|
+
let lowestNonZeroIdx = 0
|
|
363
|
+
for (let i = 0; i < segments.length; i++) {
|
|
364
|
+
if (segments[i] !== 0) {
|
|
365
|
+
lowestNonZeroIdx = i
|
|
366
|
+
break
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
// Build result (most-significant to least)
|
|
371
|
+
let result = ''
|
|
372
|
+
|
|
373
|
+
for (let i = segments.length - 1; i >= 0; i--) {
|
|
374
|
+
const segment = segments[i]
|
|
375
|
+
if (segment === 0) continue
|
|
376
|
+
|
|
377
|
+
const isLowestSegment = (i === lowestNonZeroIdx)
|
|
378
|
+
|
|
379
|
+
if (result) result += ' '
|
|
380
|
+
|
|
381
|
+
if (isLowestSegment) {
|
|
382
|
+
// Final non-zero segment gets ordinal treatment
|
|
383
|
+
if (i === 0) {
|
|
384
|
+
// Units position: use ordinal segment
|
|
385
|
+
result += buildOrdinalSegment(segment)
|
|
386
|
+
} else {
|
|
387
|
+
// Scale position with no remainder below: "one millionth"
|
|
388
|
+
result += buildSegment(segment).word + ' ' + SCALES[i - 1] + 'th'
|
|
389
|
+
}
|
|
390
|
+
} else {
|
|
391
|
+
// Non-final segments are cardinal
|
|
392
|
+
result += buildSegment(segment).word
|
|
393
|
+
if (i > 0) {
|
|
394
|
+
result += ' ' + SCALES[i - 1]
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
return result
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Converts a numeric value to South African English ordinal words.
|
|
404
|
+
*
|
|
405
|
+
* @param {number | string | bigint} value - The numeric value to convert (must be a positive integer)
|
|
406
|
+
* @returns {string} The number as ordinal words (e.g., "first", "forty-second")
|
|
407
|
+
* @throws {TypeError} If value is not a valid numeric type
|
|
408
|
+
* @throws {RangeError} If value is negative, zero, or has a decimal part
|
|
409
|
+
*
|
|
410
|
+
* @example
|
|
411
|
+
* toOrdinal(1) // 'first'
|
|
412
|
+
* toOrdinal(2) // 'second'
|
|
413
|
+
* toOrdinal(3) // 'third'
|
|
414
|
+
* toOrdinal(21) // 'twenty-first'
|
|
415
|
+
* toOrdinal(42) // 'forty-second'
|
|
416
|
+
* toOrdinal(100) // 'one hundredth'
|
|
417
|
+
* toOrdinal(101) // 'one hundred first'
|
|
418
|
+
* toOrdinal(1000) // 'one thousandth'
|
|
419
|
+
*/
|
|
420
|
+
function toOrdinal (value) {
|
|
421
|
+
const integerPart = parseOrdinalValue(value)
|
|
422
|
+
return integerToOrdinal(integerPart)
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
// ============================================================================
|
|
426
|
+
// CURRENCY: toCurrency(value, options?)
|
|
427
|
+
// ============================================================================
|
|
428
|
+
|
|
429
|
+
/**
|
|
430
|
+
* Converts a numeric value to South African English currency words.
|
|
431
|
+
*
|
|
432
|
+
* @param {number | string | bigint} value - The currency amount to convert
|
|
433
|
+
* @param {Object} [options] - Optional configuration
|
|
434
|
+
* @param {boolean} [options.and=true] - Use "and" between rand and cents (e.g., "one rand and fifty cents")
|
|
435
|
+
* @returns {string} The amount in South African English currency words
|
|
436
|
+
* @throws {TypeError} If value is not a valid numeric type
|
|
437
|
+
* @throws {Error} If value is not a valid number format
|
|
438
|
+
*
|
|
439
|
+
* @example
|
|
440
|
+
* toCurrency(42.50) // 'forty-two rand and fifty cents'
|
|
441
|
+
* toCurrency(1) // 'one rand'
|
|
442
|
+
* toCurrency(0.99) // 'ninety-nine cents'
|
|
443
|
+
* toCurrency(0.01) // 'one cent'
|
|
444
|
+
* toCurrency(42.50, { and: false }) // 'forty-two rand fifty cents'
|
|
445
|
+
*/
|
|
446
|
+
function toCurrency (value, options) {
|
|
447
|
+
options = validateOptions(options)
|
|
448
|
+
const { isNegative, dollars: rand, cents } = parseCurrencyValue(value)
|
|
449
|
+
const { and: useAnd = true } = options
|
|
450
|
+
|
|
451
|
+
// Build result
|
|
452
|
+
let result = ''
|
|
453
|
+
if (isNegative) result = NEGATIVE + ' '
|
|
454
|
+
|
|
455
|
+
// Rand part (show if non-zero, or if no cents)
|
|
456
|
+
// Note: "rand" is invariable (same singular/plural)
|
|
457
|
+
if (rand > 0n || cents === 0n) {
|
|
458
|
+
result += integerToWords(rand)
|
|
459
|
+
result += ' ' + RAND
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
// Cents part
|
|
463
|
+
if (cents > 0n) {
|
|
464
|
+
if (rand > 0n) {
|
|
465
|
+
result += useAnd ? ' and ' : ' '
|
|
466
|
+
}
|
|
467
|
+
result += integerToWords(cents)
|
|
468
|
+
result += ' ' + (cents === 1n ? CENT : CENTS)
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
return result
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
// ============================================================================
|
|
475
|
+
// Public API
|
|
476
|
+
// ============================================================================
|
|
477
|
+
|
|
478
|
+
export { toCardinal, toOrdinal, toCurrency }
|
package/src/es-ES.d.ts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a numeric value to Spanish 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
|
+
* @param {Object} [options] - Optional configuration
|
|
9
|
+
* @param {('masculine'|'feminine')} [options.gender='masculine'] - Grammatical gender
|
|
10
|
+
* @returns {string} The number in Spanish words
|
|
11
|
+
* @throws {TypeError} If value is not a valid numeric type
|
|
12
|
+
* @throws {Error} If value is not a valid number format
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* toCardinal(21) // 'veintiuno'
|
|
16
|
+
* toCardinal(21, {gender: 'feminine'}) // 'veintiuna'
|
|
17
|
+
* toCardinal(1000000) // 'un millón'
|
|
18
|
+
*/
|
|
19
|
+
export function toCardinal(value: number | string | bigint, options?: {
|
|
20
|
+
gender?: "masculine" | "feminine" | undefined;
|
|
21
|
+
}): string;
|
|
22
|
+
/**
|
|
23
|
+
* Converts a numeric value to Spanish ordinal words.
|
|
24
|
+
*
|
|
25
|
+
* Spanish ordinals agree in gender with the noun they modify.
|
|
26
|
+
* Only positive integers are valid for ordinals.
|
|
27
|
+
*
|
|
28
|
+
* @param {number | string | bigint} value - The positive integer to convert
|
|
29
|
+
* @param {Object} [options] - Optional configuration
|
|
30
|
+
* @param {('masculine'|'feminine')} [options.gender='masculine'] - Grammatical gender
|
|
31
|
+
* @returns {string} The number in Spanish ordinal words
|
|
32
|
+
* @throws {TypeError} If value is not a valid numeric type
|
|
33
|
+
* @throws {Error} If value is not a positive integer
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* toOrdinal(1) // 'primero'
|
|
37
|
+
* toOrdinal(1, { gender: 'feminine' }) // 'primera'
|
|
38
|
+
* toOrdinal(21) // 'vigésimo primero'
|
|
39
|
+
* toOrdinal(100) // 'centésimo'
|
|
40
|
+
*/
|
|
41
|
+
export function toOrdinal(value: number | string | bigint, options?: {
|
|
42
|
+
gender?: "masculine" | "feminine" | undefined;
|
|
43
|
+
}): string;
|
|
44
|
+
/**
|
|
45
|
+
* Converts a numeric value to Spanish Euro currency words.
|
|
46
|
+
*
|
|
47
|
+
* Spanish currency uses masculine gender for euros (el euro)
|
|
48
|
+
* and masculine for céntimos (el céntimo).
|
|
49
|
+
*
|
|
50
|
+
* @param {number | string | bigint} value - The currency amount to convert
|
|
51
|
+
* @param {Object} [options] - Optional configuration
|
|
52
|
+
* @param {boolean} [options.and=true] - Use "con" between euros and cents
|
|
53
|
+
* @returns {string} The amount in Spanish currency words
|
|
54
|
+
* @throws {TypeError} If value is not a valid numeric type
|
|
55
|
+
* @throws {Error} If value is not a valid number format
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* toCurrency(42.50) // 'cuarenta y dos euros con cincuenta céntimos'
|
|
59
|
+
* toCurrency(1) // 'un euro'
|
|
60
|
+
* toCurrency(0.99) // 'noventa y nueve céntimos'
|
|
61
|
+
* toCurrency(42.50, { and: false }) // 'cuarenta y dos euros cincuenta céntimos'
|
|
62
|
+
*/
|
|
63
|
+
export function toCurrency(value: number | string | bigint, options?: {
|
|
64
|
+
and?: boolean | undefined;
|
|
65
|
+
}): string;
|