n2words 1.24.0 → 2.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 (349) hide show
  1. package/README.md +285 -156
  2. package/dist/ArabicConverter.js +3 -0
  3. package/dist/ArabicConverter.js.map +1 -0
  4. package/dist/AzerbaijaniConverter.js +3 -0
  5. package/dist/AzerbaijaniConverter.js.map +1 -0
  6. package/dist/BanglaConverter.js +3 -0
  7. package/dist/BanglaConverter.js.map +1 -0
  8. package/dist/BiblicalHebrewConverter.js +3 -0
  9. package/dist/BiblicalHebrewConverter.js.map +1 -0
  10. package/dist/CroatianConverter.js +3 -0
  11. package/dist/CroatianConverter.js.map +1 -0
  12. package/dist/CzechConverter.js +3 -0
  13. package/dist/CzechConverter.js.map +1 -0
  14. package/dist/DanishConverter.js +3 -0
  15. package/dist/DanishConverter.js.map +1 -0
  16. package/dist/DutchConverter.js +3 -0
  17. package/dist/DutchConverter.js.map +1 -0
  18. package/dist/EnglishConverter.js +3 -0
  19. package/dist/EnglishConverter.js.map +1 -0
  20. package/dist/FilipinoConverter.js +3 -0
  21. package/dist/FilipinoConverter.js.map +1 -0
  22. package/dist/FrenchBelgiumConverter.js +3 -0
  23. package/dist/FrenchBelgiumConverter.js.map +1 -0
  24. package/dist/FrenchConverter.js +3 -0
  25. package/dist/FrenchConverter.js.map +1 -0
  26. package/dist/GermanConverter.js +3 -0
  27. package/dist/GermanConverter.js.map +1 -0
  28. package/dist/GreekConverter.js +3 -0
  29. package/dist/GreekConverter.js.map +1 -0
  30. package/dist/GujaratiConverter.js +3 -0
  31. package/dist/GujaratiConverter.js.map +1 -0
  32. package/dist/HebrewConverter.js +3 -0
  33. package/dist/HebrewConverter.js.map +1 -0
  34. package/dist/HindiConverter.js +3 -0
  35. package/dist/HindiConverter.js.map +1 -0
  36. package/dist/HungarianConverter.js +3 -0
  37. package/dist/HungarianConverter.js.map +1 -0
  38. package/dist/IndonesianConverter.js +3 -0
  39. package/dist/IndonesianConverter.js.map +1 -0
  40. package/dist/ItalianConverter.js +3 -0
  41. package/dist/ItalianConverter.js.map +1 -0
  42. package/dist/JapaneseConverter.js +3 -0
  43. package/dist/JapaneseConverter.js.map +1 -0
  44. package/dist/KannadaConverter.js +3 -0
  45. package/dist/KannadaConverter.js.map +1 -0
  46. package/dist/KoreanConverter.js +3 -0
  47. package/dist/KoreanConverter.js.map +1 -0
  48. package/dist/LatvianConverter.js +3 -0
  49. package/dist/LatvianConverter.js.map +1 -0
  50. package/dist/LithuanianConverter.js +3 -0
  51. package/dist/LithuanianConverter.js.map +1 -0
  52. package/dist/MalayConverter.js +3 -0
  53. package/dist/MalayConverter.js.map +1 -0
  54. package/dist/MarathiConverter.js +3 -0
  55. package/dist/MarathiConverter.js.map +1 -0
  56. package/dist/NorwegianBokmalConverter.js +3 -0
  57. package/dist/NorwegianBokmalConverter.js.map +1 -0
  58. package/dist/PersianConverter.js +3 -0
  59. package/dist/PersianConverter.js.map +1 -0
  60. package/dist/PolishConverter.js +3 -0
  61. package/dist/PolishConverter.js.map +1 -0
  62. package/dist/PortugueseConverter.js +3 -0
  63. package/dist/PortugueseConverter.js.map +1 -0
  64. package/dist/PunjabiConverter.js +3 -0
  65. package/dist/PunjabiConverter.js.map +1 -0
  66. package/dist/RomanianConverter.js +3 -0
  67. package/dist/RomanianConverter.js.map +1 -0
  68. package/dist/RussianConverter.js +3 -0
  69. package/dist/RussianConverter.js.map +1 -0
  70. package/dist/SerbianCyrillicConverter.js +3 -0
  71. package/dist/SerbianCyrillicConverter.js.map +1 -0
  72. package/dist/SerbianLatinConverter.js +3 -0
  73. package/dist/SerbianLatinConverter.js.map +1 -0
  74. package/dist/SimplifiedChineseConverter.js +3 -0
  75. package/dist/SimplifiedChineseConverter.js.map +1 -0
  76. package/dist/SpanishConverter.js +3 -0
  77. package/dist/SpanishConverter.js.map +1 -0
  78. package/dist/SwahiliConverter.js +3 -0
  79. package/dist/SwahiliConverter.js.map +1 -0
  80. package/dist/SwedishConverter.js +3 -0
  81. package/dist/SwedishConverter.js.map +1 -0
  82. package/dist/TamilConverter.js +3 -0
  83. package/dist/TamilConverter.js.map +1 -0
  84. package/dist/TeluguConverter.js +3 -0
  85. package/dist/TeluguConverter.js.map +1 -0
  86. package/dist/ThaiConverter.js +3 -0
  87. package/dist/ThaiConverter.js.map +1 -0
  88. package/dist/TraditionalChineseConverter.js +3 -0
  89. package/dist/TraditionalChineseConverter.js.map +1 -0
  90. package/dist/TurkishConverter.js +3 -0
  91. package/dist/TurkishConverter.js.map +1 -0
  92. package/dist/UkrainianConverter.js +3 -0
  93. package/dist/UkrainianConverter.js.map +1 -0
  94. package/dist/UrduConverter.js +3 -0
  95. package/dist/UrduConverter.js.map +1 -0
  96. package/dist/VietnameseConverter.js +3 -0
  97. package/dist/VietnameseConverter.js.map +1 -0
  98. package/dist/n2words.js +3 -2
  99. package/dist/n2words.js.map +1 -1
  100. package/lib/classes/abstract-language.d.ts +178 -0
  101. package/lib/classes/abstract-language.js +192 -185
  102. package/lib/classes/greedy-scale-language.d.ts +109 -0
  103. package/lib/classes/greedy-scale-language.js +96 -90
  104. package/lib/classes/slavic-language.d.ts +148 -0
  105. package/lib/classes/slavic-language.js +136 -106
  106. package/lib/classes/south-asian-language.d.ts +70 -0
  107. package/lib/classes/south-asian-language.js +58 -65
  108. package/lib/classes/turkic-language.d.ts +26 -0
  109. package/lib/classes/turkic-language.js +22 -26
  110. package/lib/languages/ar.d.ts +30 -0
  111. package/lib/languages/ar.js +49 -133
  112. package/lib/languages/az.d.ts +12 -0
  113. package/lib/languages/az.js +7 -23
  114. package/lib/languages/bn.d.ts +11 -0
  115. package/lib/languages/bn.js +12 -7
  116. package/lib/languages/cs.d.ts +88 -0
  117. package/lib/languages/cs.js +44 -113
  118. package/lib/languages/da.d.ts +15 -0
  119. package/lib/languages/da.js +40 -87
  120. package/lib/languages/de.d.ts +14 -0
  121. package/lib/languages/de.js +34 -68
  122. package/lib/languages/el.d.ts +14 -0
  123. package/lib/languages/el.js +22 -48
  124. package/lib/languages/en.d.ts +16 -0
  125. package/lib/languages/en.js +22 -59
  126. package/lib/languages/es.d.ts +15 -0
  127. package/lib/languages/es.js +49 -81
  128. package/lib/languages/fa.d.ts +47 -0
  129. package/lib/languages/fa.js +90 -73
  130. package/lib/languages/fil.d.ts +16 -0
  131. package/lib/languages/fil.js +35 -76
  132. package/lib/languages/fr-BE.d.ts +11 -0
  133. package/lib/languages/fr-BE.js +15 -51
  134. package/lib/languages/fr.d.ts +15 -0
  135. package/lib/languages/fr.js +33 -72
  136. package/lib/languages/gu.d.ts +11 -0
  137. package/lib/languages/gu.js +10 -34
  138. package/lib/languages/hbo.d.ts +113 -0
  139. package/lib/languages/hbo.js +251 -0
  140. package/lib/languages/he.d.ts +80 -0
  141. package/lib/languages/he.js +41 -164
  142. package/lib/languages/hi.d.ts +11 -0
  143. package/lib/languages/hi.js +12 -7
  144. package/lib/languages/hr.d.ts +80 -0
  145. package/lib/languages/hr.js +51 -95
  146. package/lib/languages/hu.d.ts +22 -0
  147. package/lib/languages/hu.js +35 -53
  148. package/lib/languages/id.d.ts +37 -0
  149. package/lib/languages/id.js +29 -44
  150. package/lib/languages/it.d.ts +37 -0
  151. package/lib/languages/it.js +36 -52
  152. package/lib/languages/ja.d.ts +17 -0
  153. package/lib/languages/ja.js +22 -75
  154. package/lib/languages/kn.d.ts +11 -0
  155. package/lib/languages/kn.js +10 -39
  156. package/lib/languages/ko.d.ts +14 -0
  157. package/lib/languages/ko.js +17 -45
  158. package/lib/languages/lt.d.ts +70 -0
  159. package/lib/languages/lt.js +28 -63
  160. package/lib/languages/lv.d.ts +70 -0
  161. package/lib/languages/lv.js +35 -58
  162. package/lib/languages/mr.d.ts +11 -0
  163. package/lib/languages/mr.js +10 -34
  164. package/lib/languages/ms.d.ts +31 -0
  165. package/lib/languages/ms.js +24 -20
  166. package/lib/languages/nb.d.ts +12 -0
  167. package/lib/languages/nb.js +36 -56
  168. package/lib/languages/nl.d.ts +16 -0
  169. package/lib/languages/nl.js +58 -109
  170. package/lib/languages/pa.d.ts +11 -0
  171. package/lib/languages/{pa-Guru.js → pa.js} +12 -7
  172. package/lib/languages/pl.d.ts +80 -0
  173. package/lib/languages/pl.js +26 -105
  174. package/lib/languages/pt.d.ts +29 -0
  175. package/lib/languages/pt.js +29 -64
  176. package/lib/languages/ro.d.ts +158 -0
  177. package/lib/languages/ro.js +60 -167
  178. package/lib/languages/ru.d.ts +85 -0
  179. package/lib/languages/ru.js +17 -37
  180. package/lib/languages/sr-Cyrl.d.ts +80 -0
  181. package/lib/languages/sr-Cyrl.js +113 -0
  182. package/lib/languages/sr-Latn.d.ts +80 -0
  183. package/lib/languages/sr-Latn.js +54 -98
  184. package/lib/languages/sv.d.ts +14 -0
  185. package/lib/languages/sv.js +26 -63
  186. package/lib/languages/sw.d.ts +39 -0
  187. package/lib/languages/sw.js +26 -21
  188. package/lib/languages/ta.d.ts +20 -0
  189. package/lib/languages/ta.js +26 -26
  190. package/lib/languages/te.d.ts +22 -0
  191. package/lib/languages/te.js +28 -38
  192. package/lib/languages/th.d.ts +17 -0
  193. package/lib/languages/th.js +25 -31
  194. package/lib/languages/tr.d.ts +12 -0
  195. package/lib/languages/tr.js +11 -38
  196. package/lib/languages/uk.d.ts +85 -0
  197. package/lib/languages/uk.js +18 -44
  198. package/lib/languages/ur.d.ts +11 -0
  199. package/lib/languages/ur.js +12 -7
  200. package/lib/languages/vi.d.ts +72 -0
  201. package/lib/languages/vi.js +25 -71
  202. package/lib/languages/zh-Hans.d.ts +21 -0
  203. package/lib/languages/zh-Hans.js +33 -87
  204. package/lib/languages/zh-Hant.d.ts +21 -0
  205. package/lib/languages/zh-Hant.js +111 -0
  206. package/lib/n2words.d.ts +209 -0
  207. package/lib/n2words.js +474 -191
  208. package/package.json +106 -67
  209. package/dist/languages/ar.js +0 -2
  210. package/dist/languages/ar.js.map +0 -1
  211. package/dist/languages/az.js +0 -2
  212. package/dist/languages/az.js.map +0 -1
  213. package/dist/languages/bn.js +0 -2
  214. package/dist/languages/bn.js.map +0 -1
  215. package/dist/languages/cs.js +0 -2
  216. package/dist/languages/cs.js.map +0 -1
  217. package/dist/languages/da.js +0 -2
  218. package/dist/languages/da.js.map +0 -1
  219. package/dist/languages/de.js +0 -2
  220. package/dist/languages/de.js.map +0 -1
  221. package/dist/languages/el.js +0 -2
  222. package/dist/languages/el.js.map +0 -1
  223. package/dist/languages/en.js +0 -2
  224. package/dist/languages/en.js.map +0 -1
  225. package/dist/languages/es.js +0 -2
  226. package/dist/languages/es.js.map +0 -1
  227. package/dist/languages/fa.js +0 -2
  228. package/dist/languages/fa.js.map +0 -1
  229. package/dist/languages/fil.js +0 -2
  230. package/dist/languages/fil.js.map +0 -1
  231. package/dist/languages/fr-BE.js +0 -2
  232. package/dist/languages/fr-BE.js.map +0 -1
  233. package/dist/languages/fr.js +0 -2
  234. package/dist/languages/fr.js.map +0 -1
  235. package/dist/languages/gu.js +0 -2
  236. package/dist/languages/gu.js.map +0 -1
  237. package/dist/languages/he.js +0 -2
  238. package/dist/languages/he.js.map +0 -1
  239. package/dist/languages/hi.js +0 -2
  240. package/dist/languages/hi.js.map +0 -1
  241. package/dist/languages/hr.js +0 -2
  242. package/dist/languages/hr.js.map +0 -1
  243. package/dist/languages/hu.js +0 -2
  244. package/dist/languages/hu.js.map +0 -1
  245. package/dist/languages/id.js +0 -2
  246. package/dist/languages/id.js.map +0 -1
  247. package/dist/languages/it.js +0 -2
  248. package/dist/languages/it.js.map +0 -1
  249. package/dist/languages/ja.js +0 -2
  250. package/dist/languages/ja.js.map +0 -1
  251. package/dist/languages/kn.js +0 -2
  252. package/dist/languages/kn.js.map +0 -1
  253. package/dist/languages/ko.js +0 -2
  254. package/dist/languages/ko.js.map +0 -1
  255. package/dist/languages/lt.js +0 -2
  256. package/dist/languages/lt.js.map +0 -1
  257. package/dist/languages/lv.js +0 -2
  258. package/dist/languages/lv.js.map +0 -1
  259. package/dist/languages/mr.js +0 -2
  260. package/dist/languages/mr.js.map +0 -1
  261. package/dist/languages/ms.js +0 -2
  262. package/dist/languages/ms.js.map +0 -1
  263. package/dist/languages/nb.js +0 -2
  264. package/dist/languages/nb.js.map +0 -1
  265. package/dist/languages/nl.js +0 -2
  266. package/dist/languages/nl.js.map +0 -1
  267. package/dist/languages/pa-Guru.js +0 -2
  268. package/dist/languages/pa-Guru.js.map +0 -1
  269. package/dist/languages/pl.js +0 -2
  270. package/dist/languages/pl.js.map +0 -1
  271. package/dist/languages/pt.js +0 -2
  272. package/dist/languages/pt.js.map +0 -1
  273. package/dist/languages/ro.js +0 -2
  274. package/dist/languages/ro.js.map +0 -1
  275. package/dist/languages/ru.js +0 -2
  276. package/dist/languages/ru.js.map +0 -1
  277. package/dist/languages/sr-Latn.js +0 -2
  278. package/dist/languages/sr-Latn.js.map +0 -1
  279. package/dist/languages/sv.js +0 -2
  280. package/dist/languages/sv.js.map +0 -1
  281. package/dist/languages/sw.js +0 -2
  282. package/dist/languages/sw.js.map +0 -1
  283. package/dist/languages/ta.js +0 -2
  284. package/dist/languages/ta.js.map +0 -1
  285. package/dist/languages/te.js +0 -2
  286. package/dist/languages/te.js.map +0 -1
  287. package/dist/languages/th.js +0 -2
  288. package/dist/languages/th.js.map +0 -1
  289. package/dist/languages/tr.js +0 -2
  290. package/dist/languages/tr.js.map +0 -1
  291. package/dist/languages/uk.js +0 -2
  292. package/dist/languages/uk.js.map +0 -1
  293. package/dist/languages/ur.js +0 -2
  294. package/dist/languages/ur.js.map +0 -1
  295. package/dist/languages/vi.js +0 -2
  296. package/dist/languages/vi.js.map +0 -1
  297. package/dist/languages/zh-Hans.js +0 -2
  298. package/dist/languages/zh-Hans.js.map +0 -1
  299. package/typings/classes/abstract-language.d.ts +0 -144
  300. package/typings/classes/greedy-scale-language.d.ts +0 -148
  301. package/typings/classes/slavic-language.d.ts +0 -145
  302. package/typings/classes/south-asian-language.d.ts +0 -101
  303. package/typings/classes/turkic-language.d.ts +0 -42
  304. package/typings/languages/ar.d.ts +0 -93
  305. package/typings/languages/az.d.ts +0 -25
  306. package/typings/languages/bn.d.ts +0 -1
  307. package/typings/languages/cs.d.ts +0 -120
  308. package/typings/languages/da.d.ts +0 -53
  309. package/typings/languages/de.d.ts +0 -26
  310. package/typings/languages/el.d.ts +0 -11
  311. package/typings/languages/en.d.ts +0 -30
  312. package/typings/languages/es.d.ts +0 -43
  313. package/typings/languages/fa.d.ts +0 -81
  314. package/typings/languages/fil.d.ts +0 -12
  315. package/typings/languages/fr-BE.d.ts +0 -41
  316. package/typings/languages/fr.d.ts +0 -43
  317. package/typings/languages/gu.d.ts +0 -12
  318. package/typings/languages/he.d.ts +0 -197
  319. package/typings/languages/hi.d.ts +0 -1
  320. package/typings/languages/hr.d.ts +0 -110
  321. package/typings/languages/hu.d.ts +0 -37
  322. package/typings/languages/id.d.ts +0 -69
  323. package/typings/languages/it.d.ts +0 -51
  324. package/typings/languages/ja.d.ts +0 -58
  325. package/typings/languages/kn.d.ts +0 -11
  326. package/typings/languages/ko.d.ts +0 -25
  327. package/typings/languages/lt.d.ts +0 -110
  328. package/typings/languages/lv.d.ts +0 -99
  329. package/typings/languages/mr.d.ts +0 -12
  330. package/typings/languages/ms.d.ts +0 -37
  331. package/typings/languages/nb.d.ts +0 -27
  332. package/typings/languages/nl.d.ts +0 -65
  333. package/typings/languages/pa-Guru.d.ts +0 -1
  334. package/typings/languages/pl.d.ts +0 -116
  335. package/typings/languages/pt.d.ts +0 -39
  336. package/typings/languages/ro.d.ts +0 -229
  337. package/typings/languages/ru.d.ts +0 -108
  338. package/typings/languages/sr-Latn.d.ts +0 -98
  339. package/typings/languages/sv.d.ts +0 -30
  340. package/typings/languages/sw.d.ts +0 -1
  341. package/typings/languages/ta.d.ts +0 -1
  342. package/typings/languages/te.d.ts +0 -1
  343. package/typings/languages/th.d.ts +0 -1
  344. package/typings/languages/tr.d.ts +0 -46
  345. package/typings/languages/uk.d.ts +0 -117
  346. package/typings/languages/ur.d.ts +0 -1
  347. package/typings/languages/vi.d.ts +0 -116
  348. package/typings/languages/zh-Hans.d.ts +0 -57
  349. package/typings/n2words.d.ts +0 -177
