n2words 1.24.0 → 3.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.
Files changed (280) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/README.md +183 -156
  3. package/dist/languages/am-Latn.js +3 -0
  4. package/dist/languages/am-Latn.js.map +1 -0
  5. package/dist/languages/am.js +3 -0
  6. package/dist/languages/am.js.map +1 -0
  7. package/dist/languages/ar.js +3 -2
  8. package/dist/languages/ar.js.map +1 -1
  9. package/dist/languages/az.js +3 -2
  10. package/dist/languages/az.js.map +1 -1
  11. package/dist/languages/bn.js +3 -2
  12. package/dist/languages/bn.js.map +1 -1
  13. package/dist/languages/cs.js +3 -2
  14. package/dist/languages/cs.js.map +1 -1
  15. package/dist/languages/da.js +3 -2
  16. package/dist/languages/da.js.map +1 -1
  17. package/dist/languages/de.js +3 -2
  18. package/dist/languages/de.js.map +1 -1
  19. package/dist/languages/el.js +3 -2
  20. package/dist/languages/el.js.map +1 -1
  21. package/dist/languages/en.js +3 -2
  22. package/dist/languages/en.js.map +1 -1
  23. package/dist/languages/es.js +3 -2
  24. package/dist/languages/es.js.map +1 -1
  25. package/dist/languages/fa.js +3 -2
  26. package/dist/languages/fa.js.map +1 -1
  27. package/dist/languages/fi.js +3 -0
  28. package/dist/languages/fi.js.map +1 -0
  29. package/dist/languages/fil.js +3 -2
  30. package/dist/languages/fil.js.map +1 -1
  31. package/dist/languages/fr-BE.js +3 -2
  32. package/dist/languages/fr-BE.js.map +1 -1
  33. package/dist/languages/fr.js +3 -2
  34. package/dist/languages/fr.js.map +1 -1
  35. package/dist/languages/gu.js +3 -2
  36. package/dist/languages/gu.js.map +1 -1
  37. package/dist/languages/ha.js +3 -0
  38. package/dist/languages/ha.js.map +1 -0
  39. package/dist/languages/hbo.js +3 -0
  40. package/dist/languages/hbo.js.map +1 -0
  41. package/dist/languages/he.js +3 -2
  42. package/dist/languages/he.js.map +1 -1
  43. package/dist/languages/hi.js +3 -2
  44. package/dist/languages/hi.js.map +1 -1
  45. package/dist/languages/hr.js +3 -2
  46. package/dist/languages/hr.js.map +1 -1
  47. package/dist/languages/hu.js +3 -2
  48. package/dist/languages/hu.js.map +1 -1
  49. package/dist/languages/id.js +3 -2
  50. package/dist/languages/id.js.map +1 -1
  51. package/dist/languages/it.js +3 -2
  52. package/dist/languages/it.js.map +1 -1
  53. package/dist/languages/ja.js +3 -2
  54. package/dist/languages/ja.js.map +1 -1
  55. package/dist/languages/kn.js +3 -2
  56. package/dist/languages/kn.js.map +1 -1
  57. package/dist/languages/ko.js +3 -2
  58. package/dist/languages/ko.js.map +1 -1
  59. package/dist/languages/lt.js +3 -2
  60. package/dist/languages/lt.js.map +1 -1
  61. package/dist/languages/lv.js +3 -2
  62. package/dist/languages/lv.js.map +1 -1
  63. package/dist/languages/mr.js +3 -2
  64. package/dist/languages/mr.js.map +1 -1
  65. package/dist/languages/ms.js +3 -2
  66. package/dist/languages/ms.js.map +1 -1
  67. package/dist/languages/nb.js +3 -2
  68. package/dist/languages/nb.js.map +1 -1
  69. package/dist/languages/nl.js +3 -2
  70. package/dist/languages/nl.js.map +1 -1
  71. package/dist/languages/pa.js +3 -0
  72. package/dist/languages/pa.js.map +1 -0
  73. package/dist/languages/pl.js +3 -2
  74. package/dist/languages/pl.js.map +1 -1
  75. package/dist/languages/pt.js +3 -2
  76. package/dist/languages/pt.js.map +1 -1
  77. package/dist/languages/ro.js +3 -2
  78. package/dist/languages/ro.js.map +1 -1
  79. package/dist/languages/ru.js +3 -2
  80. package/dist/languages/ru.js.map +1 -1
  81. package/dist/languages/sr-Cyrl.js +3 -0
  82. package/dist/languages/sr-Cyrl.js.map +1 -0
  83. package/dist/languages/sr-Latn.js +3 -2
  84. package/dist/languages/sr-Latn.js.map +1 -1
  85. package/dist/languages/sv.js +3 -2
  86. package/dist/languages/sv.js.map +1 -1
  87. package/dist/languages/sw.js +3 -2
  88. package/dist/languages/sw.js.map +1 -1
  89. package/dist/languages/ta.js +3 -2
  90. package/dist/languages/ta.js.map +1 -1
  91. package/dist/languages/te.js +3 -2
  92. package/dist/languages/te.js.map +1 -1
  93. package/dist/languages/th.js +3 -2
  94. package/dist/languages/th.js.map +1 -1
  95. package/dist/languages/tr.js +3 -2
  96. package/dist/languages/tr.js.map +1 -1
  97. package/dist/languages/uk.js +3 -2
  98. package/dist/languages/uk.js.map +1 -1
  99. package/dist/languages/ur.js +3 -2
  100. package/dist/languages/ur.js.map +1 -1
  101. package/dist/languages/vi.js +3 -2
  102. package/dist/languages/vi.js.map +1 -1
  103. package/dist/languages/zh-Hans.js +3 -2
  104. package/dist/languages/zh-Hans.js.map +1 -1
  105. package/dist/languages/zh-Hant.js +3 -0
  106. package/dist/languages/zh-Hant.js.map +1 -0
  107. package/dist/n2words.js +3 -2
  108. package/dist/n2words.js.map +1 -1
  109. package/lib/languages/am-Latn.d.ts +7 -0
  110. package/lib/languages/am-Latn.js +164 -0
  111. package/lib/languages/am.d.ts +7 -0
  112. package/lib/languages/am.js +164 -0
  113. package/lib/languages/ar.d.ts +17 -0
  114. package/lib/languages/ar.js +171 -209
  115. package/lib/languages/az.d.ts +7 -0
  116. package/lib/languages/az.js +167 -49
  117. package/lib/languages/bn.d.ts +7 -0
  118. package/lib/languages/bn.js +142 -123
  119. package/lib/languages/cs.d.ts +18 -0
  120. package/lib/languages/cs.js +303 -176
  121. package/lib/languages/da.d.ts +14 -0
  122. package/lib/languages/da.js +267 -139
  123. package/lib/languages/de.d.ts +17 -0
  124. package/lib/languages/de.js +310 -113
  125. package/lib/languages/el.d.ts +14 -0
  126. package/lib/languages/el.js +225 -98
  127. package/lib/languages/en.d.ts +17 -0
  128. package/lib/languages/en.js +235 -102
  129. package/lib/languages/es.d.ts +21 -0
  130. package/lib/languages/es.js +307 -125
  131. package/lib/languages/fa.d.ts +7 -0
  132. package/lib/languages/fa.js +115 -108
  133. package/lib/languages/fi.d.ts +14 -0
  134. package/lib/languages/fi.js +245 -0
  135. package/lib/languages/fil.d.ts +7 -0
  136. package/lib/languages/fil.js +199 -139
  137. package/lib/languages/fr-BE.d.ts +11 -0
  138. package/lib/languages/fr-BE.js +287 -48
  139. package/lib/languages/fr.d.ts +21 -0
  140. package/lib/languages/fr.js +343 -119
  141. package/lib/languages/gu.d.ts +7 -0
  142. package/lib/languages/gu.js +125 -144
  143. package/lib/languages/ha.d.ts +7 -0
  144. package/lib/languages/ha.js +230 -0
  145. package/lib/languages/hbo.d.ts +13 -0
  146. package/lib/languages/hbo.js +300 -0
  147. package/lib/languages/he.d.ts +13 -0
  148. package/lib/languages/he.js +230 -283
  149. package/lib/languages/hi.d.ts +7 -0
  150. package/lib/languages/hi.js +142 -123
  151. package/lib/languages/hr.d.ts +11 -0
  152. package/lib/languages/hr.js +190 -129
  153. package/lib/languages/hu.d.ts +7 -0
  154. package/lib/languages/hu.js +194 -133
  155. package/lib/languages/id.d.ts +7 -0
  156. package/lib/languages/id.js +167 -140
  157. package/lib/languages/it.d.ts +19 -0
  158. package/lib/languages/it.js +337 -108
  159. package/lib/languages/ja.d.ts +17 -0
  160. package/lib/languages/ja.js +224 -155
  161. package/lib/languages/kn.d.ts +7 -0
  162. package/lib/languages/kn.js +128 -62
  163. package/lib/languages/ko.d.ts +14 -0
  164. package/lib/languages/ko.js +250 -70
  165. package/lib/languages/lt.d.ts +18 -0
  166. package/lib/languages/lt.js +287 -148
  167. package/lib/languages/lv.d.ts +18 -0
  168. package/lib/languages/lv.js +291 -123
  169. package/lib/languages/mr.d.ts +7 -0
  170. package/lib/languages/mr.js +125 -144
  171. package/lib/languages/ms.d.ts +7 -0
  172. package/lib/languages/ms.js +171 -112
  173. package/lib/languages/nb.d.ts +14 -0
  174. package/lib/languages/nb.js +275 -100
  175. package/lib/languages/nl.d.ts +26 -0
  176. package/lib/languages/nl.js +307 -174
  177. package/lib/languages/pa.d.ts +7 -0
  178. package/lib/languages/pa.js +163 -0
  179. package/lib/languages/pl.d.ts +22 -0
  180. package/lib/languages/pl.js +299 -158
  181. package/lib/languages/pt.d.ts +17 -0
  182. package/lib/languages/pt.js +279 -120
  183. package/lib/languages/ro.d.ts +18 -0
  184. package/lib/languages/ro.js +214 -337
  185. package/lib/languages/ru.d.ts +11 -0
  186. package/lib/languages/ru.js +219 -95
  187. package/lib/languages/sr-Cyrl.d.ts +11 -0
  188. package/lib/languages/sr-Cyrl.js +215 -0
  189. package/lib/languages/sr-Latn.d.ts +11 -0
  190. package/lib/languages/sr-Latn.js +190 -132
  191. package/lib/languages/sv.d.ts +14 -0
  192. package/lib/languages/sv.js +280 -103
  193. package/lib/languages/sw.d.ts +7 -0
  194. package/lib/languages/sw.js +135 -103
  195. package/lib/languages/ta.d.ts +7 -0
  196. package/lib/languages/ta.js +133 -205
  197. package/lib/languages/te.d.ts +7 -0
  198. package/lib/languages/te.js +148 -213
  199. package/lib/languages/th.d.ts +7 -0
  200. package/lib/languages/th.js +139 -101
  201. package/lib/languages/tr.d.ts +18 -0
  202. package/lib/languages/tr.js +246 -66
  203. package/lib/languages/uk.d.ts +11 -0
  204. package/lib/languages/uk.js +197 -101
  205. package/lib/languages/ur.d.ts +7 -0
  206. package/lib/languages/ur.js +160 -123
  207. package/lib/languages/vi.d.ts +17 -0
  208. package/lib/languages/vi.js +287 -164
  209. package/lib/languages/zh-Hans.d.ts +11 -0
  210. package/lib/languages/zh-Hans.js +159 -142
  211. package/lib/languages/zh-Hant.d.ts +11 -0
  212. package/lib/languages/zh-Hant.js +202 -0
  213. package/lib/n2words.d.ts +53 -0
  214. package/lib/n2words.js +91 -227
  215. package/lib/utils/is-plain-object.d.ts +13 -0
  216. package/lib/utils/is-plain-object.js +17 -0
  217. package/lib/utils/parse-numeric.d.ts +17 -0
  218. package/lib/utils/parse-numeric.js +108 -0
  219. package/lib/utils/validate-options.d.ts +8 -0
  220. package/lib/utils/validate-options.js +16 -0
  221. package/package.json +118 -67
  222. package/dist/languages/pa-Guru.js +0 -2
  223. package/dist/languages/pa-Guru.js.map +0 -1
  224. package/lib/classes/abstract-language.js +0 -261
  225. package/lib/classes/greedy-scale-language.js +0 -195
  226. package/lib/classes/slavic-language.js +0 -251
  227. package/lib/classes/south-asian-language.js +0 -161
  228. package/lib/classes/turkic-language.js +0 -63
  229. package/lib/languages/pa-Guru.js +0 -126
  230. package/typings/classes/abstract-language.d.ts +0 -144
  231. package/typings/classes/greedy-scale-language.d.ts +0 -148
  232. package/typings/classes/slavic-language.d.ts +0 -145
  233. package/typings/classes/south-asian-language.d.ts +0 -101
  234. package/typings/classes/turkic-language.d.ts +0 -42
  235. package/typings/languages/ar.d.ts +0 -93
  236. package/typings/languages/az.d.ts +0 -25
  237. package/typings/languages/bn.d.ts +0 -1
  238. package/typings/languages/cs.d.ts +0 -120
  239. package/typings/languages/da.d.ts +0 -53
  240. package/typings/languages/de.d.ts +0 -26
  241. package/typings/languages/el.d.ts +0 -11
  242. package/typings/languages/en.d.ts +0 -30
  243. package/typings/languages/es.d.ts +0 -43
  244. package/typings/languages/fa.d.ts +0 -81
  245. package/typings/languages/fil.d.ts +0 -12
  246. package/typings/languages/fr-BE.d.ts +0 -41
  247. package/typings/languages/fr.d.ts +0 -43
  248. package/typings/languages/gu.d.ts +0 -12
  249. package/typings/languages/he.d.ts +0 -197
  250. package/typings/languages/hi.d.ts +0 -1
  251. package/typings/languages/hr.d.ts +0 -110
  252. package/typings/languages/hu.d.ts +0 -37
  253. package/typings/languages/id.d.ts +0 -69
  254. package/typings/languages/it.d.ts +0 -51
  255. package/typings/languages/ja.d.ts +0 -58
  256. package/typings/languages/kn.d.ts +0 -11
  257. package/typings/languages/ko.d.ts +0 -25
  258. package/typings/languages/lt.d.ts +0 -110
  259. package/typings/languages/lv.d.ts +0 -99
  260. package/typings/languages/mr.d.ts +0 -12
  261. package/typings/languages/ms.d.ts +0 -37
  262. package/typings/languages/nb.d.ts +0 -27
  263. package/typings/languages/nl.d.ts +0 -65
  264. package/typings/languages/pa-Guru.d.ts +0 -1
  265. package/typings/languages/pl.d.ts +0 -116
  266. package/typings/languages/pt.d.ts +0 -39
  267. package/typings/languages/ro.d.ts +0 -229
  268. package/typings/languages/ru.d.ts +0 -108
  269. package/typings/languages/sr-Latn.d.ts +0 -98
  270. package/typings/languages/sv.d.ts +0 -30
  271. package/typings/languages/sw.d.ts +0 -1
  272. package/typings/languages/ta.d.ts +0 -1
  273. package/typings/languages/te.d.ts +0 -1
  274. package/typings/languages/th.d.ts +0 -1
  275. package/typings/languages/tr.d.ts +0 -46
  276. package/typings/languages/uk.d.ts +0 -117
  277. package/typings/languages/ur.d.ts +0 -1
  278. package/typings/languages/vi.d.ts +0 -116
  279. package/typings/languages/zh-Hans.d.ts +0 -57
  280. package/typings/n2words.d.ts +0 -177
