@naturalcycles/js-lib 15.25.1 → 15.27.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/dist/array/array.util.js +2 -2
- package/dist/math/stack.util.js +3 -2
- package/dist/object/object.util.js +7 -7
- package/dist/unit/size.util.js +18 -14
- package/package.json +2 -2
- package/src/array/array.util.ts +2 -2
- package/src/math/stack.util.ts +3 -2
- package/src/object/object.util.ts +7 -7
- package/src/unit/size.util.ts +12 -10
package/dist/array/array.util.js
CHANGED
|
@@ -51,13 +51,13 @@ export function _pushUniq(a, ...items) {
|
|
|
51
51
|
*/
|
|
52
52
|
export function _pushUniqBy(a, mapper, ...items) {
|
|
53
53
|
const mappedSet = new Set(a.map(mapper));
|
|
54
|
-
|
|
54
|
+
for (const item of items) {
|
|
55
55
|
const mapped = mapper(item);
|
|
56
56
|
if (!mappedSet.has(mapped)) {
|
|
57
57
|
a.push(item);
|
|
58
58
|
mappedSet.add(mapped);
|
|
59
59
|
}
|
|
60
|
-
}
|
|
60
|
+
}
|
|
61
61
|
return a;
|
|
62
62
|
}
|
|
63
63
|
/**
|
package/dist/math/stack.util.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { _range } from '../array/range.js';
|
|
2
1
|
import { _average, _percentile, _percentiles } from './math.util.js';
|
|
3
2
|
/**
|
|
4
3
|
* Implements a "round-robin" Stack ("first-in last-out" aka FILO) with a limited size.
|
|
@@ -27,7 +26,9 @@ export class Stack {
|
|
|
27
26
|
* Fill (overwrite) the whole Stack (all its items) with the passed `item`.
|
|
28
27
|
*/
|
|
29
28
|
fill(item) {
|
|
30
|
-
|
|
29
|
+
for (let i = 0; i < this.size; i++) {
|
|
30
|
+
this.items[i] = item;
|
|
31
|
+
}
|
|
31
32
|
return this;
|
|
32
33
|
}
|
|
33
34
|
/**
|
|
@@ -256,10 +256,10 @@ export function _filterEmptyValues(obj, opt = {}) {
|
|
|
256
256
|
* Based on: https://gist.github.com/Salakar/1d7137de9cb8b704e48a
|
|
257
257
|
*/
|
|
258
258
|
export function _merge(target, ...sources) {
|
|
259
|
-
|
|
259
|
+
for (const source of sources) {
|
|
260
260
|
if (!_isObject(source))
|
|
261
|
-
|
|
262
|
-
Object.keys(source)
|
|
261
|
+
continue;
|
|
262
|
+
for (const key of Object.keys(source)) {
|
|
263
263
|
if (_isObject(source[key])) {
|
|
264
264
|
;
|
|
265
265
|
target[key] ||= {};
|
|
@@ -269,8 +269,8 @@ export function _merge(target, ...sources) {
|
|
|
269
269
|
;
|
|
270
270
|
target[key] = source[key];
|
|
271
271
|
}
|
|
272
|
-
}
|
|
273
|
-
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
274
|
return target;
|
|
275
275
|
}
|
|
276
276
|
/**
|
|
@@ -285,9 +285,9 @@ export function _deepTrim(o) {
|
|
|
285
285
|
return o.trim();
|
|
286
286
|
}
|
|
287
287
|
if (typeof o === 'object') {
|
|
288
|
-
Object.keys(o)
|
|
288
|
+
for (const k of Object.keys(o)) {
|
|
289
289
|
o[k] = _deepTrim(o[k]);
|
|
290
|
-
}
|
|
290
|
+
}
|
|
291
291
|
}
|
|
292
292
|
return o;
|
|
293
293
|
}
|
package/dist/unit/size.util.js
CHANGED
|
@@ -11,16 +11,20 @@ export function _kb(b) {
|
|
|
11
11
|
* Byte size to Human byte size string
|
|
12
12
|
*/
|
|
13
13
|
export function _hb(b = 0) {
|
|
14
|
-
if (b <
|
|
14
|
+
if (b < 100)
|
|
15
15
|
return `${Math.round(b)} byte(s)`;
|
|
16
|
-
if (b <
|
|
17
|
-
return `${(b / 1024).
|
|
18
|
-
if (b < 1024 **
|
|
19
|
-
return `${(b / 1024
|
|
20
|
-
if (b < 1024 **
|
|
21
|
-
return `${(b / 1024 **
|
|
22
|
-
if (b < 1024 **
|
|
23
|
-
return `${(b / 1024 **
|
|
16
|
+
if (b < 1000)
|
|
17
|
+
return `${(b / 1024).toFixed(2)} Kb`;
|
|
18
|
+
if (b < 0.9 * 1024 ** 2)
|
|
19
|
+
return `${Math.round(b / 1024)} Kb`;
|
|
20
|
+
if (b < 0.9 * 1024 ** 3)
|
|
21
|
+
return `${Math.round(b / 1024 ** 2)} Mb`;
|
|
22
|
+
if (b < 0.09 * 1024 ** 4)
|
|
23
|
+
return `${(b / 1024 ** 3).toFixed(2)} Gb`;
|
|
24
|
+
if (b < 0.9 * 1024 ** 4)
|
|
25
|
+
return `${Math.round(b / 1024 ** 3)} Gb`;
|
|
26
|
+
if (b < 0.9 * 1024 ** 5)
|
|
27
|
+
return `${(b / 1024 ** 4).toFixed(2)} Tb`;
|
|
24
28
|
return `${Math.round(b / 1024 ** 4)} Tb`;
|
|
25
29
|
}
|
|
26
30
|
/**
|
|
@@ -30,14 +34,14 @@ export function _hb(b = 0) {
|
|
|
30
34
|
*/
|
|
31
35
|
export function _hc(c = 0) {
|
|
32
36
|
if (c < 10 ** 4)
|
|
33
|
-
return String(c);
|
|
37
|
+
return String(Math.round(c));
|
|
34
38
|
if (c < 10 ** 6)
|
|
35
|
-
return (c / 10 ** 3)
|
|
39
|
+
return Math.round(c / 10 ** 3) + ' K';
|
|
36
40
|
if (c < 10 ** 9)
|
|
37
|
-
return (c / 10 ** 6)
|
|
41
|
+
return Math.round(c / 10 ** 6) + ' M'; // million
|
|
38
42
|
if (c < 10 ** 12)
|
|
39
|
-
return (c / 10 ** 9)
|
|
43
|
+
return Math.round(c / 10 ** 9) + ' B'; // billion
|
|
40
44
|
if (c < 10 ** 15)
|
|
41
|
-
return (c / 10 ** 12)
|
|
45
|
+
return Math.round(c / 10 ** 12) + ' T'; // trillion
|
|
42
46
|
return Math.round(c / 10 ** 12) + ' T';
|
|
43
47
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naturalcycles/js-lib",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "15.
|
|
4
|
+
"version": "15.27.0",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"tslib": "^2",
|
|
7
7
|
"zod": "^4"
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"@types/semver": "^7",
|
|
13
13
|
"crypto-js": "^4",
|
|
14
14
|
"dayjs": "^1",
|
|
15
|
-
"@naturalcycles/dev-lib": "
|
|
15
|
+
"@naturalcycles/dev-lib": "18.4.2"
|
|
16
16
|
},
|
|
17
17
|
"exports": {
|
|
18
18
|
".": "./dist/index.js",
|
package/src/array/array.util.ts
CHANGED
|
@@ -62,13 +62,13 @@ export function _pushUniq<T>(a: T[], ...items: T[]): T[] {
|
|
|
62
62
|
*/
|
|
63
63
|
export function _pushUniqBy<T>(a: T[], mapper: Mapper<T, any>, ...items: T[]): T[] {
|
|
64
64
|
const mappedSet = new Set(a.map(mapper))
|
|
65
|
-
|
|
65
|
+
for (const item of items) {
|
|
66
66
|
const mapped = mapper(item)
|
|
67
67
|
if (!mappedSet.has(mapped)) {
|
|
68
68
|
a.push(item)
|
|
69
69
|
mappedSet.add(mapped)
|
|
70
70
|
}
|
|
71
|
-
}
|
|
71
|
+
}
|
|
72
72
|
return a
|
|
73
73
|
}
|
|
74
74
|
|
package/src/math/stack.util.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { _range } from '../array/range.js'
|
|
2
1
|
import { _average, _percentile, _percentiles } from './math.util.js'
|
|
3
2
|
|
|
4
3
|
/**
|
|
@@ -29,7 +28,9 @@ export class Stack<T> {
|
|
|
29
28
|
* Fill (overwrite) the whole Stack (all its items) with the passed `item`.
|
|
30
29
|
*/
|
|
31
30
|
fill(item: T): this {
|
|
32
|
-
|
|
31
|
+
for (let i = 0; i < this.size; i++) {
|
|
32
|
+
this.items[i] = item
|
|
33
|
+
}
|
|
33
34
|
return this
|
|
34
35
|
}
|
|
35
36
|
|
|
@@ -312,18 +312,18 @@ export function _filterEmptyValues<T extends AnyObject>(obj: T, opt: MutateOptio
|
|
|
312
312
|
* Based on: https://gist.github.com/Salakar/1d7137de9cb8b704e48a
|
|
313
313
|
*/
|
|
314
314
|
export function _merge<T extends AnyObject>(target: T, ...sources: any[]): T {
|
|
315
|
-
|
|
316
|
-
if (!_isObject(source))
|
|
315
|
+
for (const source of sources) {
|
|
316
|
+
if (!_isObject(source)) continue
|
|
317
317
|
|
|
318
|
-
Object.keys(source)
|
|
318
|
+
for (const key of Object.keys(source)) {
|
|
319
319
|
if (_isObject(source[key])) {
|
|
320
320
|
;(target as any)[key] ||= {}
|
|
321
321
|
_merge(target[key], source[key])
|
|
322
322
|
} else {
|
|
323
323
|
;(target as any)[key] = source[key]
|
|
324
324
|
}
|
|
325
|
-
}
|
|
326
|
-
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
327
|
|
|
328
328
|
return target
|
|
329
329
|
}
|
|
@@ -340,9 +340,9 @@ export function _deepTrim<T extends AnyObject | string>(o: T): T {
|
|
|
340
340
|
return o.trim() as T
|
|
341
341
|
}
|
|
342
342
|
if (typeof o === 'object') {
|
|
343
|
-
Object.keys(o)
|
|
343
|
+
for (const k of Object.keys(o)) {
|
|
344
344
|
o[k] = _deepTrim(o[k])
|
|
345
|
-
}
|
|
345
|
+
}
|
|
346
346
|
}
|
|
347
347
|
|
|
348
348
|
return o
|
package/src/unit/size.util.ts
CHANGED
|
@@ -14,11 +14,13 @@ export function _kb(b: number): number {
|
|
|
14
14
|
* Byte size to Human byte size string
|
|
15
15
|
*/
|
|
16
16
|
export function _hb(b = 0): string {
|
|
17
|
-
if (b <
|
|
18
|
-
if (b <
|
|
19
|
-
if (b < 1024 **
|
|
20
|
-
if (b < 1024 **
|
|
21
|
-
if (b < 1024 **
|
|
17
|
+
if (b < 100) return `${Math.round(b)} byte(s)`
|
|
18
|
+
if (b < 1000) return `${(b / 1024).toFixed(2)} Kb`
|
|
19
|
+
if (b < 0.9 * 1024 ** 2) return `${Math.round(b / 1024)} Kb`
|
|
20
|
+
if (b < 0.9 * 1024 ** 3) return `${Math.round(b / 1024 ** 2)} Mb`
|
|
21
|
+
if (b < 0.09 * 1024 ** 4) return `${(b / 1024 ** 3).toFixed(2)} Gb`
|
|
22
|
+
if (b < 0.9 * 1024 ** 4) return `${Math.round(b / 1024 ** 3)} Gb`
|
|
23
|
+
if (b < 0.9 * 1024 ** 5) return `${(b / 1024 ** 4).toFixed(2)} Tb`
|
|
22
24
|
return `${Math.round(b / 1024 ** 4)} Tb`
|
|
23
25
|
}
|
|
24
26
|
|
|
@@ -28,10 +30,10 @@ export function _hb(b = 0): string {
|
|
|
28
30
|
* them more readable.
|
|
29
31
|
*/
|
|
30
32
|
export function _hc(c = 0): string {
|
|
31
|
-
if (c < 10 ** 4) return String(c)
|
|
32
|
-
if (c < 10 ** 6) return (c / 10 ** 3)
|
|
33
|
-
if (c < 10 ** 9) return (c / 10 ** 6)
|
|
34
|
-
if (c < 10 ** 12) return (c / 10 ** 9)
|
|
35
|
-
if (c < 10 ** 15) return (c / 10 ** 12)
|
|
33
|
+
if (c < 10 ** 4) return String(Math.round(c))
|
|
34
|
+
if (c < 10 ** 6) return Math.round(c / 10 ** 3) + ' K'
|
|
35
|
+
if (c < 10 ** 9) return Math.round(c / 10 ** 6) + ' M' // million
|
|
36
|
+
if (c < 10 ** 12) return Math.round(c / 10 ** 9) + ' B' // billion
|
|
37
|
+
if (c < 10 ** 15) return Math.round(c / 10 ** 12) + ' T' // trillion
|
|
36
38
|
return Math.round(c / 10 ** 12) + ' T'
|
|
37
39
|
}
|