n2words 1.23.1 → 1.24.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 (317) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +181 -52
  3. package/dist/languages/ar.js +2 -0
  4. package/dist/languages/ar.js.map +1 -0
  5. package/dist/languages/az.js +2 -0
  6. package/dist/languages/az.js.map +1 -0
  7. package/dist/languages/bn.js +2 -0
  8. package/dist/languages/bn.js.map +1 -0
  9. package/dist/languages/cs.js +2 -0
  10. package/dist/languages/cs.js.map +1 -0
  11. package/dist/languages/da.js +2 -0
  12. package/dist/languages/da.js.map +1 -0
  13. package/dist/languages/de.js +2 -0
  14. package/dist/languages/de.js.map +1 -0
  15. package/dist/languages/el.js +2 -0
  16. package/dist/languages/el.js.map +1 -0
  17. package/dist/languages/en.js +2 -0
  18. package/dist/languages/en.js.map +1 -0
  19. package/dist/languages/es.js +2 -0
  20. package/dist/languages/es.js.map +1 -0
  21. package/dist/languages/fa.js +2 -0
  22. package/dist/languages/fa.js.map +1 -0
  23. package/dist/languages/fil.js +2 -0
  24. package/dist/languages/fil.js.map +1 -0
  25. package/dist/languages/fr-BE.js +2 -0
  26. package/dist/languages/fr-BE.js.map +1 -0
  27. package/dist/languages/fr.js +2 -0
  28. package/dist/languages/fr.js.map +1 -0
  29. package/dist/languages/gu.js +2 -0
  30. package/dist/languages/gu.js.map +1 -0
  31. package/dist/languages/he.js +2 -0
  32. package/dist/languages/he.js.map +1 -0
  33. package/dist/languages/hi.js +2 -0
  34. package/dist/languages/hi.js.map +1 -0
  35. package/dist/languages/hr.js +2 -0
  36. package/dist/languages/hr.js.map +1 -0
  37. package/dist/languages/hu.js +2 -0
  38. package/dist/languages/hu.js.map +1 -0
  39. package/dist/languages/id.js +2 -0
  40. package/dist/languages/id.js.map +1 -0
  41. package/dist/languages/it.js +2 -0
  42. package/dist/languages/it.js.map +1 -0
  43. package/dist/languages/ja.js +2 -0
  44. package/dist/languages/ja.js.map +1 -0
  45. package/dist/languages/kn.js +2 -0
  46. package/dist/languages/kn.js.map +1 -0
  47. package/dist/languages/ko.js +2 -0
  48. package/dist/languages/ko.js.map +1 -0
  49. package/dist/languages/lt.js +2 -0
  50. package/dist/languages/lt.js.map +1 -0
  51. package/dist/languages/lv.js +2 -0
  52. package/dist/languages/lv.js.map +1 -0
  53. package/dist/languages/mr.js +2 -0
  54. package/dist/languages/mr.js.map +1 -0
  55. package/dist/languages/ms.js +2 -0
  56. package/dist/languages/ms.js.map +1 -0
  57. package/dist/languages/nb.js +2 -0
  58. package/dist/languages/nb.js.map +1 -0
  59. package/dist/languages/nl.js +2 -0
  60. package/dist/languages/nl.js.map +1 -0
  61. package/dist/languages/pa-Guru.js +2 -0
  62. package/dist/languages/pa-Guru.js.map +1 -0
  63. package/dist/languages/pl.js +2 -0
  64. package/dist/languages/pl.js.map +1 -0
  65. package/dist/languages/pt.js +2 -0
  66. package/dist/languages/pt.js.map +1 -0
  67. package/dist/languages/ro.js +2 -0
  68. package/dist/languages/ro.js.map +1 -0
  69. package/dist/languages/ru.js +2 -0
  70. package/dist/languages/ru.js.map +1 -0
  71. package/dist/languages/sr-Latn.js +2 -0
  72. package/dist/languages/sr-Latn.js.map +1 -0
  73. package/dist/languages/sv.js +2 -0
  74. package/dist/languages/sv.js.map +1 -0
  75. package/dist/languages/sw.js +2 -0
  76. package/dist/languages/sw.js.map +1 -0
  77. package/dist/languages/ta.js +2 -0
  78. package/dist/languages/ta.js.map +1 -0
  79. package/dist/languages/te.js +2 -0
  80. package/dist/languages/te.js.map +1 -0
  81. package/dist/languages/th.js +2 -0
  82. package/dist/languages/th.js.map +1 -0
  83. package/dist/languages/tr.js +2 -0
  84. package/dist/languages/tr.js.map +1 -0
  85. package/dist/languages/uk.js +2 -0
  86. package/dist/languages/uk.js.map +1 -0
  87. package/dist/languages/ur.js +2 -0
  88. package/dist/languages/ur.js.map +1 -0
  89. package/dist/languages/vi.js +2 -0
  90. package/dist/languages/vi.js.map +1 -0
  91. package/dist/languages/zh-Hans.js +2 -0
  92. package/dist/languages/zh-Hans.js.map +1 -0
  93. package/dist/n2words.js +1 -1
  94. package/dist/n2words.js.map +1 -1
  95. package/lib/classes/abstract-language.js +211 -110
  96. package/lib/classes/greedy-scale-language.js +195 -0
  97. package/lib/classes/slavic-language.js +251 -0
  98. package/lib/classes/south-asian-language.js +161 -0
  99. package/lib/classes/turkic-language.js +63 -0
  100. package/lib/languages/ar.js +243 -0
  101. package/lib/languages/az.js +58 -0
  102. package/lib/languages/bn.js +126 -0
  103. package/lib/languages/cs.js +212 -0
  104. package/lib/languages/da.js +167 -0
  105. package/lib/languages/de.js +135 -0
  106. package/lib/languages/el.js +116 -0
  107. package/lib/languages/en.js +123 -0
  108. package/lib/languages/es.js +153 -0
  109. package/lib/languages/fa.js +127 -0
  110. package/lib/languages/fil.js +162 -0
  111. package/lib/languages/fr-BE.js +61 -0
  112. package/lib/languages/fr.js +145 -0
  113. package/lib/languages/gu.js +156 -0
  114. package/lib/languages/he.js +329 -0
  115. package/lib/languages/hi.js +126 -0
  116. package/lib/languages/hr.js +157 -0
  117. package/lib/languages/hu.js +155 -0
  118. package/lib/languages/id.js +174 -0
  119. package/lib/languages/it.js +148 -0
  120. package/lib/languages/ja.js +190 -0
  121. package/lib/languages/kn.js +71 -0
  122. package/lib/languages/ko.js +83 -0
  123. package/lib/languages/lt.js +171 -0
  124. package/lib/languages/lv.js +153 -0
  125. package/lib/languages/mr.js +156 -0
  126. package/lib/languages/ms.js +146 -0
  127. package/lib/languages/nb.js +120 -0
  128. package/lib/languages/nl.js +206 -0
  129. package/lib/languages/pa-Guru.js +126 -0
  130. package/lib/languages/pl.js +189 -0
  131. package/lib/languages/pt.js +147 -0
  132. package/lib/languages/ro.js +380 -0
  133. package/lib/languages/ru.js +116 -0
  134. package/lib/languages/sr-Latn.js +157 -0
  135. package/lib/languages/sv.js +127 -0
  136. package/lib/languages/sw.js +121 -0
  137. package/lib/languages/ta.js +226 -0
  138. package/lib/languages/te.js +229 -0
  139. package/lib/languages/th.js +123 -0
  140. package/lib/languages/tr.js +83 -0
  141. package/lib/{i18n → languages}/uk.js +50 -23
  142. package/lib/languages/ur.js +126 -0
  143. package/lib/languages/vi.js +193 -0
  144. package/lib/languages/zh-Hans.js +165 -0
  145. package/lib/n2words.js +246 -75
  146. package/package.json +80 -72
  147. package/typings/classes/abstract-language.d.ts +144 -0
  148. package/typings/classes/greedy-scale-language.d.ts +148 -0
  149. package/typings/classes/slavic-language.d.ts +145 -0
  150. package/typings/classes/south-asian-language.d.ts +101 -0
  151. package/typings/classes/turkic-language.d.ts +42 -0
  152. package/typings/languages/ar.d.ts +93 -0
  153. package/typings/languages/az.d.ts +25 -0
  154. package/typings/languages/bn.d.ts +1 -0
  155. package/typings/languages/cs.d.ts +120 -0
  156. package/typings/languages/da.d.ts +53 -0
  157. package/typings/languages/de.d.ts +26 -0
  158. package/typings/languages/el.d.ts +11 -0
  159. package/typings/languages/en.d.ts +30 -0
  160. package/typings/languages/es.d.ts +43 -0
  161. package/typings/languages/fa.d.ts +81 -0
  162. package/typings/languages/fil.d.ts +12 -0
  163. package/typings/languages/fr-BE.d.ts +41 -0
  164. package/typings/languages/fr.d.ts +43 -0
  165. package/typings/languages/gu.d.ts +12 -0
  166. package/typings/languages/he.d.ts +197 -0
  167. package/typings/languages/hi.d.ts +1 -0
  168. package/typings/languages/hr.d.ts +110 -0
  169. package/typings/languages/hu.d.ts +37 -0
  170. package/typings/languages/id.d.ts +69 -0
  171. package/typings/languages/it.d.ts +51 -0
  172. package/typings/languages/ja.d.ts +58 -0
  173. package/typings/languages/kn.d.ts +11 -0
  174. package/typings/languages/ko.d.ts +25 -0
  175. package/typings/languages/lt.d.ts +110 -0
  176. package/typings/languages/lv.d.ts +99 -0
  177. package/typings/languages/mr.d.ts +12 -0
  178. package/typings/languages/ms.d.ts +37 -0
  179. package/typings/languages/nb.d.ts +27 -0
  180. package/typings/languages/nl.d.ts +65 -0
  181. package/typings/languages/pa-Guru.d.ts +1 -0
  182. package/typings/languages/pl.d.ts +116 -0
  183. package/typings/languages/pt.d.ts +39 -0
  184. package/typings/languages/ro.d.ts +229 -0
  185. package/typings/languages/ru.d.ts +108 -0
  186. package/typings/languages/sr-Latn.d.ts +98 -0
  187. package/typings/languages/sv.d.ts +30 -0
  188. package/typings/languages/sw.d.ts +1 -0
  189. package/typings/languages/ta.d.ts +1 -0
  190. package/typings/languages/te.d.ts +1 -0
  191. package/typings/languages/th.d.ts +1 -0
  192. package/typings/languages/tr.d.ts +46 -0
  193. package/typings/languages/uk.d.ts +117 -0
  194. package/typings/languages/ur.d.ts +1 -0
  195. package/typings/languages/vi.d.ts +116 -0
  196. package/typings/languages/zh-Hans.d.ts +57 -0
  197. package/typings/n2words.d.ts +177 -0
  198. package/dist/ar.js +0 -2
  199. package/dist/ar.js.map +0 -1
  200. package/dist/az.js +0 -2
  201. package/dist/az.js.map +0 -1
  202. package/dist/cz.js +0 -2
  203. package/dist/cz.js.map +0 -1
  204. package/dist/de.js +0 -2
  205. package/dist/de.js.map +0 -1
  206. package/dist/dk.js +0 -2
  207. package/dist/dk.js.map +0 -1
  208. package/dist/en.js +0 -2
  209. package/dist/en.js.map +0 -1
  210. package/dist/es.js +0 -2
  211. package/dist/es.js.map +0 -1
  212. package/dist/fa.js +0 -2
  213. package/dist/fa.js.map +0 -1
  214. package/dist/fr-BE.js +0 -2
  215. package/dist/fr-BE.js.map +0 -1
  216. package/dist/fr.js +0 -2
  217. package/dist/fr.js.map +0 -1
  218. package/dist/he.js +0 -2
  219. package/dist/he.js.map +0 -1
  220. package/dist/hr.js +0 -2
  221. package/dist/hr.js.map +0 -1
  222. package/dist/hu.js +0 -2
  223. package/dist/hu.js.map +0 -1
  224. package/dist/id.js +0 -2
  225. package/dist/id.js.map +0 -1
  226. package/dist/it.js +0 -2
  227. package/dist/it.js.map +0 -1
  228. package/dist/ko.js +0 -2
  229. package/dist/ko.js.map +0 -1
  230. package/dist/lt.js +0 -2
  231. package/dist/lt.js.map +0 -1
  232. package/dist/lv.js +0 -2
  233. package/dist/lv.js.map +0 -1
  234. package/dist/n2words.d.ts +0 -2
  235. package/dist/nl.js +0 -2
  236. package/dist/nl.js.map +0 -1
  237. package/dist/no.js +0 -2
  238. package/dist/no.js.map +0 -1
  239. package/dist/pl.js +0 -2
  240. package/dist/pl.js.map +0 -1
  241. package/dist/pt.js +0 -2
  242. package/dist/pt.js.map +0 -1
  243. package/dist/ro.js +0 -2
  244. package/dist/ro.js.map +0 -1
  245. package/dist/ru.js +0 -2
  246. package/dist/ru.js.map +0 -1
  247. package/dist/sr.js +0 -2
  248. package/dist/sr.js.map +0 -1
  249. package/dist/tr.js +0 -2
  250. package/dist/tr.js.map +0 -1
  251. package/dist/uk.js +0 -2
  252. package/dist/uk.js.map +0 -1
  253. package/dist/vi.js +0 -2
  254. package/dist/vi.js.map +0 -1
  255. package/dist/zh.js +0 -2
  256. package/dist/zh.js.map +0 -1
  257. package/lib/classes/abstract-language.d.ts +0 -54
  258. package/lib/classes/base-language.d.ts +0 -58
  259. package/lib/classes/base-language.js +0 -172
  260. package/lib/i18n/ar.d.ts +0 -41
  261. package/lib/i18n/ar.js +0 -209
  262. package/lib/i18n/az.d.ts +0 -15
  263. package/lib/i18n/az.js +0 -66
  264. package/lib/i18n/cz.d.ts +0 -68
  265. package/lib/i18n/cz.js +0 -135
  266. package/lib/i18n/de.d.ts +0 -17
  267. package/lib/i18n/de.js +0 -103
  268. package/lib/i18n/dk.d.ts +0 -14
  269. package/lib/i18n/dk.js +0 -110
  270. package/lib/i18n/en.d.ts +0 -22
  271. package/lib/i18n/en.js +0 -86
  272. package/lib/i18n/es.d.ts +0 -16
  273. package/lib/i18n/es.js +0 -110
  274. package/lib/i18n/fa.d.ts +0 -54
  275. package/lib/i18n/fa.js +0 -106
  276. package/lib/i18n/fr-BE.d.ts +0 -11
  277. package/lib/i18n/fr-BE.js +0 -20
  278. package/lib/i18n/fr.d.ts +0 -15
  279. package/lib/i18n/fr.js +0 -99
  280. package/lib/i18n/he.d.ts +0 -61
  281. package/lib/i18n/he.js +0 -132
  282. package/lib/i18n/hr.d.ts +0 -68
  283. package/lib/i18n/hr.js +0 -129
  284. package/lib/i18n/hu.d.ts +0 -17
  285. package/lib/i18n/hu.js +0 -135
  286. package/lib/i18n/id.d.ts +0 -43
  287. package/lib/i18n/id.js +0 -156
  288. package/lib/i18n/it.d.ts +0 -29
  289. package/lib/i18n/it.js +0 -137
  290. package/lib/i18n/ko.d.ts +0 -15
  291. package/lib/i18n/ko.js +0 -56
  292. package/lib/i18n/lt.d.ts +0 -68
  293. package/lib/i18n/lt.js +0 -138
  294. package/lib/i18n/lv.d.ts +0 -57
  295. package/lib/i18n/lv.js +0 -120
  296. package/lib/i18n/nl.d.ts +0 -20
  297. package/lib/i18n/nl.js +0 -125
  298. package/lib/i18n/no.d.ts +0 -15
  299. package/lib/i18n/no.js +0 -77
  300. package/lib/i18n/pl.d.ts +0 -67
  301. package/lib/i18n/pl.js +0 -126
  302. package/lib/i18n/pt.d.ts +0 -26
  303. package/lib/i18n/pt.js +0 -118
  304. package/lib/i18n/ro.d.ts +0 -109
  305. package/lib/i18n/ro.js +0 -360
  306. package/lib/i18n/ru.d.ts +0 -30
  307. package/lib/i18n/ru.js +0 -198
  308. package/lib/i18n/sr.d.ts +0 -56
  309. package/lib/i18n/sr.js +0 -127
  310. package/lib/i18n/tr.d.ts +0 -15
  311. package/lib/i18n/tr.js +0 -64
  312. package/lib/i18n/uk.d.ts +0 -78
  313. package/lib/i18n/vi.d.ts +0 -70
  314. package/lib/i18n/vi.js +0 -151
  315. package/lib/i18n/zh.d.ts +0 -18
  316. package/lib/i18n/zh.js +0 -78
  317. package/lib/n2words.d.ts +0 -9
