@naturalcycles/js-lib 14.249.0 → 14.250.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 +52 -42
- package/dist/datetime/localDate.js +30 -17
- package/dist/datetime/localTime.js +31 -18
- package/dist/error/assert.js +2 -1
- package/dist/http/fetcher.js +5 -5
- package/dist/json-schema/jsonSchemaBuilder.js +2 -2
- package/dist/math/math.util.js +14 -4
- package/dist/math/sma.js +4 -1
- package/dist/number/createDeterministicRandom.js +1 -1
- package/dist/number/number.util.js +2 -2
- package/dist/object/object.util.d.ts +1 -2
- package/dist/object/object.util.js +59 -34
- package/dist/promise/pDelay.d.ts +3 -3
- package/dist/promise/pDelay.js +1 -1
- package/dist/semver.js +22 -13
- package/dist/string/case.js +15 -6
- package/dist/string/lodash/words.js +1 -0
- package/dist/string/safeJsonStringify.js +1 -1
- package/dist-esm/array/array.util.js +52 -42
- package/dist-esm/datetime/localDate.js +30 -17
- package/dist-esm/datetime/localTime.js +31 -18
- package/dist-esm/error/assert.js +2 -1
- package/dist-esm/http/fetcher.js +5 -5
- package/dist-esm/json-schema/jsonSchemaBuilder.js +2 -2
- package/dist-esm/math/math.util.js +14 -4
- package/dist-esm/math/sma.js +4 -1
- package/dist-esm/number/createDeterministicRandom.js +1 -1
- package/dist-esm/number/number.util.js +2 -2
- package/dist-esm/object/object.util.js +60 -35
- package/dist-esm/promise/pDelay.js +1 -1
- package/dist-esm/semver.js +22 -13
- package/dist-esm/string/case.js +15 -6
- package/dist-esm/string/lodash/words.js +1 -0
- package/dist-esm/string/safeJsonStringify.js +1 -1
- package/package.json +1 -1
- package/src/array/array.util.ts +48 -40
- package/src/datetime/localDate.ts +34 -19
- package/src/datetime/localTime.ts +34 -21
- package/src/error/assert.ts +2 -1
- package/src/http/fetcher.ts +8 -6
- package/src/json-schema/jsonSchemaBuilder.ts +2 -2
- package/src/math/math.util.ts +13 -6
- package/src/math/sma.ts +3 -1
- package/src/number/createDeterministicRandom.ts +1 -1
- package/src/number/number.util.ts +4 -2
- package/src/object/object.util.ts +77 -52
- package/src/promise/pDelay.ts +6 -3
- package/src/semver.ts +22 -13
- package/src/string/case.ts +15 -12
- package/src/string/leven.ts +1 -1
- package/src/string/lodash/words.ts +1 -0
- package/src/string/safeJsonStringify.ts +1 -1
- package/src/string/string.util.ts +2 -2
package/dist/array/array.util.js
CHANGED
|
@@ -39,7 +39,7 @@ exports._minBy = _minBy;
|
|
|
39
39
|
exports._maxByOrUndefined = _maxByOrUndefined;
|
|
40
40
|
exports._minByOrUndefined = _minByOrUndefined;
|
|
41
41
|
exports._zip = _zip;
|
|
42
|
-
const
|
|
42
|
+
const assert_1 = require("../error/assert");
|
|
43
43
|
const types_1 = require("../types");
|
|
44
44
|
/**
|
|
45
45
|
* Creates an array of elements split into groups the length of size. If collection can’t be split evenly, the
|
|
@@ -54,9 +54,11 @@ const types_1 = require("../types");
|
|
|
54
54
|
* Based on: https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore#_chunk
|
|
55
55
|
*/
|
|
56
56
|
function _chunk(array, size = 1) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
const a = [];
|
|
58
|
+
for (let i = 0; i < array.length; i += size) {
|
|
59
|
+
a.push(array.slice(i, i + size));
|
|
60
|
+
}
|
|
61
|
+
return a;
|
|
60
62
|
}
|
|
61
63
|
/**
|
|
62
64
|
* Removes duplicates from given array.
|
|
@@ -117,16 +119,13 @@ function _pushUniqBy(a, mapper, ...items) {
|
|
|
117
119
|
* Based on: https://stackoverflow.com/a/40808569/4919972
|
|
118
120
|
*/
|
|
119
121
|
function _uniqBy(arr, mapper) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}, new Map())
|
|
128
|
-
.values(),
|
|
129
|
-
];
|
|
122
|
+
const map = new Map();
|
|
123
|
+
for (const [i, item] of arr.entries()) {
|
|
124
|
+
const key = item === undefined || item === null ? item : mapper(item, i);
|
|
125
|
+
if (!map.has(key))
|
|
126
|
+
map.set(key, item);
|
|
127
|
+
}
|
|
128
|
+
return [...map.values()];
|
|
130
129
|
}
|
|
131
130
|
/**
|
|
132
131
|
* const a = [
|
|
@@ -169,13 +168,14 @@ function _mapBy(items, mapper) {
|
|
|
169
168
|
* Returning `undefined` from the Mapper will EXCLUDE the item.
|
|
170
169
|
*/
|
|
171
170
|
function _groupBy(items, mapper) {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
}
|
|
171
|
+
const map = {};
|
|
172
|
+
for (const [i, item] of items.entries()) {
|
|
173
|
+
const key = mapper(item, i);
|
|
174
|
+
if (key === undefined)
|
|
175
|
+
continue;
|
|
176
|
+
(map[key] ||= []).push(item);
|
|
177
|
+
}
|
|
178
|
+
return map;
|
|
179
179
|
}
|
|
180
180
|
/**
|
|
181
181
|
* _sortBy([{age: 20}, {age: 10}], 'age')
|
|
@@ -323,7 +323,11 @@ function _intersectsWith(a1, a2) {
|
|
|
323
323
|
* // [1]
|
|
324
324
|
*/
|
|
325
325
|
function _difference(source, ...diffs) {
|
|
326
|
-
|
|
326
|
+
let a = source;
|
|
327
|
+
for (const b of diffs) {
|
|
328
|
+
a = a.filter(c => !b.includes(c));
|
|
329
|
+
}
|
|
330
|
+
return a;
|
|
327
331
|
}
|
|
328
332
|
/**
|
|
329
333
|
* Returns the sum of items, or 0 for empty array.
|
|
@@ -408,45 +412,51 @@ function _first(array) {
|
|
|
408
412
|
return array[0];
|
|
409
413
|
}
|
|
410
414
|
function _minOrUndefined(array) {
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
+
let min;
|
|
416
|
+
for (const item of array) {
|
|
417
|
+
if (item === undefined || item === null)
|
|
418
|
+
continue;
|
|
419
|
+
if (min === undefined || item < min) {
|
|
420
|
+
min = item;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
return min;
|
|
415
424
|
}
|
|
416
425
|
/**
|
|
417
426
|
* Filters out nullish values (undefined and null).
|
|
418
427
|
*/
|
|
419
428
|
function _min(array) {
|
|
420
|
-
const
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
return a.reduce((min, item) => (min <= item ? min : item));
|
|
429
|
+
const min = _minOrUndefined(array);
|
|
430
|
+
(0, assert_1._assert)(min !== undefined, '_min called on empty array');
|
|
431
|
+
return min;
|
|
424
432
|
}
|
|
425
433
|
function _maxOrUndefined(array) {
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
434
|
+
let max;
|
|
435
|
+
for (const item of array) {
|
|
436
|
+
if (item === undefined || item === null)
|
|
437
|
+
continue;
|
|
438
|
+
if (max === undefined || item > max) {
|
|
439
|
+
max = item;
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
return max;
|
|
430
443
|
}
|
|
431
444
|
/**
|
|
432
445
|
* Filters out nullish values (undefined and null).
|
|
433
446
|
*/
|
|
434
447
|
function _max(array) {
|
|
435
|
-
const
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
return a.reduce((max, item) => (max >= item ? max : item));
|
|
448
|
+
const max = _maxOrUndefined(array);
|
|
449
|
+
(0, assert_1._assert)(max !== undefined, '_max called on empty array');
|
|
450
|
+
return max;
|
|
439
451
|
}
|
|
440
452
|
function _maxBy(array, mapper) {
|
|
441
453
|
const max = _maxByOrUndefined(array, mapper);
|
|
442
|
-
|
|
443
|
-
throw new Error(`_maxBy returned undefined`);
|
|
454
|
+
(0, assert_1._assert)(max !== undefined, '_maxBy returned undefined');
|
|
444
455
|
return max;
|
|
445
456
|
}
|
|
446
457
|
function _minBy(array, mapper) {
|
|
447
458
|
const min = _minByOrUndefined(array, mapper);
|
|
448
|
-
|
|
449
|
-
throw new Error(`_minBy returned undefined`);
|
|
459
|
+
(0, assert_1._assert)(min !== undefined, '_minBy returned undefined');
|
|
450
460
|
return min;
|
|
451
461
|
}
|
|
452
462
|
// todo: looks like it _maxByOrUndefined/_minByOrUndefined can be DRYer
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.localDate = exports.LocalDate = void 0;
|
|
4
4
|
const assert_1 = require("../error/assert");
|
|
5
|
-
const is_util_1 = require("../is.util");
|
|
6
5
|
const iterable2_1 = require("../iter/iterable2");
|
|
7
6
|
const localTime_1 = require("./localTime");
|
|
8
7
|
const MDAYS = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
@@ -496,7 +495,7 @@ class LocalDateFactory {
|
|
|
496
495
|
if (input instanceof LocalDate)
|
|
497
496
|
return true;
|
|
498
497
|
if (input instanceof Date)
|
|
499
|
-
return !isNaN(input.getDate());
|
|
498
|
+
return !Number.isNaN(input.getDate());
|
|
500
499
|
return this.isValidString(input);
|
|
501
500
|
}
|
|
502
501
|
/**
|
|
@@ -516,7 +515,7 @@ class LocalDateFactory {
|
|
|
516
515
|
if (input instanceof LocalDate)
|
|
517
516
|
return input;
|
|
518
517
|
if (input instanceof Date) {
|
|
519
|
-
if (isNaN(input.getDate()))
|
|
518
|
+
if (Number.isNaN(input.getDate()))
|
|
520
519
|
return;
|
|
521
520
|
return new LocalDate(input.getFullYear(), input.getMonth() + 1, input.getDate());
|
|
522
521
|
}
|
|
@@ -574,7 +573,7 @@ class LocalDateFactory {
|
|
|
574
573
|
* Takes Date as-is, in its timezone - local or UTC.
|
|
575
574
|
*/
|
|
576
575
|
fromDate(d) {
|
|
577
|
-
(0, assert_1._assert)(!isNaN(d.getDate()),
|
|
576
|
+
(0, assert_1._assert)(!Number.isNaN(d.getDate()), 'localDate.fromDate is called on Date object that is invalid');
|
|
578
577
|
return new LocalDate(d.getFullYear(), d.getMonth() + 1, d.getDate());
|
|
579
578
|
}
|
|
580
579
|
/**
|
|
@@ -582,7 +581,7 @@ class LocalDateFactory {
|
|
|
582
581
|
* Takes Date's year/month/day components in UTC, using getUTCFullYear, getUTCMonth, getUTCDate.
|
|
583
582
|
*/
|
|
584
583
|
fromDateInUTC(d) {
|
|
585
|
-
(0, assert_1._assert)(!isNaN(d.getDate()),
|
|
584
|
+
(0, assert_1._assert)(!Number.isNaN(d.getDate()), 'localDate.fromDateInUTC is called on Date object that is invalid');
|
|
586
585
|
return new LocalDate(d.getUTCFullYear(), d.getUTCMonth() + 1, d.getUTCDate());
|
|
587
586
|
}
|
|
588
587
|
fromDateObject(o) {
|
|
@@ -600,35 +599,49 @@ class LocalDateFactory {
|
|
|
600
599
|
* Returns the earliest (min) LocalDate from the array, or undefined if the array is empty.
|
|
601
600
|
*/
|
|
602
601
|
minOrUndefined(items) {
|
|
603
|
-
|
|
602
|
+
let min;
|
|
603
|
+
for (const item of items) {
|
|
604
|
+
if (!item)
|
|
605
|
+
continue;
|
|
606
|
+
const ld = this.fromInput(item);
|
|
607
|
+
if (!min || ld.isBefore(min)) {
|
|
608
|
+
min = ld;
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
return min;
|
|
604
612
|
}
|
|
605
613
|
/**
|
|
606
614
|
* Returns the earliest LocalDate from the array.
|
|
607
615
|
* Throws if the array is empty.
|
|
608
616
|
*/
|
|
609
617
|
min(items) {
|
|
610
|
-
const
|
|
611
|
-
(0, assert_1._assert)(
|
|
612
|
-
return
|
|
613
|
-
.map(i => this.fromInput(i))
|
|
614
|
-
.reduce((min, item) => (min.isSameOrBefore(item) ? min : item));
|
|
618
|
+
const min = this.minOrUndefined(items);
|
|
619
|
+
(0, assert_1._assert)(min, 'localDate.min called on empty array');
|
|
620
|
+
return min;
|
|
615
621
|
}
|
|
616
622
|
/**
|
|
617
623
|
* Returns the latest (max) LocalDate from the array, or undefined if the array is empty.
|
|
618
624
|
*/
|
|
619
625
|
maxOrUndefined(items) {
|
|
620
|
-
|
|
626
|
+
let max;
|
|
627
|
+
for (const item of items) {
|
|
628
|
+
if (!item)
|
|
629
|
+
continue;
|
|
630
|
+
const ld = this.fromInput(item);
|
|
631
|
+
if (!max || ld.isAfter(max)) {
|
|
632
|
+
max = ld;
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
return max;
|
|
621
636
|
}
|
|
622
637
|
/**
|
|
623
638
|
* Returns the latest LocalDate from the array.
|
|
624
639
|
* Throws if the array is empty.
|
|
625
640
|
*/
|
|
626
641
|
max(items) {
|
|
627
|
-
const
|
|
628
|
-
(0, assert_1._assert)(
|
|
629
|
-
return
|
|
630
|
-
.map(i => this.fromInput(i))
|
|
631
|
-
.reduce((max, item) => (max.isSameOrAfter(item) ? max : item));
|
|
642
|
+
const max = this.maxOrUndefined(items);
|
|
643
|
+
(0, assert_1._assert)(max, 'localDate.max called on empty array');
|
|
644
|
+
return max;
|
|
632
645
|
}
|
|
633
646
|
/**
|
|
634
647
|
* Returns the range (array) of LocalDates between min and max.
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.localTime = exports.LocalTime = exports.ISODayOfWeek = void 0;
|
|
4
4
|
const assert_1 = require("../error/assert");
|
|
5
|
-
const is_util_1 = require("../is.util");
|
|
6
5
|
const time_util_1 = require("../time/time.util");
|
|
7
6
|
const localDate_1 = require("./localDate");
|
|
8
7
|
const wallTime_1 = require("./wallTime");
|
|
@@ -677,7 +676,7 @@ class LocalTimeFactory {
|
|
|
677
676
|
if (input instanceof LocalTime)
|
|
678
677
|
return true;
|
|
679
678
|
if (input instanceof Date)
|
|
680
|
-
return !isNaN(input.getDate());
|
|
679
|
+
return !Number.isNaN(input.getDate());
|
|
681
680
|
// We currently don't validate Unixtimestamp input, treat it as always valid
|
|
682
681
|
if (typeof input === 'number')
|
|
683
682
|
return true;
|
|
@@ -698,7 +697,7 @@ class LocalTimeFactory {
|
|
|
698
697
|
if (input instanceof LocalTime)
|
|
699
698
|
return input;
|
|
700
699
|
if (input instanceof Date) {
|
|
701
|
-
if (isNaN(input.getDate()))
|
|
700
|
+
if (Number.isNaN(input.getDate()))
|
|
702
701
|
return;
|
|
703
702
|
return new LocalTime(input);
|
|
704
703
|
}
|
|
@@ -762,7 +761,7 @@ class LocalTimeFactory {
|
|
|
762
761
|
return;
|
|
763
762
|
// Attempt to parse with Date constructor
|
|
764
763
|
const d = new Date(s);
|
|
765
|
-
return isNaN(d.getDate()) ? undefined : d;
|
|
764
|
+
return Number.isNaN(d.getDate()) ? undefined : d;
|
|
766
765
|
}
|
|
767
766
|
const o = {
|
|
768
767
|
year: Number(m[1]),
|
|
@@ -790,7 +789,7 @@ class LocalTimeFactory {
|
|
|
790
789
|
return hour >= 0 && hour <= 23 && minute >= 0 && minute <= 59 && second >= 0 && second <= 59;
|
|
791
790
|
}
|
|
792
791
|
fromDate(date) {
|
|
793
|
-
(0, assert_1._assert)(!isNaN(date.getDate()),
|
|
792
|
+
(0, assert_1._assert)(!Number.isNaN(date.getDate()), 'localTime.fromDate is called on Date object that is invalid');
|
|
794
793
|
return new LocalTime(date);
|
|
795
794
|
}
|
|
796
795
|
fromUnix(ts) {
|
|
@@ -845,24 +844,38 @@ class LocalTimeFactory {
|
|
|
845
844
|
});
|
|
846
845
|
}
|
|
847
846
|
minOrUndefined(items) {
|
|
848
|
-
|
|
847
|
+
let min;
|
|
848
|
+
for (const item of items) {
|
|
849
|
+
if (!item)
|
|
850
|
+
continue;
|
|
851
|
+
const lt = this.fromInput(item);
|
|
852
|
+
if (!min || lt.$date.valueOf() < min.$date.valueOf()) {
|
|
853
|
+
min = lt;
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
return min;
|
|
849
857
|
}
|
|
850
858
|
min(items) {
|
|
851
|
-
const
|
|
852
|
-
(0, assert_1._assert)(
|
|
853
|
-
return
|
|
854
|
-
.map(i => this.fromInput(i))
|
|
855
|
-
.reduce((min, item) => (min.$date.valueOf() <= item.$date.valueOf() ? min : item));
|
|
859
|
+
const min = this.minOrUndefined(items);
|
|
860
|
+
(0, assert_1._assert)(min, 'localTime.min called on empty array');
|
|
861
|
+
return min;
|
|
856
862
|
}
|
|
857
863
|
maxOrUndefined(items) {
|
|
858
|
-
|
|
864
|
+
let max;
|
|
865
|
+
for (const item of items) {
|
|
866
|
+
if (!item)
|
|
867
|
+
continue;
|
|
868
|
+
const lt = this.fromInput(item);
|
|
869
|
+
if (!max || lt.$date.valueOf() > max.$date.valueOf()) {
|
|
870
|
+
max = lt;
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
return max;
|
|
859
874
|
}
|
|
860
875
|
max(items) {
|
|
861
|
-
const
|
|
862
|
-
(0, assert_1._assert)(
|
|
863
|
-
return
|
|
864
|
-
.map(i => this.fromInput(i))
|
|
865
|
-
.reduce((max, item) => (max.$date.valueOf() >= item.$date.valueOf() ? max : item));
|
|
876
|
+
const max = this.maxOrUndefined(items);
|
|
877
|
+
(0, assert_1._assert)(max, 'localTime.max called on empty array');
|
|
878
|
+
return max;
|
|
866
879
|
}
|
|
867
880
|
}
|
|
868
881
|
// based on: https://github.com/date-fns/date-fns/blob/master/src/getISOWeek/index.ts
|
|
@@ -898,7 +911,7 @@ function getWeekYear(date) {
|
|
|
898
911
|
if (date.getTime() >= startOfNextYear.getTime()) {
|
|
899
912
|
return year + 1;
|
|
900
913
|
}
|
|
901
|
-
|
|
914
|
+
if (date.getTime() >= startOfThisYear.getTime()) {
|
|
902
915
|
return year;
|
|
903
916
|
}
|
|
904
917
|
return year - 1;
|
package/dist/error/assert.js
CHANGED
|
@@ -60,7 +60,7 @@ function _assertEquals(actual, expected, message, errorData) {
|
|
|
60
60
|
function _assertDeepEquals(actual, expected, message, errorData) {
|
|
61
61
|
if (!(0, __1._deepEquals)(actual, expected)) {
|
|
62
62
|
const msg = message ||
|
|
63
|
-
[
|
|
63
|
+
['not deeply equal', `expected: ${(0, __1._stringify)(expected)}`, `got : ${(0, __1._stringify)(actual)}`]
|
|
64
64
|
.filter(Boolean)
|
|
65
65
|
.join('\n');
|
|
66
66
|
throw new __1.AssertionError(msg, {
|
|
@@ -96,6 +96,7 @@ function _assertIsNumber(v, message) {
|
|
|
96
96
|
_assertTypeOf(v, 'number', message);
|
|
97
97
|
}
|
|
98
98
|
function _assertTypeOf(v, expectedType, message) {
|
|
99
|
+
// biome-ignore lint/suspicious/useValidTypeof: ok
|
|
99
100
|
if (typeof v !== expectedType) {
|
|
100
101
|
const msg = message || `Expected typeof ${expectedType}, actual typeof: ${typeof v}`;
|
|
101
102
|
throw new __1.AssertionError(msg);
|
package/dist/http/fetcher.js
CHANGED
|
@@ -45,7 +45,7 @@ class Fetcher {
|
|
|
45
45
|
static { this.userAgent = (0, env_1.isServerSide)() ? `fetcher${this.VERSION}` : undefined; }
|
|
46
46
|
constructor(cfg = {}) {
|
|
47
47
|
if (typeof globalThis.fetch !== 'function') {
|
|
48
|
-
throw new TypeError(
|
|
48
|
+
throw new TypeError('globalThis.fetch is not available');
|
|
49
49
|
}
|
|
50
50
|
this.cfg = this.normalizeCfg(cfg);
|
|
51
51
|
// Dynamically create all helper methods
|
|
@@ -289,7 +289,7 @@ class Fetcher {
|
|
|
289
289
|
res.body = res.fetchResponse.body;
|
|
290
290
|
if (res.body === null) {
|
|
291
291
|
// Error is to be handled upstream
|
|
292
|
-
throw new Error(
|
|
292
|
+
throw new Error('fetchResponse.body is null');
|
|
293
293
|
}
|
|
294
294
|
}
|
|
295
295
|
res.retryStatus.retryStopped = true;
|
|
@@ -418,13 +418,13 @@ class Fetcher {
|
|
|
418
418
|
}
|
|
419
419
|
else {
|
|
420
420
|
const date = new Date(retryAfterStr);
|
|
421
|
-
if (!isNaN(date)) {
|
|
421
|
+
if (!Number.isNaN(date)) {
|
|
422
422
|
timeout = Number(date) - Date.now();
|
|
423
423
|
}
|
|
424
424
|
}
|
|
425
425
|
this.cfg.logger.log(`retry-after: ${retryAfterStr}`);
|
|
426
426
|
if (!timeout) {
|
|
427
|
-
this.cfg.logger.warn(
|
|
427
|
+
this.cfg.logger.warn('retry-after could not be parsed');
|
|
428
428
|
}
|
|
429
429
|
}
|
|
430
430
|
}
|
|
@@ -577,7 +577,7 @@ class Fetcher {
|
|
|
577
577
|
const baseUrl = opt.baseUrl || this.cfg.baseUrl;
|
|
578
578
|
if (baseUrl) {
|
|
579
579
|
if (req.fullUrl.startsWith('/')) {
|
|
580
|
-
console.warn(
|
|
580
|
+
console.warn('Fetcher: url should not start with / when baseUrl is specified');
|
|
581
581
|
req.fullUrl = req.fullUrl.slice(1);
|
|
582
582
|
}
|
|
583
583
|
req.fullUrl = `${baseUrl}/${req.inputUrl}`;
|
|
@@ -144,7 +144,7 @@ class JsonSchemaAnyBuilder {
|
|
|
144
144
|
this.schema.optionalField = true;
|
|
145
145
|
}
|
|
146
146
|
else {
|
|
147
|
-
|
|
147
|
+
this.schema.optionalField = undefined;
|
|
148
148
|
}
|
|
149
149
|
return this;
|
|
150
150
|
}
|
|
@@ -281,7 +281,7 @@ class JsonSchemaObjectBuilder extends JsonSchemaAnyBuilder {
|
|
|
281
281
|
this.schema.required.push(k);
|
|
282
282
|
}
|
|
283
283
|
else {
|
|
284
|
-
|
|
284
|
+
schema.optionalField = undefined;
|
|
285
285
|
}
|
|
286
286
|
this.schema.properties[k] = schema;
|
|
287
287
|
});
|
package/dist/math/math.util.js
CHANGED
|
@@ -6,6 +6,7 @@ exports._averageWeighted = _averageWeighted;
|
|
|
6
6
|
exports._percentile = _percentile;
|
|
7
7
|
exports._percentiles = _percentiles;
|
|
8
8
|
exports._median = _median;
|
|
9
|
+
const assert_1 = require("../error/assert");
|
|
9
10
|
const number_util_1 = require("../number/number.util");
|
|
10
11
|
/**
|
|
11
12
|
* @returns Average of the array of numbers
|
|
@@ -16,20 +17,29 @@ const number_util_1 = require("../number/number.util");
|
|
|
16
17
|
* // 2.5
|
|
17
18
|
*/
|
|
18
19
|
function _average(values) {
|
|
19
|
-
|
|
20
|
+
(0, assert_1._assert)(values.length, '_average is called on empty array');
|
|
21
|
+
let total = 0;
|
|
22
|
+
for (const n of values)
|
|
23
|
+
total += n;
|
|
24
|
+
return total / values.length;
|
|
20
25
|
}
|
|
21
26
|
/**
|
|
22
27
|
* Same as _average, but safely returns null if input array is empty or nullish.
|
|
23
28
|
*/
|
|
24
29
|
function _averageOrNull(values) {
|
|
25
|
-
return values?.length ? values
|
|
30
|
+
return values?.length ? _average(values) : null;
|
|
26
31
|
}
|
|
27
32
|
/**
|
|
28
33
|
* valuesArray and weightsArray length is expected to be the same.
|
|
29
34
|
*/
|
|
30
35
|
function _averageWeighted(values, weights) {
|
|
31
|
-
|
|
32
|
-
|
|
36
|
+
let numerator = 0;
|
|
37
|
+
let denominator = 0;
|
|
38
|
+
// eslint-disable-next-line unicorn/no-for-loop
|
|
39
|
+
for (let i = 0; i < values.length; i++) {
|
|
40
|
+
numerator += values[i] * weights[i];
|
|
41
|
+
denominator += weights[i];
|
|
42
|
+
}
|
|
33
43
|
return numerator / denominator;
|
|
34
44
|
}
|
|
35
45
|
/**
|
package/dist/math/sma.js
CHANGED
|
@@ -20,7 +20,10 @@ class SimpleMovingAverage {
|
|
|
20
20
|
get avg() {
|
|
21
21
|
if (this.data.length === 0)
|
|
22
22
|
return 0;
|
|
23
|
-
|
|
23
|
+
let total = 0;
|
|
24
|
+
for (const n of this.data)
|
|
25
|
+
total += n;
|
|
26
|
+
return total / this.data.length;
|
|
24
27
|
}
|
|
25
28
|
/**
|
|
26
29
|
* Push new value.
|
|
@@ -9,7 +9,7 @@ exports._createDeterministicRandom = _createDeterministicRandom;
|
|
|
9
9
|
*/
|
|
10
10
|
function _createDeterministicRandom() {
|
|
11
11
|
let seed = 0x2f6e2b1;
|
|
12
|
-
return
|
|
12
|
+
return () => {
|
|
13
13
|
// Robert Jenkins’ 32 bit integer hash function
|
|
14
14
|
seed = (seed + 0x7ed55d16 + (seed << 12)) & 0xffffffff;
|
|
15
15
|
seed = (seed ^ 0xc761c23c ^ (seed >>> 19)) & 0xffffffff;
|
|
@@ -47,10 +47,10 @@ function _isBetween(x, min, max, incl = '[)') {
|
|
|
47
47
|
if (incl === '[)') {
|
|
48
48
|
return x >= min && x < max;
|
|
49
49
|
}
|
|
50
|
-
|
|
50
|
+
if (incl === '[]') {
|
|
51
51
|
return x >= min && x <= max;
|
|
52
52
|
}
|
|
53
|
-
|
|
53
|
+
if (incl === '(]') {
|
|
54
54
|
return x > min && x <= max;
|
|
55
55
|
}
|
|
56
56
|
return x > min && x < max;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { KeyValueTuple, Reviver, SKIP } from '../types';
|
|
1
|
+
import { AnyObject, KeyValueTuple, ObjectMapper, ObjectPredicate, Reviver, SKIP, ValueOf } from '../types';
|
|
3
2
|
/**
|
|
4
3
|
* Returns clone of `obj` with only `props` preserved.
|
|
5
4
|
* Opposite of Omit.
|