package/lib/n2words.js CHANGED
@@ -1,258 +1,122 @@
1
1
  /**
2
- * @module n2words
3
- */
4
-
5
- /** @typedef {'ar'|'az'|'bn'|'cs'|'de'|'da'|'el'|'en'|'es'|'fa'|'fr'|'fr-BE'|'gu'|'he'|'hi'|'hr'|'hu'|'id'|'it'|'ja'|'kn'|'ko'|'lt'|'lv'|'mr'|'ms'|'nl'|'nb'|'pa-Guru'|'pl'|'pt'|'ro'|'ru'|'sr-Latn'|'sv'|'sw'|'ta'|'te'|'th'|'fil'|'tr'|'uk'|'ur'|'vi'|'zh-Hans'} LanguageCode */
6
-
7
- /**
8
- * @typedef {Object} ArabicOptions
9
- * @property {string} [negativeWord='ناقص'] - Word for negative numbers (minus).
10
- * @property {boolean} [feminine=false] - Use feminine forms for numbers.
11
- */
12
-
13
- /**
14
- * @typedef {Object} ChineseOptions
15
- * @property {boolean} [formal=true] - Use formal/financial numerals (壹贰叁) vs. common numerals (一二三).
16
- */
17
-
18
- /**
19
- * @typedef {Object} HebrewOptions
20
- * @property {string} [and='ו'] - Conjunction character (typically 'ו' for and).
21
- * @property {boolean} [biblical=false] - Use biblical scale words instead of modern ones.
22
- * @property {boolean} [feminine=false] - Use feminine forms for numbers.
23
- */
24
-
25
- /**
26
- * @typedef {Object} SpanishOptions
27
- * @property {('o'|'a'|string)} [genderStem='o'] - Masculine 'o' or feminine 'a' ending.
28
- */
29
-
30
- /**
31
- * @typedef {Object} DutchOptions
32
- * @property {boolean} [includeOptionalAnd=false] - Include optional "en" separator.
33
- * @property {boolean} [noHundredPairs=false] - Disable comma before hundreds.
34
- * @property {boolean} [accentOne=true] - Use accented "één" for one.
35
- */
36
-
37
- /**
38
- * @typedef {Object} FrenchOptions
39
- * @property {boolean} [withHyphenSeparator=false] - Use hyphens (true) instead of spaces (false) in compounds.
40
- */
41
-
42
- /**
43
- * @typedef {Object} TurkishOptions
44
- * @property {boolean} [dropSpaces=false] - Remove spaces between words if true.
45
- */
46
-
47
- /**
48
- * @typedef {Object} RomanianOptions
49
- * @property {boolean} [feminine=false] - Use feminine forms for numbers.
50
- */
51
-
52
- /**
53
- * @typedef {Object} DanishOptions
54
- * @property {boolean} [ordFlag=false] - Enable ordinal number conversion.
55
- */
56
-
57
- /**
58
- * @typedef {Object} SlavicOptions
59
- * @property {boolean} [feminine=false] - Use feminine forms for numbers.
60
- */
61
-
62
- /**
63
- * Configuration object for number-to-words conversion with comprehensive language support.
2
+ * n2words - Number to words converter
3
+ *
4
+ * This module re-exports all language converters as named exports.
5
+ * Each export is a `toWords(value, options?)` function.
64
6
  *
65
- * @typedef {Object} N2WordsOptions
66
- * @property {LanguageCode} [lang='en'] - Target language code with full autocomplete support.
67
- * Supports many languages with regional variants (e.g., 'fr-BE').
68
- * Falls back progressively from most-specific to least-specific (e.g., 'fr-BE' -> 'fr').
69
- * Throws an error if no match is found after fallback attempts.
70
- * @property {string} [negativeWord] - (Arabic only) Word for negative numbers.
71
- * @property {boolean} [feminine] - (Arabic, Hebrew, Romanian, Slavic languages) Use feminine forms.
72
- * @property {boolean} [formal] - (Chinese only) Use formal/financial numerals.
73
- * @property {string} [and] - (Hebrew only) Conjunction character.
74
- * @property {boolean} [biblical] - (Hebrew only) Use biblical scale words.
75
- * @property {('o'|'a'|string)} [genderStem] - (Spanish only) Gender ending.
76
- * @property {boolean} [includeOptionalAnd] - (Dutch only) Include optional "en".
77
- * @property {boolean} [noHundredPairs] - (Dutch only) Disable comma before hundreds.
78
- * @property {boolean} [accentOne] - (Dutch only) Use accented "één".
79
- * @property {boolean} [withHyphenSeparator] - (French, Belgian French) Use hyphens.
80
- * @property {boolean} [dropSpaces] - (Turkish, Azerbaijani) Remove spaces.
81
- * @property {boolean} [ordFlag] - (Danish only) Enable ordinal conversion.
7
+ * Export names use normalized BCP 47 codes (hyphens → camelCase):
8
+ * - `en`, `fr`, `de` (simple codes unchanged)
9
+ * - `zhHans` (zh-Hans), `frBE` (fr-BE), `srCyrl` (sr-Cyrl)
82
10
  *
83
- * Language-specific options are automatically validated and forwarded to converters.
84
- * See individual language implementations for detailed option descriptions.
11
+ * Imports and exports are alphabetically sorted by normalized name.
12
+ *
13
+ * @module n2words
85
14
  */