package/package.json CHANGED
@@ -1,43 +1,24 @@
1
1
  {
2
2
  "name": "n2words",
3
- "version": "1.23.1",
4
- "description": "n2words converts a numerical number into a written one, supports 28 languages and has zero dependencies.",
3
+ "version": "1.24.0",
4
+ "description": "n2words converts a numerical number into a written one, supports 45 languages and has zero dependencies.",
5
5
  "keywords": [
6
6
  "n2words",
7
- "convert",
8
- "number",
9
- "word",
10
- "text",
11
- "natural",
12
- "language",
13
- "english",
14
- "french",
15
- "spanish",
16
- "german",
17
- "portuguese",
18
- "italian",
19
- "turkish",
20
- "russian",
21
- "czech",
22
- "norwegian",
23
- "danish",
24
- "polish",
25
- "ukrainian",
26
- "lithuanian",
27
- "latvian",
28
- "arabic",
29
- "hebrew",
30
- "korean",
31
- "dutch",
32
- "serbian",
33
- "farsi",
34
- "persian",
35
- "chinese",
36
- "hungarian",
37
- "indonesian",
38
- "croatian",
39
- "vietnamese",
40
- "azerbaijani"
7
+ "number-to-words",
8
+ "cardinal",
9
+ "spellout",
10
+ "conversion",
11
+ "internationalization",
12
+ "localization",
13
+ "multilingual",
14
+ "pluralization",
15
+ "typescript",
16
+ "browser",
17
+ "nodejs",
18
+ "zero-dependencies",
19
+ "bigint",
20
+ "formatting",
21
+ "utility"
41
22
  ],
42
23
  "homepage": "https://github.com/forzagreen/n2words#readme",
43
24
  "bugs": {
@@ -55,35 +36,66 @@
55
36
  "sideEffects": false,
56
37
  "type": "module",
57
38
  "exports": {
58
- ".": "./lib/n2words.js",
59
- "./i18n/*.js": "./lib/i18n/*.js"
39
+ ".": {
40
+ "import": "./lib/n2words.js",
41
+ "types": "./typings/n2words.d.ts"
42
+ },
43
+ "./languages/*": {
44
+ "import": "./lib/languages/*.js",
45
+ "types": "./typings/languages/*.d.ts"
46
+ }
60
47
  },
48
+ "main": "lib/n2words.js",
61
49
  "jsdelivr": "dist/n2words.js",
62
50
  "unpkg": "dist/n2words.js",
51
+ "types": "typings/n2words.d.ts",
52
+ "typesVersions": {
53
+ "*": {
54
+ "n2words/*": [
55
+ "typings/*"
56
+ ]
57
+ }
58
+ },
63
59
  "files": [
64
60
  "lib/*",
65
- "dist/*"
61
+ "dist/*",
62
+ "typings/*"
66
63
  ],
67
64
  "scripts": {
68
- "bench": "node bench.js",
69
- "build": "webpack --progress",
70
- "build:types": "npx -p typescript tsc lib/n2words.js dist/n2words.js --target es6 --module nodenext --allowJs --declaration --emitDeclarationOnly",
71
- "coverage": "c8 ava",
72
- "docs": "jsdoc -c ./conf.json",
65
+ "bench:perf": "node bench.js",
66
+ "bench:memory": "node --expose-gc bench-memory.js",
67
+ "clean": "npm run types:clean && npm run web:clean && npm run docs:clean && npm run coverage:clean",
68
+ "coverage:clean": "node -e \"import { rmSync } from 'fs'; try { rmSync('coverage', { recursive: true, force: true }) } catch (e) {}\"",
69
+ "coverage:generate": "c8 npm run test",
70
+ "docs:generate": "npm run docs:clean && jsdoc -c ./conf.json && npm run docs:validate",
71
+ "docs:clean": "node -e \"import { rmSync } from 'fs'; try { rmSync('docs', { recursive: true, force: true }) } catch (e) {}\"",
72
+ "docs:validate": "echo 'Documentation generated successfully'",
73
+ "lang:add": "node scripts/add-language.js",
74
+ "lang:validate": "node scripts/validate-language.js",
73
75
  "lint": "npm run lint:js && npm run lint:md",
74
- "lint:js": "eslint lib/ test/ examples/ *.js",
75
- "lint:md": "markdownlint-cli2 *.md",
76
- "test": "ava --verbose",
77
- "test:cjs": "ava --verbose test/import.cjs",
78
- "test:core": "ava --verbose test/core.js",
79
- "test:i18n": "ava --verbose test/i18n.js",
80
- "test:web": "ava --verbose test/web.js"
76
+ "lint:js": "standard examples/ lib/ scripts/ test/ *.js",
77
+ "lint:md": "markdownlint-cli2 *.md scripts/*.md",
78
+ "test": "npm run test:unit && npm run test:integration",
79
+ "test:integration": "ava --verbose test/integration/*.{js,cjs}",
80
+ "test:unit": "ava --verbose test/unit/*.js",
81
+ "types:generate": "tsc --project tsconfig.json",
82
+ "types:clean": "node -e \"import { rmSync } from 'fs'; try { rmSync('typings', { recursive: true, force: true }) } catch (e) {}\"",
83
+ "types:validate": "tsc --noEmit --project test/tsconfig.test.json && node --import tsx --test test/typescript/*.ts",
84
+ "web:build": "webpack --progress",
85
+ "web:clean": "node -e \"import { rmSync } from 'fs'; try { rmSync('dist', { recursive: true, force: true }) } catch (e) {}\"",
86
+ "web:test": "ava --verbose test/web/*.js"
81
87
  },
82
88
  "ava": {
89
+ "extensions": [
90
+ "js",
91
+ "cjs"
92
+ ],
83
93
  "files": [
84
- "test/*",
85
- "!test/web.js"
86
- ]
94
+ "test/unit/*.js",
95
+ "test/integration/*.{js,cjs}",
96
+ "test/web/*.js"
97
+ ],
98
+ "timeout": "30s"
87
99
  },
88
100
  "c8": {
89
101
  "all": true,
@@ -96,28 +108,24 @@
96
108
  ]
97
109
  },
