@valkyriestudios/utils 12.29.0 → 12.30.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/README.md +2 -0
- package/deep/get.js +34 -10
- package/package.json +406 -1
- package/string/humanizeNumber.js +2 -3
package/README.md
CHANGED
package/deep/get.js
CHANGED
|
@@ -21,11 +21,23 @@ function deepGet(obj, path, get_parent = false) {
|
|
|
21
21
|
if (!key)
|
|
22
22
|
break;
|
|
23
23
|
if (Array.isArray(node)) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
if (!isNaN(Number(key))) {
|
|
25
|
+
const ix = parseInt(key, 10);
|
|
26
|
+
if (ix < 0 || ix > node.length - 1)
|
|
27
|
+
return undefined;
|
|
28
|
+
node = node[ix];
|
|
29
|
+
nodes.push(node);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
const extracted = [];
|
|
33
|
+
for (let y = 0; y < node.length; y++) {
|
|
34
|
+
const el = deepGet(node[y], key);
|
|
35
|
+
if (el !== undefined)
|
|
36
|
+
extracted.push(el);
|
|
37
|
+
}
|
|
38
|
+
node = extracted.length ? extracted.flat() : undefined;
|
|
39
|
+
nodes.push(node);
|
|
40
|
+
}
|
|
29
41
|
}
|
|
30
42
|
else if (typeof node === 'object' && node !== null) {
|
|
31
43
|
node = node[key];
|
|
@@ -45,11 +57,23 @@ function deepGet(obj, path, get_parent = false) {
|
|
|
45
57
|
}
|
|
46
58
|
if (key) {
|
|
47
59
|
if (Array.isArray(node)) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
60
|
+
if (!isNaN(Number(key))) {
|
|
61
|
+
const ix = parseInt(key, 10);
|
|
62
|
+
if (ix < 0 || ix > node.length - 1)
|
|
63
|
+
return undefined;
|
|
64
|
+
node = node[ix];
|
|
65
|
+
nodes.push(node);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
const extracted = [];
|
|
69
|
+
for (let i = 0; i < node.length; i++) {
|
|
70
|
+
const el = node[i];
|
|
71
|
+
if (el?.[key] !== undefined)
|
|
72
|
+
extracted.push(el?.[key]);
|
|
73
|
+
}
|
|
74
|
+
node = extracted.length ? extracted : undefined;
|
|
75
|
+
nodes.push(node);
|
|
76
|
+
}
|
|
53
77
|
}
|
|
54
78
|
else if (typeof node === 'object' && node !== null) {
|
|
55
79
|
node = node[key];
|
package/package.json
CHANGED
|
@@ -1 +1,406 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"name": "@valkyriestudios/utils",
|
|
3
|
+
"version": "12.30.0",
|
|
4
|
+
"description": "A collection of single-function utilities for common tasks",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "Peter Vermeulen",
|
|
7
|
+
"url": "https://www.linkedin.com/in/petervermeulen1/"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [
|
|
10
|
+
"utility",
|
|
11
|
+
"library",
|
|
12
|
+
"javascript",
|
|
13
|
+
"js",
|
|
14
|
+
"node",
|
|
15
|
+
"bun"
|
|
16
|
+
],
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "npm run lint && npm run test && tsc -p ./tsconfig.build.json && tsc -p ./tsconfig.types.json && tsc -p ./tsconfig.types_all.json",
|
|
20
|
+
"test": "node --icu-data-dir=node_modules/full-icu --require esbuild-register --test ./test/lib/**/*.ts ./test/lib/*.ts",
|
|
21
|
+
"test:only": "node --icu-data-dir=node_modules/full-icu --require esbuild-register --test --test-only ./test/lib/**/*.ts ./test/lib/*.ts",
|
|
22
|
+
"test:coverage": "nyc npm run test",
|
|
23
|
+
"lint": "npm run lint:src && npm run lint:test",
|
|
24
|
+
"lint:src": "./node_modules/.bin/eslint ./lib",
|
|
25
|
+
"lint:test": "./node_modules/.bin/eslint ./test",
|
|
26
|
+
"codecov": "codecov",
|
|
27
|
+
"benchmark": "node --require esbuild-register ./test/benchmark.ts"
|
|
28
|
+
},
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "git+https://github.com/ValkyrieStudios/utils.git"
|
|
32
|
+
},
|
|
33
|
+
"bugs": {
|
|
34
|
+
"url": "https://github.com/ValkyrieStudios/utils/issues"
|
|
35
|
+
},
|
|
36
|
+
"homepage": "https://github.com/ValkyrieStudios/utils#readme",
|
|
37
|
+
"types": "index.d.ts",
|
|
38
|
+
"sideEffects": false,
|
|
39
|
+
"exports": {
|
|
40
|
+
".": {
|
|
41
|
+
"import": "./index.js",
|
|
42
|
+
"types": "./index.d.ts"
|
|
43
|
+
},
|
|
44
|
+
"./package.json": "./package.json",
|
|
45
|
+
"./equal": {
|
|
46
|
+
"import": "./equal.js",
|
|
47
|
+
"types": "./equal.d.ts"
|
|
48
|
+
},
|
|
49
|
+
"./is": {
|
|
50
|
+
"import": "./is.js",
|
|
51
|
+
"types": "./is.d.ts"
|
|
52
|
+
},
|
|
53
|
+
"./array": {
|
|
54
|
+
"import": "./array/index.js",
|
|
55
|
+
"types": "./array/index.d.ts"
|
|
56
|
+
},
|
|
57
|
+
"./array/dedupe": {
|
|
58
|
+
"import": "./array/dedupe.js",
|
|
59
|
+
"types": "./array/dedupe.d.ts"
|
|
60
|
+
},
|
|
61
|
+
"./array/groupBy": {
|
|
62
|
+
"import": "./array/groupBy.js",
|
|
63
|
+
"types": "./array/groupBy.d.ts"
|
|
64
|
+
},
|
|
65
|
+
"./array/is": {
|
|
66
|
+
"import": "./array/is.js",
|
|
67
|
+
"types": "./array/is.d.ts"
|
|
68
|
+
},
|
|
69
|
+
"./array/isNotEmpty": {
|
|
70
|
+
"import": "./array/isNotEmpty.js",
|
|
71
|
+
"types": "./array/isNotEmpty.d.ts"
|
|
72
|
+
},
|
|
73
|
+
"./array/join": {
|
|
74
|
+
"import": "./array/join.js",
|
|
75
|
+
"types": "./array/join.d.ts"
|
|
76
|
+
},
|
|
77
|
+
"./array/mapFn": {
|
|
78
|
+
"import": "./array/mapFn.js",
|
|
79
|
+
"types": "./array/mapFn.d.ts"
|
|
80
|
+
},
|
|
81
|
+
"./array/mapKey": {
|
|
82
|
+
"import": "./array/mapKey.js",
|
|
83
|
+
"types": "./array/mapKey.d.ts"
|
|
84
|
+
},
|
|
85
|
+
"./array/mapPrimitive": {
|
|
86
|
+
"import": "./array/mapPrimitive.js",
|
|
87
|
+
"types": "./array/mapPrimitive.d.ts"
|
|
88
|
+
},
|
|
89
|
+
"./array/shuffle": {
|
|
90
|
+
"import": "./array/shuffle.js",
|
|
91
|
+
"types": "./array/shuffle.d.ts"
|
|
92
|
+
},
|
|
93
|
+
"./array/sort": {
|
|
94
|
+
"import": "./array/sort.js",
|
|
95
|
+
"types": "./array/sort.d.ts"
|
|
96
|
+
},
|
|
97
|
+
"./array/split": {
|
|
98
|
+
"import": "./array/split.js",
|
|
99
|
+
"types": "./array/split.d.ts"
|
|
100
|
+
},
|
|
101
|
+
"./boolean": {
|
|
102
|
+
"import": "./boolean/index.js",
|
|
103
|
+
"types": "./boolean/index.d.ts"
|
|
104
|
+
},
|
|
105
|
+
"./boolean/is": {
|
|
106
|
+
"import": "./boolean/is.js",
|
|
107
|
+
"types": "./boolean/is.d.ts"
|
|
108
|
+
},
|
|
109
|
+
"./caching": {
|
|
110
|
+
"import": "./caching/index.js",
|
|
111
|
+
"types": "./caching/index.d.ts"
|
|
112
|
+
},
|
|
113
|
+
"./caching/LRU": {
|
|
114
|
+
"import": "./caching/LRU.js",
|
|
115
|
+
"types": "./caching/LRU.d.ts"
|
|
116
|
+
},
|
|
117
|
+
"./caching/memoize": {
|
|
118
|
+
"import": "./caching/memoize.js",
|
|
119
|
+
"types": "./caching/memoize.d.ts"
|
|
120
|
+
},
|
|
121
|
+
"./date": {
|
|
122
|
+
"import": "./date/index.js",
|
|
123
|
+
"types": "./date/index.d.ts"
|
|
124
|
+
},
|
|
125
|
+
"./date/addUTC": {
|
|
126
|
+
"import": "./date/addUTC.js",
|
|
127
|
+
"types": "./date/addUTC.d.ts"
|
|
128
|
+
},
|
|
129
|
+
"./date/convertToDate": {
|
|
130
|
+
"import": "./date/convertToDate.js",
|
|
131
|
+
"types": "./date/convertToDate.d.ts"
|
|
132
|
+
},
|
|
133
|
+
"./date/diff": {
|
|
134
|
+
"import": "./date/diff.js",
|
|
135
|
+
"types": "./date/diff.d.ts"
|
|
136
|
+
},
|
|
137
|
+
"./date/endOfUTC": {
|
|
138
|
+
"import": "./date/endOfUTC.js",
|
|
139
|
+
"types": "./date/endOfUTC.d.ts"
|
|
140
|
+
},
|
|
141
|
+
"./date/format": {
|
|
142
|
+
"import": "./date/format.js",
|
|
143
|
+
"types": "./date/format.d.ts"
|
|
144
|
+
},
|
|
145
|
+
"./date/is": {
|
|
146
|
+
"import": "./date/is.js",
|
|
147
|
+
"types": "./date/is.d.ts"
|
|
148
|
+
},
|
|
149
|
+
"./date/isFormat": {
|
|
150
|
+
"import": "./date/isFormat.js",
|
|
151
|
+
"types": "./date/isFormat.d.ts"
|
|
152
|
+
},
|
|
153
|
+
"./date/isLeap": {
|
|
154
|
+
"import": "./date/isLeap.js",
|
|
155
|
+
"types": "./date/isLeap.d.ts"
|
|
156
|
+
},
|
|
157
|
+
"./date/nowUnix": {
|
|
158
|
+
"import": "./date/nowUnix.js",
|
|
159
|
+
"types": "./date/nowUnix.d.ts"
|
|
160
|
+
},
|
|
161
|
+
"./date/nowUnixMs": {
|
|
162
|
+
"import": "./date/nowUnixMs.js",
|
|
163
|
+
"types": "./date/nowUnixMs.d.ts"
|
|
164
|
+
},
|
|
165
|
+
"./date/setTimeUTC": {
|
|
166
|
+
"import": "./date/setTimeUTC.js",
|
|
167
|
+
"types": "./date/setTimeUTC.d.ts"
|
|
168
|
+
},
|
|
169
|
+
"./date/startOfUTC": {
|
|
170
|
+
"import": "./date/startOfUTC.js",
|
|
171
|
+
"types": "./date/startOfUTC.d.ts"
|
|
172
|
+
},
|
|
173
|
+
"./date/toUnix": {
|
|
174
|
+
"import": "./date/toUnix.js",
|
|
175
|
+
"types": "./date/toUnix.d.ts"
|
|
176
|
+
},
|
|
177
|
+
"./date/toUTC": {
|
|
178
|
+
"import": "./date/toUTC.js",
|
|
179
|
+
"types": "./date/toUTC.d.ts"
|
|
180
|
+
},
|
|
181
|
+
"./deep": {
|
|
182
|
+
"import": "./deep/index.js",
|
|
183
|
+
"types": "./deep/index.d.ts"
|
|
184
|
+
},
|
|
185
|
+
"./deep/freeze": {
|
|
186
|
+
"import": "./deep/freeze.js",
|
|
187
|
+
"types": "./deep/freeze.d.ts"
|
|
188
|
+
},
|
|
189
|
+
"./deep/get": {
|
|
190
|
+
"import": "./deep/get.js",
|
|
191
|
+
"types": "./deep/get.d.ts"
|
|
192
|
+
},
|
|
193
|
+
"./deep/seal": {
|
|
194
|
+
"import": "./deep/seal.js",
|
|
195
|
+
"types": "./deep/seal.d.ts"
|
|
196
|
+
},
|
|
197
|
+
"./deep/set": {
|
|
198
|
+
"import": "./deep/set.js",
|
|
199
|
+
"types": "./deep/set.d.ts"
|
|
200
|
+
},
|
|
201
|
+
"./formdata": {
|
|
202
|
+
"import": "./formdata/index.js",
|
|
203
|
+
"types": "./formdata/index.d.ts"
|
|
204
|
+
},
|
|
205
|
+
"./formdata/is": {
|
|
206
|
+
"import": "./formdata/is.js",
|
|
207
|
+
"types": "./formdata/is.d.ts"
|
|
208
|
+
},
|
|
209
|
+
"./formdata/toObject": {
|
|
210
|
+
"import": "./formdata/toObject.js",
|
|
211
|
+
"types": "./formdata/toObject.d.ts"
|
|
212
|
+
},
|
|
213
|
+
"./function": {
|
|
214
|
+
"import": "./function/index.js",
|
|
215
|
+
"types": "./function/index.d.ts"
|
|
216
|
+
},
|
|
217
|
+
"./function/debounce": {
|
|
218
|
+
"import": "./function/debounce.js",
|
|
219
|
+
"types": "./function/debounce.d.ts"
|
|
220
|
+
},
|
|
221
|
+
"./function/is": {
|
|
222
|
+
"import": "./function/is.js",
|
|
223
|
+
"types": "./function/is.d.ts"
|
|
224
|
+
},
|
|
225
|
+
"./function/isAsync": {
|
|
226
|
+
"import": "./function/isAsync.js",
|
|
227
|
+
"types": "./function/isAsync.d.ts"
|
|
228
|
+
},
|
|
229
|
+
"./function/noop": {
|
|
230
|
+
"import": "./function/noop.js",
|
|
231
|
+
"types": "./function/noop.d.ts"
|
|
232
|
+
},
|
|
233
|
+
"./function/noopresolve": {
|
|
234
|
+
"import": "./function/noopresolve.js",
|
|
235
|
+
"types": "./function/noopresolve.d.ts"
|
|
236
|
+
},
|
|
237
|
+
"./function/noopreturn": {
|
|
238
|
+
"import": "./function/noopreturn.js",
|
|
239
|
+
"types": "./function/noopreturn.d.ts"
|
|
240
|
+
},
|
|
241
|
+
"./function/sleep": {
|
|
242
|
+
"import": "./function/sleep.js",
|
|
243
|
+
"types": "./function/sleep.d.ts"
|
|
244
|
+
},
|
|
245
|
+
"./hash": {
|
|
246
|
+
"import": "./hash/index.js",
|
|
247
|
+
"types": "./hash/index.d.ts"
|
|
248
|
+
},
|
|
249
|
+
"./hash/fnv1A": {
|
|
250
|
+
"import": "./hash/fnv1A.js",
|
|
251
|
+
"types": "./hash/fnv1A.d.ts"
|
|
252
|
+
},
|
|
253
|
+
"./hash/guid": {
|
|
254
|
+
"import": "./hash/guid.js",
|
|
255
|
+
"types": "./hash/guid.d.ts"
|
|
256
|
+
},
|
|
257
|
+
"./number": {
|
|
258
|
+
"import": "./number/index.js",
|
|
259
|
+
"types": "./number/index.d.ts"
|
|
260
|
+
},
|
|
261
|
+
"./number/is": {
|
|
262
|
+
"import": "./number/is.js",
|
|
263
|
+
"types": "./number/is.d.ts"
|
|
264
|
+
},
|
|
265
|
+
"./number/isAbove": {
|
|
266
|
+
"import": "./number/isAbove.js",
|
|
267
|
+
"types": "./number/isAbove.d.ts"
|
|
268
|
+
},
|
|
269
|
+
"./number/isAboveOrEqual": {
|
|
270
|
+
"import": "./number/isAboveOrEqual.js",
|
|
271
|
+
"types": "./number/isAboveOrEqual.d.ts"
|
|
272
|
+
},
|
|
273
|
+
"./number/isBelow": {
|
|
274
|
+
"import": "./number/isBelow.js",
|
|
275
|
+
"types": "./number/isBelow.d.ts"
|
|
276
|
+
},
|
|
277
|
+
"./number/isBelowOrEqual": {
|
|
278
|
+
"import": "./number/isBelowOrEqual.js",
|
|
279
|
+
"types": "./number/isBelowOrEqual.d.ts"
|
|
280
|
+
},
|
|
281
|
+
"./number/isBetween": {
|
|
282
|
+
"import": "./number/isBetween.js",
|
|
283
|
+
"types": "./number/isBetween.d.ts"
|
|
284
|
+
},
|
|
285
|
+
"./number/isInteger": {
|
|
286
|
+
"import": "./number/isInteger.js",
|
|
287
|
+
"types": "./number/isInteger.d.ts"
|
|
288
|
+
},
|
|
289
|
+
"./number/isIntegerAbove": {
|
|
290
|
+
"import": "./number/isIntegerAbove.js",
|
|
291
|
+
"types": "./number/isIntegerAbove.d.ts"
|
|
292
|
+
},
|
|
293
|
+
"./number/isIntegerAboveOrEqual": {
|
|
294
|
+
"import": "./number/isIntegerAboveOrEqual.js",
|
|
295
|
+
"types": "./number/isIntegerAboveOrEqual.d.ts"
|
|
296
|
+
},
|
|
297
|
+
"./number/isIntegerBelow": {
|
|
298
|
+
"import": "./number/isIntegerBelow.js",
|
|
299
|
+
"types": "./number/isIntegerBelow.d.ts"
|
|
300
|
+
},
|
|
301
|
+
"./number/isIntegerBelowOrEqual": {
|
|
302
|
+
"import": "./number/isIntegerBelowOrEqual.js",
|
|
303
|
+
"types": "./number/isIntegerBelowOrEqual.d.ts"
|
|
304
|
+
},
|
|
305
|
+
"./number/isIntegerBetween": {
|
|
306
|
+
"import": "./number/isIntegerBetween.js",
|
|
307
|
+
"types": "./number/isIntegerBetween.d.ts"
|
|
308
|
+
},
|
|
309
|
+
"./number/isNumericalNaN": {
|
|
310
|
+
"import": "./number/isNumericalNaN.js",
|
|
311
|
+
"types": "./number/isNumericalNaN.d.ts"
|
|
312
|
+
},
|
|
313
|
+
"./number/randomBetween": {
|
|
314
|
+
"import": "./number/randomBetween.js",
|
|
315
|
+
"types": "./number/randomBetween.d.ts"
|
|
316
|
+
},
|
|
317
|
+
"./number/randomIntBetween": {
|
|
318
|
+
"import": "./number/randomIntBetween.js",
|
|
319
|
+
"types": "./number/randomIntBetween.d.ts"
|
|
320
|
+
},
|
|
321
|
+
"./number/round": {
|
|
322
|
+
"import": "./number/round.js",
|
|
323
|
+
"types": "./number/round.d.ts"
|
|
324
|
+
},
|
|
325
|
+
"./number/toPercentage": {
|
|
326
|
+
"import": "./number/toPercentage.js",
|
|
327
|
+
"types": "./number/toPercentage.d.ts"
|
|
328
|
+
},
|
|
329
|
+
"./object": {
|
|
330
|
+
"import": "./object/index.js",
|
|
331
|
+
"types": "./object/index.d.ts"
|
|
332
|
+
},
|
|
333
|
+
"./object/define": {
|
|
334
|
+
"import": "./object/define.js",
|
|
335
|
+
"types": "./object/define.d.ts"
|
|
336
|
+
},
|
|
337
|
+
"./object/is": {
|
|
338
|
+
"import": "./object/is.js",
|
|
339
|
+
"types": "./object/is.d.ts"
|
|
340
|
+
},
|
|
341
|
+
"./object/isNotEmpty": {
|
|
342
|
+
"import": "./object/isNotEmpty.js",
|
|
343
|
+
"types": "./object/isNotEmpty.d.ts"
|
|
344
|
+
},
|
|
345
|
+
"./object/merge": {
|
|
346
|
+
"import": "./object/merge.js",
|
|
347
|
+
"types": "./object/merge.d.ts"
|
|
348
|
+
},
|
|
349
|
+
"./object/omit": {
|
|
350
|
+
"import": "./object/omit.js",
|
|
351
|
+
"types": "./object/omit.d.ts"
|
|
352
|
+
},
|
|
353
|
+
"./object/pick": {
|
|
354
|
+
"import": "./object/pick.js",
|
|
355
|
+
"types": "./object/pick.d.ts"
|
|
356
|
+
},
|
|
357
|
+
"./regexp": {
|
|
358
|
+
"import": "./regexp/index.js",
|
|
359
|
+
"types": "./regexp/index.d.ts"
|
|
360
|
+
},
|
|
361
|
+
"./regexp/is": {
|
|
362
|
+
"import": "./regexp/is.js",
|
|
363
|
+
"types": "./regexp/is.d.ts"
|
|
364
|
+
},
|
|
365
|
+
"./regexp/sanitize": {
|
|
366
|
+
"import": "./regexp/sanitize.js",
|
|
367
|
+
"types": "./regexp/sanitize.d.ts"
|
|
368
|
+
},
|
|
369
|
+
"./string": {
|
|
370
|
+
"import": "./string/index.js",
|
|
371
|
+
"types": "./string/index.d.ts"
|
|
372
|
+
},
|
|
373
|
+
"./string/humanizeBytes": {
|
|
374
|
+
"import": "./string/humanizeBytes.js",
|
|
375
|
+
"types": "./string/humanizeBytes.d.ts"
|
|
376
|
+
},
|
|
377
|
+
"./string/humanizeNumber": {
|
|
378
|
+
"import": "./string/humanizeNumber.js",
|
|
379
|
+
"types": "./string/humanizeNumber.d.ts"
|
|
380
|
+
},
|
|
381
|
+
"./string/is": {
|
|
382
|
+
"import": "./string/is.js",
|
|
383
|
+
"types": "./string/is.d.ts"
|
|
384
|
+
},
|
|
385
|
+
"./string/isBetween": {
|
|
386
|
+
"import": "./string/isBetween.js",
|
|
387
|
+
"types": "./string/isBetween.d.ts"
|
|
388
|
+
},
|
|
389
|
+
"./string/isNotEmpty": {
|
|
390
|
+
"import": "./string/isNotEmpty.js",
|
|
391
|
+
"types": "./string/isNotEmpty.d.ts"
|
|
392
|
+
},
|
|
393
|
+
"./string/shorten": {
|
|
394
|
+
"import": "./string/shorten.js",
|
|
395
|
+
"types": "./string/shorten.d.ts"
|
|
396
|
+
}
|
|
397
|
+
},
|
|
398
|
+
"devDependencies": {
|
|
399
|
+
"@types/node": "^22.13.1",
|
|
400
|
+
"esbuild-register": "^3.6.0",
|
|
401
|
+
"eslint": "^9.19.0",
|
|
402
|
+
"nyc": "^17.1.0",
|
|
403
|
+
"typescript": "^5.7.3",
|
|
404
|
+
"typescript-eslint": "^8.23.0"
|
|
405
|
+
}
|
|
406
|
+
}
|
package/string/humanizeNumber.js
CHANGED
|
@@ -3,13 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.humanizeNumber = humanizeNumber;
|
|
4
4
|
exports.default = humanizeNumber;
|
|
5
5
|
const round_1 = require("../number/round");
|
|
6
|
-
const isIntegerAboveOrEqual_1 = require("../number/isIntegerAboveOrEqual");
|
|
7
6
|
const DEFAULT_UNITS = ['', 'k', 'm', 'b', 't', 'q'];
|
|
8
7
|
function humanizeNumber(val, options = {}) {
|
|
9
8
|
const DELIM = typeof options?.delim === 'string' ? options.delim : ',';
|
|
10
9
|
const SEPARATOR = typeof options?.separator === 'string' && options.separator.trim().length ? options.separator : '.';
|
|
11
|
-
const PRECISION =
|
|
12
|
-
const DIVIDER =
|
|
10
|
+
const PRECISION = Number.isInteger(options?.precision) && options.precision >= 0 ? options.precision : 2;
|
|
11
|
+
const DIVIDER = Number.isInteger(options?.divider) && options.divider >= 2 ? options.divider : 1000;
|
|
13
12
|
const REAL = options?.real === true;
|
|
14
13
|
const UNITS = Array.isArray(options?.units) && options.units.length
|
|
15
14
|
? options.units
|