86
15
 
87
- import ar from './languages/ar.js'
88
- import az from './languages/az.js'
89
- import cs from './languages/cs.js'
90
- import de from './languages/de.js'
91
- import da from './languages/da.js'
92
- import en from './languages/en.js'
93
- import es from './languages/es.js'
94
- import fa from './languages/fa.js'
95
- import sw from './languages/sw.js'
96
- import fr from './languages/fr.js'
97
- import frBE from './languages/fr-BE.js'
98
- import he from './languages/he.js'
99
- import hr from './languages/hr.js'
100
- import hu from './languages/hu.js'
101
- import id from './languages/id.js'
102
- import ms from './languages/ms.js'
103
- import it from './languages/it.js'
104
- import ja from './languages/ja.js'
105
- import hi from './languages/hi.js'
106
- import bn from './languages/bn.js'
107
- import ko from './languages/ko.js'
108
- import th from './languages/th.js'
109
- import ta from './languages/ta.js'
110
- import te from './languages/te.js'
111
- import sv from './languages/sv.js'
112
- import lt from './languages/lt.js'
113
- import lv from './languages/lv.js'
114
- import nl from './languages/nl.js'
115
- import nb from './languages/nb.js'
116
- import pl from './languages/pl.js'
117
- import pt from './languages/pt.js'
118
- import ro from './languages/ro.js'
119
- import ru from './languages/ru.js'
120
- import srLatn from './languages/sr-Latn.js'
121
- import tr from './languages/tr.js'
122
- import uk from './languages/uk.js'
123
- import vi from './languages/vi.js'
124
- import zhHans from './languages/zh-Hans.js'
125
- import ur from './languages/ur.js'
126
- import paGuru from './languages/pa-Guru.js'
127
- import fil from './languages/fil.js'
128
- import mr from './languages/mr.js'
129
- import gu from './languages/gu.js'
130
- import kn from './languages/kn.js'
131
- import el from './languages/el.js'
132
-
133
- /**
134
- * Language converter registry.
135
- * Contains converters for all supported languages, statically imported to work
136
- * in both Node.js and browser environments (enables bundler dead-code elimination).
137
- * Keys are language codes (e.g., 'en', 'fr', 'fr-BE'); values are converter functions.
138
- * @type {Object<string, Function>}
139
- */
140
- const dict = {
16
+ import { toWords as am } from './languages/am.js'
17
+ import { toWords as amLatn } from './languages/am-Latn.js'
18
+ import { toWords as ar } from './languages/ar.js'
19
+ import { toWords as az } from './languages/az.js'
20
+ import { toWords as bn } from './languages/bn.js'
21
+ import { toWords as cs } from './languages/cs.js'
22
+ import { toWords as da } from './languages/da.js'
23
+ import { toWords as de } from './languages/de.js'
24
+ import { toWords as el } from './languages/el.js'
25
+ import { toWords as en } from './languages/en.js'
26
+ import { toWords as es } from './languages/es.js'
27
+ import { toWords as fa } from './languages/fa.js'
28
+ import { toWords as fi } from './languages/fi.js'
29
+ import { toWords as fil } from './languages/fil.js'
30
+ import { toWords as fr } from './languages/fr.js'
31
+ import { toWords as frBE } from './languages/fr-BE.js'
32
+ import { toWords as gu } from './languages/gu.js'
33
+ import { toWords as ha } from './languages/ha.js'
34
+ import { toWords as hbo } from './languages/hbo.js'
35
+ import { toWords as he } from './languages/he.js'
36
+ import { toWords as hi } from './languages/hi.js'
37
+ import { toWords as hr } from './languages/hr.js'
38
+ import { toWords as hu } from './languages/hu.js'
39
+ import { toWords as id } from './languages/id.js'
40
+ import { toWords as it } from './languages/it.js'
41
+ import { toWords as ja } from './languages/ja.js'
42
+ import { toWords as kn } from './languages/kn.js'
43
+ import { toWords as ko } from './languages/ko.js'
44
+ import { toWords as lt } from './languages/lt.js'
45
+ import { toWords as lv } from './languages/lv.js'
46
+ import { toWords as mr } from './languages/mr.js'
47
+ import { toWords as ms } from './languages/ms.js'
48
+ import { toWords as nb } from './languages/nb.js'
49
+ import { toWords as nl } from './languages/nl.js'
50
+ import { toWords as pa } from './languages/pa.js'
51
+ import { toWords as pl } from './languages/pl.js'
52
+ import { toWords as pt } from './languages/pt.js'
53
+ import { toWords as ro } from './languages/ro.js'
54
+ import { toWords as ru } from './languages/ru.js'
55
+ import { toWords as srCyrl } from './languages/sr-Cyrl.js'
56
+ import { toWords as srLatn } from './languages/sr-Latn.js'
57
+ import { toWords as sv } from './languages/sv.js'
58
+ import { toWords as sw } from './languages/sw.js'
59
+ import { toWords as ta } from './languages/ta.js'
60
+ import { toWords as te } from './languages/te.js'
61
+ import { toWords as th } from './languages/th.js'
62
+ import { toWords as tr } from './languages/tr.js'
63
+ import { toWords as uk } from './languages/uk.js'
64
+ import { toWords as ur } from './languages/ur.js'
65
+ import { toWords as vi } from './languages/vi.js'
66
+ import { toWords as zhHans } from './languages/zh-Hans.js'
67
+ import { toWords as zhHant } from './languages/zh-Hant.js'
68
+
69
+ export {
70
+ am,
71
+ amLatn,
141
72
  ar,
142
73
  az,
74
+ bn,
143
75
  cs,
144
- de,
145
76
  da,
77
+ de,
78
+ el,
146
79
  en,
147
80
  es,
148
81
  fa,
149
- sw,
82
+ fi,
83
+ fil,
150
84
  fr,
151
- 'fr-BE': frBE,
85
+ frBE,
86
+ gu,
87
+ ha,
88
+ hbo,
152
89
  he,
90
+ hi,
153
91
  hr,
154
92
  hu,
155
93
  id,
156
- ms,
157
94
  it,
158
95
  ja,
159
- hi,
160
- bn,
96
+ kn,
161
97
  ko,
162
- th,
163
- ta,
164
- te,
165
- sv,
166
98
  lt,
167
99
  lv,
168
- nl,
100
+ mr,
101
+ ms,
169
102
  nb,
103
+ nl,
104
+ pa,
170
105
  pl,
171
106
  pt,
172
107
  ro,
173
108
  ru,
174
- 'sr-Latn': srLatn,
109
+ srCyrl,
110
+ srLatn,
111
+ sv,
112
+ sw,
113
+ ta,
114
+ te,
115
+ th,
175
116
  tr,
176
117
  uk,
177
- vi,
178
- 'zh-Hans': zhHans,
179
118
  ur,
180
- 'pa-Guru': paGuru,
181
- fil,
182
- mr,
183
- gu,
184
- kn,
185
- el
186
- }
187
-
188
- /**
189
- * Convert a numeric value to its cardinal (written) form in the requested language.
190
- *
191
- * This is the main entry point. The library dispatches synchronously to the appropriate
192
- * per-language converter based on the `lang` option. For browser builds, language converters
193
- * are statically imported so bundlers (webpack/rollup) can include them in output; Node.js
194
- * maintains identical behavior via the same static imports.
195
- *
196
- * @param {number|string|bigint} value The number to convert. Accepts:
197
- * - `number` (integer or floating-point),
198
- * - `string` (numeric string, possibly with decimal point),
199
- * - `bigint` for very large integers.
200
- * Decimal numbers as strings preserve precision that `number` type cannot.
201
- * @param {N2WordsOptions} [options={}] Optional configuration object.
202
- *
203
- * @returns {string} A human-readable cardinal representation of `value` in the
204
- * requested language.
205
- *
206
- * @throws {TypeError} If `options` is provided but is not an object.
207
- * @throws {Error} If the requested language is unsupported (no match after fallback).
208
- *
209
- * @example
210
- * // Basic usage
211
- * convertToWords(1, { lang: 'en' }) // => 'one'
212
- * convertToWords('45.67', { lang: 'en' }) // => 'forty-five point six seven'
213
- * convertToWords(123n, { lang: 'fr' }) // => 'cent vingt-trois'
214
- *
215
- * @example
216
- * // Language-specific options (see individual language implementations)
217
- * convertToWords(1, { lang: 'zh-Hans', formal: true }) // Chinese formal style
218
- * convertToWords(1, { lang: 'cs', feminine: true }) // Czech feminine form
219
- */
220
- export default function (value, options = {}) {
221
- if (options !== null && options !== undefined && typeof options !== 'object') {
222
- throw new TypeError('Options must be an object, received: ' + typeof options)
223
- }
224
-
225
- if (options === null) {
226
- options = {}
227
- }
228
-
229
- let languageCode = options.lang
230
-
231
- if (languageCode === undefined) {
232
- return dict.en(value, options)
233
- }
234
-
235
- if (typeof languageCode !== 'string') {
236
- languageCode = String(languageCode)
237
- }
238
-
239
- let languageConverter = dict[languageCode]
240
- if (languageConverter !== undefined) {
241
- return languageConverter(value, options)
242
- }
243
-
244
- // Progressive fallback for regional variants: strip suffix on each iteration.
245
- // Example: 'fr-BE-XX' -> try 'fr-BE' -> try 'fr' -> throw error
246
- // Uses lastIndexOf for efficiency (O(n) vs O(n²) with repeated substring)
247
- let lastDashIndex = languageCode.lastIndexOf('-')
248
- while (lastDashIndex > 0) {
249
- const candidateLanguageCode = languageCode.slice(0, lastDashIndex)
250
- languageConverter = dict[candidateLanguageCode]
251
- if (languageConverter !== undefined) {
252
- return languageConverter(value, options)
253
- }
254
- lastDashIndex = candidateLanguageCode.lastIndexOf('-')
255
- }
256
-
257
- throw new Error('Unsupported language: "' + languageCode + '". Check supported language codes in the documentation.')
119
+ vi,
120
+ zhHans,
121
+ zhHant
258
122
  }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Checks if a value is a plain object (not null, array, or other object types).
3
+ *
4
+ * A plain object is one created by:
5
+ * - Object literal: `{}`
6
+ * - Object.create(null): null-prototype object
7
+ *
8
+ * This excludes arrays, class instances, Map, Set, and other object types.
9
+ *
10
+ * @param {*} value Value to check
11
+ * @returns {boolean} True if value is a plain object
12
+ */
13
+ export function isPlainObject(value: any): boolean;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Checks if a value is a plain object (not null, array, or other object types).
3
+ *
4
+ * A plain object is one created by:
5
+ * - Object literal: `{}`
6
+ * - Object.create(null): null-prototype object
7
+ *
8
+ * This excludes arrays, class instances, Map, Set, and other object types.
9
+ *
10
+ * @param {*} value Value to check
11
+ * @returns {boolean} True if value is a plain object
12
+ */
13
+ export function isPlainObject (value) {
14
+ if (value === null || typeof value !== 'object') return false
15
+ const proto = Object.getPrototypeOf(value)
16
+ return proto === null || proto === Object.prototype
17
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Numeric value parsing utility.
3
+ * Transforms user input (number, string, or bigint) into normalized components.
4
+ * @module parse-numeric
5
+ */
6
+ /**
7
+ * Parses a numeric value into its components.
8
+ * @param {number|string|bigint} value
9
+ * @returns {{isNegative: boolean, integerPart: bigint, decimalPart?: string}}
10
+ * @throws {TypeError} If value is not number, string, or bigint
11
+ * @throws {Error} If value is not a valid number format
12
+ */
13
+ export function parseNumericValue(value: number | string | bigint): {
14
+ isNegative: boolean;
15
+ integerPart: bigint;
16
+ decimalPart?: string;
17
+ };
@@ -0,0 +1,108 @@
1
+ /**
2
+ * Numeric value parsing utility.
3
+ * Transforms user input (number, string, or bigint) into normalized components.
4
+ * @module parse-numeric
5
+ */
6
+
7
+ /**
8
+ * Parses a numeric value into its components.
9
+ * @param {number|string|bigint} value
10
+ * @returns {{isNegative: boolean, integerPart: bigint, decimalPart?: string}}
11
+ * @throws {TypeError} If value is not number, string, or bigint
12
+ * @throws {Error} If value is not a valid number format
13
+ */
14
+ export function parseNumericValue (value) {
15
+ const type = typeof value
16
+
17
+ // BigInt: simplest case
18
+ if (type === 'bigint') {
19
+ return value < 0n
20
+ ? { isNegative: true, integerPart: -value }
21
+ : { isNegative: false, integerPart: value }
22
+ }
23
+
24
+ // Number: fast path for safe integers
25
+ if (type === 'number') {
26
+ if (!Number.isFinite(value)) {
27
+ throw new Error('Number must be finite (NaN and Infinity are not supported)')
28
+ }
29
+ if (Number.isSafeInteger(value)) {
30
+ return value < 0
31
+ ? { isNegative: true, integerPart: BigInt(-value) }
32
+ : { isNegative: false, integerPart: BigInt(value) }
33
+ }
34
+ return parseNumericString(numberToString(value))
35
+ }
36
+
37
+ // String input
38
+ if (type === 'string') {
39
+ return parseNumericString(normalizeString(value))
40
+ }
41
+
42
+ throw new TypeError(
43
+ `Invalid value type: expected number, string, or bigint, received ${type}`
44
+ )
45
+ }
46
+
47
+ /**
48
+ * Converts a number to decimal string, expanding scientific notation if needed.
49
+ */
50
+ function numberToString (value) {
51
+ const str = value.toString()
52
+ return (str.includes('e') || str.includes('E'))
53
+ ? expandScientificNotation(str)
54
+ : str
55
+ }
56
+
57
+ /**
58
+ * Validates and normalizes a string numeric input.
59
+ */
60
+ function normalizeString (value) {
61
+ const trimmed = value.trim()
62
+ if (trimmed.length === 0 || Number.isNaN(Number(trimmed))) {
63
+ throw new Error(`Invalid number format: "${value}"`)
64
+ }
65
+ return (trimmed.includes('e') || trimmed.includes('E'))
66
+ ? expandScientificNotation(trimmed)
67
+ : trimmed
68
+ }
69
+
70
+ /**
71
+ * Parses a normalized numeric string into components.
72
+ */
73
+ function parseNumericString (str) {
74
+ const isNegative = str[0] === '-'
75
+ if (isNegative) str = str.slice(1)
76
+
77
+ const dotIndex = str.indexOf('.')
78
+ if (dotIndex === -1) {
79
+ return { isNegative, integerPart: BigInt(str) }
80
+ }
81
+
82
+ const integerStr = str.slice(0, dotIndex) || '0'
83
+ const decimalPart = str.slice(dotIndex + 1)
84
+ return { isNegative, integerPart: BigInt(integerStr), decimalPart }
85
+ }
86
+
87
+ /**
88
+ * Expands scientific notation to decimal form (e.g., "1e21" → "1000...").
89
+ */
90
+ function expandScientificNotation (str) {
91
+ const [mantissa, expStr] = str.toLowerCase().split('e')
92
+ const exp = parseInt(expStr, 10)
93
+
94
+ const dotIndex = mantissa.indexOf('.')
95
+ const digits = dotIndex === -1
96
+ ? mantissa
97
+ : mantissa.slice(0, dotIndex) + mantissa.slice(dotIndex + 1)
98
+ const integerLength = dotIndex === -1 ? mantissa.length : dotIndex
99
+ const newDotPosition = integerLength + exp
100
+
101
+ if (newDotPosition >= digits.length) {
102
+ return digits + '0'.repeat(newDotPosition - digits.length)
103
+ }
104
+ if (newDotPosition <= 0) {
105
+ return '0.' + '0'.repeat(-newDotPosition) + digits
106
+ }
107
+ return digits.slice(0, newDotPosition) + '.' + digits.slice(newDotPosition)
108
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Validates and normalizes the options parameter.
3
+ *
4
+ * @param {*} options The options value to validate
5
+ * @returns {Object} A valid options object (empty object if undefined)
6
+ * @throws {TypeError} If options is not undefined or a plain object
7
+ */
8
+ export function validateOptions(options: any): Object;
@@ -0,0 +1,16 @@
1
+ import { isPlainObject } from './is-plain-object.js'
2
+
3
+ /**
4
+ * Validates and normalizes the options parameter.
5
+ *
6
+ * @param {*} options The options value to validate
7
+ * @returns {Object} A valid options object (empty object if undefined)
8
+ * @throws {TypeError} If options is not undefined or a plain object
9
+ */
10
+ export function validateOptions (options) {
11
+ if (options === undefined) return {}
12
+ if (isPlainObject(options)) return options
13
+ throw new TypeError(
14
+ `Invalid options: expected plain object or undefined, got ${typeof options}`
15
+ )
16
+ }