98
110
  "devDependencies": {
99
- "@babel/core": "^7.28.0",
100
- "@babel/preset-env": "^7.28.0",
101
- "@eslint/js": "^9.32.0",
102
- "@stylistic/eslint-plugin-js": "^2.13.0",
111
+ "@babel/core": "^7.28.5",
112
+ "@babel/preset-env": "^7.28.5",
103
113
  "ava": "^6.4.1",
104
- "babel-loader": "^9.2.1",
114
+ "babel-loader": "^10.0.0",
105
115
  "benchmark": "^2.1.4",
106
116
  "c8": "^10.1.3",
107
- "chalk": "^5.5.0",
108
- "chromedriver": "^138.0.5",
109
- "core-js": "^3.45.0",
110
- "eslint": "^9.32.0",
111
- "eslint-plugin-ava": "^15.1.0",
112
- "eslint-plugin-jsdoc": "^52.0.3",
113
- "eslint-plugin-n": "^17.21.3",
114
- "eslint-plugin-unicorn": "^60.0.0",
115
- "jsdoc": "^4.0.4",
116
- "markdownlint-cli2": "^0.18.1",
117
+ "chalk": "^5.6.2",
118
+ "chromedriver": "^143.0.3",
119
+ "core-js": "^3.47.0",
120
+ "jsdoc": "^4.0.5",
121
+ "markdownlint-cli2": "^0.20.0",
117
122
  "microtime": "^3.1.1",
118
- "selenium-webdriver": "^4.34.0",
119
- "webpack": "^5.101.0",
120
- "webpack-cli": "^5.1.4"
123
+ "selenium-webdriver": "^4.39.0",
124
+ "standard": "^17.1.2",
125
+ "tsx": "^4.21.0",
126
+ "typescript": "^5.9.3",
127
+ "webpack": "^5.104.1",
128
+ "webpack-cli": "^6.0.1"
121
129
  },
