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/it-IT.js
ADDED
|
@@ -0,0 +1,506 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Italian (Italy) language converter
|
|
3
|
+
*
|
|
4
|
+
* CLDR: it-IT | Italian as used in Italy
|
|
5
|
+
*
|
|
6
|
+
* Italian-specific rules:
|
|
7
|
+
* - Concatenation without spaces within segments ("ventotto" not "venti otto")
|
|
8
|
+
* - Phonetic vowel elision: "venti" + "otto" → "ventotto"
|
|
9
|
+
* - Accent on final "tre" in compounds: "ventitré"
|
|
10
|
+
* - mille/mila alternation for thousands
|
|
11
|
+
* - Scale words: milione/milioni, miliardo/miliardi, etc.
|
|
12
|
+
* - "e" connector before simple final remainder
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { parseCardinalValue } from './utils/parse-cardinal.js'
|
|
16
|
+
import { parseCurrencyValue } from './utils/parse-currency.js'
|
|
17
|
+
import { parseOrdinalValue } from './utils/parse-ordinal.js'
|
|
18
|
+
import { validateOptions } from './utils/validate-options.js'
|
|
19
|
+
|
|
20
|
+
// ============================================================================
|
|
21
|
+
// Vocabulary (module-level constants)
|
|
22
|
+
// ============================================================================
|
|
23
|
+
|
|
24
|
+
// Base vocabulary
|
|
25
|
+
const ONES = ['', 'uno', 'due', 'tre', 'quattro', 'cinque', 'sei', 'sette', 'otto', 'nove']
|
|
26
|
+
const TEENS = ['dieci', 'undici', 'dodici', 'tredici', 'quattordici', 'quindici', 'sedici', 'diciassette', 'diciotto', 'diciannove']
|
|
27
|
+
const TENS = ['', '', 'venti', 'trenta', 'quaranta', 'cinquanta', 'sessanta', 'settanta', 'ottanta', 'novanta']
|
|
28
|
+
const HUNDREDS = ['', 'cento', 'duecento', 'trecento', 'quattrocento', 'cinquecento', 'seicento', 'settecento', 'ottocento', 'novecento']
|
|
29
|
+
|
|
30
|
+
// Pre-elided tens stems (drop final vowel before 'uno'/'otto')
|
|
31
|
+
// vent- (from venti), trent- (from trenta), etc.
|
|
32
|
+
const TENS_STEM = ['', '', 'vent', 'trent', 'quarant', 'cinquant', 'sessant', 'settant', 'ottant', 'novant']
|
|
33
|
+
|
|
34
|
+
const ZERO = 'zero'
|
|
35
|
+
const NEGATIVE = 'meno'
|
|
36
|
+
const DECIMAL_SEP = 'virgola'
|
|
37
|
+
|
|
38
|
+
// Thousands
|
|
39
|
+
const THOUSAND_SINGULAR = 'mille'
|
|
40
|
+
const THOUSAND_PLURAL_SUFFIX = 'mila'
|
|
41
|
+
|
|
42
|
+
// Scale word generation
|
|
43
|
+
const SCALE_PREFIXES = ['m', 'b', 'tr', 'quadr', 'quint', 'sest', 'sett', 'ott', 'nov', 'dec']
|
|
44
|
+
|
|
45
|
+
// ============================================================================
|
|
46
|
+
// Ordinal Vocabulary
|
|
47
|
+
// ============================================================================
|
|
48
|
+
|
|
49
|
+
// Irregular ordinals 1-10 (masculine form)
|
|
50
|
+
const ORDINAL_ONES = ['', 'primo', 'secondo', 'terzo', 'quarto', 'quinto', 'sesto', 'settimo', 'ottavo', 'nono', 'decimo']
|
|
51
|
+
|
|
52
|
+
// Ordinal suffix for 11+
|
|
53
|
+
const ORDINAL_SUFFIX = 'esimo'
|
|
54
|
+
|
|
55
|
+
// ============================================================================
|
|
56
|
+
// Currency Vocabulary (Euro)
|
|
57
|
+
// ============================================================================
|
|
58
|
+
|
|
59
|
+
const EURO = 'euro'
|
|
60
|
+
const CENTESIMO = 'centesimo'
|
|
61
|
+
const CENTESIMI = 'centesimi'
|
|
62
|
+
|
|
63
|
+
// ============================================================================
|
|
64
|
+
// Segment Building
|
|
65
|
+
// ============================================================================
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Builds the segment word for a number 0-999.
|
|
69
|
+
* Handles Italian phonetic elision inline (no regex).
|
|
70
|
+
*
|
|
71
|
+
* Elision rules:
|
|
72
|
+
* - Tens ending in vowel + uno/otto → drop tens vowel: ventuno, ventotto
|
|
73
|
+
* - Hundreds cento + otto/ottanta → centotto, centottanta (drop 'o')
|
|
74
|
+
* - Final 'tre' in compounds becomes 'tré': ventitré, trentatré
|
|
75
|
+
*/
|
|
76
|
+
function buildSegment (n) {
|
|
77
|
+
if (n === 0) return ''
|
|
78
|
+
|
|
79
|
+
const ones = n % 10
|
|
80
|
+
const tens = Math.trunc(n / 10) % 10
|
|
81
|
+
const hundreds = Math.trunc(n / 100)
|
|
82
|
+
|
|
83
|
+
let result = ''
|
|
84
|
+
|
|
85
|
+
// Hundreds
|
|
86
|
+
if (hundreds > 0) {
|
|
87
|
+
// Elision: *cento + otto/ottanta → *centotto/centottanta (drop final 'o')
|
|
88
|
+
// Only applies when tens = 8 (ottanta) or tens = 0 and ones = 8 (otto)
|
|
89
|
+
if (tens === 8 || (tens === 0 && ones === 8)) {
|
|
90
|
+
// Remove final 'o' from hundreds: cento→cent, duecento→duecent, etc.
|
|
91
|
+
result = HUNDREDS[hundreds].slice(0, -1)
|
|
92
|
+
} else {
|
|
93
|
+
result = HUNDREDS[hundreds]
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Tens and ones
|
|
98
|
+
if (tens === 0 && ones === 0) {
|
|
99
|
+
// Nothing more (just hundreds)
|
|
100
|
+
} else if (tens === 1) {
|
|
101
|
+
// Teens: 10-19
|
|
102
|
+
result += TEENS[ones]
|
|
103
|
+
} else if (tens >= 2) {
|
|
104
|
+
// 20-99: handle elision for uno (1) and otto (8)
|
|
105
|
+
if (ones === 1 || ones === 8) {
|
|
106
|
+
// Use stem form: vent + uno = ventuno, vent + otto = ventotto
|
|
107
|
+
result += TENS_STEM[tens] + ONES[ones]
|
|
108
|
+
} else if (ones === 3) {
|
|
109
|
+
// Final tre becomes tré
|
|
110
|
+
result += TENS[tens] + 'tré'
|
|
111
|
+
} else if (ones > 0) {
|
|
112
|
+
result += TENS[tens] + ONES[ones]
|
|
113
|
+
} else {
|
|
114
|
+
result += TENS[tens]
|
|
115
|
+
}
|
|
116
|
+
} else if (ones > 0) {
|
|
117
|
+
// 1-9 (tens === 0)
|
|
118
|
+
if (ones === 3 && hundreds > 0) {
|
|
119
|
+
// centotré, duecentotré, etc.
|
|
120
|
+
result += 'tré'
|
|
121
|
+
} else {
|
|
122
|
+
result += ONES[ones]
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return result
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Builds segment word with "un" for scale context (millions, billions).
|
|
131
|
+
* Same as buildSegment but returns "un" for 1 instead of "uno".
|
|
132
|
+
*/
|
|
133
|
+
function buildSegmentForScale (n) {
|
|
134
|
+
if (n === 0) return ''
|
|
135
|
+
if (n === 1) return 'un' // "un milione" not "uno milione"
|
|
136
|
+
return buildSegment(n)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Builds thousands word for 1-999 thousand.
|
|
141
|
+
* Handles elision: tre + mila = tremila (no accent), otto + mila = ottomila
|
|
142
|
+
*/
|
|
143
|
+
function buildThousands (n) {
|
|
144
|
+
if (n === 0) return ''
|
|
145
|
+
if (n === 1) return THOUSAND_SINGULAR // "mille"
|
|
146
|
+
|
|
147
|
+
// Build segment and append "mila"
|
|
148
|
+
// Note: elision of segment ending vowel + 'mila' not needed (mila starts with 'm')
|
|
149
|
+
// But we need to handle cases like "ottomila" (no double-o issue since we build directly)
|
|
150
|
+
return buildSegment(n) + THOUSAND_PLURAL_SUFFIX
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// ============================================================================
|
|
154
|
+
// Scale Word Functions
|
|
155
|
+
// ============================================================================
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Gets singular scale word for index.
|
|
159
|
+
* @param {number} scaleIndex - 2=million, 3=billion, etc.
|
|
160
|
+
*/
|
|
161
|
+
function getScaleWordSingular (scaleIndex) {
|
|
162
|
+
if (scaleIndex < 2) return ''
|
|
163
|
+
const prefixIndex = Math.trunc((scaleIndex - 2) / 2)
|
|
164
|
+
const isIardo = (scaleIndex - 2) % 2 === 1
|
|
165
|
+
const prefix = SCALE_PREFIXES[prefixIndex]
|
|
166
|
+
if (!prefix) return ''
|
|
167
|
+
return prefix + (isIardo ? 'iliardo' : 'ilione')
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Gets plural scale word for index.
|
|
172
|
+
* @param {number} scaleIndex - 2=million, 3=billion, etc.
|
|
173
|
+
*/
|
|
174
|
+
function getScaleWordPlural (scaleIndex) {
|
|
175
|
+
if (scaleIndex < 2) return ''
|
|
176
|
+
const prefixIndex = Math.trunc((scaleIndex - 2) / 2)
|
|
177
|
+
const isIardo = (scaleIndex - 2) % 2 === 1
|
|
178
|
+
const prefix = SCALE_PREFIXES[prefixIndex]
|
|
179
|
+
if (!prefix) return ''
|
|
180
|
+
return prefix + (isIardo ? 'iliardi' : 'ilioni')
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// ============================================================================
|
|
184
|
+
// Conversion Functions
|
|
185
|
+
// ============================================================================
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Converts a non-negative integer to Italian words.
|
|
189
|
+
*
|
|
190
|
+
* @param {bigint} n - Non-negative integer to convert
|
|
191
|
+
* @returns {string} Italian words
|
|
192
|
+
*/
|
|
193
|
+
function integerToWords (n) {
|
|
194
|
+
if (n === 0n) return ZERO
|
|
195
|
+
|
|
196
|
+
// Fast path: numbers < 1000
|
|
197
|
+
if (n < 1000n) {
|
|
198
|
+
return buildSegment(Number(n))
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// Fast path: numbers < 1,000,000 (thousands)
|
|
202
|
+
if (n < 1_000_000n) {
|
|
203
|
+
const thousands = Number(n / 1000n)
|
|
204
|
+
const remainder = Number(n % 1000n)
|
|
205
|
+
|
|
206
|
+
if (remainder === 0) {
|
|
207
|
+
return buildThousands(thousands)
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// Concatenate thousands + remainder
|
|
211
|
+
return buildThousands(thousands) + buildSegment(remainder)
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// For numbers >= 1,000,000, use scale decomposition
|
|
215
|
+
return buildLargeNumberWords(n)
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Builds words for numbers >= 1,000,000.
|
|
220
|
+
*
|
|
221
|
+
* @param {bigint} n - Number >= 1,000,000
|
|
222
|
+
* @returns {string} Italian words
|
|
223
|
+
*/
|
|
224
|
+
function buildLargeNumberWords (n) {
|
|
225
|
+
const parts = []
|
|
226
|
+
let remaining = n
|
|
227
|
+
|
|
228
|
+
// Find the highest scale
|
|
229
|
+
let maxScale = 2
|
|
230
|
+
let testValue = 1_000_000n
|
|
231
|
+
while (testValue * 1000n <= remaining) {
|
|
232
|
+
testValue *= 1000n
|
|
233
|
+
maxScale++
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// Process from highest scale down
|
|
237
|
+
for (let scaleIndex = maxScale; scaleIndex >= 0; scaleIndex--) {
|
|
238
|
+
const divisor = 1000n ** BigInt(scaleIndex)
|
|
239
|
+
const segment = remaining / divisor
|
|
240
|
+
remaining = remaining % divisor
|
|
241
|
+
|
|
242
|
+
if (segment === 0n) continue
|
|
243
|
+
|
|
244
|
+
const segNum = Number(segment)
|
|
245
|
+
|
|
246
|
+
if (scaleIndex >= 2) {
|
|
247
|
+
// Millions and above: "segment scaleWord"
|
|
248
|
+
const segmentWords = buildSegmentForScale(segNum)
|
|
249
|
+
const scaleWord = segment === 1n
|
|
250
|
+
? getScaleWordSingular(scaleIndex)
|
|
251
|
+
: getScaleWordPlural(scaleIndex)
|
|
252
|
+
parts.push(segmentWords + ' ' + scaleWord)
|
|
253
|
+
} else if (scaleIndex === 1) {
|
|
254
|
+
// Thousands
|
|
255
|
+
parts.push(buildThousands(segNum))
|
|
256
|
+
} else {
|
|
257
|
+
// Units (scaleIndex === 0): just the segment
|
|
258
|
+
parts.push(buildSegment(segNum))
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
return joinPartsWithConnector(parts)
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Joins parts with Italian connector rules.
|
|
267
|
+
* Uses "e" before simple (non-compound) final segment.
|
|
268
|
+
*
|
|
269
|
+
* @param {string[]} parts - Parts to join
|
|
270
|
+
* @returns {string} Joined string
|
|
271
|
+
*/
|
|
272
|
+
function joinPartsWithConnector (parts) {
|
|
273
|
+
const len = parts.length
|
|
274
|
+
if (len === 0) return ''
|
|
275
|
+
if (len === 1) return parts[0]
|
|
276
|
+
|
|
277
|
+
// Check if last part is "simple" (no space = no scale word)
|
|
278
|
+
const lastPart = parts[len - 1]
|
|
279
|
+
if (lastPart.indexOf(' ') === -1) {
|
|
280
|
+
// Join all but last with space, then add "e" connector
|
|
281
|
+
let result = parts[0]
|
|
282
|
+
for (let i = 1; i < len - 1; i++) {
|
|
283
|
+
result += ' ' + parts[i]
|
|
284
|
+
}
|
|
285
|
+
return result + ' e ' + lastPart
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// Join with spaces
|
|
289
|
+
let result = parts[0]
|
|
290
|
+
for (let i = 1; i < len; i++) {
|
|
291
|
+
result += ' ' + parts[i]
|
|
292
|
+
}
|
|
293
|
+
return result
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* Converts decimal digits to Italian words.
|
|
298
|
+
*
|
|
299
|
+
* @param {string} decimalPart - Decimal digits (without the point)
|
|
300
|
+
* @returns {string} Italian words for decimal part
|
|
301
|
+
*/
|
|
302
|
+
function decimalPartToWords (decimalPart) {
|
|
303
|
+
let result = ''
|
|
304
|
+
|
|
305
|
+
// Handle leading zeros
|
|
306
|
+
let i = 0
|
|
307
|
+
while (i < decimalPart.length && decimalPart[i] === '0') {
|
|
308
|
+
if (result) result += ' '
|
|
309
|
+
result += ZERO
|
|
310
|
+
i++
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// Convert remainder as a single number
|
|
314
|
+
const remainder = decimalPart.slice(i)
|
|
315
|
+
if (remainder) {
|
|
316
|
+
if (result) result += ' '
|
|
317
|
+
result += integerToWords(BigInt(remainder))
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
return result
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Converts a numeric value to Italian words.
|
|
325
|
+
*
|
|
326
|
+
* This is the main public API. It accepts any valid numeric input
|
|
327
|
+
* (number, string, or bigint) and handles parsing internally.
|
|
328
|
+
*
|
|
329
|
+
* @param {number | string | bigint} value - The numeric value to convert
|
|
330
|
+
* @returns {string} The number in Italian words
|
|
331
|
+
* @throws {TypeError} If value is not a valid numeric type
|
|
332
|
+
* @throws {Error} If value is not a valid number format
|
|
333
|
+
*
|
|
334
|
+
* @example
|
|
335
|
+
* toCardinal(28) // 'ventotto'
|
|
336
|
+
* toCardinal(23) // 'ventitré'
|
|
337
|
+
* toCardinal(1000) // 'mille'
|
|
338
|
+
* toCardinal(2000) // 'duemila'
|
|
339
|
+
* toCardinal(1000000) // 'un milione'
|
|
340
|
+
*/
|
|
341
|
+
function toCardinal (value) {
|
|
342
|
+
const { isNegative, integerPart, decimalPart } = parseCardinalValue(value)
|
|
343
|
+
|
|
344
|
+
let result = ''
|
|
345
|
+
|
|
346
|
+
if (isNegative) {
|
|
347
|
+
result = NEGATIVE + ' '
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
result += integerToWords(integerPart)
|
|
351
|
+
|
|
352
|
+
if (decimalPart) {
|
|
353
|
+
result += ' ' + DECIMAL_SEP + ' ' + decimalPartToWords(decimalPart)
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
return result
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
// ============================================================================
|
|
360
|
+
// ORDINAL: toOrdinal(value)
|
|
361
|
+
// ============================================================================
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* Converts a cardinal word to ordinal form by dropping final vowel and adding -esimo.
|
|
365
|
+
*
|
|
366
|
+
* @param {string} cardinalWord - Cardinal word to convert
|
|
367
|
+
* @returns {string} Ordinal form
|
|
368
|
+
*/
|
|
369
|
+
function cardinalToOrdinal (cardinalWord) {
|
|
370
|
+
// Handle accented 'é' at end (tré → tre + esimo = treesimo)
|
|
371
|
+
if (cardinalWord.endsWith('é')) {
|
|
372
|
+
return cardinalWord.slice(0, -1) + 'e' + ORDINAL_SUFFIX
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
// Handle "mila" ending (duemila → duemillesimo, not duemilesimo)
|
|
376
|
+
// The ordinal of thousand is "millesimo" (from mille), not "milesimo"
|
|
377
|
+
if (cardinalWord.endsWith('mila')) {
|
|
378
|
+
return cardinalWord.slice(0, -4) + 'mill' + ORDINAL_SUFFIX
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
// Handle "mille" ending (mille → millesimo)
|
|
382
|
+
if (cardinalWord.endsWith('mille')) {
|
|
383
|
+
return cardinalWord.slice(0, -1) + ORDINAL_SUFFIX
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
// Handle -ardo/-ardi endings (miliardo → miliardiesimo)
|
|
387
|
+
// These scale words get -iesimo not -esimo
|
|
388
|
+
if (cardinalWord.endsWith('ardo') || cardinalWord.endsWith('ardi')) {
|
|
389
|
+
return cardinalWord.slice(0, -1) + 'i' + ORDINAL_SUFFIX
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
// Drop final regular vowel before adding -esimo
|
|
393
|
+
const lastChar = cardinalWord.slice(-1)
|
|
394
|
+
if ('aeiouàèìòù'.includes(lastChar)) {
|
|
395
|
+
return cardinalWord.slice(0, -1) + ORDINAL_SUFFIX
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
// If doesn't end in vowel, just add suffix
|
|
399
|
+
return cardinalWord + ORDINAL_SUFFIX
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Converts a positive integer to Italian ordinal words.
|
|
404
|
+
*
|
|
405
|
+
* @param {bigint} n - Positive integer
|
|
406
|
+
* @returns {string} Italian ordinal words (masculine form)
|
|
407
|
+
*/
|
|
408
|
+
function integerToOrdinal (n) {
|
|
409
|
+
// Special cases: 1-10 have irregular forms
|
|
410
|
+
if (n <= 10n) {
|
|
411
|
+
return ORDINAL_ONES[Number(n)]
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
// For 11+, convert cardinal and apply -esimo
|
|
415
|
+
const cardinalWord = integerToWords(n)
|
|
416
|
+
return cardinalToOrdinal(cardinalWord)
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* Converts a numeric value to Italian ordinal words.
|
|
421
|
+
*
|
|
422
|
+
* Italian ordinals: primo, secondo, terzo... (1-10 irregular)
|
|
423
|
+
* For 11+: cardinal word (drop final vowel) + -esimo
|
|
424
|
+
*
|
|
425
|
+
* @param {number | string | bigint} value - The numeric value to convert (positive integer)
|
|
426
|
+
* @returns {string} The number as ordinal words (masculine form)
|
|
427
|
+
* @throws {TypeError} If value is not a valid numeric type
|
|
428
|
+
* @throws {RangeError} If value is negative, zero, or has a decimal part
|
|
429
|
+
*
|
|
430
|
+
* @example
|
|
431
|
+
* toOrdinal(1) // 'primo'
|
|
432
|
+
* toOrdinal(2) // 'secondo'
|
|
433
|
+
* toOrdinal(11) // 'undicesimo'
|
|
434
|
+
* toOrdinal(21) // 'ventunesimo'
|
|
435
|
+
* toOrdinal(100) // 'centesimo'
|
|
436
|
+
* toOrdinal(1000) // 'millesimo'
|
|
437
|
+
*/
|
|
438
|
+
function toOrdinal (value) {
|
|
439
|
+
const integerPart = parseOrdinalValue(value)
|
|
440
|
+
return integerToOrdinal(integerPart)
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
// ============================================================================
|
|
444
|
+
// CURRENCY: toCurrency(value, options?)
|
|
445
|
+
// ============================================================================
|
|
446
|
+
|
|
447
|
+
/**
|
|
448
|
+
* Converts a numeric value to Italian currency words (Euro).
|
|
449
|
+
*
|
|
450
|
+
* @param {number | string | bigint} value - The currency amount to convert
|
|
451
|
+
* @param {Object} [options] - Optional configuration
|
|
452
|
+
* @param {boolean} [options.and=true] - Use "e" between euros and centesimi
|
|
453
|
+
* @returns {string} The amount in Italian currency words
|
|
454
|
+
* @throws {TypeError} If value is not a valid numeric type
|
|
455
|
+
* @throws {Error} If value is not a valid number format
|
|
456
|
+
*
|
|
457
|
+
* @example
|
|
458
|
+
* toCurrency(42.50) // 'quarantadue euro e cinquanta centesimi'
|
|
459
|
+
* toCurrency(1) // 'un euro'
|
|
460
|
+
* toCurrency(0.99) // 'novantanove centesimi'
|
|
461
|
+
* toCurrency(0.01) // 'un centesimo'
|
|
462
|
+
* toCurrency(42.50, { and: false }) // 'quarantadue euro cinquanta centesimi'
|
|
463
|
+
*/
|
|
464
|
+
function toCurrency (value, options) {
|
|
465
|
+
options = validateOptions(options)
|
|
466
|
+
const { isNegative, dollars: euros, cents: centesimi } = parseCurrencyValue(value)
|
|
467
|
+
const { and: useAnd = true } = options
|
|
468
|
+
|
|
469
|
+
// Build result
|
|
470
|
+
let result = ''
|
|
471
|
+
if (isNegative) result = NEGATIVE + ' '
|
|
472
|
+
|
|
473
|
+
// Euros part
|
|
474
|
+
if (euros > 0n || centesimi === 0n) {
|
|
475
|
+
// Use "un" for 1 euro instead of "uno"
|
|
476
|
+
if (euros === 1n) {
|
|
477
|
+
result += 'un'
|
|
478
|
+
} else {
|
|
479
|
+
result += integerToWords(euros)
|
|
480
|
+
}
|
|
481
|
+
// Euro is invariable (doesn't change for plural in Italian)
|
|
482
|
+
result += ' ' + EURO
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
// Centesimi part
|
|
486
|
+
if (centesimi > 0n) {
|
|
487
|
+
if (euros > 0n) {
|
|
488
|
+
result += useAnd ? ' e ' : ' '
|
|
489
|
+
}
|
|
490
|
+
// Use "un" for 1 centesimo instead of "uno"
|
|
491
|
+
if (centesimi === 1n) {
|
|
492
|
+
result += 'un'
|
|
493
|
+
} else {
|
|
494
|
+
result += integerToWords(centesimi)
|
|
495
|
+
}
|
|
496
|
+
result += ' ' + (centesimi === 1n ? CENTESIMO : CENTESIMI)
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
return result
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
// ============================================================================
|
|
503
|
+
// Public API
|
|
504
|
+
// ============================================================================
|
|
505
|
+
|
|
506
|
+
export { toCardinal, toOrdinal, toCurrency }
|
package/src/ja-JP.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a numeric value to Japanese 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 Japanese kanji 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) // '四十二'
|
|
14
|
+
* toCardinal(10000) // '一万'
|
|
15
|
+
* toCardinal(100000000) // '一億'
|
|
16
|
+
*/
|
|
17
|
+
export function toCardinal(value: number | string | bigint): string;
|
|
18
|
+
/**
|
|
19
|
+
* Converts a numeric value to Japanese ordinal words.
|
|
20
|
+
*
|
|
21
|
+
* @param {number | string | bigint} value - The numeric value to convert (positive integer)
|
|
22
|
+
* @returns {string} The number as ordinal words
|
|
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) // '第一'
|
|
28
|
+
* toOrdinal(10) // '第十'
|
|
29
|
+
* toOrdinal(100) // '第百'
|
|
30
|
+
*/
|
|
31
|
+
export function toOrdinal(value: number | string | bigint): string;
|
|
32
|
+
/**
|
|
33
|
+
* Converts a numeric value to Japanese currency words (Yen).
|
|
34
|
+
*
|
|
35
|
+
* Note: Sen (銭, 1/100 yen) is included for completeness but is rarely used
|
|
36
|
+
* in modern Japan. Most transactions are in whole yen.
|
|
37
|
+
*
|
|
38
|
+
* @param {number | string | bigint} value - The currency amount to convert
|
|
39
|
+
* @returns {string} The amount in Japanese currency words
|
|
40
|
+
* @throws {TypeError} If value is not a valid numeric type
|
|
41
|
+
* @throws {Error} If value is not a valid number format
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* toCurrency(42) // '四十二円'
|
|
45
|
+
* toCurrency(1) // '一円'
|
|
46
|
+
* toCurrency(0.50) // '五十銭'
|
|
47
|
+
* toCurrency(42.50) // '四十二円五十銭'
|
|
48
|
+
*/
|
|
49
|
+
export function toCurrency(value: number | string | bigint): string;
|