@@ -1,148 +0,0 @@
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';
@@ -1,145 +0,0 @@
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';
@@ -1,101 +0,0 @@
1
- export default SouthAsianLanguage;
2
- /**
3
- * Array of scale words for the Indian numbering system, in ascending order.
4
- * - Index 0: Usually empty/unused (ones place)
5
- * - Index 1: Thousands (hazaar/হাজার/हजार)
6
- * - Index 2: Lakhs (lakh/লাখ/लाख)
7
- * - Index 3: Crores (crore/কোটি/करोड़)
8
- * - Index 4: Arabs (arab/আরব/अरब)
9
- * Each index i represents the scale word for groups at position i in the Indian system.
10
- */
11
- export type SouthAsianScaleWords = Array<string>;
12
- /**
13
- * Array of words for numbers 0-99, indexed directly.
14
- * belowHundred[0] = word for 0, belowHundred[42] = word for 42, etc.
15
- */
16
- export type SouthAsianBelowHundred = Array<string>;
17
- /**
18
- * @typedef {Array<string>} SouthAsianScaleWords
19
- * Array of scale words for the Indian numbering system, in ascending order.
20
- * - Index 0: Usually empty/unused (ones place)
21
- * - Index 1: Thousands (hazaar/হাজার/हजार)
22
- * - Index 2: Lakhs (lakh/লাখ/लाख)
23
- * - Index 3: Crores (crore/কোটি/करोड़)
24
- * - Index 4: Arabs (arab/আরব/अरब)
25
- * Each index i represents the scale word for groups at position i in the Indian system.
26
- */
27
- /**
28
- * @typedef {Array<string>} SouthAsianBelowHundred
29
- * Array of words for numbers 0-99, indexed directly.
30
- * belowHundred[0] = word for 0, belowHundred[42] = word for 42, etc.
31
- */
32
- /**
33
- * Base class for South Asian languages with shared grouping patterns.
34
- *
35
- * This class provides a reusable implementation for South Asian languages that share:
36
- * - Indian-style number grouping: last 3 digits, then 2-2 (1,23,45,67,89)
37
- * - Lakh (100,000), Crore (10,000,000), Arab (1,000,000,000) scale words
38
- * - Standard negative and decimal handling (inherits AbstractLanguage decimal logic,
39
- * including `convertDecimalsPerDigit` support when set by subclasses)
40
- *
41
- * Used by: Hindi (hi), Bengali (bn), Urdu (ur), Punjabi (pa), Marathi (mr), Gujarati (gu), Kannada (kn)
42
- *
43
- * Subclasses MUST define language-specific vocabulary via class properties:
44
- * - `belowHundred` array with digit and teen words (0-99)
45
- * - `hundredWord` string used inside `convertBelowThousand`
46
- * - `scaleWords` array with grouping words (hazaar, lakh, crore, etc.) indexed by grouping level
47
- * - `negativeWord`, `decimalSeparatorWord`, `zeroWord`, `wordSeparator`
48
- *
49
- * @abstract
50
- * @extends AbstractLanguage
51
- */
52
- declare class SouthAsianLanguage extends AbstractLanguage {
53
- /**
54
- * Array of words for numbers 0-99 (digits and teens).
55
- * Index directly: belowHundred[0] through belowHundred[99].
56
- * @type {Array<string>}
57
- */
58
- belowHundred: Array<string>;
59
- /**
60
- * Word for "hundred" in the language (e.g., 'सौ' in Hindi, 'শত' in Bengali).
61
- * Used to construct hundreds (e.g., "1 hundred", "2 hundred").
62
- * @type {string}
63
- */
64
- hundredWord: string;
65
- /**
66
- * Array of scale words for Indian-style grouping (hazaar, lakh, crore, arab, etc.).
67
- * Index 0 is typically unused (ones place, no scale word).
68
- * Index 1 is for thousands, Index 2 for lakhs, Index 3 for crores, etc.
69
- * @type {Array<string>}
70
- */
71
- scaleWords: Array<string>;
72
- /**
73
- * Split a number into Indian numbering system groups.
74
- *
75
- * The Indian system groups differently than Western (3-3-3) systems:
76
- * - First group (rightmost): Up to 3 digits (ones, tens, hundreds)
77
- * - Subsequent groups: Exactly 2 digits each (thousands, lakhs, crores, etc.)
78
- *
79
- * This creates the familiar Indian comma pattern: 1,23,45,67,890
80
- *
81
- * @protected
82
- * @param {bigint} number The number to split into groups
83
- * @returns {Array<number>} Array of groups from most significant to least significant
84
- *
85
- * @example
86
- * // splitToGroups(1234567n) → [12, 34, 567]
87
- * // Reads as: 12 lakhs, 34 thousands, 567 units
88
- * // splitToGroups(98765432n) → [9, 87, 65, 432]
89
- * // Reads as: 9 crores, 87 lakhs, 65 thousands, 432 units
90
- */
91
- protected splitToGroups(number: bigint): Array<number>;
92
- /**
93
- * Convert a number below 1000 to words (0-999).
94
- *
95
- * @protected
96
- * @param {number} number Value between 0 and 999
97
- * @returns {string} Language-specific word representation
98
- */
99
- protected convertBelowThousand(number: number): string;
100
- }
101
- import AbstractLanguage from './abstract-language.js';
@@ -1,42 +0,0 @@
1
- export default TurkicLanguage;
2
- export type TurkicWordPair = {
3
- /**
4
- * - The Turkic word or phrase
5
- */
6
- word: string;
7
- /**
8
- * - The numeric value represented by the word
9
- */
10
- value: bigint;
11
- };
12
- /**
13
- * @typedef {Object} TurkicWordPair
14
- * @property {string} word - The Turkic word or phrase
15
- * @property {bigint} value - The numeric value represented by the word
16
- */
17
- /**
18
- * Base class for Turkic languages with shared grammar patterns.
19
- *
20
- * This class provides a reusable implementation for Turkic languages that share:
21
- * - Space-separated number combinations
22
- * - Implicit 'bir' (one) before hundreds and thousands
23
- * - Simple multiplication/addition logic
24
- * - Consistent magnitude handling
25
- * - Inherits decimal handling from AbstractLanguage via GreedyScaleLanguage
26
- * (supports both grouped and per-digit modes via the `convertDecimalsPerDigit` class property).
27
- *
28
- * Used by: Turkish (TR), Azerbaijani (AZ)
29
- *
30
- * Subclasses MUST define (from GreedyScaleLanguage requirements):
31
- * - `scaleWordPairs` array of [value, word] pairs as a class property (ordered descending by value).
32
- * Optionally, language-specific class properties (e.g., `negativeWord`, `zeroWord`, `decimalSeparatorWord`, `wordSeparator`).
33
- *
34
- * TurkicLanguage provides a default `mergeScales()` implementation; subclasses may override
35
- * if specialized merge logic is needed (unlikely for Turkic languages).
36
- *
37
- * @abstract
38
- * @extends GreedyScaleLanguage
39
- */
40
- declare class TurkicLanguage extends GreedyScaleLanguage {
41
- }
42
- import GreedyScaleLanguage from './greedy-scale-language.js';
@@ -1,93 +0,0 @@
1
- /**
2
- * Converts a number to Arabic cardinal (written) form.
3
- *
4
- * @param {number|string|bigint} value The number to convert.
5
- * @param {ArabicOptions} [options={}] Configuration options.
6
- * @returns {string} The number expressed in Arabic words.
7
- * @throws {TypeError} If value is NaN or invalid type.
8
- * @throws {Error} If value is an invalid number string.
9
- */
10
- export default function convertToWords(value: number | string | bigint, options?: ArabicOptions): string;
11
- /**
12
- * @typedef {Object} ArabicOptions
13
- * @property {string} [negativeWord='ناقص'] Word for negative numbers (minus).
14
- * @property {boolean} [feminine=false] Use feminine forms for numbers.
15
- */
16
- /**
17
- * Arabic language converter.
18
- *
19
- * Converts numbers to Arabic words with full grammatical support:
20
- * - Gender agreement (masculine/feminine forms)
21
- * - Complex pluralization rules (singular, dual, plural forms)
22
- * - Special handling for hundreds, thousands, millions, etc.
23
- * - Right-to-left text orientation
24
- * - Traditional Arabic number naming conventions
25
- *
26
- * Key Features:
27
- * - Gender-aware number forms (واحد masculine vs واحدة feminine)
28
- * - Dual forms: اثنان/اثنتان (two masculine/feminine)
29
- * - Complex rule system for numbers 3-10 (requiring feminine when referring to countables)
30
- * - Group-based algorithm: splits number by powers of 1000 (ones, thousands, millions, billions)
31
- * - Tanween (nunation) for indefinite numbers
32
- * - Sophisticated pluralization with singular, dual, and plural forms
33
- *
34
- * Algorithm:
35
- * 1. Break number into groups of 3 digits (right to left)
36
- * 2. For each non-zero group, convert to words using gender and plural rules
37
- * 3. Append the appropriate magnitude word (ألف/مليون/مليار) with proper plural form
38
- * 4. Join all groups with spaces
39
- *
40
- * Features:
41
- * - Support for gender-aware number forms
42
- * - Proper handling of Arabic dual forms (اثنان/اثنتان)
43
- * - Complex group processing for large numbers
44
- * - Right-to-left text orientation
45
- * - Traditional Arabic number naming conventions
46
- */
47
- export class Arabic extends AbstractLanguage {
48
- /**
49
- * Initializes the Arabic converter with language-specific options.
50
- *
51
- * @param {ArabicOptions} [options={}] Configuration options.
52
- */
53
- constructor({ negativeWord, feminine }?: ArabicOptions);
54
- arabicTens: string[];
55
- arabicHundreds: string[];
56
- arabicAppendedTwos: string[];
57
- arabicTwos: string[];
58
- arabicGroup: string[];
59
- arabicAppendedGroup: string[];
60
- arabicPluralGroups: string[];
61
- ones: {
62
- masculine: string[];
63
- feminine: string[];
64
- };
65
- feminine: boolean;
66
- selectedOnes: string[];
67
- /**
68
- * Returns the feminine status of a given digit (1-9).
69
- *
70
- * @param {number} digit - The digit to check (1-9).
71
- * @returns {string} The word form of the digit based on feminine status.
72
- */
73
- digitFeminineStatus(digit: number): string;
74
- /**
75
- * Processes the Arabic group number and returns the corresponding Arabic representation.
76
- * @param {number} groupNumber - The number to process. (Range: 1-999)
77
- * @param {number} groupLevel - Group level to process. (See example)
78
- * @returns {string} The Arabic representation of the group number.
79
- * @example 12345678 is processed in blocks of 3: '678' (group 0), '345' (group 1), '12' (group 2).
80
- */
81
- processArabicGroup(groupNumber: number, groupLevel: number, fullNumber: any): string;
82
- }
83
- export type ArabicOptions = {
84
- /**
85
- * Word for negative numbers (minus).
86
- */
87
- negativeWord?: string;
88
- /**
89
- * Use feminine forms for numbers.
90
- */
91
- feminine?: boolean;
92
- };
93
- import AbstractLanguage from '../classes/abstract-language.js';
@@ -1,25 +0,0 @@
1
- /**
2
- * Converts a number to Azerbaijani cardinal (written) form.
3
- *
4
- * @param {number|string|bigint} value The number to convert.
5
- * @param {Object} [options] Conversion options (see AZ class).
6
- * @returns {string} The number expressed in Azerbaijani words.
7
- * @throws {TypeError} If value is NaN or invalid type.
8
- * @throws {Error} If value is an invalid number string.
9
- *
10
- * @example
11
- * convertToWords(42, { lang: 'az' }); // 'qırx iki'
12
- * convertToWords(1000, { lang: 'az' }); // 'min'
13
- */
14
- export default function convertToWords(value: number | string | bigint, options?: any): string;
15
- /**
16
- * Azerbaijani language converter.
17
- *
18
- * Inherits from TurkicLanguage shared patterns:
19
- * - Space-separated number combinations
20
- * - Omits '1' before hundreds and thousands
21
- * - Supports flexible word spacing configuration
22
- */
23
- export class Azerbaijani extends TurkicLanguage {
24
- }
25
- import TurkicLanguage from '../classes/turkic-language.js';
@@ -1 +0,0 @@
1
- export default function convertToWords(value: any, options?: {}): string;
@@ -1,120 +0,0 @@
1
- /**
2
- * Converts a number to Czech cardinal (written) form.
3
- *
4
- * @param {number|string|bigint} value The number to convert.
5
- * @param {SlavicOptions} [options={}] Configuration options.
6
- * @returns {string} The number expressed in Czech words.
7
- * @throws {TypeError} If value is NaN or invalid type.
8
- * @throws {Error} If value is an invalid number string.
9
- */
10
- export default function convertToWords(value: number | string | bigint, options?: SlavicOptions): string;
11
- /**
12
- * @typedef {Object} SlavicOptions
13
- * @property {boolean} [feminine=false] Use feminine forms for numbers.
14
- */
15
- /**
16
- * Czech language converter.
17
- *
18
- * Implements Czech number words using the Slavic language pattern:
19
- * - Czech number words (jedna, dva, tři, čtyři, pět...)
20
- * - Slavic three-form pluralization (tisíc/tisíce/tisíc)
21
- * - Gender agreement for numbers 1-2
22
- * - Czech-specific number word endings
23
- *
24
- * Key Features:
25
- * - Three-form pluralization system shared across Slavic languages
26
- * * Form 1 (singular): 1 (e.g., "tisíc")
27
- * * Form 2 (few): 2-4, 22-24, 32-34... excluding teens (e.g., "tisíce")
28
- * * Form 3 (many): all other numbers (e.g., "tisíc")
29
- * - Chunk-based decomposition (splits into groups of 3 digits: ones, thousands, millions, etc.)
30
- * - Large number handling via thousands[] array with indexed [singular, few, many] forms
31
- *
32
- * Inherits from SlavicLanguage:
33
- * - Complex pluralization rules (one/few/many forms)
34
- * - Group-based large number handling (chunk decomposition via splitByX())
35
- * - Proper declension patterns via pluralize() method
36
- */
37
- export class Czech extends SlavicLanguage {
38
- ones: {
39
- 1: string;
40
- 2: string;
41
- 3: string;
42
- 4: string;
43
- 5: string;
44
- 6: string;
45
- 7: string;
46
- 8: string;
47
- 9: string;
48
- };
49
- tens: {
50
- 0: string;
51
- 1: string;
52
- 2: string;
53
- 3: string;
54
- 4: string;
55
- 5: string;
56
- 6: string;
57
- 7: string;
58
- 8: string;
59
- 9: string;
60
- };
61
- twenties: {
62
- 2: string;
63
- 3: string;
64
- 4: string;
65
- 5: string;
66
- 6: string;
67
- 7: string;
68
- 8: string;
69
- 9: string;
70
- };
71
- hundreds: {
72
- 1: string;
73
- 2: string;
74
- 3: string;
75
- 4: string;
76
- 5: string;
77
- 6: string;
78
- 7: string;
79
- 8: string;
80
- 9: string;
81
- };
82
- thousands: {
83
- 1: string[];
84
- 2: string[];
85
- 3: string[];
86
- 4: string[];
87
- 5: string[];
88
- 6: string[];
89
- 7: string[];
90
- 8: string[];
91
- 9: string[];
92
- 10: string[];
93
- };
94
- /**
95
- * Returns the Czech word for the decimal separator based on the whole number.
96
- *
97
- * @returns {string} The Czech word for the decimal separator.
98
- */
99
- get decimalSeparatorWord(): string;
100
- /**
101
- * Implements Czech-specific three-form pluralization rules.
102
- *
103
- * Czech three-form system:
104
- * - Form 1 (singular): exactly n=1 (e.g., "tisíc")
105
- * - Form 2 (few): n ends in 2-4, excluding teens (22-24, 32-34...) (e.g., "tisíce")
106
- * - Form 3 (many): all other numbers (e.g., "tisíc" for 0, 5+)
107
- *
108
- * @param {bigint} n The number to classify.
109
- * @param {Array<string>} forms Array of [singular, few, many] word forms.
110
- * @returns {string} The appropriate form for the number n.
111
- */
112
- pluralize(n: bigint, forms: Array<string>): string;
113
- }
114
- export type SlavicOptions = {
115
- /**
116
- * Use feminine forms for numbers.
117
- */
118
- feminine?: boolean;
119
- };
120
- import SlavicLanguage from '../classes/slavic-language.js';