@gks101/numtowords 1.0.0 → 1.0.1
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/LICENSE +34 -0
- package/README.md +65 -68
- package/dist/core/converter.js +8 -8
- package/dist/index.cjs.js +321 -148
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.esm.js +321 -148
- package/dist/index.esm.js.map +1 -1
- package/dist/index.umd.js +321 -148
- package/dist/index.umd.js.map +1 -1
- package/dist/locales/de.js +52 -30
- package/dist/locales/en.js +49 -25
- package/dist/locales/fr.js +55 -31
- package/dist/locales/hi.js +116 -37
- package/dist/locales/in.js +46 -22
- package/dist/types/core/converter.d.ts +1 -1
- package/dist/types/core/types.d.ts +1 -1
- package/dist/types/index.d.ts +7 -7
- package/dist/types/locales/de.d.ts +1 -1
- package/dist/types/locales/en.d.ts +1 -1
- package/dist/types/locales/fr.d.ts +1 -1
- package/dist/types/locales/hi.d.ts +1 -1
- package/dist/types/locales/in.d.ts +1 -1
- package/package.json +23 -6
package/dist/index.esm.js
CHANGED
|
@@ -19,7 +19,7 @@ function getLocale(id) {
|
|
|
19
19
|
const def = registry.get(id);
|
|
20
20
|
if (!def) {
|
|
21
21
|
throw new Error(`[numtowords] Locale "${id}" is not registered. ` +
|
|
22
|
-
`Available: ${[...registry.keys()].join(
|
|
22
|
+
`Available: ${[...registry.keys()].join(', ')}`);
|
|
23
23
|
}
|
|
24
24
|
return def;
|
|
25
25
|
}
|
|
@@ -29,10 +29,10 @@ function availableLocales() {
|
|
|
29
29
|
}
|
|
30
30
|
// ─── Defaults ────────────────────────────────────────────────────────────────
|
|
31
31
|
const DEFAULT_OPTIONS = {
|
|
32
|
-
locale:
|
|
32
|
+
locale: 'en',
|
|
33
33
|
capitalize: true,
|
|
34
34
|
useAnd: true,
|
|
35
|
-
currency:
|
|
35
|
+
currency: '',
|
|
36
36
|
};
|
|
37
37
|
// ─── Main convert function ────────────────────────────────────────────────────
|
|
38
38
|
/**
|
|
@@ -48,27 +48,27 @@ function convert(input, options) {
|
|
|
48
48
|
// ── Normalise input ────────────────────────────────────────────────────────
|
|
49
49
|
let raw = String(input).trim();
|
|
50
50
|
let negative = false;
|
|
51
|
-
if (raw.startsWith(
|
|
51
|
+
if (raw.startsWith('-')) {
|
|
52
52
|
negative = true;
|
|
53
53
|
raw = raw.slice(1);
|
|
54
54
|
}
|
|
55
55
|
// Strip commas / underscores used as separators
|
|
56
|
-
raw = raw.replace(/[,_\s]/g,
|
|
56
|
+
raw = raw.replace(/[,_\s]/g, '');
|
|
57
57
|
if (!/^\d+$/.test(raw)) {
|
|
58
58
|
throw new Error(`[numtowords] Invalid numeric input: "${input}"`);
|
|
59
59
|
}
|
|
60
60
|
// Remove leading zeros
|
|
61
|
-
raw = raw.replace(/^0+/,
|
|
61
|
+
raw = raw.replace(/^0+/, '') || '0';
|
|
62
62
|
const n = BigInt(raw);
|
|
63
63
|
// ── Delegate to locale ─────────────────────────────────────────────────────
|
|
64
64
|
const locale = getLocale(opts.locale);
|
|
65
65
|
let result = locale.convert(n, opts);
|
|
66
66
|
if (negative)
|
|
67
|
-
result =
|
|
67
|
+
result = 'Negative ' + result;
|
|
68
68
|
// ── Capitalise ─────────────────────────────────────────────────────────────
|
|
69
69
|
if (opts.capitalize) {
|
|
70
70
|
// Do not capitalise German zero (tests expect lowercase 'null')
|
|
71
|
-
if (!(n === 0n && opts.locale ===
|
|
71
|
+
if (!(n === 0n && opts.locale === 'de')) {
|
|
72
72
|
result = result.charAt(0).toUpperCase() + result.slice(1);
|
|
73
73
|
}
|
|
74
74
|
}
|
|
@@ -81,37 +81,61 @@ function convert(input, options) {
|
|
|
81
81
|
|
|
82
82
|
// ─── Word tables ──────────────────────────────────────────────────────────────
|
|
83
83
|
const ONES$1 = [
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
84
|
+
'',
|
|
85
|
+
'one',
|
|
86
|
+
'two',
|
|
87
|
+
'three',
|
|
88
|
+
'four',
|
|
89
|
+
'five',
|
|
90
|
+
'six',
|
|
91
|
+
'seven',
|
|
92
|
+
'eight',
|
|
93
|
+
'nine',
|
|
94
|
+
'ten',
|
|
95
|
+
'eleven',
|
|
96
|
+
'twelve',
|
|
97
|
+
'thirteen',
|
|
98
|
+
'fourteen',
|
|
99
|
+
'fifteen',
|
|
100
|
+
'sixteen',
|
|
101
|
+
'seventeen',
|
|
102
|
+
'eighteen',
|
|
103
|
+
'nineteen',
|
|
88
104
|
];
|
|
89
105
|
const TENS$1 = [
|
|
90
|
-
|
|
91
|
-
|
|
106
|
+
'',
|
|
107
|
+
'',
|
|
108
|
+
'twenty',
|
|
109
|
+
'thirty',
|
|
110
|
+
'forty',
|
|
111
|
+
'fifty',
|
|
112
|
+
'sixty',
|
|
113
|
+
'seventy',
|
|
114
|
+
'eighty',
|
|
115
|
+
'ninety',
|
|
92
116
|
];
|
|
93
117
|
/**
|
|
94
118
|
* Scale names in the short (American/modern British) scale.
|
|
95
119
|
* Index 0 = thousands, 1 = millions, …
|
|
96
120
|
*/
|
|
97
121
|
const SCALES = [
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
122
|
+
'thousand',
|
|
123
|
+
'million',
|
|
124
|
+
'billion',
|
|
125
|
+
'trillion',
|
|
126
|
+
'quadrillion',
|
|
127
|
+
'quintillion',
|
|
128
|
+
'sextillion',
|
|
129
|
+
'septillion',
|
|
130
|
+
'octillion',
|
|
131
|
+
'nonillion',
|
|
132
|
+
'decillion',
|
|
109
133
|
];
|
|
110
134
|
// ─── Helpers ──────────────────────────────────────────────────────────────────
|
|
111
135
|
/** Convert 0–999 to words */
|
|
112
136
|
function hundredsToWords$1(n, useAnd) {
|
|
113
137
|
if (n === 0)
|
|
114
|
-
return
|
|
138
|
+
return '';
|
|
115
139
|
const parts = [];
|
|
116
140
|
const h = Math.floor(n / 100);
|
|
117
141
|
const remainder = n % 100;
|
|
@@ -121,7 +145,7 @@ function hundredsToWords$1(n, useAnd) {
|
|
|
121
145
|
if (remainder === 0) ;
|
|
122
146
|
else {
|
|
123
147
|
if (h > 0 && useAnd)
|
|
124
|
-
parts.push(
|
|
148
|
+
parts.push('and');
|
|
125
149
|
if (remainder < 20) {
|
|
126
150
|
parts.push(ONES$1[remainder]);
|
|
127
151
|
}
|
|
@@ -131,14 +155,14 @@ function hundredsToWords$1(n, useAnd) {
|
|
|
131
155
|
parts.push(o === 0 ? TENS$1[t] : `${TENS$1[t]}-${ONES$1[o]}`);
|
|
132
156
|
}
|
|
133
157
|
}
|
|
134
|
-
return parts.join(
|
|
158
|
+
return parts.join(' ');
|
|
135
159
|
}
|
|
136
160
|
// ─── Locale definition ────────────────────────────────────────────────────────
|
|
137
161
|
const en = {
|
|
138
|
-
name:
|
|
162
|
+
name: 'English',
|
|
139
163
|
convert(n, opts) {
|
|
140
164
|
if (n === 0n)
|
|
141
|
-
return
|
|
165
|
+
return 'zero';
|
|
142
166
|
const useAnd = opts.useAnd;
|
|
143
167
|
const chunks = [];
|
|
144
168
|
// Split number into groups of 3 from the right
|
|
@@ -165,21 +189,45 @@ const en = {
|
|
|
165
189
|
parts.push(`${words} ${scaleName}`);
|
|
166
190
|
}
|
|
167
191
|
}
|
|
168
|
-
return parts.join(
|
|
192
|
+
return parts.join(' ');
|
|
169
193
|
},
|
|
170
194
|
};
|
|
171
|
-
registerLocale(
|
|
195
|
+
registerLocale('en', en);
|
|
172
196
|
|
|
173
197
|
// ─── Word tables ──────────────────────────────────────────────────────────────
|
|
174
198
|
const ONES = [
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
199
|
+
'',
|
|
200
|
+
'one',
|
|
201
|
+
'two',
|
|
202
|
+
'three',
|
|
203
|
+
'four',
|
|
204
|
+
'five',
|
|
205
|
+
'six',
|
|
206
|
+
'seven',
|
|
207
|
+
'eight',
|
|
208
|
+
'nine',
|
|
209
|
+
'ten',
|
|
210
|
+
'eleven',
|
|
211
|
+
'twelve',
|
|
212
|
+
'thirteen',
|
|
213
|
+
'fourteen',
|
|
214
|
+
'fifteen',
|
|
215
|
+
'sixteen',
|
|
216
|
+
'seventeen',
|
|
217
|
+
'eighteen',
|
|
218
|
+
'nineteen',
|
|
179
219
|
];
|
|
180
220
|
const TENS = [
|
|
181
|
-
|
|
182
|
-
|
|
221
|
+
'',
|
|
222
|
+
'',
|
|
223
|
+
'twenty',
|
|
224
|
+
'thirty',
|
|
225
|
+
'forty',
|
|
226
|
+
'fifty',
|
|
227
|
+
'sixty',
|
|
228
|
+
'seventy',
|
|
229
|
+
'eighty',
|
|
230
|
+
'ninety',
|
|
183
231
|
];
|
|
184
232
|
/**
|
|
185
233
|
* Indian scale names (each 100× the previous after thousand):
|
|
@@ -190,19 +238,19 @@ const TENS = [
|
|
|
190
238
|
* …
|
|
191
239
|
*/
|
|
192
240
|
const INDIAN_SCALES = [
|
|
193
|
-
[100000000000000000n,
|
|
194
|
-
[1000000000000000n,
|
|
195
|
-
[10000000000000n,
|
|
196
|
-
[100000000000n,
|
|
197
|
-
[1000000000n,
|
|
198
|
-
[10000000n,
|
|
199
|
-
[100000n,
|
|
200
|
-
[1000n,
|
|
241
|
+
[100000000000000000n, 'shankh'], // 10^17
|
|
242
|
+
[1000000000000000n, 'padma'], // 10^15
|
|
243
|
+
[10000000000000n, 'neel'], // 10^13
|
|
244
|
+
[100000000000n, 'kharab'], // 10^11
|
|
245
|
+
[1000000000n, 'arab'], // 10^9
|
|
246
|
+
[10000000n, 'crore'], // 10^7
|
|
247
|
+
[100000n, 'lakh'], // 10^5
|
|
248
|
+
[1000n, 'thousand'],
|
|
201
249
|
];
|
|
202
250
|
// ─── Helpers ──────────────────────────────────────────────────────────────────
|
|
203
251
|
function twoDigits(n) {
|
|
204
252
|
if (n === 0)
|
|
205
|
-
return
|
|
253
|
+
return '';
|
|
206
254
|
if (n < 20)
|
|
207
255
|
return ONES[n];
|
|
208
256
|
const t = Math.floor(n / 10);
|
|
@@ -211,7 +259,7 @@ function twoDigits(n) {
|
|
|
211
259
|
}
|
|
212
260
|
function hundredsToWords(n) {
|
|
213
261
|
if (n === 0)
|
|
214
|
-
return
|
|
262
|
+
return '';
|
|
215
263
|
const h = Math.floor(n / 100);
|
|
216
264
|
const rem = n % 100;
|
|
217
265
|
const parts = [];
|
|
@@ -220,14 +268,14 @@ function hundredsToWords(n) {
|
|
|
220
268
|
const two = twoDigits(rem);
|
|
221
269
|
if (two)
|
|
222
270
|
parts.push(two);
|
|
223
|
-
return parts.join(
|
|
271
|
+
return parts.join(' ');
|
|
224
272
|
}
|
|
225
273
|
// ─── Locale definition ────────────────────────────────────────────────────────
|
|
226
274
|
const indian = {
|
|
227
|
-
name:
|
|
275
|
+
name: 'Indian',
|
|
228
276
|
convert(n, _opts) {
|
|
229
277
|
if (n === 0n)
|
|
230
|
-
return
|
|
278
|
+
return 'zero';
|
|
231
279
|
const parts = [];
|
|
232
280
|
let remaining = n;
|
|
233
281
|
for (const [scale, name] of INDIAN_SCALES) {
|
|
@@ -244,53 +292,132 @@ const indian = {
|
|
|
244
292
|
if (remaining > 0n) {
|
|
245
293
|
parts.push(hundredsToWords(Number(remaining)));
|
|
246
294
|
}
|
|
247
|
-
return parts.join(
|
|
295
|
+
return parts.join(' ');
|
|
248
296
|
},
|
|
249
297
|
};
|
|
250
|
-
registerLocale(
|
|
298
|
+
registerLocale('in', indian);
|
|
251
299
|
|
|
252
300
|
// ─── Word tables ──────────────────────────────────────────────────────────────
|
|
253
301
|
/** 1–99 in Hindi */
|
|
254
302
|
const HINDI_ONES = {
|
|
255
|
-
1:
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
303
|
+
1: 'एक',
|
|
304
|
+
2: 'दो',
|
|
305
|
+
3: 'तीन',
|
|
306
|
+
4: 'चार',
|
|
307
|
+
5: 'पाँच',
|
|
308
|
+
6: 'छह',
|
|
309
|
+
7: 'सात',
|
|
310
|
+
8: 'आठ',
|
|
311
|
+
9: 'नौ',
|
|
312
|
+
10: 'दस',
|
|
313
|
+
11: 'ग्यारह',
|
|
314
|
+
12: 'बारह',
|
|
315
|
+
13: 'तेरह',
|
|
316
|
+
14: 'चौदह',
|
|
317
|
+
15: 'पन्द्रह',
|
|
318
|
+
16: 'सोलह',
|
|
319
|
+
17: 'सत्रह',
|
|
320
|
+
18: 'अट्ठारह',
|
|
321
|
+
19: 'उन्नीस',
|
|
322
|
+
20: 'बीस',
|
|
323
|
+
21: 'इक्कीस',
|
|
324
|
+
22: 'बाईस',
|
|
325
|
+
23: 'तेईस',
|
|
326
|
+
24: 'चौबीस',
|
|
327
|
+
25: 'पच्चीस',
|
|
328
|
+
26: 'छब्बीस',
|
|
329
|
+
27: 'सत्ताईस',
|
|
330
|
+
28: 'अट्ठाईस',
|
|
331
|
+
29: 'उनतीस',
|
|
332
|
+
30: 'तीस',
|
|
333
|
+
31: 'इकतीस',
|
|
334
|
+
32: 'बत्तीस',
|
|
335
|
+
33: 'तैंतीस',
|
|
336
|
+
34: 'चौंतीस',
|
|
337
|
+
35: 'पैंतीस',
|
|
338
|
+
36: 'छत्तीस',
|
|
339
|
+
37: 'सैंतीस',
|
|
340
|
+
38: 'अड़तीस',
|
|
341
|
+
39: 'उनतालीस',
|
|
342
|
+
40: 'चालीस',
|
|
343
|
+
41: 'इकतालीस',
|
|
344
|
+
42: 'बयालीस',
|
|
345
|
+
43: 'तैंतालीस',
|
|
346
|
+
44: 'चौवालीस',
|
|
347
|
+
45: 'पैंतालीस',
|
|
348
|
+
46: 'छियालीस',
|
|
349
|
+
47: 'सैंतालीस',
|
|
350
|
+
48: 'अड़तालीस',
|
|
351
|
+
49: 'उनचास',
|
|
352
|
+
50: 'पचास',
|
|
353
|
+
51: 'इक्यावन',
|
|
354
|
+
52: 'बावन',
|
|
355
|
+
53: 'तिरपन',
|
|
356
|
+
54: 'चौवन',
|
|
357
|
+
55: 'पचपन',
|
|
358
|
+
56: 'छप्पन',
|
|
359
|
+
57: 'सत्तावन',
|
|
360
|
+
58: 'अट्ठावन',
|
|
361
|
+
59: 'उनसठ',
|
|
362
|
+
60: 'साठ',
|
|
363
|
+
61: 'इकसठ',
|
|
364
|
+
62: 'बासठ',
|
|
365
|
+
63: 'तिरसठ',
|
|
366
|
+
64: 'चौंसठ',
|
|
367
|
+
65: 'पैंसठ',
|
|
368
|
+
66: 'छियासठ',
|
|
369
|
+
67: 'सड़सठ',
|
|
370
|
+
68: 'अड़सठ',
|
|
371
|
+
69: 'उनहत्तर',
|
|
372
|
+
70: 'सत्तर',
|
|
373
|
+
71: 'इकहत्तर',
|
|
374
|
+
72: 'बहत्तर',
|
|
375
|
+
73: 'तिहत्तर',
|
|
376
|
+
74: 'चौहत्तर',
|
|
377
|
+
75: 'पचहत्तर',
|
|
378
|
+
76: 'छिहत्तर',
|
|
379
|
+
77: 'सत्तहत्तर',
|
|
380
|
+
78: 'अठहत्तर',
|
|
381
|
+
79: 'उन्यासी',
|
|
382
|
+
80: 'अस्सी',
|
|
383
|
+
81: 'इक्यासी',
|
|
384
|
+
82: 'बयासी',
|
|
385
|
+
83: 'तिरासी',
|
|
386
|
+
84: 'चौरासी',
|
|
387
|
+
85: 'पचासी',
|
|
388
|
+
86: 'छियासी',
|
|
389
|
+
87: 'सत्तासी',
|
|
390
|
+
88: 'अट्ठासी',
|
|
391
|
+
89: 'नवासी',
|
|
392
|
+
90: 'नब्बे',
|
|
393
|
+
91: 'इक्यानबे',
|
|
394
|
+
92: 'बानवे',
|
|
395
|
+
93: 'तिरानवे',
|
|
396
|
+
94: 'चौरानवे',
|
|
397
|
+
95: 'पचानवे',
|
|
398
|
+
96: 'छियानवे',
|
|
399
|
+
97: 'सत्तानवे',
|
|
400
|
+
98: 'अट्ठानवे',
|
|
401
|
+
99: 'निन्यानवे',
|
|
275
402
|
};
|
|
276
|
-
const HINDI_HUNDRED =
|
|
403
|
+
const HINDI_HUNDRED = 'सौ';
|
|
277
404
|
const INDIAN_SCALES_HI = [
|
|
278
|
-
[100000000000000000n,
|
|
279
|
-
[1000000000000000n,
|
|
280
|
-
[10000000000000n,
|
|
281
|
-
[100000000000n,
|
|
282
|
-
[1000000000n,
|
|
283
|
-
[10000000n,
|
|
284
|
-
[100000n,
|
|
285
|
-
[1000n,
|
|
405
|
+
[100000000000000000n, 'शंख'], // 10^17
|
|
406
|
+
[1000000000000000n, 'पद्म'], // 10^15
|
|
407
|
+
[10000000000000n, 'नील'], // 10^13
|
|
408
|
+
[100000000000n, 'खरब'], // 10^11
|
|
409
|
+
[1000000000n, 'अरब'], // 10^9
|
|
410
|
+
[10000000n, 'करोड़'], // 10^7
|
|
411
|
+
[100000n, 'लाख'], // 10^5
|
|
412
|
+
[1000n, 'हज़ार'], // 10^3
|
|
286
413
|
];
|
|
287
414
|
// ─── Helpers ──────────────────────────────────────────────────────────────────
|
|
288
415
|
function upToNinetyNine$2(n) {
|
|
289
|
-
return HINDI_ONES[n] ??
|
|
416
|
+
return HINDI_ONES[n] ?? '';
|
|
290
417
|
}
|
|
291
418
|
function hundredsHindi(n) {
|
|
292
419
|
if (n === 0)
|
|
293
|
-
return
|
|
420
|
+
return '';
|
|
294
421
|
const h = Math.floor(n / 100);
|
|
295
422
|
const rem = n % 100;
|
|
296
423
|
const parts = [];
|
|
@@ -300,14 +427,14 @@ function hundredsHindi(n) {
|
|
|
300
427
|
}
|
|
301
428
|
if (rem > 0)
|
|
302
429
|
parts.push(upToNinetyNine$2(rem));
|
|
303
|
-
return parts.join(
|
|
430
|
+
return parts.join(' ');
|
|
304
431
|
}
|
|
305
432
|
// ─── Locale definition ────────────────────────────────────────────────────────
|
|
306
433
|
const hi = {
|
|
307
|
-
name:
|
|
434
|
+
name: 'Hindi',
|
|
308
435
|
convert(n, _opts) {
|
|
309
436
|
if (n === 0n)
|
|
310
|
-
return
|
|
437
|
+
return 'शून्य';
|
|
311
438
|
const parts = [];
|
|
312
439
|
let remaining = n;
|
|
313
440
|
for (const [scale, name] of INDIAN_SCALES_HI) {
|
|
@@ -321,26 +448,50 @@ const hi = {
|
|
|
321
448
|
if (remaining > 0n) {
|
|
322
449
|
parts.push(hundredsHindi(Number(remaining)));
|
|
323
450
|
}
|
|
324
|
-
return parts.join(
|
|
451
|
+
return parts.join(' ');
|
|
325
452
|
},
|
|
326
453
|
};
|
|
327
|
-
registerLocale(
|
|
454
|
+
registerLocale('hi', hi);
|
|
328
455
|
|
|
329
456
|
// ─── Word tables ──────────────────────────────────────────────────────────────
|
|
330
457
|
const ONES_DE = [
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
458
|
+
'',
|
|
459
|
+
'ein',
|
|
460
|
+
'zwei',
|
|
461
|
+
'drei',
|
|
462
|
+
'vier',
|
|
463
|
+
'fünf',
|
|
464
|
+
'sechs',
|
|
465
|
+
'sieben',
|
|
466
|
+
'acht',
|
|
467
|
+
'neun',
|
|
468
|
+
'zehn',
|
|
469
|
+
'elf',
|
|
470
|
+
'zwölf',
|
|
471
|
+
'dreizehn',
|
|
472
|
+
'vierzehn',
|
|
473
|
+
'fünfzehn',
|
|
474
|
+
'sechzehn',
|
|
475
|
+
'siebzehn',
|
|
476
|
+
'achtzehn',
|
|
477
|
+
'neunzehn',
|
|
335
478
|
];
|
|
336
479
|
const TENS_DE = [
|
|
337
|
-
|
|
338
|
-
|
|
480
|
+
'',
|
|
481
|
+
'',
|
|
482
|
+
'zwanzig',
|
|
483
|
+
'dreißig',
|
|
484
|
+
'vierzig',
|
|
485
|
+
'fünfzig',
|
|
486
|
+
'sechzig',
|
|
487
|
+
'siebzig',
|
|
488
|
+
'achtzig',
|
|
489
|
+
'neunzig',
|
|
339
490
|
];
|
|
340
491
|
/** German uses "und" between ones and tens: einundzwanzig */
|
|
341
492
|
function upToNinetyNine$1(n) {
|
|
342
493
|
if (n === 0)
|
|
343
|
-
return
|
|
494
|
+
return '';
|
|
344
495
|
if (n < 20)
|
|
345
496
|
return ONES_DE[n];
|
|
346
497
|
const t = Math.floor(n / 10);
|
|
@@ -351,42 +502,42 @@ function upToNinetyNine$1(n) {
|
|
|
351
502
|
}
|
|
352
503
|
function hundredsDE(n) {
|
|
353
504
|
if (n === 0)
|
|
354
|
-
return
|
|
505
|
+
return '';
|
|
355
506
|
const h = Math.floor(n / 100);
|
|
356
507
|
const rem = n % 100;
|
|
357
508
|
const parts = [];
|
|
358
509
|
if (h === 1)
|
|
359
|
-
parts.push(
|
|
510
|
+
parts.push('einhundert');
|
|
360
511
|
else if (h > 1)
|
|
361
512
|
parts.push(`${ONES_DE[h]}hundert`);
|
|
362
513
|
if (rem > 0)
|
|
363
514
|
parts.push(upToNinetyNine$1(rem));
|
|
364
|
-
return parts.join(
|
|
515
|
+
return parts.join('');
|
|
365
516
|
}
|
|
366
517
|
const SCALES_DE = [
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
518
|
+
'tausend',
|
|
519
|
+
'Million',
|
|
520
|
+
'Milliarde',
|
|
521
|
+
'Billion',
|
|
522
|
+
'Billiarde',
|
|
523
|
+
'Trillion',
|
|
373
524
|
];
|
|
374
525
|
/** Scales that are grammatically feminine in German (require "eine" not "ein") */
|
|
375
526
|
const FEMININE_SCALES = new Set([1, 2, 4, 6]); // indices: Million, Milliarde, Billiarde, Trillion
|
|
376
527
|
const SCALES_DE_PLURAL = [
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
528
|
+
'tausend',
|
|
529
|
+
'Millionen',
|
|
530
|
+
'Milliarden',
|
|
531
|
+
'Billionen',
|
|
532
|
+
'Billiarden',
|
|
533
|
+
'Trillionen',
|
|
383
534
|
];
|
|
384
535
|
// ─── Locale definition ────────────────────────────────────────────────────────
|
|
385
536
|
const de = {
|
|
386
|
-
name:
|
|
537
|
+
name: 'German',
|
|
387
538
|
convert(n, _opts) {
|
|
388
539
|
if (n === 0n)
|
|
389
|
-
return
|
|
540
|
+
return 'null';
|
|
390
541
|
const chunks = [];
|
|
391
542
|
let remaining = n;
|
|
392
543
|
let idx = 0;
|
|
@@ -411,52 +562,74 @@ const de = {
|
|
|
411
562
|
const scaleIdx = scale - 1;
|
|
412
563
|
const isFeminine = FEMININE_SCALES.has(scaleIdx);
|
|
413
564
|
// Replace trailing "ein" with "eine" for feminine scales
|
|
414
|
-
const adjustedWords = value === 1 && isFeminine
|
|
415
|
-
? words.replace(/ein$/, "eine")
|
|
416
|
-
: words;
|
|
565
|
+
const adjustedWords = value === 1 && isFeminine ? words.replace(/ein$/, 'eine') : words;
|
|
417
566
|
const scaleName = value === 1 ? SCALES_DE[scaleIdx] : SCALES_DE_PLURAL[scaleIdx];
|
|
418
567
|
parts.push(`${adjustedWords} ${scaleName}`);
|
|
419
568
|
}
|
|
420
569
|
}
|
|
421
|
-
return parts.join(
|
|
570
|
+
return parts.join(' ').trim();
|
|
422
571
|
},
|
|
423
572
|
};
|
|
424
|
-
registerLocale(
|
|
573
|
+
registerLocale('de', de);
|
|
425
574
|
|
|
426
575
|
// ─── Word tables ──────────────────────────────────────────────────────────────
|
|
427
576
|
const ONES_FR = [
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
577
|
+
'',
|
|
578
|
+
'un',
|
|
579
|
+
'deux',
|
|
580
|
+
'trois',
|
|
581
|
+
'quatre',
|
|
582
|
+
'cinq',
|
|
583
|
+
'six',
|
|
584
|
+
'sept',
|
|
585
|
+
'huit',
|
|
586
|
+
'neuf',
|
|
587
|
+
'dix',
|
|
588
|
+
'onze',
|
|
589
|
+
'douze',
|
|
590
|
+
'treize',
|
|
591
|
+
'quatorze',
|
|
592
|
+
'quinze',
|
|
593
|
+
'seize',
|
|
594
|
+
'dix-sept',
|
|
595
|
+
'dix-huit',
|
|
596
|
+
'dix-neuf',
|
|
432
597
|
];
|
|
433
598
|
const TENS_FR = [
|
|
434
|
-
|
|
435
|
-
|
|
599
|
+
'',
|
|
600
|
+
'',
|
|
601
|
+
'vingt',
|
|
602
|
+
'trente',
|
|
603
|
+
'quarante',
|
|
604
|
+
'cinquante',
|
|
605
|
+
'soixante',
|
|
606
|
+
'soixante',
|
|
607
|
+
'quatre-vingt',
|
|
608
|
+
'quatre-vingt',
|
|
436
609
|
];
|
|
437
610
|
/**
|
|
438
611
|
* French has irregular 70s (soixante-dix + 10–19) and 90s (quatre-vingt-dix + 10–19).
|
|
439
612
|
*/
|
|
440
613
|
function upToNinetyNine(n) {
|
|
441
614
|
if (n === 0)
|
|
442
|
-
return
|
|
615
|
+
return '';
|
|
443
616
|
if (n < 20)
|
|
444
617
|
return ONES_FR[n];
|
|
445
618
|
const t = Math.floor(n / 10);
|
|
446
619
|
const o = n % 10;
|
|
447
620
|
if (t === 7) {
|
|
448
621
|
// soixante + (10 + o)
|
|
449
|
-
return o === 0 ?
|
|
622
|
+
return o === 0 ? 'soixante-dix' : `soixante-${ONES_FR[10 + o]}`;
|
|
450
623
|
}
|
|
451
624
|
if (t === 8) {
|
|
452
625
|
// quatre-vingt(s) + o
|
|
453
626
|
if (o === 0)
|
|
454
|
-
return
|
|
627
|
+
return 'quatre-vingts';
|
|
455
628
|
return `quatre-vingt-${ONES_FR[o]}`;
|
|
456
629
|
}
|
|
457
630
|
if (t === 9) {
|
|
458
631
|
// quatre-vingt-dix + (0 + o)
|
|
459
|
-
return o === 0 ?
|
|
632
|
+
return o === 0 ? 'quatre-vingt-dix' : `quatre-vingt-${ONES_FR[10 + o]}`;
|
|
460
633
|
}
|
|
461
634
|
if (o === 0)
|
|
462
635
|
return TENS_FR[t];
|
|
@@ -466,12 +639,12 @@ function upToNinetyNine(n) {
|
|
|
466
639
|
}
|
|
467
640
|
function hundredsFR(n) {
|
|
468
641
|
if (n === 0)
|
|
469
|
-
return
|
|
642
|
+
return '';
|
|
470
643
|
const h = Math.floor(n / 100);
|
|
471
644
|
const rem = n % 100;
|
|
472
645
|
const parts = [];
|
|
473
646
|
if (h === 1) {
|
|
474
|
-
parts.push(
|
|
647
|
+
parts.push('cent');
|
|
475
648
|
}
|
|
476
649
|
else if (h > 1) {
|
|
477
650
|
parts.push(`${ONES_FR[h]} cents`);
|
|
@@ -483,30 +656,30 @@ function hundredsFR(n) {
|
|
|
483
656
|
}
|
|
484
657
|
parts.push(upToNinetyNine(rem));
|
|
485
658
|
}
|
|
486
|
-
return parts.join(
|
|
659
|
+
return parts.join(' ');
|
|
487
660
|
}
|
|
488
661
|
const SCALES_FR = [
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
662
|
+
'mille',
|
|
663
|
+
'million',
|
|
664
|
+
'milliard',
|
|
665
|
+
'billion',
|
|
666
|
+
'billiard',
|
|
667
|
+
'trillion',
|
|
495
668
|
];
|
|
496
669
|
const SCALES_FR_PLURAL = [
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
670
|
+
'mille',
|
|
671
|
+
'millions',
|
|
672
|
+
'milliards',
|
|
673
|
+
'billions',
|
|
674
|
+
'billiards',
|
|
675
|
+
'trillions',
|
|
503
676
|
];
|
|
504
677
|
// ─── Locale definition ────────────────────────────────────────────────────────
|
|
505
678
|
const fr = {
|
|
506
|
-
name:
|
|
679
|
+
name: 'French',
|
|
507
680
|
convert(n, _opts) {
|
|
508
681
|
if (n === 0n)
|
|
509
|
-
return
|
|
682
|
+
return 'zéro';
|
|
510
683
|
const chunks = [];
|
|
511
684
|
let remaining = n;
|
|
512
685
|
let idx = 0;
|
|
@@ -525,7 +698,7 @@ const fr = {
|
|
|
525
698
|
}
|
|
526
699
|
else if (scale === 1) {
|
|
527
700
|
// "mille" does not pluralise and drops "un" prefix
|
|
528
|
-
parts.push(value === 1 ?
|
|
701
|
+
parts.push(value === 1 ? 'mille' : `${words} mille`);
|
|
529
702
|
}
|
|
530
703
|
else {
|
|
531
704
|
const scaleIdx = scale - 1;
|
|
@@ -533,10 +706,10 @@ const fr = {
|
|
|
533
706
|
parts.push(`${words} ${scaleName}`);
|
|
534
707
|
}
|
|
535
708
|
}
|
|
536
|
-
return parts.join(
|
|
709
|
+
return parts.join(' ').trim();
|
|
537
710
|
},
|
|
538
711
|
};
|
|
539
|
-
registerLocale(
|
|
712
|
+
registerLocale('fr', fr);
|
|
540
713
|
|
|
541
714
|
export { availableLocales, convert, getLocale, registerLocale };
|
|
542
715
|
//# sourceMappingURL=index.esm.js.map
|