@naturalcycles/js-lib 15.8.0 → 15.9.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.d.ts +14 -6
- package/dist/array/array.util.js +57 -36
- package/dist/array/range.d.ts +1 -1
- package/dist/array/range.js +1 -1
- package/dist/datetime/dateInterval.d.ts +4 -5
- package/dist/datetime/dateInterval.js +8 -11
- package/dist/datetime/localDate.d.ts +3 -3
- package/dist/datetime/localDate.js +5 -7
- package/dist/datetime/localTime.d.ts +1 -1
- package/dist/datetime/localTime.js +2 -3
- package/dist/datetime/timeInterval.d.ts +2 -2
- package/dist/datetime/timeInterval.js +3 -4
- package/dist/http/fetcher.js +1 -1
- package/dist/json-schema/jsonSchema.util.js +1 -1
- package/dist/math/math.util.js +0 -1
- package/dist/number/number.util.d.ts +1 -1
- package/dist/number/number.util.js +6 -11
- package/dist/object/object.util.d.ts +14 -13
- package/dist/object/object.util.js +26 -26
- package/dist/types.d.ts +7 -5
- package/dist/types.js +1 -1
- package/package.json +1 -1
- package/src/array/array.util.ts +73 -45
- package/src/array/range.ts +1 -1
- package/src/datetime/dateInterval.ts +9 -12
- package/src/datetime/localDate.ts +6 -7
- package/src/datetime/localTime.ts +2 -3
- package/src/datetime/timeInterval.ts +4 -5
- package/src/http/fetcher.ts +1 -1
- package/src/json-schema/jsonSchema.util.ts +1 -1
- package/src/math/math.util.ts +0 -1
- package/src/number/number.util.ts +4 -11
- package/src/object/object.util.ts +30 -26
- package/src/types.ts +11 -6
|
@@ -90,6 +90,18 @@ export declare function _mapBy<ITEM, KEY>(items: readonly ITEM[], mapper: Mapper
|
|
|
90
90
|
* Returning `undefined` from the Mapper will EXCLUDE the item.
|
|
91
91
|
*/
|
|
92
92
|
export declare function _groupBy<T>(items: readonly T[], mapper: Mapper<T, any>): StringMap<T[]>;
|
|
93
|
+
export interface MutateOptions {
|
|
94
|
+
/**
|
|
95
|
+
* Defaults to false.
|
|
96
|
+
*/
|
|
97
|
+
mutate?: boolean;
|
|
98
|
+
}
|
|
99
|
+
export interface SortByOptions extends MutateOptions {
|
|
100
|
+
/**
|
|
101
|
+
* Defaults to 'asc'.
|
|
102
|
+
*/
|
|
103
|
+
dir?: SortDirection;
|
|
104
|
+
}
|
|
93
105
|
/**
|
|
94
106
|
* _sortBy([{age: 20}, {age: 10}], 'age')
|
|
95
107
|
* // => [{age: 10}, {age: 20}]
|
|
@@ -97,11 +109,7 @@ export declare function _groupBy<T>(items: readonly T[], mapper: Mapper<T, any>)
|
|
|
97
109
|
* Same:
|
|
98
110
|
* _sortBy([{age: 20}, {age: 10}], o => o.age)
|
|
99
111
|
*/
|
|
100
|
-
export declare function _sortBy<T>(items: T[], mapper: Mapper<T,
|
|
101
|
-
/**
|
|
102
|
-
* Alias for _sortBy with descending order.
|
|
103
|
-
*/
|
|
104
|
-
export declare function _sortDescBy<T>(items: T[], mapper: Mapper<T, any>, mutate?: boolean): T[];
|
|
112
|
+
export declare function _sortBy<T, COMPARE_TYPE extends string | number>(items: T[], mapper: Mapper<T, COMPARE_TYPE>, opt?: SortByOptions): T[];
|
|
105
113
|
/**
|
|
106
114
|
* Similar to `Array.find`, but the `predicate` may return `END` to stop the iteration early.
|
|
107
115
|
*
|
|
@@ -194,7 +202,7 @@ export declare function _mapToObject<T, V>(array: Iterable<T>, mapper: (item: T)
|
|
|
194
202
|
* Fisher–Yates algorithm.
|
|
195
203
|
* Based on: https://stackoverflow.com/a/12646864/4919972
|
|
196
204
|
*/
|
|
197
|
-
export declare function _shuffle<T>(array: T[],
|
|
205
|
+
export declare function _shuffle<T>(array: T[], opt?: MutateOptions): T[];
|
|
198
206
|
/**
|
|
199
207
|
* Returns last item of non-empty array.
|
|
200
208
|
* Throws if array is empty.
|
package/dist/array/array.util.js
CHANGED
|
@@ -50,9 +50,9 @@ export function _pushUniq(a, ...items) {
|
|
|
50
50
|
* Mutates the array (same as normal `push`).
|
|
51
51
|
*/
|
|
52
52
|
export function _pushUniqBy(a, mapper, ...items) {
|
|
53
|
-
const mappedSet = new Set(a.map(
|
|
54
|
-
items.forEach(
|
|
55
|
-
const mapped = mapper(item
|
|
53
|
+
const mappedSet = new Set(a.map(mapper));
|
|
54
|
+
items.forEach(item => {
|
|
55
|
+
const mapped = mapper(item);
|
|
56
56
|
if (!mappedSet.has(mapped)) {
|
|
57
57
|
a.push(item);
|
|
58
58
|
mappedSet.add(mapped);
|
|
@@ -79,8 +79,9 @@ export function _pushUniqBy(a, mapper, ...items) {
|
|
|
79
79
|
*/
|
|
80
80
|
export function _uniqBy(arr, mapper) {
|
|
81
81
|
const map = new Map();
|
|
82
|
-
for (
|
|
83
|
-
const
|
|
82
|
+
for (let i = 0; i < arr.length; i++) {
|
|
83
|
+
const item = arr[i];
|
|
84
|
+
const key = item === undefined || item === null ? item : mapper(item);
|
|
84
85
|
if (!map.has(key))
|
|
85
86
|
map.set(key, item);
|
|
86
87
|
}
|
|
@@ -107,13 +108,29 @@ export function _uniqBy(arr, mapper) {
|
|
|
107
108
|
* Returning `undefined` from the Mapper will EXCLUDE the item.
|
|
108
109
|
*/
|
|
109
110
|
export function _by(items, mapper) {
|
|
110
|
-
|
|
111
|
+
const map = {};
|
|
112
|
+
for (let i = 0; i < items.length; i++) {
|
|
113
|
+
const v = items[i];
|
|
114
|
+
const k = mapper(v);
|
|
115
|
+
if (k !== undefined) {
|
|
116
|
+
map[k] = v;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return map;
|
|
111
120
|
}
|
|
112
121
|
/**
|
|
113
122
|
* Map an array of items by a key, that is calculated by a Mapper.
|
|
114
123
|
*/
|
|
115
124
|
export function _mapBy(items, mapper) {
|
|
116
|
-
|
|
125
|
+
const map = new Map();
|
|
126
|
+
for (let i = 0; i < items.length; i++) {
|
|
127
|
+
const item = items[i];
|
|
128
|
+
const key = mapper(item);
|
|
129
|
+
if (key !== undefined) {
|
|
130
|
+
map.set(key, item);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return map;
|
|
117
134
|
}
|
|
118
135
|
/**
|
|
119
136
|
* const a = [1, 2, 3, 4, 5]
|
|
@@ -128,11 +145,13 @@ export function _mapBy(items, mapper) {
|
|
|
128
145
|
*/
|
|
129
146
|
export function _groupBy(items, mapper) {
|
|
130
147
|
const map = {};
|
|
131
|
-
for (
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
148
|
+
for (let i = 0; i < items.length; i++) {
|
|
149
|
+
const item = items[i];
|
|
150
|
+
const key = mapper(item);
|
|
151
|
+
if (key !== undefined) {
|
|
152
|
+
;
|
|
153
|
+
(map[key] ||= []).push(item);
|
|
154
|
+
}
|
|
136
155
|
}
|
|
137
156
|
return map;
|
|
138
157
|
}
|
|
@@ -143,28 +162,30 @@ export function _groupBy(items, mapper) {
|
|
|
143
162
|
* Same:
|
|
144
163
|
* _sortBy([{age: 20}, {age: 10}], o => o.age)
|
|
145
164
|
*/
|
|
146
|
-
export function _sortBy(items, mapper,
|
|
147
|
-
const mod = dir === 'desc' ? -1 : 1;
|
|
148
|
-
return (mutate ? items : [...items]).sort((_a, _b) => {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
165
|
+
export function _sortBy(items, mapper, opt = {}) {
|
|
166
|
+
const mod = opt.dir === 'desc' ? -1 : 1;
|
|
167
|
+
return (opt.mutate ? items : [...items]).sort((_a, _b) => {
|
|
168
|
+
// This implementation may call mapper more than once per item,
|
|
169
|
+
// but the benchmarks show no significant difference in performance.
|
|
170
|
+
const a = mapper(_a);
|
|
171
|
+
const b = mapper(_b);
|
|
172
|
+
// if (typeof a === 'number' && typeof b === 'number') return (a - b) * mod
|
|
173
|
+
// return String(a).localeCompare(String(b)) * mod
|
|
174
|
+
if (a > b)
|
|
175
|
+
return mod;
|
|
176
|
+
if (a < b)
|
|
177
|
+
return -mod;
|
|
178
|
+
return 0;
|
|
153
179
|
});
|
|
154
180
|
}
|
|
155
|
-
/**
|
|
156
|
-
* Alias for _sortBy with descending order.
|
|
157
|
-
*/
|
|
158
|
-
export function _sortDescBy(items, mapper, mutate = false) {
|
|
159
|
-
return _sortBy(items, mapper, mutate, 'desc');
|
|
160
|
-
}
|
|
161
181
|
/**
|
|
162
182
|
* Similar to `Array.find`, but the `predicate` may return `END` to stop the iteration early.
|
|
163
183
|
*
|
|
164
184
|
* Use `Array.find` if you don't need to stop the iteration early.
|
|
165
185
|
*/
|
|
166
186
|
export function _find(items, predicate) {
|
|
167
|
-
for (
|
|
187
|
+
for (let i = 0; i < items.length; i++) {
|
|
188
|
+
const item = items[i];
|
|
168
189
|
const result = predicate(item, i);
|
|
169
190
|
if (result === END)
|
|
170
191
|
return;
|
|
@@ -241,9 +262,8 @@ export function _count(items, predicate, limit) {
|
|
|
241
262
|
}
|
|
242
263
|
export function _countBy(items, mapper) {
|
|
243
264
|
const map = {};
|
|
244
|
-
let i = 0;
|
|
245
265
|
for (const item of items) {
|
|
246
|
-
const key = mapper(item
|
|
266
|
+
const key = mapper(item);
|
|
247
267
|
map[key] = (map[key] || 0) + 1;
|
|
248
268
|
}
|
|
249
269
|
return map;
|
|
@@ -301,9 +321,8 @@ export function _sum(items) {
|
|
|
301
321
|
}
|
|
302
322
|
export function _sumBy(items, mapper) {
|
|
303
323
|
let sum = 0;
|
|
304
|
-
let i = 0;
|
|
305
324
|
for (const n of items) {
|
|
306
|
-
const v = mapper(n
|
|
325
|
+
const v = mapper(n);
|
|
307
326
|
if (typeof v === 'number') {
|
|
308
327
|
// count only numbers, nothing else
|
|
309
328
|
sum = (sum + v);
|
|
@@ -339,8 +358,8 @@ export function _mapToObject(array, mapper) {
|
|
|
339
358
|
* Fisher–Yates algorithm.
|
|
340
359
|
* Based on: https://stackoverflow.com/a/12646864/4919972
|
|
341
360
|
*/
|
|
342
|
-
export function _shuffle(array,
|
|
343
|
-
const a = mutate ? array : [...array];
|
|
361
|
+
export function _shuffle(array, opt = {}) {
|
|
362
|
+
const a = opt.mutate ? array : [...array];
|
|
344
363
|
for (let i = a.length - 1; i > 0; i--) {
|
|
345
364
|
const j = Math.floor(Math.random() * (i + 1));
|
|
346
365
|
[a[i], a[j]] = [a[j], a[i]];
|
|
@@ -425,8 +444,9 @@ export function _maxByOrUndefined(array, mapper) {
|
|
|
425
444
|
return;
|
|
426
445
|
let maxItem;
|
|
427
446
|
let max;
|
|
428
|
-
for (
|
|
429
|
-
const
|
|
447
|
+
for (let i = 0; i < array.length; i++) {
|
|
448
|
+
const item = array[i];
|
|
449
|
+
const v = mapper(item);
|
|
430
450
|
if (v !== undefined && (max === undefined || v > max)) {
|
|
431
451
|
maxItem = item;
|
|
432
452
|
max = v;
|
|
@@ -439,8 +459,9 @@ export function _minByOrUndefined(array, mapper) {
|
|
|
439
459
|
return;
|
|
440
460
|
let minItem;
|
|
441
461
|
let min;
|
|
442
|
-
for (
|
|
443
|
-
const
|
|
462
|
+
for (let i = 0; i < array.length; i++) {
|
|
463
|
+
const item = array[i];
|
|
464
|
+
const v = mapper(item);
|
|
444
465
|
if (v !== undefined && (min === undefined || v < min)) {
|
|
445
466
|
minItem = item;
|
|
446
467
|
min = v;
|
package/dist/array/range.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ export declare function _range(fromIncl: Integer, toExcl: Integer, step?: number
|
|
|
22
22
|
* Fill is Primitive, because it's safe to shallow-copy.
|
|
23
23
|
* If it was an object - it'll paste the same object reference, which can create bugs.
|
|
24
24
|
*/
|
|
25
|
-
export declare function
|
|
25
|
+
export declare function _arrayFilled<T extends Primitive>(length: Integer, fill: T): T[];
|
|
26
26
|
/**
|
|
27
27
|
* Like _range, but returns an Iterable2.
|
|
28
28
|
*/
|
package/dist/array/range.js
CHANGED
|
@@ -19,7 +19,7 @@ export function _range(fromIncl, toExcl, step = 1) {
|
|
|
19
19
|
* Fill is Primitive, because it's safe to shallow-copy.
|
|
20
20
|
* If it was an object - it'll paste the same object reference, which can create bugs.
|
|
21
21
|
*/
|
|
22
|
-
export function
|
|
22
|
+
export function _arrayFilled(length, fill) {
|
|
23
23
|
// biome-ignore lint/style/useConsistentBuiltinInstantiation: ok
|
|
24
24
|
return Array(length).fill(fill);
|
|
25
25
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { Inclusiveness } from '../types.js';
|
|
2
1
|
import type { LocalDate, LocalDateInput, LocalDateUnit } from './localDate.js';
|
|
3
2
|
export type DateIntervalConfig = DateInterval | DateIntervalString;
|
|
4
3
|
export type DateIntervalString = string;
|
|
@@ -24,18 +23,18 @@ export declare class DateInterval {
|
|
|
24
23
|
/**
|
|
25
24
|
* Ranges of DateInterval (start, end) are INCLUSIVE.
|
|
26
25
|
*/
|
|
27
|
-
includes(d: LocalDateInput
|
|
28
|
-
intersects(int: DateIntervalConfig
|
|
26
|
+
includes(d: LocalDateInput): boolean;
|
|
27
|
+
intersects(int: DateIntervalConfig): boolean;
|
|
29
28
|
/**
|
|
30
29
|
* DateIntervals compare by start date.
|
|
31
30
|
* If it's the same - then by end date.
|
|
32
31
|
*/
|
|
33
32
|
cmp(d: DateIntervalConfig): -1 | 0 | 1;
|
|
34
|
-
getDays(
|
|
33
|
+
getDays(): LocalDate[];
|
|
35
34
|
/**
|
|
36
35
|
* Returns an array of LocalDates that are included in the interval.
|
|
37
36
|
*/
|
|
38
|
-
range(
|
|
37
|
+
range(step?: number, stepUnit?: LocalDateUnit): LocalDate[];
|
|
39
38
|
toString(): DateIntervalString;
|
|
40
39
|
toJSON(): DateIntervalString;
|
|
41
40
|
}
|
|
@@ -46,15 +46,12 @@ export class DateInterval {
|
|
|
46
46
|
/**
|
|
47
47
|
* Ranges of DateInterval (start, end) are INCLUSIVE.
|
|
48
48
|
*/
|
|
49
|
-
includes(d
|
|
50
|
-
|
|
51
|
-
// eslint-disable-next-line @typescript-eslint/prefer-string-starts-ends-with
|
|
52
|
-
return d.isAfter(this.start, incl[0] === '[') && d.isBefore(this.end, incl[1] === ']');
|
|
49
|
+
includes(d) {
|
|
50
|
+
return localDate(d).isBetween(this.start, this.end, '[]');
|
|
53
51
|
}
|
|
54
|
-
intersects(int
|
|
52
|
+
intersects(int) {
|
|
55
53
|
const $int = DateInterval.parse(int);
|
|
56
|
-
|
|
57
|
-
return this.includes($int.start, incl) || this.includes($int.end, incl);
|
|
54
|
+
return this.includes($int.start) || this.includes($int.end);
|
|
58
55
|
}
|
|
59
56
|
/**
|
|
60
57
|
* DateIntervals compare by start date.
|
|
@@ -64,14 +61,14 @@ export class DateInterval {
|
|
|
64
61
|
d = DateInterval.parse(d);
|
|
65
62
|
return this.start.compare(d.start) || this.end.compare(d.end);
|
|
66
63
|
}
|
|
67
|
-
getDays(
|
|
68
|
-
return localDate.range(this.start, this.end,
|
|
64
|
+
getDays() {
|
|
65
|
+
return localDate.range(this.start, this.end, '[]', 1, 'day');
|
|
69
66
|
}
|
|
70
67
|
/**
|
|
71
68
|
* Returns an array of LocalDates that are included in the interval.
|
|
72
69
|
*/
|
|
73
|
-
range(
|
|
74
|
-
return localDate.range(this.start, this.end,
|
|
70
|
+
range(step = 1, stepUnit = 'day') {
|
|
71
|
+
return localDate.range(this.start, this.end, '[]', step, stepUnit);
|
|
75
72
|
}
|
|
76
73
|
toString() {
|
|
77
74
|
return [this.start, this.end].join('/');
|
|
@@ -38,7 +38,7 @@ export declare class LocalDate {
|
|
|
38
38
|
isSameOrBefore(d: LocalDateInput): boolean;
|
|
39
39
|
isAfter(d: LocalDateInput, inclusive?: boolean): boolean;
|
|
40
40
|
isSameOrAfter(d: LocalDateInput): boolean;
|
|
41
|
-
isBetween(min: LocalDateInput, max: LocalDateInput, incl
|
|
41
|
+
isBetween(min: LocalDateInput, max: LocalDateInput, incl: Inclusiveness): boolean;
|
|
42
42
|
/**
|
|
43
43
|
* Checks if this localDate is older (<) than "today" by X units.
|
|
44
44
|
*
|
|
@@ -269,12 +269,12 @@ declare class LocalDateFactory {
|
|
|
269
269
|
* Returns the range (array) of LocalDates between min and max.
|
|
270
270
|
* By default, min is included, max is excluded.
|
|
271
271
|
*/
|
|
272
|
-
range(min: LocalDateInput, max: LocalDateInput, incl
|
|
272
|
+
range(min: LocalDateInput, max: LocalDateInput, incl: Inclusiveness, step?: number, stepUnit?: LocalDateUnit): LocalDate[];
|
|
273
273
|
/**
|
|
274
274
|
* Returns the Iterable2 of LocalDates between min and max.
|
|
275
275
|
* By default, min is included, max is excluded.
|
|
276
276
|
*/
|
|
277
|
-
rangeIterable(min: LocalDateInput, max: LocalDateInput, incl
|
|
277
|
+
rangeIterable(min: LocalDateInput, max: LocalDateInput, incl: Inclusiveness, step?: number, stepUnit?: LocalDateUnit): Iterable2<LocalDate>;
|
|
278
278
|
getYearLength(year: number): number;
|
|
279
279
|
getMonthLength(year: number, month: number): number;
|
|
280
280
|
isLeapYear(year: number): boolean;
|
|
@@ -88,10 +88,9 @@ export class LocalDate {
|
|
|
88
88
|
isSameOrAfter(d) {
|
|
89
89
|
return this.compare(d) >= 0;
|
|
90
90
|
}
|
|
91
|
-
isBetween(min, max, incl
|
|
91
|
+
isBetween(min, max, incl) {
|
|
92
92
|
let r = this.compare(min);
|
|
93
|
-
|
|
94
|
-
if (r < 0 || (r === 0 && incl[0] === '('))
|
|
93
|
+
if (r < 0)
|
|
95
94
|
return false;
|
|
96
95
|
r = this.compare(max);
|
|
97
96
|
if (r > 0 || (r === 0 && incl[1] === ')'))
|
|
@@ -669,14 +668,14 @@ class LocalDateFactory {
|
|
|
669
668
|
* Returns the range (array) of LocalDates between min and max.
|
|
670
669
|
* By default, min is included, max is excluded.
|
|
671
670
|
*/
|
|
672
|
-
range(min, max, incl
|
|
671
|
+
range(min, max, incl, step = 1, stepUnit = 'day') {
|
|
673
672
|
return this.rangeIterable(min, max, incl, step, stepUnit).toArray();
|
|
674
673
|
}
|
|
675
674
|
/**
|
|
676
675
|
* Returns the Iterable2 of LocalDates between min and max.
|
|
677
676
|
* By default, min is included, max is excluded.
|
|
678
677
|
*/
|
|
679
|
-
rangeIterable(min, max, incl
|
|
678
|
+
rangeIterable(min, max, incl, step = 1, stepUnit = 'day') {
|
|
680
679
|
if (stepUnit === 'week') {
|
|
681
680
|
step *= 7;
|
|
682
681
|
stepUnit = 'day';
|
|
@@ -684,8 +683,7 @@ class LocalDateFactory {
|
|
|
684
683
|
const $min = this.fromInput(min).startOf(stepUnit);
|
|
685
684
|
const $max = this.fromInput(max).startOf(stepUnit);
|
|
686
685
|
let value = $min;
|
|
687
|
-
|
|
688
|
-
if (value.isAfter($min, incl[0] === '[')) {
|
|
686
|
+
if (value.isSameOrAfter($min)) {
|
|
689
687
|
// ok
|
|
690
688
|
}
|
|
691
689
|
else {
|
|
@@ -148,7 +148,7 @@ export declare class LocalTime {
|
|
|
148
148
|
isSameOrBefore(d: LocalTimeInput): boolean;
|
|
149
149
|
isAfter(d: LocalTimeInput, inclusive?: boolean): boolean;
|
|
150
150
|
isSameOrAfter(d: LocalTimeInput): boolean;
|
|
151
|
-
isBetween(min: LocalTimeInput, max: LocalTimeInput, incl
|
|
151
|
+
isBetween(min: LocalTimeInput, max: LocalTimeInput, incl: Inclusiveness): boolean;
|
|
152
152
|
/**
|
|
153
153
|
* Checks if this localTime is older (<) than "now" by X units.
|
|
154
154
|
*
|
|
@@ -426,10 +426,9 @@ export class LocalTime {
|
|
|
426
426
|
isSameOrAfter(d) {
|
|
427
427
|
return this.compare(d) >= 0;
|
|
428
428
|
}
|
|
429
|
-
isBetween(min, max, incl
|
|
429
|
+
isBetween(min, max, incl) {
|
|
430
430
|
let r = this.compare(min);
|
|
431
|
-
|
|
432
|
-
if (r < 0 || (r === 0 && incl[0] === '('))
|
|
431
|
+
if (r < 0)
|
|
433
432
|
return false;
|
|
434
433
|
r = this.compare(max);
|
|
435
434
|
if (r > 0 || (r === 0 && incl[1] === ')'))
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { UnixTimestamp } from '../types.js';
|
|
2
2
|
import type { LocalTime, LocalTimeInput } from './localTime.js';
|
|
3
3
|
export type TimeIntervalConfig = TimeInterval | TimeIntervalString;
|
|
4
4
|
export type TimeIntervalString = string;
|
|
@@ -26,7 +26,7 @@ export declare class TimeInterval {
|
|
|
26
26
|
isSameOrBefore(d: TimeIntervalConfig): boolean;
|
|
27
27
|
isAfter(d: TimeIntervalConfig, inclusive?: boolean): boolean;
|
|
28
28
|
isSameOrAfter(d: TimeIntervalConfig): boolean;
|
|
29
|
-
includes(d: LocalTimeInput
|
|
29
|
+
includes(d: LocalTimeInput): boolean;
|
|
30
30
|
/**
|
|
31
31
|
* TimeIntervals compare by start date.
|
|
32
32
|
* If it's the same - then by end date.
|
|
@@ -56,12 +56,11 @@ export class TimeInterval {
|
|
|
56
56
|
isSameOrAfter(d) {
|
|
57
57
|
return this.cmp(d) >= 0;
|
|
58
58
|
}
|
|
59
|
-
includes(d
|
|
59
|
+
includes(d) {
|
|
60
60
|
d = localTime.fromInput(d).unix;
|
|
61
|
-
|
|
62
|
-
if (d < this.$start || (d === this.$start && incl[0] === '('))
|
|
61
|
+
if (d < this.$start)
|
|
63
62
|
return false;
|
|
64
|
-
if (d > this.$end
|
|
63
|
+
if (d > this.$end)
|
|
65
64
|
return false;
|
|
66
65
|
return true;
|
|
67
66
|
}
|
package/dist/http/fetcher.js
CHANGED
|
@@ -668,7 +668,7 @@ export class Fetcher {
|
|
|
668
668
|
}),
|
|
669
669
|
};
|
|
670
670
|
// Because all header values are stringified, so `a: undefined` becomes `undefined` as a string
|
|
671
|
-
_filterNullishValues(req.init.headers, true);
|
|
671
|
+
_filterNullishValues(req.init.headers, { mutate: true });
|
|
672
672
|
// setup url
|
|
673
673
|
const baseUrl = opt.baseUrl || this.cfg.baseUrl;
|
|
674
674
|
if (baseUrl) {
|
|
@@ -23,5 +23,5 @@ export function mergeJsonSchemaObjects(s1, s2) {
|
|
|
23
23
|
s1.required.push(...s2.required);
|
|
24
24
|
s1.required = _uniq(s1.required).sort();
|
|
25
25
|
// `additionalProperties` remains the same
|
|
26
|
-
return _filterNullishValues(s1, true);
|
|
26
|
+
return _filterNullishValues(s1, { mutate: true });
|
|
27
27
|
}
|
package/dist/math/math.util.js
CHANGED
|
@@ -27,7 +27,6 @@ export function _averageOrNull(values) {
|
|
|
27
27
|
export function _averageWeighted(values, weights) {
|
|
28
28
|
let numerator = 0;
|
|
29
29
|
let denominator = 0;
|
|
30
|
-
// eslint-disable-next-line unicorn/no-for-loop
|
|
31
30
|
for (let i = 0; i < values.length; i++) {
|
|
32
31
|
numerator += values[i] * weights[i];
|
|
33
32
|
denominator += weights[i];
|
|
@@ -26,7 +26,7 @@ export declare function _runLessOften(percent: number): boolean;
|
|
|
26
26
|
* Also works with strings:
|
|
27
27
|
* _isBetween('2020-01-03', '2020-01-01', '2020-01-05') // true
|
|
28
28
|
*/
|
|
29
|
-
export declare function _isBetween<T extends number | string>(x: T, min: T, max: T, incl
|
|
29
|
+
export declare function _isBetween<T extends number | string>(x: T, min: T, max: T, incl: Inclusiveness): boolean;
|
|
30
30
|
export declare function _clamp(x: number, minIncl: number, maxIncl: number): number;
|
|
31
31
|
/**
|
|
32
32
|
* This function exists, because in JS you cannot just .sort() numbers,
|
|
@@ -32,17 +32,12 @@ export function _runLessOften(percent) {
|
|
|
32
32
|
* Also works with strings:
|
|
33
33
|
* _isBetween('2020-01-03', '2020-01-01', '2020-01-05') // true
|
|
34
34
|
*/
|
|
35
|
-
export function _isBetween(x, min, max, incl
|
|
36
|
-
if (
|
|
37
|
-
return
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
if (incl === '(]') {
|
|
43
|
-
return x > min && x <= max;
|
|
44
|
-
}
|
|
45
|
-
return x > min && x < max;
|
|
35
|
+
export function _isBetween(x, min, max, incl) {
|
|
36
|
+
if (x < min || x > max)
|
|
37
|
+
return false;
|
|
38
|
+
if (x === max && incl === '[)')
|
|
39
|
+
return false;
|
|
40
|
+
return true;
|
|
46
41
|
}
|
|
47
42
|
export function _clamp(x, minIncl, maxIncl) {
|
|
48
43
|
// eslint-disable-next-line unicorn/prefer-math-min-max
|
|
@@ -1,25 +1,26 @@
|
|
|
1
|
+
import type { MutateOptions } from '../array/array.util.js';
|
|
1
2
|
import type { AnyObject, KeyValueTuple, ObjectMapper, ObjectPredicate, Reviver, ValueOf } from '../types.js';
|
|
2
3
|
import { SKIP } from '../types.js';
|
|
3
4
|
/**
|
|
4
5
|
* Returns clone of `obj` with only `props` preserved.
|
|
5
6
|
* Opposite of Omit.
|
|
6
7
|
*/
|
|
7
|
-
export declare function _pick<T extends AnyObject, K extends keyof T>(obj: T, props: readonly K[],
|
|
8
|
+
export declare function _pick<T extends AnyObject, K extends keyof T>(obj: T, props: readonly K[], opt?: MutateOptions): T;
|
|
8
9
|
/**
|
|
9
10
|
* Sets all properties of an object except passed ones to `undefined`.
|
|
10
11
|
* This is a more performant alternative to `_pick` that does picking/deleting.
|
|
11
12
|
*/
|
|
12
|
-
export declare function _pickWithUndefined<T extends AnyObject, K extends keyof T>(obj: T, props: readonly K[],
|
|
13
|
+
export declare function _pickWithUndefined<T extends AnyObject, K extends keyof T>(obj: T, props: readonly K[], opt?: MutateOptions): T;
|
|
13
14
|
/**
|
|
14
15
|
* Returns clone of `obj` with `props` omitted.
|
|
15
16
|
* Opposite of Pick.
|
|
16
17
|
*/
|
|
17
|
-
export declare function _omit<T extends AnyObject, K extends keyof T>(obj: T, props: readonly K[],
|
|
18
|
+
export declare function _omit<T extends AnyObject, K extends keyof T>(obj: T, props: readonly K[], opt?: MutateOptions): T;
|
|
18
19
|
/**
|
|
19
20
|
* Sets all passed properties of an object to `undefined`.
|
|
20
21
|
* This is a more performant alternative to `_omit` that does picking/deleting.
|
|
21
22
|
*/
|
|
22
|
-
export declare function _omitWithUndefined<T extends AnyObject, K extends keyof T>(obj: T, props: readonly K[],
|
|
23
|
+
export declare function _omitWithUndefined<T extends AnyObject, K extends keyof T>(obj: T, props: readonly K[], opt?: MutateOptions): T;
|
|
23
24
|
/**
|
|
24
25
|
* Returns object with filtered keys from `props` array.
|
|
25
26
|
* E.g:
|
|
@@ -28,26 +29,26 @@ export declare function _omitWithUndefined<T extends AnyObject, K extends keyof
|
|
|
28
29
|
* 'account.updated',
|
|
29
30
|
* ])
|
|
30
31
|
*/
|
|
31
|
-
export declare function _mask<T extends AnyObject>(obj: T, props: string[],
|
|
32
|
+
export declare function _mask<T extends AnyObject>(obj: T, props: string[], opt?: MutateOptions): T;
|
|
32
33
|
/**
|
|
33
34
|
* Removes "falsy" values from the object.
|
|
34
35
|
*/
|
|
35
|
-
export declare function _filterFalsyValues<T extends AnyObject>(obj: T,
|
|
36
|
+
export declare function _filterFalsyValues<T extends AnyObject>(obj: T, opt?: MutateOptions): T;
|
|
36
37
|
/**
|
|
37
38
|
* Removes values from the object that are `null` or `undefined`.
|
|
38
39
|
*/
|
|
39
|
-
export declare function _filterNullishValues<T extends AnyObject>(obj: T,
|
|
40
|
+
export declare function _filterNullishValues<T extends AnyObject>(obj: T, opt?: MutateOptions): T;
|
|
40
41
|
/**
|
|
41
42
|
* Removes values from the object that are `undefined`.
|
|
42
43
|
* Only `undefined` values are removed. `null` values are kept!
|
|
43
44
|
*/
|
|
44
|
-
export declare function _filterUndefinedValues<T extends AnyObject>(obj: T,
|
|
45
|
-
export declare function _filterEmptyArrays<T extends AnyObject>(obj: T,
|
|
45
|
+
export declare function _filterUndefinedValues<T extends AnyObject>(obj: T, opt?: MutateOptions): T;
|
|
46
|
+
export declare function _filterEmptyArrays<T extends AnyObject>(obj: T, opt?: MutateOptions): T;
|
|
46
47
|
/**
|
|
47
48
|
* Returns clone of `obj` without properties that does not pass `predicate`.
|
|
48
49
|
* Allows filtering by both key and value.
|
|
49
50
|
*/
|
|
50
|
-
export declare function _filterObject<T extends AnyObject>(obj: T, predicate: ObjectPredicate<T>,
|
|
51
|
+
export declare function _filterObject<T extends AnyObject>(obj: T, predicate: ObjectPredicate<T>, opt?: MutateOptions): T;
|
|
51
52
|
/**
|
|
52
53
|
* var users = {
|
|
53
54
|
* 'fred': { 'user': 'fred', 'age': 40 },
|
|
@@ -59,7 +60,7 @@ export declare function _filterObject<T extends AnyObject>(obj: T, predicate: Ob
|
|
|
59
60
|
*
|
|
60
61
|
* To skip some key-value pairs - use _mapObject instead.
|
|
61
62
|
*/
|
|
62
|
-
export declare function _mapValues<OUT = unknown, IN extends AnyObject = AnyObject>(obj: IN, mapper: ObjectMapper<IN, any>,
|
|
63
|
+
export declare function _mapValues<OUT = unknown, IN extends AnyObject = AnyObject>(obj: IN, mapper: ObjectMapper<IN, any>, opt?: MutateOptions): OUT;
|
|
63
64
|
/**
|
|
64
65
|
* _.mapKeys({ 'a': 1, 'b': 2 }, (key, value) => key + value)
|
|
65
66
|
* // => { 'a1': 1, 'b2': 2 }
|
|
@@ -87,7 +88,7 @@ export declare function _mapKeys<T extends AnyObject>(obj: T, mapper: ObjectMapp
|
|
|
87
88
|
*/
|
|
88
89
|
export declare function _mapObject<OUT = unknown, IN extends AnyObject = AnyObject>(obj: IN, mapper: ObjectMapper<IN, KeyValueTuple<string, any> | typeof SKIP>): OUT;
|
|
89
90
|
export declare function _findKeyByValue<T extends AnyObject>(obj: T, v: ValueOf<T>): keyof T | undefined;
|
|
90
|
-
export declare function _objectNullValuesToUndefined<T extends AnyObject>(obj: T,
|
|
91
|
+
export declare function _objectNullValuesToUndefined<T extends AnyObject>(obj: T, opt?: MutateOptions): T;
|
|
91
92
|
/**
|
|
92
93
|
* Deep copy object (by json parse/stringify, since it has unbeatable performance+simplicity combo).
|
|
93
94
|
*/
|
|
@@ -100,7 +101,7 @@ export declare function _undefinedIfEmpty<T>(obj: T | undefined): T | undefined;
|
|
|
100
101
|
/**
|
|
101
102
|
* Filters the object by removing all key-value pairs where Value is Empty (according to _isEmpty() specification).
|
|
102
103
|
*/
|
|
103
|
-
export declare function _filterEmptyValues<T extends AnyObject>(obj: T,
|
|
104
|
+
export declare function _filterEmptyValues<T extends AnyObject>(obj: T, opt?: MutateOptions): T;
|
|
104
105
|
/**
|
|
105
106
|
* Recursively merges own and inherited enumerable properties of source
|
|
106
107
|
* objects into the destination object, skipping source properties that resolve
|