122
130
  "engines": {
123
131
  "node": "^20 || ^22 || >=24"
@@ -0,0 +1,144 @@
1
+ export default AbstractLanguage;
2
+ /**
3
+ * Abstract base class for language converters.
4
+ *
5
+ * What this class handles:
6
+ * - Validates and normalizes caller input (`number | string | bigint`), rejecting NaN/invalid strings.
7
+ * - Splits sign, whole, and decimal parts, caching the whole part for languages that need it.
8
+ * - Delegates whole-number wording to `convertWholePart(wholeNumber)` implemented by subclasses.
9
+ * - Converts decimals via `decimalDigitsToWords()`, preserving leading zeros and supporting per-digit mode when `convertDecimalsPerDigit` is true.
10
+ *
11
+ * What subclasses must provide:
12
+ * - `convertWholePart(wholeNumber)` method implementation (required; abstract).
13
+ * - `negativeWord` class property (word preceding negative numbers, e.g., "minus").
14
+ * - `zeroWord` class property (word for digit 0, e.g., "zero").
15
+ * - `decimalSeparatorWord` class property (word between whole and decimal, e.g., "point").
16
+ * - `wordSeparator` class property (word separator in output, typically a space).
17
+ * Optional: override `convertDecimalsPerDigit`, `digits`, or `convertDigitToWord()` for custom behavior.
18
+ *
19
+ * This class stays minimal; language grammar lives in subclasses.
20
+ *
21
+ * @abstract
22
+ */
23
+ declare class AbstractLanguage {
24
+ /**
25
+ * Word that precedes negative numbers (e.g., "minus", "negative", "moins").
26
+ * @type {string}
27
+ */
28
+ negativeWord: string;
29
+ /**
30
+ * Word that separates whole and decimal parts (e.g., "point", "virgule", "comma").
31
+ * @type {string}
32
+ */
33
+ decimalSeparatorWord: string;
34
+ /**
35
+ * Word representation for the digit 0 (e.g., "zero", "zéro", "null").
36
+ * @type {string}
37
+ */
38
+ zeroWord: string;
39
+ /**
40
+ * Character(s) used to separate words in the output (typically a space).
41
+ * @type {string}
42
+ */
43
+ wordSeparator: string;
44
+ /**
45
+ * Cached whole number portion from the most recent conversion.
46
+ * Some languages need access to this value during conversion for
47
+ * pluralization rules or special cases (e.g., Czech, Hebrew).
48
+ * @type {bigint}
49
+ */
50
+ cachedWholeNumber: bigint;
51
+ /**
52
+ * Whether to convert decimal digits individually rather than grouped.
53
+ * - `true`: Each digit converted separately (e.g., "05" → "zero five")
54
+ * - `false`: Leading zeros preserved, remaining grouped (e.g., "14" → "fourteen")
55
+ * Used by languages like Japanese, Thai, Tamil, Telugu.
56
+ * @type {boolean}
57
+ */
58
+ convertDecimalsPerDigit: boolean;
59
+ /**
60
+ * Optional array of digit words for direct lookup in `convertDigitToWord()`.
61
+ * - Length 10: indices 0–9 map directly to digit words
62
+ * - Length 9: indices 0–8 map to words for digits 1–9
63
+ * - `null`: Falls back to `convertWholePart()` for digit conversion
64
+ * @type {string[]|null}
65
+ */
66
+ digits: string[] | null;
67
+ /**
68
+ * Convert a single decimal digit (0-9) to its word representation.
69
+ *
70
+ * Default behavior:
71
+ * - 0 returns the language's `zeroWord`
72
+ * - If a `digits` array is present, use it for direct lookup
73
+ * - Length 10: indices 0–9 map directly
74
+ * - Length 9: indices 1–9 map via `idx - 1`
75
+ * - Otherwise delegate to `convertWholePart(digit)`
76
+ *
77
+ * Subclasses may override this for custom logic.
78
+ *
79
+ * @protected
80
+ * @param {bigint} digit A single digit value (0-9) as BigInt
81
+ * @returns {string} The word representation of the digit
82
+ */
83
+ protected convertDigitToWord(digit: bigint): string;
84
+ /**
85
+ * Convert the decimal fractional digits into words.
86
+ *
87
+ * Behavior depends on the `convertDecimalsPerDigit` class property:
88
+ *
89
+ * **Per-digit mode** (`convertDecimalsPerDigit: true`):
90
+ * - Each decimal digit is converted individually using `convertDigitToWord()`
91
+ * - Example: "05" -> [zero, 'five'], "14" -> ['one', 'four']
92
+ * - Used by: Japanese, Thai, Tamil, Telugu
93
+ *
94
+ * **Grouped mode** (default, `convertDecimalsPerDigit: false`):
95
+ * - Leading zeros are preserved as individual `zeroWord` entries
96
+ * - Remaining digits are grouped and converted as a number
97
+ * - Example: "05" -> [zero, 'five'], "14" -> ['fourteen']
98
+ * - Used by: Most languages (English, Spanish, French, etc.)
99
+ *
100
+ * @protected
101
+ * @param {string} decimalString The decimal digits as a string (e.g. `'05'` for 3.05).
102
+ * @returns {Array<string>} Array of word tokens representing the fractional part.
103
+ *
104
+ * @example
105
+ * // Per-digit mode
106
+ * decimalDigitsToWords('05'); // -> [this.zeroWord, 'five']
107
+ * decimalDigitsToWords('14'); // -> ['one', 'four']
108
+ *
109
+ * // Grouped mode
110
+ * decimalDigitsToWords('05'); // -> [this.zeroWord, 'five']
111
+ * decimalDigitsToWords('14'); // -> ['fourteen']
112
+ */
113
+ protected decimalDigitsToWords(decimalString: string): Array<string>;
114
+ /**
115
+ * Convert a numeric input into its language cardinal representation.
116
+ *
117
+ * This is the public entry point used by consumers. It normalizes the input
118
+ * (accepting `number | string | bigint`), validates it, splits sign and
119
+ * fractional parts, and delegates whole-number conversion to
120
+ * `convertWholePart(BigInt)` and fractional conversion to `decimalDigitsToWords()`.
121
+ *
122
+ * Errors and validation:
123
+ * - Passing `NaN` (as `number`) throws `TypeError`.
124
+ * - Passing a non-numeric `string` throws `Error`.
125
+ * - Passing an unsupported type throws `TypeError`.
126
+ *
127
+ * @public
128
+ * @param {number|string|bigint} value Numeric input to convert. Strings may include a single `.` decimal marker.
129
+ * @returns {string} The localized cardinal string.
130
+ * @throws {TypeError|Error} For invalid input as described above.
131
+ */
132
+ public convertToWords(value: number | string | bigint): string;
133
+ /**
134
+ * Convert a BigInt whole number to its cardinal word representation.
135
+ *
136
+ * This is a template method that subclasses MUST implement to provide
137
+ * language-specific number conversion logic.
138
+ *
139
+ * @abstract
140
+ * @param {bigint} wholeNumber The whole number part to convert
141
+ * @returns {string} The cardinal representation in the target language
142
+ */
143
+ convertWholePart(wholeNumber: bigint): string;
144
+ }
@@ -0,0 +1,148 @@
1
+ export default GreedyScaleLanguage;
2
+ export type WordSet = {
3
+ /**
4
+ * - The language word or phrase
5
+ */
6
+ word: string;
7
+ /**
8
+ * - The numeric value represented by the word
9
+ */
10
+ value: bigint;
11
+ };
12
+ /**
13
+ * Array of scale word pairs in descending order. Each pair contains:
14
+ * - [0]: BigInt numeric value
15
+ * - [1]: String word representation
16
+ * Must be ordered largest to smallest for the greedy algorithm.
17
+ */
18
+ export type ScaleWordPairs = Array<Array<(bigint | string)>>;
19
+ /**
20
+ * @typedef {Object} WordSet
21
+ * @property {string} word - The language word or phrase
22
+ * @property {bigint} value - The numeric value represented by the word
23
+ */
24
+ /**
25
+ * @typedef {Array.<Array.<(bigint|string)>>} ScaleWordPairs
26
+ * Array of scale word pairs in descending order. Each pair contains:
27
+ * - [0]: BigInt numeric value
28
+ * - [1]: String word representation
29
+ * Must be ordered largest to smallest for the greedy algorithm.
30
+ */
31
+ /**
32
+ * Greedy scale language converter implementing the "highest-matching scale word" algorithm.
33
+ *
34
+ * Responsibilities:
35
+ * - Decompose a whole-number value into a sequence of scale word-sets.
36
+ * - Provide helpers to merge and post-process matched word-sets.
37
+ * - Inherits decimal handling from AbstractLanguage (supports grouped and per-digit
38
+ * modes via the `convertDecimalsPerDigit` class property).
39
+ *
40
+ * Subclass requirements:
41
+ * - Define `scaleWordPairs` (ordered descending) as `[BigInt, string]` tuples.
42
+ * - Implement `mergeScales(leftWordSet, rightWordSet)` to combine adjacent word-sets
43
+ * per language grammar.
44
+ *
45
+ * Scale words specification:
46
+ * - `scaleWordPairs` is an Array of 2-tuples: `[BigInt, string]` where the first element
47
+ * is the numeric value (BigInt) and the second is the word used for that value.
48
+ * - Scale words MUST be ordered from largest to smallest (descending) for the algorithm
49
+ * to function correctly.
50
+ *
51
+ * @abstract
52
+ * @extends AbstractLanguage
53
+ * @example
54
+ * // Example `scaleWordPairs` for English (descending order):
55
+ * // [[1000000000n, 'billion'], [1000000n, 'million'], [1000n, 'thousand'], [100n, 'hundred'], ..., [1n, 'one']]
56
+ */
57
+ declare class GreedyScaleLanguage extends AbstractLanguage {
58
+ /**
59
+ * Array of scale word pairs mapping numeric values to their word representations.
60
+ *
61
+ * Each element is a 2-tuple: `[BigInt, string]` where the first element is the
62
+ * numeric value and the second is the word for that value. The array MUST be
63
+ * ordered from largest to smallest (descending) for the greedy algorithm to work correctly.
64
+ *
65
+ * @type {Array.<Array.<(bigint|string)>>}
66
+ * @example
67
+ * // English scale words (descending order):
68
+ * // [[1000000000n, 'billion'], [1000000n, 'million'], [1000n, 'thousand'], [100n, 'hundred'], ..., [1n, 'one']]
69
+ */
70
+ scaleWordPairs: Array<Array<(bigint | string)>>;
71
+ /**
72
+ * Return the word associated with an exact scale word-set numeric value.
73
+ *
74
+ * @param {bigint|number} scaleValue Numeric word-set object key (prefer BigInt for exact matching).
75
+ * @returns {string|undefined} The word for the provided scale value, or `undefined`.
76
+ */
77
+ getScaleWord(scaleValue: bigint | number): string | undefined;
78
+ /**
79
+ * Decompose a whole-number into a sequence of scale word-sets.
80
+ *
81
+ * This internal helper returns a nested structure that represents quantities and
82
+ * their matching scale words (e.g. `[{ 'one': 1n }, { 'hundred': 100n }, ...]`).
83
+ * The result is designed to be reduced by `mergeWordSets()` using language-specific `mergeScales()`.
84
+ *
85
+ * For quantities > 1, the multiplier is recursively decomposed. For quantity = 1,
86
+ * the implicit "one" is represented with `{ 'one': 1n }` and typically omitted during mergeScales().
87
+ *
88
+ * @protected
89
+ * @param {bigint} wholeNumber The integer value to decompose (BigInt preferred).
90
+ * @returns {Array<Object|Array>} An array of word-set objects and possibly nested arrays.
91
+ */
92
+ protected decomposeToScales(wholeNumber: bigint): Array<any | any[]>;
93
+ /**
94
+ * Reduce a nested array of word-sets into a single merged word-set object.
95
+ *
96
+ * This method repeatedly applies the subclass `mergeScales()` operation until a single
97
+ * object remains. It normalizes nested arrays by recursively merging them.
98
+ *
99
+ * @protected
100
+ * @param {Array<Object|Array>} mergeWordSetsList Array of word-set objects and nested arrays.
101
+ * @returns {Object} Merged word-set where the single object key is the language string
102
+ * and its value is the numeric BigInt result for that string.
103
+ */
104
+ protected mergeWordSets(mergeWordSetsList: Array<any | any[]>): any;
105
+ /**
106
+ * Combine two adjacent word-sets into a single merged word-set.
107
+ *
108
+ * This is the core language-specific method that must be implemented by subclasses
109
+ * to define how adjacent word-sets are combined according to the language's grammar.
110
+ * For example, English combines "twenty" + "three" → "twenty-three", while
111
+ * French might combine "quatre-vingts" + "dix" → "quatre-vingt-dix".
112
+ *
113
+ * @abstract
114
+ * @protected
115
+ * @param {Object} leftWordSet Left operand as `{ word: bigint }` pair.
116
+ * @param {Object} rightWordSet Right operand as `{ word: bigint }` pair.
117
+ * @returns {Object} Single merged word-set object with combined text and numeric value.
118
+ *
119
+ * @example
120
+ * // English implementation might handle:
121
+ * // mergeScales({ 'twenty': 20n }, { 'three': 3n }) → { 'twenty-three': 23n }
122
+ * // mergeScales({ 'one': 1n }, { 'hundred': 100n }) → { 'one hundred': 100n }
123
+ */
124
+ protected mergeScales(leftWordSet: any, rightWordSet: any): any;
125
+ /**
126
+ * Final string post-processing hook.
127
+ *
128
+ * Subclasses may override to apply language-specific whitespace, punctuation or
129
+ * orthographic corrections.
130
+ *
131
+ * @protected
132
+ * @param {string} output Merged language string produced by `convertWholePart` flow.
133
+ * @returns {string} Final formatted string.
134
+ */
135
+ protected finalizeWords(output: string): string;
136
+ /**
137
+ * Convert an integer value to its language-specific cardinal words.
138
+ *
139
+ * This method orchestrates decomposition, merging and final formatting. It does
140
+ * not handle decimals or sign; those concerns are implemented in
141
+ * `AbstractLanguage.convertToWords` which calls this helper for the whole-number part.
142
+ *
143
+ * @param {bigint|number} wholeNumber Whole-number value to convert (BigInt is preferred).
144
+ * @returns {string} The cardinal representation for `value` in the language.
145
+ */
146
+ convertWholePart(wholeNumber: bigint | number): string;
147
+ }
148
+ import AbstractLanguage from './abstract-language.js';
@@ -0,0 +1,145 @@
1
+ export default SlavicLanguage;
2
+ /**
3
+ * Array of three plural forms for Slavic languages:
4
+ * - [0]: Singular form (for numbers ending in 1, except 11)
5
+ * - [1]: Few form (for numbers ending in 2-4, except 12-14)
6
+ * - [2]: Many form (for all other numbers: 0, 5-20, and numbers ending in 0, 5-9, 11-19)
7
+ */
8
+ export type SlavicPluralForms = string[];
9
+ /**
10
+ * Mapping from power indices to their plural forms.
11
+ * Example: { '0': ['тысяча', 'тысячи', 'тысяч'], '1': ['миллион', 'миллиона', 'миллионов'] }
12
+ */
13
+ export type SlavicThousandsMap = {
14
+ [x: string]: SlavicPluralForms;
15
+ };
16
+ /**
17
+ * @typedef {string[]} SlavicPluralForms
18
+ * Array of three plural forms for Slavic languages:
19
+ * - [0]: Singular form (for numbers ending in 1, except 11)
20
+ * - [1]: Few form (for numbers ending in 2-4, except 12-14)
21
+ * - [2]: Many form (for all other numbers: 0, 5-20, and numbers ending in 0, 5-9, 11-19)
22
+ */
23
+ /**
24
+ * @typedef {Object.<string, SlavicPluralForms>} SlavicThousandsMap
25
+ * Mapping from power indices to their plural forms.
26
+ * Example: { '0': ['тысяча', 'тысячи', 'тысяч'], '1': ['миллион', 'миллиона', 'миллионов'] }
27
+ */
28
+ /**
29
+ * Base class for Slavic and related languages with complex pluralization.
30
+ *
31
+ * This class provides a reusable implementation for languages that share:
32
+ * - Three-form pluralization (singular/few/many)
33
+ * - Gender-aware number forms (masculine/feminine for 1, 2)
34
+ * - Hundreds, tens, ones decomposition
35
+ * - Chunk-based large number handling (thousands, millions, etc.)
36
+ * - Inherits decimal handling from AbstractLanguage (supports both grouped and
37
+ * per-digit modes via the `convertDecimalsPerDigit` class property).
38
+ *
39
+ * Used by: Russian, Czech, Polish, Ukrainian, Serbian, Croatian,
40
+ * as well as Baltic (Lithuanian, Latvian) and Hebrew languages.
41
+ *
42
+ * Subclasses MUST define these properties with language-specific vocabulary:
43
+ * - `ones` - Object mapping 1-9 to masculine forms
44
+ * - `onesFeminine` - Object mapping 1-9 to feminine forms
45
+ * - `tens` - Object mapping 0-9 to teen numbers (10-19)
46
+ * - `twenties` - Object mapping 2-9 to tens (20-90)
47
+ * - `hundreds` - Object mapping 1-9 to hundreds (100-900)
48
+ * - `thousands` - Object mapping power indices to [singular, few, many] forms
49
+ * - `feminine` - Boolean indicating if feminine forms should be used (optional)
50
+ *
51
+ * @abstract
52
+ * @extends AbstractLanguage
53
+ */
54
+ declare class SlavicLanguage extends AbstractLanguage {
55
+ /**
56
+ * Initializes the Slavic language converter with language-specific options.
57
+ *
58
+ * @param {Object} [options={}] Configuration options.
59
+ * @param {boolean} [options.feminine=false] Use feminine forms for numbers (affects gender agreement).
60
+ */
61
+ constructor({ feminine }?: {
62
+ feminine?: boolean;
63
+ });
64
+ /**
65
+ * Masculine forms for digits 1-9.
66
+ *
67
+ * @type {object}
68
+ */
69
+ ones: object;
70
+ /**
71
+ * Feminine forms for digits 1-9.
72
+ *
73
+ * @type {object}
74
+ */
75
+ onesFeminine: object;
76
+ /**
77
+ * Words for tens (10, 20, 30, etc.).
78
+ *
79
+ * @type {object}
80
+ */
81
+ tens: object;
82
+ /**
83
+ * Special forms for 21-29 in some languages.
84
+ *
85
+ * @type {object}
86
+ */
87
+ twenties: object;
88
+ /**
89
+ * Words for hundreds (100, 200, 300, etc.).
90
+ *
91
+ * @type {object}
92
+ */
93
+ hundreds: object;
94
+ /**
95
+ * Scale words for thousands, millions, etc.
96
+ *
97
+ * @type {object}
98
+ */
99
+ thousands: object;
100
+ /**
101
+ * Use feminine forms for numbers (affects 1-9).
102
+ *
103
+ * @type {boolean}
104
+ */
105
+ feminine: boolean;
106
+ /**
107
+ * Splits a number string into chunks of X digits.
108
+ *
109
+ * Example: splitByX('1234567', 3) => [1n, 234n, 567n]
110
+ *
111
+ * @param {string} numberString The number as a string.
112
+ * @param {number} chunkSize Chunk size (typically 3 for thousands grouping).
113
+ * @returns {bigint[]} Array of BigInt chunks.
114
+ */
115
+ splitByX(numberString: string, chunkSize: number): bigint[];
116
+ /**
117
+ * Extracts individual digits from a number (units, tens, hundreds).
118
+ *
119
+ * Returns digits in reverse order: [ones, tens, hundreds]
120
+ * Example: 456 => [6n, 5n, 4n]
121
+ *
122
+ * @param {bigint} value The number to extract digits from (0-999).
123
+ * @returns {bigint[]} Array of [ones, tens, hundreds] as BigInts.
124
+ */
125
+ getDigits(value: bigint): bigint[];
126
+ /**
127
+ * Selects the correct plural form based on Slavic pluralization rules.
128
+ *
129
+ * Slavic languages use three forms:
130
+ * - Form 0 (singular): numbers ending in 1 (but not 11)
131
+ * - Form 1 (few): numbers ending in 2-4 (but not 12-14)
132
+ * - Form 2 (many): all other numbers (0, 5-20, 25-30, etc.)
133
+ *
134
+ * Examples (Russian):
135
+ * - 1, 21, 31... => тысяча (form 0)
136
+ * - 2-4, 22-24, 32-34... => тысячи (form 1)
137
+ * - 0, 5-20, 25-30... => тысяч (form 2)
138
+ *
139
+ * @param {bigint} n The number to check.
140
+ * @param {string[]} forms Array of [singular, few, many] forms.
141
+ * @returns {string} The appropriate form for the number.
142
+ */
143
+ pluralize(number: any, pluralForms: any): string;
144
+ }
145
+ import AbstractLanguage from './abstract-language.js';