@naturalcycles/js-lib 14.216.0 → 14.217.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 +11 -11
- package/dist/form.util.js +3 -1
- package/dist/http/fetcher.js +2 -2
- package/dist/math/math.util.js +2 -2
- package/dist/object/object.util.js +6 -3
- package/dist-esm/array/array.util.js +11 -11
- package/dist-esm/form.util.js +3 -1
- package/dist-esm/http/fetcher.js +2 -2
- package/dist-esm/math/math.util.js +2 -2
- package/dist-esm/object/object.util.js +6 -3
- package/package.json +1 -1
- package/src/array/array.util.ts +13 -11
- package/src/form.util.ts +3 -1
- package/src/http/fetcher.ts +2 -2
- package/src/math/math.util.ts +2 -2
- package/src/object/object.util.ts +7 -3
package/dist/array/array.util.js
CHANGED
|
@@ -42,10 +42,10 @@ exports._uniq = _uniq;
|
|
|
42
42
|
* a = _uniq([...a, item])
|
|
43
43
|
*/
|
|
44
44
|
function _pushUniq(a, ...items) {
|
|
45
|
-
|
|
45
|
+
for (const item of items) {
|
|
46
46
|
if (!a.includes(item))
|
|
47
47
|
a.push(item);
|
|
48
|
-
}
|
|
48
|
+
}
|
|
49
49
|
return a;
|
|
50
50
|
}
|
|
51
51
|
exports._pushUniq = _pushUniq;
|
|
@@ -221,8 +221,8 @@ function _count(items, predicate) {
|
|
|
221
221
|
exports._count = _count;
|
|
222
222
|
function _countBy(items, mapper) {
|
|
223
223
|
const map = {};
|
|
224
|
-
items.forEach((item,
|
|
225
|
-
const key = mapper(item,
|
|
224
|
+
items.forEach((item, i) => {
|
|
225
|
+
const key = mapper(item, i);
|
|
226
226
|
map[key] = (map[key] || 0) + 1;
|
|
227
227
|
});
|
|
228
228
|
return map;
|
|
@@ -296,12 +296,12 @@ exports._sumBy = _sumBy;
|
|
|
296
296
|
*/
|
|
297
297
|
function _mapToObject(array, mapper) {
|
|
298
298
|
const m = {};
|
|
299
|
-
|
|
299
|
+
for (const item of array) {
|
|
300
300
|
const r = mapper(item);
|
|
301
301
|
if (!r)
|
|
302
|
-
|
|
302
|
+
continue; // filtering
|
|
303
303
|
m[r[0]] = r[1];
|
|
304
|
-
}
|
|
304
|
+
}
|
|
305
305
|
return m;
|
|
306
306
|
}
|
|
307
307
|
exports._mapToObject = _mapToObject;
|
|
@@ -400,13 +400,13 @@ function _maxByOrUndefined(array, mapper) {
|
|
|
400
400
|
return;
|
|
401
401
|
let maxItem;
|
|
402
402
|
let max;
|
|
403
|
-
array.
|
|
403
|
+
for (const [i, item] of array.entries()) {
|
|
404
404
|
const v = mapper(item, i);
|
|
405
405
|
if (v !== undefined && (max === undefined || v > max)) {
|
|
406
406
|
maxItem = item;
|
|
407
407
|
max = v;
|
|
408
408
|
}
|
|
409
|
-
}
|
|
409
|
+
}
|
|
410
410
|
return maxItem;
|
|
411
411
|
}
|
|
412
412
|
exports._maxByOrUndefined = _maxByOrUndefined;
|
|
@@ -415,13 +415,13 @@ function _minByOrUndefined(array, mapper) {
|
|
|
415
415
|
return;
|
|
416
416
|
let minItem;
|
|
417
417
|
let min;
|
|
418
|
-
array.
|
|
418
|
+
for (const [i, item] of array.entries()) {
|
|
419
419
|
const v = mapper(item, i);
|
|
420
420
|
if (v !== undefined && (min === undefined || v < min)) {
|
|
421
421
|
minItem = item;
|
|
422
422
|
min = v;
|
|
423
423
|
}
|
|
424
|
-
}
|
|
424
|
+
}
|
|
425
425
|
return minItem;
|
|
426
426
|
}
|
|
427
427
|
exports._minByOrUndefined = _minByOrUndefined;
|
package/dist/form.util.js
CHANGED
|
@@ -9,7 +9,9 @@ exports.formDataToObject = exports.objectToFormData = void 0;
|
|
|
9
9
|
*/
|
|
10
10
|
function objectToFormData(obj = {}) {
|
|
11
11
|
const fd = new FormData();
|
|
12
|
-
|
|
12
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
13
|
+
fd.append(k, v);
|
|
14
|
+
}
|
|
13
15
|
return fd;
|
|
14
16
|
}
|
|
15
17
|
exports.objectToFormData = objectToFormData;
|
package/dist/http/fetcher.js
CHANGED
|
@@ -48,7 +48,7 @@ class Fetcher {
|
|
|
48
48
|
}
|
|
49
49
|
this.cfg = this.normalizeCfg(cfg);
|
|
50
50
|
// Dynamically create all helper methods
|
|
51
|
-
http_model_1.HTTP_METHODS
|
|
51
|
+
for (const method of http_model_1.HTTP_METHODS) {
|
|
52
52
|
const m = method.toLowerCase();
|
|
53
53
|
this[`${m}Void`] = async (url, opt) => {
|
|
54
54
|
return await this.fetch({
|
|
@@ -77,7 +77,7 @@ class Fetcher {
|
|
|
77
77
|
...opt,
|
|
78
78
|
});
|
|
79
79
|
};
|
|
80
|
-
}
|
|
80
|
+
}
|
|
81
81
|
}
|
|
82
82
|
/**
|
|
83
83
|
* Add BeforeRequest hook at the end of the hooks list.
|
package/dist/math/math.util.js
CHANGED
|
@@ -58,14 +58,14 @@ exports._percentile = _percentile;
|
|
|
58
58
|
function _percentiles(values, pcs) {
|
|
59
59
|
const r = {};
|
|
60
60
|
const sorted = (0, number_util_1._sortNumbers)(values);
|
|
61
|
-
|
|
61
|
+
for (const pc of pcs) {
|
|
62
62
|
// Floating pos in the range of [0; length - 1]
|
|
63
63
|
const pos = ((values.length - 1) * pc) / 100;
|
|
64
64
|
const dec = pos % 1;
|
|
65
65
|
const floorPos = Math.floor(pos);
|
|
66
66
|
const ceilPos = Math.ceil(pos);
|
|
67
67
|
r[pc] = _averageWeighted([sorted[floorPos], sorted[ceilPos]], [1 - dec, dec]);
|
|
68
|
-
}
|
|
68
|
+
}
|
|
69
69
|
return r;
|
|
70
70
|
}
|
|
71
71
|
exports._percentiles = _percentiles;
|
|
@@ -402,8 +402,11 @@ exports._deepFreeze = _deepFreeze;
|
|
|
402
402
|
*/
|
|
403
403
|
function _objectAssignExact(target, source) {
|
|
404
404
|
Object.assign(target, source);
|
|
405
|
-
Object.keys(target)
|
|
406
|
-
|
|
407
|
-
|
|
405
|
+
for (const k of Object.keys(target)) {
|
|
406
|
+
if (!(k in source)) {
|
|
407
|
+
// consider setting it to undefined maybe?
|
|
408
|
+
delete target[k];
|
|
409
|
+
}
|
|
410
|
+
}
|
|
408
411
|
}
|
|
409
412
|
exports._objectAssignExact = _objectAssignExact;
|
|
@@ -37,10 +37,10 @@ export function _uniq(a) {
|
|
|
37
37
|
* a = _uniq([...a, item])
|
|
38
38
|
*/
|
|
39
39
|
export function _pushUniq(a, ...items) {
|
|
40
|
-
|
|
40
|
+
for (const item of items) {
|
|
41
41
|
if (!a.includes(item))
|
|
42
42
|
a.push(item);
|
|
43
|
-
}
|
|
43
|
+
}
|
|
44
44
|
return a;
|
|
45
45
|
}
|
|
46
46
|
/**
|
|
@@ -202,8 +202,8 @@ export function _count(items, predicate) {
|
|
|
202
202
|
}
|
|
203
203
|
export function _countBy(items, mapper) {
|
|
204
204
|
const map = {};
|
|
205
|
-
items.forEach((item,
|
|
206
|
-
const key = mapper(item,
|
|
205
|
+
items.forEach((item, i) => {
|
|
206
|
+
const key = mapper(item, i);
|
|
207
207
|
map[key] = (map[key] || 0) + 1;
|
|
208
208
|
});
|
|
209
209
|
return map;
|
|
@@ -271,12 +271,12 @@ export function _sumBy(items, mapper) {
|
|
|
271
271
|
*/
|
|
272
272
|
export function _mapToObject(array, mapper) {
|
|
273
273
|
const m = {};
|
|
274
|
-
|
|
274
|
+
for (const item of array) {
|
|
275
275
|
const r = mapper(item);
|
|
276
276
|
if (!r)
|
|
277
|
-
|
|
277
|
+
continue; // filtering
|
|
278
278
|
m[r[0]] = r[1];
|
|
279
|
-
}
|
|
279
|
+
}
|
|
280
280
|
return m;
|
|
281
281
|
}
|
|
282
282
|
/**
|
|
@@ -364,13 +364,13 @@ export function _maxByOrUndefined(array, mapper) {
|
|
|
364
364
|
return;
|
|
365
365
|
let maxItem;
|
|
366
366
|
let max;
|
|
367
|
-
array.
|
|
367
|
+
for (const [i, item] of array.entries()) {
|
|
368
368
|
const v = mapper(item, i);
|
|
369
369
|
if (v !== undefined && (max === undefined || v > max)) {
|
|
370
370
|
maxItem = item;
|
|
371
371
|
max = v;
|
|
372
372
|
}
|
|
373
|
-
}
|
|
373
|
+
}
|
|
374
374
|
return maxItem;
|
|
375
375
|
}
|
|
376
376
|
export function _minByOrUndefined(array, mapper) {
|
|
@@ -378,13 +378,13 @@ export function _minByOrUndefined(array, mapper) {
|
|
|
378
378
|
return;
|
|
379
379
|
let minItem;
|
|
380
380
|
let min;
|
|
381
|
-
array.
|
|
381
|
+
for (const [i, item] of array.entries()) {
|
|
382
382
|
const v = mapper(item, i);
|
|
383
383
|
if (v !== undefined && (min === undefined || v < min)) {
|
|
384
384
|
minItem = item;
|
|
385
385
|
min = v;
|
|
386
386
|
}
|
|
387
|
-
}
|
|
387
|
+
}
|
|
388
388
|
return minItem;
|
|
389
389
|
}
|
|
390
390
|
export function _zip(array1, array2) {
|
package/dist-esm/form.util.js
CHANGED
|
@@ -6,7 +6,9 @@
|
|
|
6
6
|
*/
|
|
7
7
|
export function objectToFormData(obj = {}) {
|
|
8
8
|
const fd = new FormData();
|
|
9
|
-
|
|
9
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
10
|
+
fd.append(k, v);
|
|
11
|
+
}
|
|
10
12
|
return fd;
|
|
11
13
|
}
|
|
12
14
|
export function formDataToObject(formData) {
|
package/dist-esm/http/fetcher.js
CHANGED
|
@@ -38,7 +38,7 @@ export class Fetcher {
|
|
|
38
38
|
}
|
|
39
39
|
this.cfg = this.normalizeCfg(cfg);
|
|
40
40
|
// Dynamically create all helper methods
|
|
41
|
-
|
|
41
|
+
for (const method of HTTP_METHODS) {
|
|
42
42
|
const m = method.toLowerCase();
|
|
43
43
|
this[`${m}Void`] = async (url, opt) => {
|
|
44
44
|
return await this.fetch(Object.assign({ url,
|
|
@@ -55,7 +55,7 @@ export class Fetcher {
|
|
|
55
55
|
return await this.fetch(Object.assign({ url,
|
|
56
56
|
method, responseType: 'json' }, opt));
|
|
57
57
|
};
|
|
58
|
-
}
|
|
58
|
+
}
|
|
59
59
|
}
|
|
60
60
|
/**
|
|
61
61
|
* Add BeforeRequest hook at the end of the hooks list.
|
|
@@ -51,14 +51,14 @@ export function _percentile(values, pc) {
|
|
|
51
51
|
export function _percentiles(values, pcs) {
|
|
52
52
|
const r = {};
|
|
53
53
|
const sorted = _sortNumbers(values);
|
|
54
|
-
|
|
54
|
+
for (const pc of pcs) {
|
|
55
55
|
// Floating pos in the range of [0; length - 1]
|
|
56
56
|
const pos = ((values.length - 1) * pc) / 100;
|
|
57
57
|
const dec = pos % 1;
|
|
58
58
|
const floorPos = Math.floor(pos);
|
|
59
59
|
const ceilPos = Math.ceil(pos);
|
|
60
60
|
r[pc] = _averageWeighted([sorted[floorPos], sorted[ceilPos]], [1 - dec, dec]);
|
|
61
|
-
}
|
|
61
|
+
}
|
|
62
62
|
return r;
|
|
63
63
|
}
|
|
64
64
|
/**
|
|
@@ -376,7 +376,10 @@ export function _deepFreeze(o) {
|
|
|
376
376
|
*/
|
|
377
377
|
export function _objectAssignExact(target, source) {
|
|
378
378
|
Object.assign(target, source);
|
|
379
|
-
Object.keys(target)
|
|
380
|
-
|
|
381
|
-
|
|
379
|
+
for (const k of Object.keys(target)) {
|
|
380
|
+
if (!(k in source)) {
|
|
381
|
+
// consider setting it to undefined maybe?
|
|
382
|
+
delete target[k];
|
|
383
|
+
}
|
|
384
|
+
}
|
|
382
385
|
}
|
package/package.json
CHANGED
package/src/array/array.util.ts
CHANGED
|
@@ -48,9 +48,9 @@ export function _uniq<T>(a: readonly T[]): T[] {
|
|
|
48
48
|
* a = _uniq([...a, item])
|
|
49
49
|
*/
|
|
50
50
|
export function _pushUniq<T>(a: T[], ...items: T[]): T[] {
|
|
51
|
-
|
|
51
|
+
for (const item of items) {
|
|
52
52
|
if (!a.includes(item)) a.push(item)
|
|
53
|
-
}
|
|
53
|
+
}
|
|
54
54
|
return a
|
|
55
55
|
}
|
|
56
56
|
|
|
@@ -245,8 +245,8 @@ export function _count<T>(items: T[], predicate: AbortablePredicate<T>): number
|
|
|
245
245
|
export function _countBy<T>(items: T[], mapper: Mapper<T, any>): StringMap<number> {
|
|
246
246
|
const map: StringMap<number> = {}
|
|
247
247
|
|
|
248
|
-
items.forEach((item,
|
|
249
|
-
const key = mapper(item,
|
|
248
|
+
items.forEach((item, i) => {
|
|
249
|
+
const key = mapper(item, i)
|
|
250
250
|
map[key] = (map[key] || 0) + 1
|
|
251
251
|
})
|
|
252
252
|
|
|
@@ -326,12 +326,12 @@ export function _mapToObject<T, V>(
|
|
|
326
326
|
): StringMap<V> {
|
|
327
327
|
const m: StringMap<V> = {}
|
|
328
328
|
|
|
329
|
-
|
|
329
|
+
for (const item of array) {
|
|
330
330
|
const r = mapper(item)
|
|
331
|
-
if (!r)
|
|
331
|
+
if (!r) continue // filtering
|
|
332
332
|
|
|
333
333
|
m[r[0]] = r[1]
|
|
334
|
-
}
|
|
334
|
+
}
|
|
335
335
|
|
|
336
336
|
return m
|
|
337
337
|
}
|
|
@@ -428,13 +428,14 @@ export function _maxByOrUndefined<T>(
|
|
|
428
428
|
if (!array.length) return
|
|
429
429
|
let maxItem: T | undefined
|
|
430
430
|
let max: number | string | undefined
|
|
431
|
-
|
|
431
|
+
|
|
432
|
+
for (const [i, item] of array.entries()) {
|
|
432
433
|
const v = mapper(item, i)
|
|
433
434
|
if (v !== undefined && (max === undefined || v > max)) {
|
|
434
435
|
maxItem = item
|
|
435
436
|
max = v
|
|
436
437
|
}
|
|
437
|
-
}
|
|
438
|
+
}
|
|
438
439
|
|
|
439
440
|
return maxItem
|
|
440
441
|
}
|
|
@@ -446,13 +447,14 @@ export function _minByOrUndefined<T>(
|
|
|
446
447
|
if (!array.length) return
|
|
447
448
|
let minItem: T | undefined
|
|
448
449
|
let min: number | string | undefined
|
|
449
|
-
|
|
450
|
+
|
|
451
|
+
for (const [i, item] of array.entries()) {
|
|
450
452
|
const v = mapper(item, i)
|
|
451
453
|
if (v !== undefined && (min === undefined || v < min)) {
|
|
452
454
|
minItem = item
|
|
453
455
|
min = v
|
|
454
456
|
}
|
|
455
|
-
}
|
|
457
|
+
}
|
|
456
458
|
|
|
457
459
|
return minItem
|
|
458
460
|
}
|
package/src/form.util.ts
CHANGED
|
@@ -8,7 +8,9 @@ import type { AnyObject } from './types'
|
|
|
8
8
|
*/
|
|
9
9
|
export function objectToFormData(obj: AnyObject = {}): FormData {
|
|
10
10
|
const fd = new FormData()
|
|
11
|
-
|
|
11
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
12
|
+
fd.append(k, v)
|
|
13
|
+
}
|
|
12
14
|
return fd
|
|
13
15
|
}
|
|
14
16
|
|
package/src/http/fetcher.ts
CHANGED
|
@@ -82,7 +82,7 @@ export class Fetcher {
|
|
|
82
82
|
this.cfg = this.normalizeCfg(cfg)
|
|
83
83
|
|
|
84
84
|
// Dynamically create all helper methods
|
|
85
|
-
|
|
85
|
+
for (const method of HTTP_METHODS) {
|
|
86
86
|
const m = method.toLowerCase()
|
|
87
87
|
|
|
88
88
|
// responseType=void
|
|
@@ -114,7 +114,7 @@ export class Fetcher {
|
|
|
114
114
|
...opt,
|
|
115
115
|
})
|
|
116
116
|
}
|
|
117
|
-
}
|
|
117
|
+
}
|
|
118
118
|
}
|
|
119
119
|
|
|
120
120
|
/**
|
package/src/math/math.util.ts
CHANGED
|
@@ -62,7 +62,7 @@ export function _percentiles(values: number[], pcs: number[]): Record<number, nu
|
|
|
62
62
|
|
|
63
63
|
const sorted = _sortNumbers(values)
|
|
64
64
|
|
|
65
|
-
|
|
65
|
+
for (const pc of pcs) {
|
|
66
66
|
// Floating pos in the range of [0; length - 1]
|
|
67
67
|
const pos = ((values.length - 1) * pc) / 100
|
|
68
68
|
const dec = pos % 1
|
|
@@ -70,7 +70,7 @@ export function _percentiles(values: number[], pcs: number[]): Record<number, nu
|
|
|
70
70
|
const ceilPos = Math.ceil(pos)
|
|
71
71
|
|
|
72
72
|
r[pc] = _averageWeighted([sorted[floorPos]!, sorted[ceilPos]!], [1 - dec, dec])
|
|
73
|
-
}
|
|
73
|
+
}
|
|
74
74
|
|
|
75
75
|
return r
|
|
76
76
|
}
|
|
@@ -440,7 +440,11 @@ export function _deepFreeze(o: any): void {
|
|
|
440
440
|
*/
|
|
441
441
|
export function _objectAssignExact<T extends AnyObject>(target: T, source: T): void {
|
|
442
442
|
Object.assign(target, source)
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
443
|
+
|
|
444
|
+
for (const k of Object.keys(target)) {
|
|
445
|
+
if (!(k in source)) {
|
|
446
|
+
// consider setting it to undefined maybe?
|
|
447
|
+
delete target[k]
|
|
448
|
+
}
|
|
449
|
+
}
|
|
446
450
|
}
|