n2words 4.0.0 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +53 -0
- package/README.md +14 -12
- package/dist/am-ET.js +2 -2
- package/dist/am-ET.umd.js +2 -2
- package/dist/am-Latn-ET.js +2 -2
- package/dist/am-Latn-ET.umd.js +2 -2
- package/dist/ar-SA.js +2 -2
- package/dist/ar-SA.umd.js +2 -2
- package/dist/az-AZ.js +2 -2
- package/dist/az-AZ.umd.js +2 -2
- package/dist/bn-BD.js +2 -2
- package/dist/bn-BD.umd.js +2 -2
- package/dist/cs-CZ.js +2 -2
- package/dist/cs-CZ.umd.js +2 -2
- package/dist/da-DK.js +2 -2
- package/dist/da-DK.umd.js +2 -2
- package/dist/de-DE.js +2 -2
- package/dist/de-DE.umd.js +2 -2
- package/dist/el-GR.js +2 -2
- package/dist/el-GR.umd.js +2 -2
- package/dist/en-AU.js +2 -2
- package/dist/en-AU.umd.js +2 -2
- package/dist/en-BD.js +2 -2
- package/dist/en-BD.umd.js +2 -2
- package/dist/en-CA.js +2 -2
- package/dist/en-CA.umd.js +2 -2
- package/dist/en-GB.js +2 -2
- package/dist/en-GB.umd.js +2 -2
- package/dist/en-GH.js +2 -2
- package/dist/en-GH.umd.js +2 -2
- package/dist/en-IE.js +2 -2
- package/dist/en-IE.umd.js +2 -2
- package/dist/en-IN.js +2 -2
- package/dist/en-IN.umd.js +2 -2
- package/dist/en-KE.js +2 -2
- package/dist/en-KE.umd.js +2 -2
- package/dist/en-MY.js +2 -2
- package/dist/en-MY.umd.js +2 -2
- package/dist/en-NG.js +2 -2
- package/dist/en-NG.umd.js +2 -2
- package/dist/en-NZ.js +2 -2
- package/dist/en-NZ.umd.js +2 -2
- package/dist/en-PH.js +2 -2
- package/dist/en-PH.umd.js +2 -2
- package/dist/en-PK.js +2 -2
- package/dist/en-PK.umd.js +2 -2
- package/dist/en-SG.js +2 -2
- package/dist/en-SG.umd.js +2 -2
- package/dist/en-US.js +2 -2
- package/dist/en-US.umd.js +2 -2
- package/dist/en-ZA.js +2 -2
- package/dist/en-ZA.umd.js +2 -2
- package/dist/es-ES.js +2 -2
- package/dist/es-ES.umd.js +2 -2
- package/dist/es-MX.js +2 -2
- package/dist/es-MX.umd.js +2 -2
- package/dist/es-US.js +2 -2
- package/dist/es-US.umd.js +2 -2
- package/dist/fa-IR.js +2 -2
- package/dist/fa-IR.umd.js +2 -2
- package/dist/fi-FI.js +2 -2
- package/dist/fi-FI.umd.js +2 -2
- package/dist/fil-PH.js +2 -2
- package/dist/fil-PH.umd.js +2 -2
- package/dist/fr-BE.js +2 -2
- package/dist/fr-BE.umd.js +2 -2
- package/dist/fr-FR.js +2 -2
- package/dist/fr-FR.umd.js +2 -2
- package/dist/gu-IN.js +2 -2
- package/dist/gu-IN.umd.js +2 -2
- package/dist/ha-NG.js +2 -2
- package/dist/ha-NG.umd.js +2 -2
- package/dist/hbo-IL.js +2 -2
- package/dist/hbo-IL.umd.js +2 -2
- package/dist/he-IL.js +2 -2
- package/dist/he-IL.umd.js +2 -2
- package/dist/hi-IN.js +2 -2
- package/dist/hi-IN.umd.js +2 -2
- package/dist/hr-HR.js +2 -2
- package/dist/hr-HR.umd.js +2 -2
- package/dist/hu-HU.js +2 -2
- package/dist/hu-HU.umd.js +2 -2
- package/dist/id-ID.js +2 -2
- package/dist/id-ID.umd.js +2 -2
- package/dist/it-IT.js +2 -2
- package/dist/it-IT.umd.js +2 -2
- package/dist/ja-JP.js +2 -2
- package/dist/ja-JP.umd.js +2 -2
- package/dist/ka-GE.js +2 -2
- package/dist/ka-GE.umd.js +2 -2
- package/dist/kn-IN.js +2 -2
- package/dist/kn-IN.umd.js +2 -2
- package/dist/ko-KR.js +2 -2
- package/dist/ko-KR.umd.js +2 -2
- package/dist/lt-LT.js +2 -2
- package/dist/lt-LT.umd.js +2 -2
- package/dist/lv-LV.js +2 -2
- package/dist/lv-LV.umd.js +2 -2
- package/dist/mr-IN.js +2 -2
- package/dist/mr-IN.umd.js +2 -2
- package/dist/ms-MY.js +2 -2
- package/dist/ms-MY.umd.js +2 -2
- package/dist/nb-NO.js +2 -2
- package/dist/nb-NO.umd.js +2 -2
- package/dist/nl-NL.js +2 -2
- package/dist/nl-NL.umd.js +2 -2
- package/dist/pa-IN.js +2 -2
- package/dist/pa-IN.umd.js +2 -2
- package/dist/pl-PL.js +2 -2
- package/dist/pl-PL.umd.js +2 -2
- package/dist/pt-BR.js +2 -0
- package/dist/pt-BR.umd.js +2 -0
- package/dist/pt-PT.js +2 -2
- package/dist/pt-PT.umd.js +2 -2
- package/dist/ro-RO.js +2 -2
- package/dist/ro-RO.umd.js +2 -2
- package/dist/ru-RU.js +2 -2
- package/dist/ru-RU.umd.js +2 -2
- package/dist/sr-Cyrl-RS.js +2 -2
- package/dist/sr-Cyrl-RS.umd.js +2 -2
- package/dist/sr-Latn-RS.js +2 -2
- package/dist/sr-Latn-RS.umd.js +2 -2
- package/dist/sv-SE.js +2 -2
- package/dist/sv-SE.umd.js +2 -2
- package/dist/sw-KE.js +2 -2
- package/dist/sw-KE.umd.js +2 -2
- package/dist/ta-IN.js +2 -2
- package/dist/ta-IN.umd.js +2 -2
- package/dist/te-IN.js +2 -2
- package/dist/te-IN.umd.js +2 -2
- package/dist/th-TH.js +2 -2
- package/dist/th-TH.umd.js +2 -2
- package/dist/tr-TR.js +2 -2
- package/dist/tr-TR.umd.js +2 -2
- package/dist/uk-UA.js +2 -2
- package/dist/uk-UA.umd.js +2 -2
- package/dist/ur-PK.js +2 -2
- package/dist/ur-PK.umd.js +2 -2
- package/dist/vi-VN.js +2 -2
- package/dist/vi-VN.umd.js +2 -2
- package/dist/yo-NG.js +2 -2
- package/dist/yo-NG.umd.js +2 -2
- package/dist/zh-Hans-CN.js +2 -2
- package/dist/zh-Hans-CN.umd.js +2 -2
- package/dist/zh-Hant-TW.js +2 -2
- package/dist/zh-Hant-TW.umd.js +2 -2
- package/package.json +53 -36
- package/src/am-ET.d.ts +3 -5
- package/src/am-ET.js +41 -16
- package/src/am-Latn-ET.d.ts +3 -5
- package/src/am-Latn-ET.js +45 -16
- package/src/ar-SA.d.ts +44 -18
- package/src/ar-SA.js +93 -40
- package/src/az-AZ.d.ts +3 -5
- package/src/az-AZ.js +58 -20
- package/src/bn-BD.d.ts +3 -5
- package/src/bn-BD.js +32 -16
- package/src/cs-CZ.d.ts +3 -6
- package/src/cs-CZ.js +66 -42
- package/src/da-DK.d.ts +3 -6
- package/src/da-DK.js +53 -48
- package/src/de-DE.d.ts +17 -11
- package/src/de-DE.js +88 -57
- package/src/el-GR.d.ts +3 -6
- package/src/el-GR.js +45 -32
- package/src/en-AU.d.ts +17 -11
- package/src/en-AU.js +56 -41
- package/src/en-BD.d.ts +17 -11
- package/src/en-BD.js +60 -41
- package/src/en-CA.d.ts +36 -18
- package/src/en-CA.js +67 -46
- package/src/en-GB.d.ts +17 -11
- package/src/en-GB.js +56 -41
- package/src/en-GH.d.ts +32 -3
- package/src/en-GH.js +104 -26
- package/src/en-IE.d.ts +17 -11
- package/src/en-IE.js +56 -41
- package/src/en-IN.d.ts +17 -11
- package/src/en-IN.js +60 -41
- package/src/en-KE.d.ts +28 -3
- package/src/en-KE.js +93 -26
- package/src/en-MY.d.ts +26 -3
- package/src/en-MY.js +91 -26
- package/src/en-NG.d.ts +17 -11
- package/src/en-NG.js +56 -41
- package/src/en-NZ.d.ts +32 -3
- package/src/en-NZ.js +85 -31
- package/src/en-PH.d.ts +32 -3
- package/src/en-PH.js +97 -26
- package/src/en-PK.d.ts +17 -11
- package/src/en-PK.js +60 -41
- package/src/en-SG.d.ts +28 -3
- package/src/en-SG.js +93 -26
- package/src/en-US.d.ts +36 -18
- package/src/en-US.js +70 -47
- package/src/en-ZA.d.ts +17 -11
- package/src/en-ZA.js +56 -41
- package/src/es-ES.d.ts +53 -21
- package/src/es-ES.js +104 -56
- package/src/es-MX.d.ts +53 -21
- package/src/es-MX.js +104 -56
- package/src/es-US.d.ts +53 -21
- package/src/es-US.js +92 -51
- package/src/fa-IR.d.ts +3 -5
- package/src/fa-IR.js +28 -13
- package/src/fi-FI.d.ts +3 -6
- package/src/fi-FI.js +47 -29
- package/src/fil-PH.d.ts +3 -5
- package/src/fil-PH.js +61 -28
- package/src/fr-BE.d.ts +31 -15
- package/src/fr-BE.js +128 -57
- package/src/fr-FR.d.ts +31 -16
- package/src/fr-FR.js +97 -60
- package/src/gu-IN.d.ts +3 -5
- package/src/gu-IN.js +31 -16
- package/src/ha-NG.d.ts +3 -5
- package/src/ha-NG.js +55 -27
- package/src/hbo-IL.d.ts +26 -12
- package/src/hbo-IL.js +92 -51
- package/src/he-IL.d.ts +17 -10
- package/src/he-IL.js +92 -50
- package/src/hi-IN.d.ts +3 -5
- package/src/hi-IN.js +30 -17
- package/src/hr-HR.d.ts +21 -10
- package/src/hr-HR.js +89 -33
- package/src/hu-HU.d.ts +3 -5
- package/src/hu-HU.js +57 -23
- package/src/id-ID.d.ts +3 -5
- package/src/id-ID.js +56 -23
- package/src/it-IT.d.ts +17 -11
- package/src/it-IT.js +74 -43
- package/src/ja-JP.d.ts +3 -6
- package/src/ja-JP.js +39 -26
- package/src/ka-GE.d.ts +3 -6
- package/src/ka-GE.js +38 -26
- package/src/kn-IN.d.ts +3 -5
- package/src/kn-IN.js +31 -16
- package/src/ko-KR.d.ts +3 -6
- package/src/ko-KR.js +34 -26
- package/src/lt-LT.d.ts +21 -11
- package/src/lt-LT.js +64 -42
- package/src/lv-LV.d.ts +21 -11
- package/src/lv-LV.js +79 -51
- package/src/mr-IN.d.ts +3 -5
- package/src/mr-IN.js +31 -16
- package/src/ms-MY.d.ts +3 -5
- package/src/ms-MY.js +58 -24
- package/src/nb-NO.d.ts +3 -6
- package/src/nb-NO.js +54 -34
- package/src/nl-NL.d.ts +41 -20
- package/src/nl-NL.js +111 -69
- package/src/pa-IN.d.ts +3 -5
- package/src/pa-IN.js +32 -16
- package/src/pl-PL.d.ts +21 -11
- package/src/pl-PL.js +69 -45
- package/src/pt-BR.d.ts +42 -0
- package/src/pt-BR.js +574 -0
- package/src/pt-PT.d.ts +17 -11
- package/src/pt-PT.js +80 -48
- package/src/ro-RO.d.ts +21 -11
- package/src/ro-RO.js +77 -39
- package/src/ru-RU.d.ts +35 -15
- package/src/ru-RU.js +100 -38
- package/src/sr-Cyrl-RS.d.ts +35 -15
- package/src/sr-Cyrl-RS.js +100 -38
- package/src/sr-Latn-RS.d.ts +35 -15
- package/src/sr-Latn-RS.js +100 -38
- package/src/sv-SE.d.ts +3 -6
- package/src/sv-SE.js +53 -34
- package/src/sw-KE.d.ts +3 -5
- package/src/sw-KE.js +50 -20
- package/src/ta-IN.d.ts +3 -5
- package/src/ta-IN.js +29 -17
- package/src/te-IN.d.ts +3 -5
- package/src/te-IN.js +31 -16
- package/src/th-TH.d.ts +3 -5
- package/src/th-TH.js +42 -19
- package/src/tr-TR.d.ts +17 -11
- package/src/tr-TR.js +63 -37
- package/src/uk-UA.d.ts +21 -10
- package/src/uk-UA.js +89 -33
- package/src/ur-PK.d.ts +3 -5
- package/src/ur-PK.js +32 -16
- package/src/utils/check-max.d.ts +26 -0
- package/src/utils/check-max.js +33 -0
- package/src/utils/expand-scientific.d.ts +0 -4
- package/src/utils/expand-scientific.js +7 -9
- package/src/utils/is-plain-object.d.ts +3 -4
- package/src/utils/is-plain-object.js +3 -4
- package/src/utils/parse-cardinal.d.ts +1 -2
- package/src/utils/parse-cardinal.js +12 -9
- package/src/utils/parse-currency.d.ts +1 -2
- package/src/utils/parse-currency.js +9 -11
- package/src/utils/parse-ordinal.d.ts +0 -1
- package/src/utils/parse-ordinal.js +9 -10
- package/src/utils/resolve-options.d.ts +17 -0
- package/src/utils/resolve-options.js +56 -0
- package/src/utils/scale.d.ts +49 -0
- package/src/utils/scale.js +65 -0
- package/src/vi-VN.d.ts +3 -6
- package/src/vi-VN.js +41 -28
- package/src/yo-NG.d.ts +3 -5
- package/src/yo-NG.js +49 -33
- package/src/zh-Hans-CN.d.ts +45 -20
- package/src/zh-Hans-CN.js +84 -31
- package/src/zh-Hant-TW.d.ts +45 -20
- package/src/zh-Hant-TW.js +85 -34
- package/src/utils/validate-options.d.ts +0 -8
- package/src/utils/validate-options.js +0 -16
package/src/ha-NG.js
CHANGED
|
@@ -16,6 +16,8 @@
|
|
|
16
16
|
import { parseCardinalValue } from './utils/parse-cardinal.js'
|
|
17
17
|
import { parseCurrencyValue } from './utils/parse-currency.js'
|
|
18
18
|
import { parseOrdinalValue } from './utils/parse-ordinal.js'
|
|
19
|
+
import { checkMax } from './utils/check-max.js'
|
|
20
|
+
import { western } from './utils/scale.js'
|
|
19
21
|
|
|
20
22
|
// ============================================================================
|
|
21
23
|
// Vocabulary
|
|
@@ -24,7 +26,7 @@ import { parseOrdinalValue } from './utils/parse-ordinal.js'
|
|
|
24
26
|
const ONES = ['', 'ɗaya', 'biyu', 'uku', 'huɗu', 'biyar', 'shida', 'bakwai', 'takwas', 'tara']
|
|
25
27
|
const TEENS = ['goma', 'sha ɗaya', 'sha biyu', 'sha uku', 'sha huɗu', 'sha biyar', 'sha shida', 'sha bakwai', 'sha takwas', 'sha tara']
|
|
26
28
|
// Arabic loanwords for tens
|
|
27
|
-
const TENS = ['', '', 'ashirin', 'talatin',
|
|
29
|
+
const TENS = ['', '', 'ashirin', 'talatin', 'arba\'in', 'hamsin', 'sittin', 'saba\'in', 'tamanin', 'tis\'in']
|
|
28
30
|
|
|
29
31
|
const HUNDRED = 'ɗari'
|
|
30
32
|
const THOUSAND = 'dubu'
|
|
@@ -36,6 +38,11 @@ const DECIMAL_SEP = 'digo'
|
|
|
36
38
|
// Short scale
|
|
37
39
|
const SCALE_WORDS = ['', THOUSAND, 'miliyan', 'biliyan']
|
|
38
40
|
|
|
41
|
+
// Supported magnitude ceiling (checked at the public entry points), derived from the scale table.
|
|
42
|
+
export const cardinalMax = western(SCALE_WORDS.length - 1)
|
|
43
|
+
export const ordinalMax = western(SCALE_WORDS.length - 1)
|
|
44
|
+
export const currencyMax = western(SCALE_WORDS.length - 1)
|
|
45
|
+
|
|
39
46
|
// ============================================================================
|
|
40
47
|
// Ordinal Vocabulary
|
|
41
48
|
// ============================================================================
|
|
@@ -60,8 +67,10 @@ const KOBO = 'kobo'
|
|
|
60
67
|
* Build segment for 0-999 with Hausa patterns.
|
|
61
68
|
* Hausa uses reversed order for hundreds: "biyu ɗari" (200)
|
|
62
69
|
* And "da" connector for ones: "ashirin da ɗaya" (21)
|
|
70
|
+
* @param {number} n - Integer segment value (0-999)
|
|
71
|
+
* @returns {string} The segment in Hausa words
|
|
63
72
|
*/
|
|
64
|
-
function buildSegment
|
|
73
|
+
function buildSegment(n) {
|
|
65
74
|
if (n === 0) return ''
|
|
66
75
|
|
|
67
76
|
const ones = n % 10
|
|
@@ -74,7 +83,8 @@ function buildSegment (n) {
|
|
|
74
83
|
if (hundredsDigit > 0) {
|
|
75
84
|
if (hundredsDigit === 1) {
|
|
76
85
|
parts.push(HUNDRED)
|
|
77
|
-
}
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
78
88
|
// Reversed: multiplier + hundredWord
|
|
79
89
|
parts.push(ONES[hundredsDigit] + ' ' + HUNDRED)
|
|
80
90
|
}
|
|
@@ -85,20 +95,25 @@ function buildSegment (n) {
|
|
|
85
95
|
|
|
86
96
|
if (tensOnes === 0) {
|
|
87
97
|
// Just hundreds
|
|
88
|
-
}
|
|
98
|
+
}
|
|
99
|
+
else if (tensOnes < 10) {
|
|
89
100
|
// Single digit - with "da" connector if after hundreds
|
|
90
101
|
if (hundredsDigit > 0) {
|
|
91
102
|
parts.push('da ' + ONES[ones])
|
|
92
|
-
}
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
93
105
|
parts.push(ONES[ones])
|
|
94
106
|
}
|
|
95
|
-
}
|
|
107
|
+
}
|
|
108
|
+
else if (tensOnes < 20) {
|
|
96
109
|
// Teens (10-19): "sha X"
|
|
97
110
|
parts.push(TEENS[ones])
|
|
98
|
-
}
|
|
111
|
+
}
|
|
112
|
+
else if (ones === 0) {
|
|
99
113
|
// Even tens (20, 30, 40, etc.)
|
|
100
114
|
parts.push(TENS[tensDigit])
|
|
101
|
-
}
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
102
117
|
// Tens + ones with "da" connector
|
|
103
118
|
parts.push(TENS[tensDigit] + ' da ' + ONES[ones])
|
|
104
119
|
}
|
|
@@ -110,7 +125,11 @@ function buildSegment (n) {
|
|
|
110
125
|
// Conversion Functions
|
|
111
126
|
// ============================================================================
|
|
112
127
|
|
|
113
|
-
|
|
128
|
+
/**
|
|
129
|
+
* @param {bigint} n - Non-negative integer value
|
|
130
|
+
* @returns {string} The integer in Hausa words
|
|
131
|
+
*/
|
|
132
|
+
function integerToWords(n) {
|
|
114
133
|
if (n === 0n) return ZERO
|
|
115
134
|
|
|
116
135
|
if (n < 1000n) {
|
|
@@ -122,12 +141,18 @@ function integerToWords (n) {
|
|
|
122
141
|
|
|
123
142
|
/**
|
|
124
143
|
* Checks if a word is a single digit (1-9).
|
|
144
|
+
* @param {string} word - Word to test
|
|
145
|
+
* @returns {boolean} True if the word is a single digit (1-9)
|
|
125
146
|
*/
|
|
126
|
-
function isSingleDigit
|
|
147
|
+
function isSingleDigit(word) {
|
|
127
148
|
return ONES.slice(1).includes(word)
|
|
128
149
|
}
|
|
129
150
|
|
|
130
|
-
|
|
151
|
+
/**
|
|
152
|
+
* @param {bigint} n - Integer value of 1000 or greater
|
|
153
|
+
* @returns {string} The number in Hausa words
|
|
154
|
+
*/
|
|
155
|
+
function buildLargeNumberWords(n) {
|
|
131
156
|
const numStr = n.toString()
|
|
132
157
|
const len = numStr.length
|
|
133
158
|
|
|
@@ -157,7 +182,8 @@ function buildLargeNumberWords (n) {
|
|
|
157
182
|
|
|
158
183
|
if (scaleIndex === 0) {
|
|
159
184
|
rawParts.push(buildSegment(segment))
|
|
160
|
-
}
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
161
187
|
rawParts.push(buildSegment(segment))
|
|
162
188
|
rawParts.push(scaleWord)
|
|
163
189
|
}
|
|
@@ -188,11 +214,12 @@ function buildLargeNumberWords (n) {
|
|
|
188
214
|
|
|
189
215
|
// Determine if we need "da" connector
|
|
190
216
|
// Use "da" when current is a single digit following a scale word
|
|
191
|
-
if (prevPart && isSingleDigit(part)
|
|
192
|
-
|
|
193
|
-
|
|
217
|
+
if (prevPart && isSingleDigit(part)
|
|
218
|
+
&& (prevPart === THOUSAND || prevPart === HUNDRED
|
|
219
|
+
|| SCALE_WORDS.includes(prevPart))) {
|
|
194
220
|
result.push(' da ')
|
|
195
|
-
}
|
|
221
|
+
}
|
|
222
|
+
else if (i > 0) {
|
|
196
223
|
result.push(' ')
|
|
197
224
|
}
|
|
198
225
|
|
|
@@ -202,7 +229,11 @@ function buildLargeNumberWords (n) {
|
|
|
202
229
|
return result.join('')
|
|
203
230
|
}
|
|
204
231
|
|
|
205
|
-
|
|
232
|
+
/**
|
|
233
|
+
* @param {string} decimalPart - Digit string of the fractional part
|
|
234
|
+
* @returns {string} The fractional digits in Hausa words
|
|
235
|
+
*/
|
|
236
|
+
function decimalPartToWords(decimalPart) {
|
|
206
237
|
// Per-digit decimal reading
|
|
207
238
|
const digits = []
|
|
208
239
|
for (const char of decimalPart) {
|
|
@@ -214,12 +245,12 @@ function decimalPartToWords (decimalPart) {
|
|
|
214
245
|
|
|
215
246
|
/**
|
|
216
247
|
* Converts a numeric value to Hausa words.
|
|
217
|
-
*
|
|
218
248
|
* @param {number | string | bigint} value - The numeric value to convert
|
|
219
249
|
* @returns {string} The number in Hausa words
|
|
220
250
|
*/
|
|
221
|
-
function toCardinal
|
|
251
|
+
function toCardinal(value) {
|
|
222
252
|
const { isNegative, integerPart, decimalPart } = parseCardinalValue(value)
|
|
253
|
+
checkMax(integerPart, cardinalMax)
|
|
223
254
|
|
|
224
255
|
let result = ''
|
|
225
256
|
|
|
@@ -244,11 +275,10 @@ function toCardinal (value) {
|
|
|
244
275
|
* Converts a non-negative integer to Hausa ordinal words.
|
|
245
276
|
*
|
|
246
277
|
* Hausa ordinals: na farko (1st), na biyu (2nd), na uku (3rd), etc.
|
|
247
|
-
*
|
|
248
278
|
* @param {bigint} n - Positive integer to convert
|
|
249
279
|
* @returns {string} Hausa ordinal words
|
|
250
280
|
*/
|
|
251
|
-
function integerToOrdinal
|
|
281
|
+
function integerToOrdinal(n) {
|
|
252
282
|
// Special form for first
|
|
253
283
|
if (n === 1n) return ORDINAL_FIRST
|
|
254
284
|
|
|
@@ -258,19 +288,18 @@ function integerToOrdinal (n) {
|
|
|
258
288
|
|
|
259
289
|
/**
|
|
260
290
|
* Converts a numeric value to Hausa ordinal words.
|
|
261
|
-
*
|
|
262
291
|
* @param {number | string | bigint} value - The numeric value to convert (positive integer)
|
|
263
292
|
* @returns {string} The number as ordinal words
|
|
264
293
|
* @throws {TypeError} If value is not a valid numeric type
|
|
265
294
|
* @throws {RangeError} If value is negative, zero, or has a decimal part
|
|
266
|
-
*
|
|
267
295
|
* @example
|
|
268
296
|
* toOrdinal(1) // 'na farko'
|
|
269
297
|
* toOrdinal(2) // 'na biyu'
|
|
270
298
|
* toOrdinal(10) // 'na goma'
|
|
271
299
|
*/
|
|
272
|
-
function toOrdinal
|
|
300
|
+
function toOrdinal(value) {
|
|
273
301
|
const integerPart = parseOrdinalValue(value)
|
|
302
|
+
checkMax(integerPart, ordinalMax)
|
|
274
303
|
return integerToOrdinal(integerPart)
|
|
275
304
|
}
|
|
276
305
|
|
|
@@ -282,19 +311,18 @@ function toOrdinal (value) {
|
|
|
282
311
|
* Converts a numeric value to Hausa currency words (Nigerian Naira).
|
|
283
312
|
*
|
|
284
313
|
* Uses naira and kobo (100 kobo = 1 naira).
|
|
285
|
-
*
|
|
286
314
|
* @param {number | string | bigint} value - The currency amount to convert
|
|
287
315
|
* @returns {string} The amount in Hausa currency words
|
|
288
316
|
* @throws {TypeError} If value is not a valid numeric type
|
|
289
317
|
* @throws {Error} If value is not a valid number format
|
|
290
|
-
*
|
|
291
318
|
* @example
|
|
292
319
|
* toCurrency(42) // 'arba'in da biyu naira'
|
|
293
320
|
* toCurrency(1.50) // 'ɗaya naira da hamsin kobo'
|
|
294
321
|
* toCurrency(-5) // 'babu biyar naira'
|
|
295
322
|
*/
|
|
296
|
-
function toCurrency
|
|
323
|
+
function toCurrency(value) {
|
|
297
324
|
const { isNegative, dollars: naira, cents: kobo } = parseCurrencyValue(value)
|
|
325
|
+
checkMax(naira, currencyMax)
|
|
298
326
|
|
|
299
327
|
let result = ''
|
|
300
328
|
if (isNegative) {
|
package/src/hbo-IL.d.ts
CHANGED
|
@@ -1,24 +1,40 @@
|
|
|
1
|
+
export const cardinalMax: bigint;
|
|
2
|
+
export const ordinalMax: bigint;
|
|
3
|
+
export const currencyMax: bigint;
|
|
4
|
+
/**
|
|
5
|
+
* @typedef {object} CardinalOptions
|
|
6
|
+
* @property {('masculine'|'feminine')} [gender] - Grammatical gender
|
|
7
|
+
* @property {string} [andWord] - Custom conjunction word
|
|
8
|
+
*/
|
|
9
|
+
/** @type {Required<CardinalOptions>} */
|
|
10
|
+
export const cardinalDefaults: Required<CardinalOptions>;
|
|
11
|
+
/** @type {{ gender: ReadonlyArray<Required<CardinalOptions>['gender']> }} */
|
|
12
|
+
export const cardinalValues: {
|
|
13
|
+
gender: ReadonlyArray<Required<CardinalOptions>["gender"]>;
|
|
14
|
+
};
|
|
15
|
+
export type CardinalOptions = {
|
|
16
|
+
/**
|
|
17
|
+
* - Grammatical gender
|
|
18
|
+
*/
|
|
19
|
+
gender?: "feminine" | "masculine" | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* - Custom conjunction word
|
|
22
|
+
*/
|
|
23
|
+
andWord?: string | undefined;
|
|
24
|
+
};
|
|
1
25
|
/**
|
|
2
26
|
* Converts a numeric value to Biblical Hebrew words.
|
|
3
|
-
*
|
|
4
27
|
* @param {number | string | bigint} value - The numeric value to convert
|
|
5
|
-
* @param {
|
|
6
|
-
* @param {('masculine'|'feminine')} [options.gender='masculine'] - Grammatical gender
|
|
7
|
-
* @param {string} [options.andWord='ו'] - Custom conjunction word
|
|
28
|
+
* @param {CardinalOptions} [options] - Optional configuration
|
|
8
29
|
* @returns {string} The number in Biblical Hebrew words
|
|
9
30
|
*/
|
|
10
|
-
export function toCardinal(value: number | string | bigint, options?:
|
|
11
|
-
gender?: "masculine" | "feminine" | undefined;
|
|
12
|
-
andWord?: string | undefined;
|
|
13
|
-
}): string;
|
|
31
|
+
export function toCardinal(value: number | string | bigint, options?: CardinalOptions): string;
|
|
14
32
|
/**
|
|
15
33
|
* Converts a numeric value to Biblical Hebrew ordinal words.
|
|
16
|
-
*
|
|
17
34
|
* @param {number | string | bigint} value - The numeric value to convert
|
|
18
35
|
* @returns {string} The ordinal in Biblical Hebrew words
|
|
19
36
|
* @throws {TypeError} If value is not a valid numeric type
|
|
20
37
|
* @throws {Error} If value is not a positive integer
|
|
21
|
-
*
|
|
22
38
|
* @example
|
|
23
39
|
* toOrdinal(1) // 'ראשון'
|
|
24
40
|
* toOrdinal(21) // 'עשרים וראשון'
|
|
@@ -26,12 +42,10 @@ export function toCardinal(value: number | string | bigint, options?: {
|
|
|
26
42
|
export function toOrdinal(value: number | string | bigint): string;
|
|
27
43
|
/**
|
|
28
44
|
* Converts a numeric value to Biblical Hebrew Shekel currency words.
|
|
29
|
-
*
|
|
30
45
|
* @param {number | string | bigint} value - The numeric value to convert
|
|
31
46
|
* @returns {string} The currency in Biblical Hebrew words
|
|
32
47
|
* @throws {TypeError} If value is not a valid numeric type
|
|
33
48
|
* @throws {Error} If value is not a valid number format
|
|
34
|
-
*
|
|
35
49
|
* @example
|
|
36
50
|
* toCurrency(1) // 'שקל אחד'
|
|
37
51
|
* toCurrency(2.50) // 'שניים שקלים חמישים גרות'
|
package/src/hbo-IL.js
CHANGED
|
@@ -14,7 +14,9 @@
|
|
|
14
14
|
import { parseCardinalValue } from './utils/parse-cardinal.js'
|
|
15
15
|
import { parseCurrencyValue } from './utils/parse-currency.js'
|
|
16
16
|
import { parseOrdinalValue } from './utils/parse-ordinal.js'
|
|
17
|
-
import {
|
|
17
|
+
import { checkMax } from './utils/check-max.js'
|
|
18
|
+
import { bounded, western } from './utils/scale.js'
|
|
19
|
+
import { resolveOptions } from './utils/resolve-options.js'
|
|
18
20
|
|
|
19
21
|
// ============================================================================
|
|
20
22
|
// Vocabulary (arrays for indexed access - faster than object property lookup)
|
|
@@ -39,6 +41,15 @@ const HUNDREDS_FEM = ['', 'מאה', 'מאתיים', 'שלש מאות', 'ארבע
|
|
|
39
41
|
const SCALE = ['', 'אלף', 'מיליון', 'מיליארד', 'טריליון', 'קוודרליון', 'קווינטיליון']
|
|
40
42
|
const SCALE_PLURAL = ['', 'אלפים', 'מיליונים', 'מיליארדים', 'טריליונים', 'קוודרליונים', 'קווינטיליונים']
|
|
41
43
|
|
|
44
|
+
// Supported magnitude ceilings (checked at the public entry points). Cardinal
|
|
45
|
+
// SCALE reaches index SCALE.length-1 (10^18), so cardinals/currency must stay
|
|
46
|
+
// below 10^(SCALE.length * 3) = 10^21. Ordinals are bounded lower: past 10^6
|
|
47
|
+
// the millions multiplier is built with buildScaleSegment (0-999), so n must
|
|
48
|
+
// stay below 10^9. Decimals are read digit-by-digit (no ceiling).
|
|
49
|
+
export const cardinalMax = western(SCALE.length - 1)
|
|
50
|
+
export const ordinalMax = bounded(9)
|
|
51
|
+
export const currencyMax = western(SCALE.length - 1)
|
|
52
|
+
|
|
42
53
|
const ZERO = 'אפס'
|
|
43
54
|
const NEGATIVE = 'מינוס'
|
|
44
55
|
const DECIMAL_SEP = 'נקודה'
|
|
@@ -62,8 +73,14 @@ const GERAH_PLURAL = 'גרות'
|
|
|
62
73
|
/**
|
|
63
74
|
* Builds segment word for scale segments (thousands, millions, etc.).
|
|
64
75
|
* "ו" is added before tens and ones when following hundreds.
|
|
76
|
+
* @param {number} n - Segment value (0-999)
|
|
77
|
+
* @param {string} andWord - Conjunction word
|
|
78
|
+
* @param {string[]} ONES - Ones vocabulary
|
|
79
|
+
* @param {string[]} TEENS - Teens vocabulary
|
|
80
|
+
* @param {string[]} HUNDREDS_ARR - Hundreds vocabulary
|
|
81
|
+
* @returns {string} Segment word
|
|
65
82
|
*/
|
|
66
|
-
function buildScaleSegment
|
|
83
|
+
function buildScaleSegment(n, andWord, ONES, TEENS, HUNDREDS_ARR) {
|
|
67
84
|
if (n === 0) return ''
|
|
68
85
|
|
|
69
86
|
const ones = n % 10
|
|
@@ -83,15 +100,18 @@ function buildScaleSegment (n, andWord, ONES, TEENS, HUNDREDS_ARR) {
|
|
|
83
100
|
const teenWord = TEENS[ones]
|
|
84
101
|
if (result) {
|
|
85
102
|
result += ' ' + andWord + teenWord
|
|
86
|
-
}
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
87
105
|
result = teenWord
|
|
88
106
|
}
|
|
89
|
-
}
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
90
109
|
// Tens (20-90)
|
|
91
110
|
if (tens >= 2) {
|
|
92
111
|
if (result) {
|
|
93
112
|
result += ' ' + andWord + TENS[tens]
|
|
94
|
-
}
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
95
115
|
result = TENS[tens]
|
|
96
116
|
}
|
|
97
117
|
}
|
|
@@ -100,7 +120,8 @@ function buildScaleSegment (n, andWord, ONES, TEENS, HUNDREDS_ARR) {
|
|
|
100
120
|
if (ones > 0) {
|
|
101
121
|
if (result) {
|
|
102
122
|
result += ' ' + andWord + ONES[ones]
|
|
103
|
-
}
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
104
125
|
result = ONES[ones]
|
|
105
126
|
}
|
|
106
127
|
}
|
|
@@ -112,8 +133,14 @@ function buildScaleSegment (n, andWord, ONES, TEENS, HUNDREDS_ARR) {
|
|
|
112
133
|
/**
|
|
113
134
|
* Builds segment word for units segment (no scale word).
|
|
114
135
|
* "ו" is only added before the final ones digit.
|
|
136
|
+
* @param {number} n - Segment value (0-999)
|
|
137
|
+
* @param {string} andWord - Conjunction word
|
|
138
|
+
* @param {string[]} ONES - Ones vocabulary
|
|
139
|
+
* @param {string[]} TEENS - Teens vocabulary
|
|
140
|
+
* @param {string[]} HUNDREDS_ARR - Hundreds vocabulary
|
|
141
|
+
* @returns {string} Segment word
|
|
115
142
|
*/
|
|
116
|
-
function buildUnitsSegment
|
|
143
|
+
function buildUnitsSegment(n, andWord, ONES, TEENS, HUNDREDS_ARR) {
|
|
117
144
|
if (n === 0) return ''
|
|
118
145
|
|
|
119
146
|
const ones = n % 10
|
|
@@ -132,14 +159,17 @@ function buildUnitsSegment (n, andWord, ONES, TEENS, HUNDREDS_ARR) {
|
|
|
132
159
|
// Teens (10-19)
|
|
133
160
|
if (result) {
|
|
134
161
|
result += ' ' + TEENS[ones]
|
|
135
|
-
}
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
136
164
|
result = TEENS[ones]
|
|
137
165
|
}
|
|
138
|
-
}
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
139
168
|
if (tens >= 2) {
|
|
140
169
|
if (result) {
|
|
141
170
|
result += ' ' + TENS[tens]
|
|
142
|
-
}
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
143
173
|
result = TENS[tens]
|
|
144
174
|
}
|
|
145
175
|
}
|
|
@@ -148,7 +178,8 @@ function buildUnitsSegment (n, andWord, ONES, TEENS, HUNDREDS_ARR) {
|
|
|
148
178
|
if (ones > 0) {
|
|
149
179
|
if (result) {
|
|
150
180
|
result += ' ' + andWord + ONES[ones]
|
|
151
|
-
}
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
152
183
|
result = ONES[ones]
|
|
153
184
|
}
|
|
154
185
|
}
|
|
@@ -163,12 +194,12 @@ function buildUnitsSegment (n, andWord, ONES, TEENS, HUNDREDS_ARR) {
|
|
|
163
194
|
|
|
164
195
|
/**
|
|
165
196
|
* Converts a non-negative integer to Biblical Hebrew words.
|
|
166
|
-
*
|
|
167
197
|
* @param {bigint} n - Non-negative integer to convert
|
|
168
|
-
* @param {
|
|
198
|
+
* @param {('masculine'|'feminine')} gender - Grammatical gender
|
|
199
|
+
* @param {string} andWord - Conjunction word
|
|
169
200
|
* @returns {string} Biblical Hebrew words
|
|
170
201
|
*/
|
|
171
|
-
function integerToWords
|
|
202
|
+
function integerToWords(n, gender, andWord) {
|
|
172
203
|
if (n === 0n) return ZERO
|
|
173
204
|
|
|
174
205
|
const isFeminine = gender === 'feminine'
|
|
@@ -206,28 +237,34 @@ function integerToWords (n, gender, andWord) {
|
|
|
206
237
|
// Add "ו" before single-digit units when following scale words
|
|
207
238
|
if (segment <= 9) {
|
|
208
239
|
result += ' ' + andWord + segmentWord
|
|
209
|
-
}
|
|
240
|
+
}
|
|
241
|
+
else {
|
|
210
242
|
result += ' ' + segmentWord
|
|
211
243
|
}
|
|
212
|
-
}
|
|
244
|
+
}
|
|
245
|
+
else {
|
|
213
246
|
result = segmentWord
|
|
214
247
|
}
|
|
215
|
-
}
|
|
248
|
+
}
|
|
249
|
+
else if (i === 1) {
|
|
216
250
|
// Thousands - special handling for 1-9
|
|
217
251
|
if (segment <= 9) {
|
|
218
252
|
if (result) result += ' '
|
|
219
253
|
result += THOUSANDS_SPECIAL[segment]
|
|
220
|
-
}
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
221
256
|
const segmentWord = buildScaleSegment(segment, andWord, ONES, TEENS, HUNDREDS_ARR)
|
|
222
257
|
if (result) result += ' '
|
|
223
258
|
result += segmentWord + ' ' + SCALE[1]
|
|
224
259
|
}
|
|
225
|
-
}
|
|
260
|
+
}
|
|
261
|
+
else {
|
|
226
262
|
// Millions and above
|
|
227
263
|
if (segment === 1) {
|
|
228
264
|
if (result) result += ' '
|
|
229
265
|
result += SCALE[i]
|
|
230
|
-
}
|
|
266
|
+
}
|
|
267
|
+
else {
|
|
231
268
|
const segmentWord = buildScaleSegment(segment, andWord, ONES, TEENS, HUNDREDS_ARR)
|
|
232
269
|
if (result) result += ' '
|
|
233
270
|
result += segmentWord + ' ' + SCALE_PLURAL[i]
|
|
@@ -240,12 +277,11 @@ function integerToWords (n, gender, andWord) {
|
|
|
240
277
|
|
|
241
278
|
/**
|
|
242
279
|
* Converts decimal digits to Biblical Hebrew words (digit by digit).
|
|
243
|
-
*
|
|
244
280
|
* @param {string} decimalPart - Decimal digits (without the point)
|
|
245
|
-
* @param {
|
|
281
|
+
* @param {('masculine'|'feminine')} gender - Grammatical gender
|
|
246
282
|
* @returns {string} Biblical Hebrew words for decimal part
|
|
247
283
|
*/
|
|
248
|
-
function decimalPartToWords
|
|
284
|
+
function decimalPartToWords(decimalPart, gender) {
|
|
249
285
|
const ONES = gender === 'feminine' ? ONES_FEM : ONES_MASC
|
|
250
286
|
|
|
251
287
|
let result = ''
|
|
@@ -258,24 +294,28 @@ function decimalPartToWords (decimalPart, gender, andWord) {
|
|
|
258
294
|
return result
|
|
259
295
|
}
|
|
260
296
|
|
|
297
|
+
/**
|
|
298
|
+
* @typedef {object} CardinalOptions
|
|
299
|
+
* @property {('masculine'|'feminine')} [gender] - Grammatical gender
|
|
300
|
+
* @property {string} [andWord] - Custom conjunction word
|
|
301
|
+
*/
|
|
302
|
+
|
|
303
|
+
/** @type {Required<CardinalOptions>} */
|
|
304
|
+
export const cardinalDefaults = { gender: 'masculine', andWord: 'ו' }
|
|
305
|
+
|
|
306
|
+
/** @type {{ gender: ReadonlyArray<Required<CardinalOptions>['gender']> }} */
|
|
307
|
+
export const cardinalValues = { gender: ['masculine', 'feminine'] }
|
|
308
|
+
|
|
261
309
|
/**
|
|
262
310
|
* Converts a numeric value to Biblical Hebrew words.
|
|
263
|
-
*
|
|
264
311
|
* @param {number | string | bigint} value - The numeric value to convert
|
|
265
|
-
* @param {
|
|
266
|
-
* @param {('masculine'|'feminine')} [options.gender='masculine'] - Grammatical gender
|
|
267
|
-
* @param {string} [options.andWord='ו'] - Custom conjunction word
|
|
312
|
+
* @param {CardinalOptions} [options] - Optional configuration
|
|
268
313
|
* @returns {string} The number in Biblical Hebrew words
|
|
269
314
|
*/
|
|
270
|
-
function toCardinal
|
|
271
|
-
options = validateOptions(options)
|
|
315
|
+
function toCardinal(value, options) {
|
|
272
316
|
const { isNegative, integerPart, decimalPart } = parseCardinalValue(value)
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
const {
|
|
276
|
-
gender = 'masculine',
|
|
277
|
-
andWord = 'ו'
|
|
278
|
-
} = options
|
|
317
|
+
checkMax(integerPart, cardinalMax)
|
|
318
|
+
const { gender, andWord } = resolveOptions(options, cardinalDefaults, cardinalValues)
|
|
279
319
|
|
|
280
320
|
let result = ''
|
|
281
321
|
|
|
@@ -286,7 +326,7 @@ function toCardinal (value, options) {
|
|
|
286
326
|
result += integerToWords(integerPart, gender, andWord)
|
|
287
327
|
|
|
288
328
|
if (decimalPart) {
|
|
289
|
-
result += ' ' + DECIMAL_SEP + ' ' + decimalPartToWords(decimalPart, gender
|
|
329
|
+
result += ' ' + DECIMAL_SEP + ' ' + decimalPartToWords(decimalPart, gender)
|
|
290
330
|
}
|
|
291
331
|
|
|
292
332
|
return result
|
|
@@ -298,11 +338,10 @@ function toCardinal (value, options) {
|
|
|
298
338
|
|
|
299
339
|
/**
|
|
300
340
|
* Builds ordinal for tens and ones (0-99).
|
|
301
|
-
*
|
|
302
341
|
* @param {number} n - Number 0-99
|
|
303
342
|
* @returns {string} Ordinal word
|
|
304
343
|
*/
|
|
305
|
-
function buildOrdinalTensOnes
|
|
344
|
+
function buildOrdinalTensOnes(n) {
|
|
306
345
|
if (n === 0) return ''
|
|
307
346
|
if (n < 10) return ORDINAL_ONES[n]
|
|
308
347
|
if (n < 20) return ORDINAL_TEENS[n - 10]
|
|
@@ -320,11 +359,10 @@ function buildOrdinalTensOnes (n) {
|
|
|
320
359
|
|
|
321
360
|
/**
|
|
322
361
|
* Converts a non-negative integer to Biblical Hebrew ordinal words.
|
|
323
|
-
*
|
|
324
362
|
* @param {bigint} n - Non-negative integer to convert
|
|
325
363
|
* @returns {string} Biblical Hebrew ordinal words
|
|
326
364
|
*/
|
|
327
|
-
function integerToOrdinal
|
|
365
|
+
function integerToOrdinal(n) {
|
|
328
366
|
if (n === 0n) return ''
|
|
329
367
|
if (n === 1n) return ORDINAL_ONES[1]
|
|
330
368
|
|
|
@@ -360,7 +398,8 @@ function integerToOrdinal (n) {
|
|
|
360
398
|
let result
|
|
361
399
|
if (thousands <= 9) {
|
|
362
400
|
result = THOUSANDS_MASC[thousands]
|
|
363
|
-
}
|
|
401
|
+
}
|
|
402
|
+
else {
|
|
364
403
|
result = buildScaleSegment(thousands, 'ו', ONES_MASC, TEENS_MASC, HUNDREDS) + ' ' + SCALE[1]
|
|
365
404
|
}
|
|
366
405
|
|
|
@@ -392,7 +431,8 @@ function integerToOrdinal (n) {
|
|
|
392
431
|
let result
|
|
393
432
|
if (millions === 1) {
|
|
394
433
|
result = SCALE[2]
|
|
395
|
-
}
|
|
434
|
+
}
|
|
435
|
+
else {
|
|
396
436
|
result = buildScaleSegment(millions, 'ו', ONES_MASC, TEENS_MASC, HUNDREDS) + ' ' + SCALE_PLURAL[2]
|
|
397
437
|
}
|
|
398
438
|
|
|
@@ -401,18 +441,17 @@ function integerToOrdinal (n) {
|
|
|
401
441
|
|
|
402
442
|
/**
|
|
403
443
|
* Converts a numeric value to Biblical Hebrew ordinal words.
|
|
404
|
-
*
|
|
405
444
|
* @param {number | string | bigint} value - The numeric value to convert
|
|
406
445
|
* @returns {string} The ordinal in Biblical Hebrew words
|
|
407
446
|
* @throws {TypeError} If value is not a valid numeric type
|
|
408
447
|
* @throws {Error} If value is not a positive integer
|
|
409
|
-
*
|
|
410
448
|
* @example
|
|
411
449
|
* toOrdinal(1) // 'ראשון'
|
|
412
450
|
* toOrdinal(21) // 'עשרים וראשון'
|
|
413
451
|
*/
|
|
414
|
-
function toOrdinal
|
|
452
|
+
function toOrdinal(value) {
|
|
415
453
|
const n = parseOrdinalValue(value)
|
|
454
|
+
checkMax(n, ordinalMax)
|
|
416
455
|
return integerToOrdinal(n)
|
|
417
456
|
}
|
|
418
457
|
|
|
@@ -422,18 +461,17 @@ function toOrdinal (value) {
|
|
|
422
461
|
|
|
423
462
|
/**
|
|
424
463
|
* Converts a numeric value to Biblical Hebrew Shekel currency words.
|
|
425
|
-
*
|
|
426
464
|
* @param {number | string | bigint} value - The numeric value to convert
|
|
427
465
|
* @returns {string} The currency in Biblical Hebrew words
|
|
428
466
|
* @throws {TypeError} If value is not a valid numeric type
|
|
429
467
|
* @throws {Error} If value is not a valid number format
|
|
430
|
-
*
|
|
431
468
|
* @example
|
|
432
469
|
* toCurrency(1) // 'שקל אחד'
|
|
433
470
|
* toCurrency(2.50) // 'שניים שקלים חמישים גרות'
|
|
434
471
|
*/
|
|
435
|
-
function toCurrency
|
|
472
|
+
function toCurrency(value) {
|
|
436
473
|
const { isNegative, dollars, cents } = parseCurrencyValue(value)
|
|
474
|
+
checkMax(dollars, currencyMax)
|
|
437
475
|
|
|
438
476
|
const parts = []
|
|
439
477
|
|
|
@@ -445,9 +483,11 @@ function toCurrency (value) {
|
|
|
445
483
|
if (dollars > 0n || cents === 0n) {
|
|
446
484
|
if (dollars === 1n) {
|
|
447
485
|
parts.push(SHEKEL + ' ' + ONES_MASC[1])
|
|
448
|
-
}
|
|
486
|
+
}
|
|
487
|
+
else if (dollars === 2n) {
|
|
449
488
|
parts.push(ONES_MASC[2] + ' ' + SHEKEL_PLURAL)
|
|
450
|
-
}
|
|
489
|
+
}
|
|
490
|
+
else {
|
|
451
491
|
const shekelWord = integerToWords(dollars, 'masculine', 'ו')
|
|
452
492
|
parts.push(shekelWord + ' ' + SHEKEL_PLURAL)
|
|
453
493
|
}
|
|
@@ -458,7 +498,8 @@ function toCurrency (value) {
|
|
|
458
498
|
const centNum = Number(cents)
|
|
459
499
|
if (centNum === 1) {
|
|
460
500
|
parts.push(GERAH + ' ' + ONES_FEM[1])
|
|
461
|
-
}
|
|
501
|
+
}
|
|
502
|
+
else {
|
|
462
503
|
const gerahWord = integerToWords(cents, 'feminine', 'ו')
|
|
463
504
|
parts.push(gerahWord + ' ' + GERAH_PLURAL)
|
|
464
505
|
}
|
package/src/he-IL.d.ts
CHANGED
|
@@ -1,22 +1,31 @@
|
|
|
1
|
+
export const cardinalMax: bigint;
|
|
2
|
+
export const ordinalMax: bigint;
|
|
3
|
+
export const currencyMax: bigint;
|
|
4
|
+
/**
|
|
5
|
+
* @typedef {object} CardinalOptions
|
|
6
|
+
* @property {string} [andWord] - Custom conjunction word
|
|
7
|
+
*/
|
|
8
|
+
/** @type {Required<CardinalOptions>} */
|
|
9
|
+
export const cardinalDefaults: Required<CardinalOptions>;
|
|
10
|
+
export type CardinalOptions = {
|
|
11
|
+
/**
|
|
12
|
+
* - Custom conjunction word
|
|
13
|
+
*/
|
|
14
|
+
andWord?: string | undefined;
|
|
15
|
+
};
|
|
1
16
|
/**
|
|
2
17
|
* Converts a numeric value to Modern Hebrew words.
|
|
3
|
-
*
|
|
4
18
|
* @param {number | string | bigint} value - The numeric value to convert
|
|
5
|
-
* @param {
|
|
6
|
-
* @param {string} [options.andWord='ו'] - Custom conjunction word
|
|
19
|
+
* @param {CardinalOptions} [options] - Optional configuration
|
|
7
20
|
* @returns {string} The number in Modern Hebrew words
|
|
8
21
|
*/
|
|
9
|
-
export function toCardinal(value: number | string | bigint, options?:
|
|
10
|
-
andWord?: string | undefined;
|
|
11
|
-
}): string;
|
|
22
|
+
export function toCardinal(value: number | string | bigint, options?: CardinalOptions): string;
|
|
12
23
|
/**
|
|
13
24
|
* Converts a numeric value to Hebrew ordinal words.
|
|
14
|
-
*
|
|
15
25
|
* @param {number | string | bigint} value - The numeric value to convert
|
|
16
26
|
* @returns {string} The ordinal in Hebrew words
|
|
17
27
|
* @throws {TypeError} If value is not a valid numeric type
|
|
18
28
|
* @throws {Error} If value is not a positive integer
|
|
19
|
-
*
|
|
20
29
|
* @example
|
|
21
30
|
* toOrdinal(1) // 'ראשון'
|
|
22
31
|
* toOrdinal(21) // 'עשרים וראשון'
|
|
@@ -24,12 +33,10 @@ export function toCardinal(value: number | string | bigint, options?: {
|
|
|
24
33
|
export function toOrdinal(value: number | string | bigint): string;
|
|
25
34
|
/**
|
|
26
35
|
* Converts a numeric value to Hebrew New Israeli Shekel currency words.
|
|
27
|
-
*
|
|
28
36
|
* @param {number | string | bigint} value - The numeric value to convert
|
|
29
37
|
* @returns {string} The currency in Hebrew words
|
|
30
38
|
* @throws {TypeError} If value is not a valid numeric type
|
|
31
39
|
* @throws {Error} If value is not a valid number format
|
|
32
|
-
*
|
|
33
40
|
* @example
|
|
34
41
|
* toCurrency(1) // 'שקל אחד'
|
|
35
42
|
* toCurrency(2.50) // 'שניים שקלים חמישים אגורות'
|