@naturalcycles/js-lib 15.8.1 → 15.9.1
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/datetime/dateInterval.d.ts +4 -5
- package/dist/datetime/dateInterval.js +8 -11
- package/dist/datetime/localDate.d.ts +9 -8
- package/dist/datetime/localDate.js +15 -17
- package/dist/datetime/localTime.d.ts +9 -8
- package/dist/datetime/localTime.js +35 -36
- 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/log/commonLogger.d.ts +2 -1
- package/dist/log/commonLogger.js +2 -3
- package/dist/math/math.util.js +0 -1
- package/dist/number/number.util.d.ts +4 -3
- package/dist/number/number.util.js +9 -14
- package/dist/object/object.util.d.ts +14 -13
- package/dist/object/object.util.js +26 -26
- package/dist/semver.d.ts +2 -2
- package/dist/semver.js +3 -3
- 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/datetime/dateInterval.ts +9 -12
- package/src/datetime/localDate.ts +17 -18
- package/src/datetime/localTime.ts +36 -36
- 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/log/commonLogger.ts +4 -2
- package/src/math/math.util.ts +0 -1
- package/src/number/number.util.ts +9 -19
- package/src/object/object.util.ts +30 -26
- package/src/semver.ts +4 -4
- package/src/types.ts +11 -6
|
@@ -146,8 +146,8 @@ export class LocalTime {
|
|
|
146
146
|
// second
|
|
147
147
|
return this.$date.getSeconds();
|
|
148
148
|
}
|
|
149
|
-
set(unit, v,
|
|
150
|
-
const t = mutate ? this : this.clone();
|
|
149
|
+
set(unit, v, opt = {}) {
|
|
150
|
+
const t = opt.mutate ? this : this.clone();
|
|
151
151
|
if (unit === 'year') {
|
|
152
152
|
t.$date.setFullYear(v);
|
|
153
153
|
}
|
|
@@ -167,7 +167,7 @@ export class LocalTime {
|
|
|
167
167
|
t.$date.setSeconds(v);
|
|
168
168
|
}
|
|
169
169
|
else if (unit === 'week') {
|
|
170
|
-
setWeek(t.$date, v, true);
|
|
170
|
+
setWeek(t.$date, v, { mutate: true });
|
|
171
171
|
}
|
|
172
172
|
return t;
|
|
173
173
|
}
|
|
@@ -241,8 +241,8 @@ export class LocalTime {
|
|
|
241
241
|
delta += 7;
|
|
242
242
|
return this.plus(delta, 'day');
|
|
243
243
|
}
|
|
244
|
-
setComponents(c,
|
|
245
|
-
const d = mutate ? this.$date : new Date(this.$date);
|
|
244
|
+
setComponents(c, opt = {}) {
|
|
245
|
+
const d = opt.mutate ? this.$date : new Date(this.$date);
|
|
246
246
|
// Year, month and day set all-at-once, to avoid 30/31 (and 28/29) mishap
|
|
247
247
|
if (c.day || c.month !== undefined || c.year !== undefined) {
|
|
248
248
|
d.setFullYear(c.year ?? d.getFullYear(), c.month ? c.month - 1 : d.getMonth(), c.day || d.getDate());
|
|
@@ -256,7 +256,7 @@ export class LocalTime {
|
|
|
256
256
|
if (c.second !== undefined) {
|
|
257
257
|
d.setSeconds(c.second);
|
|
258
258
|
}
|
|
259
|
-
return mutate ? this : new LocalTime(d);
|
|
259
|
+
return opt.mutate ? this : new LocalTime(d);
|
|
260
260
|
}
|
|
261
261
|
plusSeconds(num) {
|
|
262
262
|
return this.plus(num, 'second');
|
|
@@ -300,19 +300,19 @@ export class LocalTime {
|
|
|
300
300
|
minusYears(num) {
|
|
301
301
|
return this.plus(-num, 'year');
|
|
302
302
|
}
|
|
303
|
-
plus(num, unit,
|
|
303
|
+
plus(num, unit, opt = {}) {
|
|
304
304
|
if (unit === 'week') {
|
|
305
305
|
num *= 7;
|
|
306
306
|
unit = 'day';
|
|
307
307
|
}
|
|
308
308
|
if (unit === 'year' || unit === 'month') {
|
|
309
|
-
const d = addMonths(this.$date, unit === 'month' ? num : num * 12,
|
|
310
|
-
return mutate ? this : localTime.fromInput(d);
|
|
309
|
+
const d = addMonths(this.$date, unit === 'month' ? num : num * 12, opt);
|
|
310
|
+
return opt.mutate ? this : localTime.fromInput(d);
|
|
311
311
|
}
|
|
312
|
-
return this.set(unit, this.get(unit) + num,
|
|
312
|
+
return this.set(unit, this.get(unit) + num, opt);
|
|
313
313
|
}
|
|
314
|
-
minus(num, unit,
|
|
315
|
-
return this.plus(num * -1, unit,
|
|
314
|
+
minus(num, unit, opt = {}) {
|
|
315
|
+
return this.plus(num * -1, unit, opt);
|
|
316
316
|
}
|
|
317
317
|
absDiff(other, unit) {
|
|
318
318
|
return Math.abs(this.diff(other, unit));
|
|
@@ -348,10 +348,10 @@ export class LocalTime {
|
|
|
348
348
|
// `|| 0` is to avoid returning -0
|
|
349
349
|
return Math.trunc(r) || 0;
|
|
350
350
|
}
|
|
351
|
-
startOf(unit,
|
|
351
|
+
startOf(unit, opt = {}) {
|
|
352
352
|
if (unit === 'second')
|
|
353
353
|
return this;
|
|
354
|
-
const d = mutate ? this.$date : new Date(this.$date);
|
|
354
|
+
const d = opt.mutate ? this.$date : new Date(this.$date);
|
|
355
355
|
d.setSeconds(0, 0);
|
|
356
356
|
if (unit !== 'minute') {
|
|
357
357
|
d.setMinutes(0);
|
|
@@ -368,17 +368,17 @@ export class LocalTime {
|
|
|
368
368
|
}
|
|
369
369
|
else {
|
|
370
370
|
// week
|
|
371
|
-
startOfWeek(d, true);
|
|
371
|
+
startOfWeek(d, { mutate: true });
|
|
372
372
|
}
|
|
373
373
|
}
|
|
374
374
|
}
|
|
375
375
|
}
|
|
376
|
-
return mutate ? this : new LocalTime(d);
|
|
376
|
+
return opt.mutate ? this : new LocalTime(d);
|
|
377
377
|
}
|
|
378
|
-
endOf(unit,
|
|
378
|
+
endOf(unit, opt = {}) {
|
|
379
379
|
if (unit === 'second')
|
|
380
380
|
return this;
|
|
381
|
-
const d = mutate ? this.$date : new Date(this.$date);
|
|
381
|
+
const d = opt.mutate ? this.$date : new Date(this.$date);
|
|
382
382
|
d.setSeconds(59, 0);
|
|
383
383
|
if (unit !== 'minute') {
|
|
384
384
|
d.setMinutes(59);
|
|
@@ -390,7 +390,7 @@ export class LocalTime {
|
|
|
390
390
|
d.setMonth(11);
|
|
391
391
|
}
|
|
392
392
|
if (unit === 'week') {
|
|
393
|
-
endOfWeek(d, true);
|
|
393
|
+
endOfWeek(d, { mutate: true });
|
|
394
394
|
}
|
|
395
395
|
else {
|
|
396
396
|
// year or month
|
|
@@ -400,7 +400,7 @@ export class LocalTime {
|
|
|
400
400
|
}
|
|
401
401
|
}
|
|
402
402
|
}
|
|
403
|
-
return mutate ? this : new LocalTime(d);
|
|
403
|
+
return opt.mutate ? this : new LocalTime(d);
|
|
404
404
|
}
|
|
405
405
|
/**
|
|
406
406
|
* Returns how many days are in the current month.
|
|
@@ -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] === ')'))
|
|
@@ -857,9 +856,9 @@ class LocalTimeFactory {
|
|
|
857
856
|
return true; // we deliberately consider UTC a valid timezone, while it's mostly used in testing
|
|
858
857
|
return Intl.supportedValuesOf('timeZone').includes(tz);
|
|
859
858
|
}
|
|
860
|
-
sort(items, dir = 'asc',
|
|
859
|
+
sort(items, dir = 'asc', opt = {}) {
|
|
861
860
|
const mod = dir === 'desc' ? -1 : 1;
|
|
862
|
-
return (mutate ? items : [...items]).sort((a, b) => {
|
|
861
|
+
return (opt.mutate ? items : [...items]).sort((a, b) => {
|
|
863
862
|
const v1 = a.$date.valueOf();
|
|
864
863
|
const v2 = b.$date.valueOf();
|
|
865
864
|
if (v1 === v2)
|
|
@@ -907,8 +906,8 @@ function getWeek(date) {
|
|
|
907
906
|
const diff = startOfWeek(date).getTime() - startOfWeekYear(date).getTime();
|
|
908
907
|
return Math.round(diff / MILLISECONDS_IN_WEEK) + 1;
|
|
909
908
|
}
|
|
910
|
-
function setWeek(date, week,
|
|
911
|
-
const d = mutate ? date : new Date(date);
|
|
909
|
+
function setWeek(date, week, opt = {}) {
|
|
910
|
+
const d = opt.mutate ? date : new Date(date);
|
|
912
911
|
const diff = getWeek(d) - week;
|
|
913
912
|
d.setDate(d.getDate() - diff * 7);
|
|
914
913
|
return d;
|
|
@@ -919,7 +918,7 @@ function startOfWeekYear(date) {
|
|
|
919
918
|
const fourthOfJanuary = new Date(0);
|
|
920
919
|
fourthOfJanuary.setFullYear(year, 0, 4);
|
|
921
920
|
fourthOfJanuary.setHours(0, 0, 0, 0);
|
|
922
|
-
return startOfWeek(fourthOfJanuary, true);
|
|
921
|
+
return startOfWeek(fourthOfJanuary, { mutate: true });
|
|
923
922
|
}
|
|
924
923
|
// based on: https://github.com/date-fns/date-fns/blob/fd6bb1a0bab143f2da068c05a9c562b9bee1357d/src/getISOWeekYear/index.ts
|
|
925
924
|
function getWeekYear(date) {
|
|
@@ -927,11 +926,11 @@ function getWeekYear(date) {
|
|
|
927
926
|
const fourthOfJanuaryOfNextYear = new Date(0);
|
|
928
927
|
fourthOfJanuaryOfNextYear.setFullYear(year + 1, 0, 4);
|
|
929
928
|
fourthOfJanuaryOfNextYear.setHours(0, 0, 0, 0);
|
|
930
|
-
const startOfNextYear = startOfWeek(fourthOfJanuaryOfNextYear, true);
|
|
929
|
+
const startOfNextYear = startOfWeek(fourthOfJanuaryOfNextYear, { mutate: true });
|
|
931
930
|
const fourthOfJanuaryOfThisYear = new Date(0);
|
|
932
931
|
fourthOfJanuaryOfThisYear.setFullYear(year, 0, 4);
|
|
933
932
|
fourthOfJanuaryOfThisYear.setHours(0, 0, 0, 0);
|
|
934
|
-
const startOfThisYear = startOfWeek(fourthOfJanuaryOfThisYear, true);
|
|
933
|
+
const startOfThisYear = startOfWeek(fourthOfJanuaryOfThisYear, { mutate: true });
|
|
935
934
|
if (date.getTime() >= startOfNextYear.getTime()) {
|
|
936
935
|
return year + 1;
|
|
937
936
|
}
|
|
@@ -941,8 +940,8 @@ function getWeekYear(date) {
|
|
|
941
940
|
return year - 1;
|
|
942
941
|
}
|
|
943
942
|
// based on: https://github.com/date-fns/date-fns/blob/fd6bb1a0bab143f2da068c05a9c562b9bee1357d/src/startOfWeek/index.ts
|
|
944
|
-
function startOfWeek(date,
|
|
945
|
-
const d = mutate ? date : new Date(date);
|
|
943
|
+
function startOfWeek(date, opt = {}) {
|
|
944
|
+
const d = opt.mutate ? date : new Date(date);
|
|
946
945
|
const day = d.getDay();
|
|
947
946
|
const diff = (day < weekStartsOn ? 7 : 0) + day - weekStartsOn;
|
|
948
947
|
d.setDate(d.getDate() - diff);
|
|
@@ -950,15 +949,15 @@ function startOfWeek(date, mutate = false) {
|
|
|
950
949
|
return d;
|
|
951
950
|
}
|
|
952
951
|
// based on: https://github.com/date-fns/date-fns/blob/master/src/endOfWeek/index.ts
|
|
953
|
-
function endOfWeek(date,
|
|
954
|
-
const d = mutate ? date : new Date(date);
|
|
952
|
+
function endOfWeek(date, opt = {}) {
|
|
953
|
+
const d = opt.mutate ? date : new Date(date);
|
|
955
954
|
const day = d.getDay();
|
|
956
955
|
const diff = (day < weekStartsOn ? -7 : 0) + 6 - (day - weekStartsOn);
|
|
957
956
|
d.setDate(d.getDate() + diff);
|
|
958
957
|
return d;
|
|
959
958
|
}
|
|
960
|
-
function addMonths(d, num,
|
|
961
|
-
if (!mutate)
|
|
959
|
+
function addMonths(d, num, opt = {}) {
|
|
960
|
+
if (!opt.mutate)
|
|
962
961
|
d = new Date(d);
|
|
963
962
|
let day = d.getDate();
|
|
964
963
|
let month = d.getMonth() + 1 + num;
|
|
@@ -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
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { MutateOptions } from '../array/array.util.js';
|
|
1
2
|
/**
|
|
2
3
|
* These levels follow console.* naming,
|
|
3
4
|
* so you can use console[level] safely.
|
|
@@ -38,7 +39,7 @@ export declare const commonLoggerNoop: CommonLogger;
|
|
|
38
39
|
/**
|
|
39
40
|
* Creates a "child" logger that is "limited" to the specified CommonLogLevel.
|
|
40
41
|
*/
|
|
41
|
-
export declare function commonLoggerMinLevel(logger: CommonLogger, minLevel: CommonLogLevel,
|
|
42
|
+
export declare function commonLoggerMinLevel(logger: CommonLogger, minLevel: CommonLogLevel, opt?: MutateOptions): CommonLogger;
|
|
42
43
|
/**
|
|
43
44
|
* Creates a "proxy" CommonLogger that pipes log messages to all provided sub-loggers.
|
|
44
45
|
*/
|
package/dist/log/commonLogger.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// copy-pasted to avoid weird circular dependency
|
|
2
1
|
const _noop = (..._args) => undefined;
|
|
3
2
|
export const commonLogLevelNumber = {
|
|
4
3
|
log: 10,
|
|
@@ -18,9 +17,9 @@ export const commonLoggerNoop = {
|
|
|
18
17
|
/**
|
|
19
18
|
* Creates a "child" logger that is "limited" to the specified CommonLogLevel.
|
|
20
19
|
*/
|
|
21
|
-
export function commonLoggerMinLevel(logger, minLevel,
|
|
20
|
+
export function commonLoggerMinLevel(logger, minLevel, opt = {}) {
|
|
22
21
|
const level = commonLogLevelNumber[minLevel];
|
|
23
|
-
if (mutate) {
|
|
22
|
+
if (opt.mutate) {
|
|
24
23
|
if (level > commonLogLevelNumber['log']) {
|
|
25
24
|
logger.log = _noop;
|
|
26
25
|
if (level > commonLogLevelNumber['warn']) {
|
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];
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { SortOptions } from '../array/array.util.js';
|
|
2
|
+
import type { Inclusiveness } from '../types.js';
|
|
2
3
|
export declare function _randomInt(minIncl: number, maxIncl: number): number;
|
|
3
4
|
/**
|
|
4
5
|
* Returns random item from an array.
|
|
@@ -26,7 +27,7 @@ export declare function _runLessOften(percent: number): boolean;
|
|
|
26
27
|
* Also works with strings:
|
|
27
28
|
* _isBetween('2020-01-03', '2020-01-01', '2020-01-05') // true
|
|
28
29
|
*/
|
|
29
|
-
export declare function _isBetween<T extends number | string>(x: T, min: T, max: T, incl
|
|
30
|
+
export declare function _isBetween<T extends number | string>(x: T, min: T, max: T, incl: Inclusiveness): boolean;
|
|
30
31
|
export declare function _clamp(x: number, minIncl: number, maxIncl: number): number;
|
|
31
32
|
/**
|
|
32
33
|
* This function exists, because in JS you cannot just .sort() numbers,
|
|
@@ -37,7 +38,7 @@ export declare function _clamp(x: number, minIncl: number, maxIncl: number): num
|
|
|
37
38
|
* _sortNumbers([1, 3, 2])
|
|
38
39
|
* // [1, 2, 3]
|
|
39
40
|
*/
|
|
40
|
-
export declare function _sortNumbers(numbers: number[],
|
|
41
|
+
export declare function _sortNumbers(numbers: number[], opt?: SortOptions): number[];
|
|
41
42
|
/**
|
|
42
43
|
* Same as .toFixed(), but conveniently casts the output to Number.
|
|
43
44
|
*
|
|
@@ -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
|
|
@@ -57,9 +52,9 @@ export function _clamp(x, minIncl, maxIncl) {
|
|
|
57
52
|
* _sortNumbers([1, 3, 2])
|
|
58
53
|
* // [1, 2, 3]
|
|
59
54
|
*/
|
|
60
|
-
export function _sortNumbers(numbers,
|
|
61
|
-
const mod = dir === 'desc' ? -1 : 1;
|
|
62
|
-
return (mutate ? numbers : [...numbers]).sort((a, b) => (a - b) * mod);
|
|
55
|
+
export function _sortNumbers(numbers, opt = {}) {
|
|
56
|
+
const mod = opt.dir === 'desc' ? -1 : 1;
|
|
57
|
+
return (opt.mutate ? numbers : [...numbers]).sort((a, b) => (a - b) * mod);
|
|
63
58
|
}
|
|
64
59
|
/**
|
|
65
60
|
* Same as .toFixed(), but conveniently casts the output to Number.
|
|
@@ -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
|
|
@@ -4,8 +4,8 @@ import { _objectEntries, SKIP } from '../types.js';
|
|
|
4
4
|
* Returns clone of `obj` with only `props` preserved.
|
|
5
5
|
* Opposite of Omit.
|
|
6
6
|
*/
|
|
7
|
-
export function _pick(obj, props,
|
|
8
|
-
if (mutate) {
|
|
7
|
+
export function _pick(obj, props, opt = {}) {
|
|
8
|
+
if (opt.mutate) {
|
|
9
9
|
// Start as original object (mutable), DELETE properties that are not whitelisted
|
|
10
10
|
for (const k of Object.keys(obj)) {
|
|
11
11
|
if (!props.includes(k))
|
|
@@ -25,8 +25,8 @@ export function _pick(obj, props, mutate = false) {
|
|
|
25
25
|
* Sets all properties of an object except passed ones to `undefined`.
|
|
26
26
|
* This is a more performant alternative to `_pick` that does picking/deleting.
|
|
27
27
|
*/
|
|
28
|
-
export function _pickWithUndefined(obj, props,
|
|
29
|
-
const r = mutate ? obj : { ...obj };
|
|
28
|
+
export function _pickWithUndefined(obj, props, opt = {}) {
|
|
29
|
+
const r = opt.mutate ? obj : { ...obj };
|
|
30
30
|
for (const k of Object.keys(r)) {
|
|
31
31
|
if (!props.includes(k)) {
|
|
32
32
|
r[k] = undefined;
|
|
@@ -38,8 +38,8 @@ export function _pickWithUndefined(obj, props, mutate = false) {
|
|
|
38
38
|
* Returns clone of `obj` with `props` omitted.
|
|
39
39
|
* Opposite of Pick.
|
|
40
40
|
*/
|
|
41
|
-
export function _omit(obj, props,
|
|
42
|
-
if (mutate) {
|
|
41
|
+
export function _omit(obj, props, opt = {}) {
|
|
42
|
+
if (opt.mutate) {
|
|
43
43
|
for (const k of props) {
|
|
44
44
|
delete obj[k];
|
|
45
45
|
}
|
|
@@ -56,8 +56,8 @@ export function _omit(obj, props, mutate = false) {
|
|
|
56
56
|
* Sets all passed properties of an object to `undefined`.
|
|
57
57
|
* This is a more performant alternative to `_omit` that does picking/deleting.
|
|
58
58
|
*/
|
|
59
|
-
export function _omitWithUndefined(obj, props,
|
|
60
|
-
const r = mutate ? obj : { ...obj };
|
|
59
|
+
export function _omitWithUndefined(obj, props, opt = {}) {
|
|
60
|
+
const r = opt.mutate ? obj : { ...obj };
|
|
61
61
|
for (const k of props) {
|
|
62
62
|
r[k] = undefined;
|
|
63
63
|
}
|
|
@@ -71,8 +71,8 @@ export function _omitWithUndefined(obj, props, mutate = false) {
|
|
|
71
71
|
* 'account.updated',
|
|
72
72
|
* ])
|
|
73
73
|
*/
|
|
74
|
-
export function _mask(obj, props,
|
|
75
|
-
const r = mutate ? obj : _deepCopy(obj);
|
|
74
|
+
export function _mask(obj, props, opt = {}) {
|
|
75
|
+
const r = opt.mutate ? obj : _deepCopy(obj);
|
|
76
76
|
for (const k of props) {
|
|
77
77
|
_unset(r, k);
|
|
78
78
|
}
|
|
@@ -81,31 +81,31 @@ export function _mask(obj, props, mutate = false) {
|
|
|
81
81
|
/**
|
|
82
82
|
* Removes "falsy" values from the object.
|
|
83
83
|
*/
|
|
84
|
-
export function _filterFalsyValues(obj,
|
|
85
|
-
return _filterObject(obj, (_k, v) => !!v,
|
|
84
|
+
export function _filterFalsyValues(obj, opt = {}) {
|
|
85
|
+
return _filterObject(obj, (_k, v) => !!v, opt);
|
|
86
86
|
}
|
|
87
87
|
/**
|
|
88
88
|
* Removes values from the object that are `null` or `undefined`.
|
|
89
89
|
*/
|
|
90
|
-
export function _filterNullishValues(obj,
|
|
91
|
-
return _filterObject(obj, (_k, v) => v !== undefined && v !== null,
|
|
90
|
+
export function _filterNullishValues(obj, opt = {}) {
|
|
91
|
+
return _filterObject(obj, (_k, v) => v !== undefined && v !== null, opt);
|
|
92
92
|
}
|
|
93
93
|
/**
|
|
94
94
|
* Removes values from the object that are `undefined`.
|
|
95
95
|
* Only `undefined` values are removed. `null` values are kept!
|
|
96
96
|
*/
|
|
97
|
-
export function _filterUndefinedValues(obj,
|
|
98
|
-
return _filterObject(obj, (_k, v) => v !== undefined,
|
|
97
|
+
export function _filterUndefinedValues(obj, opt = {}) {
|
|
98
|
+
return _filterObject(obj, (_k, v) => v !== undefined, opt);
|
|
99
99
|
}
|
|
100
|
-
export function _filterEmptyArrays(obj,
|
|
101
|
-
return _filterObject(obj, (_k, v) => !Array.isArray(v) || v.length > 0,
|
|
100
|
+
export function _filterEmptyArrays(obj, opt = {}) {
|
|
101
|
+
return _filterObject(obj, (_k, v) => !Array.isArray(v) || v.length > 0, opt);
|
|
102
102
|
}
|
|
103
103
|
/**
|
|
104
104
|
* Returns clone of `obj` without properties that does not pass `predicate`.
|
|
105
105
|
* Allows filtering by both key and value.
|
|
106
106
|
*/
|
|
107
|
-
export function _filterObject(obj, predicate,
|
|
108
|
-
if (mutate) {
|
|
107
|
+
export function _filterObject(obj, predicate, opt = {}) {
|
|
108
|
+
if (opt.mutate) {
|
|
109
109
|
for (const [k, v] of _objectEntries(obj)) {
|
|
110
110
|
if (!predicate(k, v, obj)) {
|
|
111
111
|
delete obj[k];
|
|
@@ -132,8 +132,8 @@ export function _filterObject(obj, predicate, mutate = false) {
|
|
|
132
132
|
*
|
|
133
133
|
* To skip some key-value pairs - use _mapObject instead.
|
|
134
134
|
*/
|
|
135
|
-
export function _mapValues(obj, mapper,
|
|
136
|
-
const map = mutate ? obj : {};
|
|
135
|
+
export function _mapValues(obj, mapper, opt = {}) {
|
|
136
|
+
const map = opt.mutate ? obj : {};
|
|
137
137
|
for (const [k, v] of Object.entries(obj)) {
|
|
138
138
|
map[k] = mapper(k, v, obj);
|
|
139
139
|
}
|
|
@@ -183,8 +183,8 @@ export function _mapObject(obj, mapper) {
|
|
|
183
183
|
export function _findKeyByValue(obj, v) {
|
|
184
184
|
return Object.entries(obj).find(([_, value]) => value === v)?.[0];
|
|
185
185
|
}
|
|
186
|
-
export function _objectNullValuesToUndefined(obj,
|
|
187
|
-
return _mapValues(obj, (_k, v) => (v === null ? undefined : v),
|
|
186
|
+
export function _objectNullValuesToUndefined(obj, opt = {}) {
|
|
187
|
+
return _mapValues(obj, (_k, v) => (v === null ? undefined : v), opt);
|
|
188
188
|
}
|
|
189
189
|
/**
|
|
190
190
|
* Deep copy object (by json parse/stringify, since it has unbeatable performance+simplicity combo).
|
|
@@ -202,8 +202,8 @@ export function _undefinedIfEmpty(obj) {
|
|
|
202
202
|
/**
|
|
203
203
|
* Filters the object by removing all key-value pairs where Value is Empty (according to _isEmpty() specification).
|
|
204
204
|
*/
|
|
205
|
-
export function _filterEmptyValues(obj,
|
|
206
|
-
return _filterObject(obj, (_k, v) => !_isEmpty(v),
|
|
205
|
+
export function _filterEmptyValues(obj, opt = {}) {
|
|
206
|
+
return _filterObject(obj, (_k, v) => !_isEmpty(v), opt);
|
|
207
207
|
}
|
|
208
208
|
/**
|
|
209
209
|
* Recursively merges own and inherited enumerable properties of source
|
package/dist/semver.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { SortOptions } from './array/array.util.js';
|
|
2
2
|
export type SemverInput = string | Semver;
|
|
3
3
|
export type SemverInputNullable = SemverInput | null | undefined;
|
|
4
4
|
export type SemverTokens = [major: number, minor: number, patch: number];
|
|
@@ -62,7 +62,7 @@ declare class SemverFactory {
|
|
|
62
62
|
/**
|
|
63
63
|
* Sorts an array of Semvers in `dir` order (ascending by default).
|
|
64
64
|
*/
|
|
65
|
-
sort(items: Semver[],
|
|
65
|
+
sort(items: Semver[], opt?: SortOptions): Semver[];
|
|
66
66
|
}
|
|
67
67
|
interface SemverFn extends SemverFactory {
|
|
68
68
|
(input: SemverInput): Semver;
|
package/dist/semver.js
CHANGED
|
@@ -118,9 +118,9 @@ class SemverFactory {
|
|
|
118
118
|
/**
|
|
119
119
|
* Sorts an array of Semvers in `dir` order (ascending by default).
|
|
120
120
|
*/
|
|
121
|
-
sort(items,
|
|
122
|
-
const mod = dir === 'desc' ? -1 : 1;
|
|
123
|
-
return (mutate ? items : [...items]).sort((a, b) => a.compare(b) * mod);
|
|
121
|
+
sort(items, opt = {}) {
|
|
122
|
+
const mod = opt.dir === 'desc' ? -1 : 1;
|
|
123
|
+
return (opt.mutate ? items : [...items]).sort((a, b) => a.compare(b) * mod);
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
126
|
const semverFactory = new SemverFactory();
|
package/dist/types.d.ts
CHANGED
|
@@ -117,10 +117,12 @@ export declare const MISS: unique symbol;
|
|
|
117
117
|
/**
|
|
118
118
|
* Function which is called for every item in `input`. Expected to return a `Promise` or value.
|
|
119
119
|
*/
|
|
120
|
-
export type AsyncMapper<IN = any, OUT = any> = (input: IN
|
|
121
|
-
export type
|
|
122
|
-
export
|
|
123
|
-
export
|
|
120
|
+
export type AsyncMapper<IN = any, OUT = any> = (input: IN) => OUT | PromiseLike<OUT>;
|
|
121
|
+
export type AsyncIndexedMapper<IN = any, OUT = any> = (input: IN, index: number) => OUT | PromiseLike<OUT>;
|
|
122
|
+
export type Mapper<IN = any, OUT = any> = (input: IN) => OUT;
|
|
123
|
+
export type IndexedMapper<IN = any, OUT = any> = (input: IN, index: number) => OUT;
|
|
124
|
+
export declare const _passthroughMapper: IndexedMapper;
|
|
125
|
+
export declare const _passUndefinedMapper: IndexedMapper<any, void>;
|
|
124
126
|
/**
|
|
125
127
|
* Function that does nothings and returns `undefined`.
|
|
126
128
|
*/
|
|
@@ -326,7 +328,7 @@ export declare const _objectAssign: <T extends AnyObject>(target: T, part: Parti
|
|
|
326
328
|
*/
|
|
327
329
|
export type ErrorDataTuple<T = unknown, ERR = Error> = [err: null, data: T] | [err: ERR, data: null];
|
|
328
330
|
export type SortDirection = 'asc' | 'desc';
|
|
329
|
-
export type Inclusiveness = '
|
|
331
|
+
export type Inclusiveness = '[]' | '[)';
|
|
330
332
|
/**
|
|
331
333
|
* @experimental
|
|
332
334
|
*/
|
package/dist/types.js
CHANGED
|
@@ -24,7 +24,7 @@ export const _passNothingPredicate = () => false;
|
|
|
24
24
|
* Like _stringMapValues, but values are sorted.
|
|
25
25
|
*/
|
|
26
26
|
export function _stringMapValuesSorted(map, mapper, dir = 'asc') {
|
|
27
|
-
return _sortBy(_stringMapValues(map), mapper,
|
|
27
|
+
return _sortBy(_stringMapValues(map), mapper, { dir });
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
30
30
|
* Needed due to https://github.com/microsoft/TypeScript/issues/13778
|