@naturalcycles/js-lib 14.101.0 → 14.104.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 +15 -6
- package/dist/array/array.util.js +22 -8
- package/dist/decorators/memo.util.js +2 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +1 -0
- package/dist/is.util.d.ts +40 -0
- package/dist/is.util.js +72 -0
- package/dist/json-schema/jsonSchemaBuilder.d.ts +3 -0
- package/dist/json-schema/jsonSchemaBuilder.js +7 -2
- package/dist/json-schema/jsonSchemas.js +4 -4
- package/dist/object/object.util.d.ts +0 -17
- package/dist/object/object.util.js +9 -52
- package/dist/object/sortObjectDeep.js +2 -2
- package/dist/types.d.ts +2 -0
- package/dist-esm/array/array.util.js +22 -8
- package/dist-esm/datetime/localTime.js +1 -2
- package/dist-esm/decorators/createPromiseDecorator.js +10 -5
- package/dist-esm/decorators/debounce.js +6 -1
- package/dist-esm/decorators/memo.util.js +1 -1
- package/dist-esm/error/assert.js +12 -3
- package/dist-esm/error/error.util.js +8 -7
- package/dist-esm/error/tryCatch.js +1 -1
- package/dist-esm/index.js +1 -0
- package/dist-esm/is.util.js +59 -0
- package/dist-esm/json-schema/jsonSchema.util.js +2 -3
- package/dist-esm/json-schema/jsonSchemaBuilder.js +8 -4
- package/dist-esm/json-schema/jsonSchemas.js +4 -4
- package/dist-esm/math/math.util.js +1 -1
- package/dist-esm/object/object.util.js +4 -44
- package/dist-esm/object/sortObjectDeep.js +1 -1
- package/dist-esm/promise/pMap.js +15 -27
- package/dist-esm/promise/pQueue.js +7 -2
- package/dist-esm/promise/pRetry.js +4 -1
- package/dist-esm/promise/pTimeout.js +4 -1
- package/dist-esm/string/json.util.js +1 -1
- package/dist-esm/string/safeJsonStringify.js +1 -1
- package/dist-esm/string/stringifyAny.js +1 -1
- package/dist-esm/vendor/is.js +7 -8
- package/package.json +1 -1
- package/src/array/array.util.ts +28 -14
- package/src/decorators/memo.util.ts +1 -1
- package/src/index.ts +6 -0
- package/src/is.util.ts +77 -0
- package/src/json-schema/jsonSchemaBuilder.ts +7 -2
- package/src/json-schema/jsonSchemas.ts +4 -4
- package/src/object/object.util.ts +1 -49
- package/src/object/sortObjectDeep.ts +1 -1
- package/src/types.ts +3 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RecursiveArray } from '../lodash.types';
|
|
2
|
-
import { Mapper, Predicate, StringMap } from '../types';
|
|
2
|
+
import { FalsyValue, Mapper, Predicate, StringMap } from '../types';
|
|
3
3
|
/**
|
|
4
4
|
* Creates an array of elements split into groups the length of size. If collection can’t be split evenly, the
|
|
5
5
|
* final chunk will be the remaining elements.
|
|
@@ -115,6 +115,9 @@ export declare function _intersection<T>(...arrays: T[][]): T[];
|
|
|
115
115
|
* // [1]
|
|
116
116
|
*/
|
|
117
117
|
export declare function _difference<T>(source: T[], ...diffs: T[][]): T[];
|
|
118
|
+
/**
|
|
119
|
+
* Returns the sum of items, or 0 for empty array.
|
|
120
|
+
*/
|
|
118
121
|
export declare function _sum(items: number[]): number;
|
|
119
122
|
export declare function _sumBy<T>(items: T[], mapper: Mapper<T, number | undefined>): number;
|
|
120
123
|
/**
|
|
@@ -130,7 +133,7 @@ export declare function _sumBy<T>(items: T[], mapper: Mapper<T, number | undefin
|
|
|
130
133
|
* _mapToObject([1, 2, 3], n => [n, `id${n}`])
|
|
131
134
|
* // { '1': 'id1, '2': 'id2', '3': 'id3' }
|
|
132
135
|
*/
|
|
133
|
-
export declare function _mapToObject<T, V>(array: T[], mapper: (item: T) => [key: any, value: V] |
|
|
136
|
+
export declare function _mapToObject<T, V>(array: T[], mapper: (item: T) => [key: any, value: V] | FalsyValue): StringMap<V>;
|
|
134
137
|
/**
|
|
135
138
|
* Randomly shuffle an array values.
|
|
136
139
|
* Fisher–Yates algorithm.
|
|
@@ -146,7 +149,13 @@ export declare function _last<T>(array: T[]): T;
|
|
|
146
149
|
* Returns last item of the array (or undefined if array is empty).
|
|
147
150
|
*/
|
|
148
151
|
export declare function _lastOrUndefined<T>(array: T[]): T | undefined;
|
|
149
|
-
export declare function _minOrUndefined<T>(array: T[]): T | undefined;
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
152
|
+
export declare function _minOrUndefined<T>(array: T[]): NonNullable<T> | undefined;
|
|
153
|
+
/**
|
|
154
|
+
* Filters out nullish values (undefined and null).
|
|
155
|
+
*/
|
|
156
|
+
export declare function _min<T>(array: T[]): NonNullable<T>;
|
|
157
|
+
export declare function _maxOrUndefined<T>(array: T[]): NonNullable<T> | undefined;
|
|
158
|
+
/**
|
|
159
|
+
* Filters out nullish values (undefined and null).
|
|
160
|
+
*/
|
|
161
|
+
export declare function _max<T>(array: T[]): NonNullable<T>;
|
package/dist/array/array.util.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports._max = exports._maxOrUndefined = exports._min = exports._minOrUndefined = exports._lastOrUndefined = exports._last = exports._shuffle = exports._mapToObject = exports._sumBy = exports._sum = exports._difference = exports._intersection = exports._countBy = exports._dropRightWhile = exports._dropWhile = exports._takeRightWhile = exports._takeWhile = exports._findLast = exports._sortBy = exports._groupBy = exports._by = exports._uniqBy = exports._uniq = exports._flattenDeep = exports._flatten = exports._chunk = void 0;
|
|
4
|
+
const is_util_1 = require("../is.util");
|
|
4
5
|
/**
|
|
5
6
|
* Creates an array of elements split into groups the length of size. If collection can’t be split evenly, the
|
|
6
7
|
* final chunk will be the remaining elements.
|
|
@@ -210,6 +211,9 @@ function _difference(source, ...diffs) {
|
|
|
210
211
|
return diffs.reduce((a, b) => a.filter(c => !b.includes(c)), source);
|
|
211
212
|
}
|
|
212
213
|
exports._difference = _difference;
|
|
214
|
+
/**
|
|
215
|
+
* Returns the sum of items, or 0 for empty array.
|
|
216
|
+
*/
|
|
213
217
|
function _sum(items) {
|
|
214
218
|
return items.reduce((sum, n) => sum + n, 0);
|
|
215
219
|
}
|
|
@@ -277,26 +281,36 @@ function _lastOrUndefined(array) {
|
|
|
277
281
|
}
|
|
278
282
|
exports._lastOrUndefined = _lastOrUndefined;
|
|
279
283
|
function _minOrUndefined(array) {
|
|
280
|
-
|
|
284
|
+
const a = array.filter(is_util_1._isNotNullish);
|
|
285
|
+
if (!a.length)
|
|
281
286
|
return;
|
|
282
|
-
return _min(
|
|
287
|
+
return _min(a);
|
|
283
288
|
}
|
|
284
289
|
exports._minOrUndefined = _minOrUndefined;
|
|
290
|
+
/**
|
|
291
|
+
* Filters out nullish values (undefined and null).
|
|
292
|
+
*/
|
|
285
293
|
function _min(array) {
|
|
286
|
-
|
|
294
|
+
const a = array.filter(is_util_1._isNotNullish);
|
|
295
|
+
if (!a.length)
|
|
287
296
|
throw new Error('_min called on empty array');
|
|
288
|
-
return
|
|
297
|
+
return a.reduce((min, item) => (min <= item ? min : item));
|
|
289
298
|
}
|
|
290
299
|
exports._min = _min;
|
|
291
300
|
function _maxOrUndefined(array) {
|
|
292
|
-
|
|
301
|
+
const a = array.filter(is_util_1._isNotNullish);
|
|
302
|
+
if (!a.length)
|
|
293
303
|
return;
|
|
294
|
-
return _max(
|
|
304
|
+
return _max(a);
|
|
295
305
|
}
|
|
296
306
|
exports._maxOrUndefined = _maxOrUndefined;
|
|
307
|
+
/**
|
|
308
|
+
* Filters out nullish values (undefined and null).
|
|
309
|
+
*/
|
|
297
310
|
function _max(array) {
|
|
298
|
-
|
|
311
|
+
const a = array.filter(is_util_1._isNotNullish);
|
|
312
|
+
if (!a.length)
|
|
299
313
|
throw new Error('_max called on empty array');
|
|
300
|
-
return
|
|
314
|
+
return a.reduce((max, item) => (max >= item ? max : item));
|
|
301
315
|
}
|
|
302
316
|
exports._max = _max;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MapMemoCache = exports.jsonMemoSerializer = void 0;
|
|
4
|
-
const
|
|
4
|
+
const __1 = require("..");
|
|
5
5
|
const jsonMemoSerializer = args => {
|
|
6
6
|
if (args.length === 0)
|
|
7
7
|
return undefined;
|
|
8
|
-
if (args.length === 1 && (0,
|
|
8
|
+
if (args.length === 1 && (0, __1._isPrimitive)(args[0]))
|
|
9
9
|
return args[0];
|
|
10
10
|
return JSON.stringify(args);
|
|
11
11
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -50,8 +50,9 @@ export * from './string/json.util';
|
|
|
50
50
|
export * from './string/string.util';
|
|
51
51
|
import { JsonStringifyFunction, StringifyAnyOptions, _stringifyAny } from './string/stringifyAny';
|
|
52
52
|
export * from './time/time.util';
|
|
53
|
+
export * from './is.util';
|
|
53
54
|
import { Class, ConditionalExcept, ConditionalPick, Merge, Promisable, ReadonlyDeep, Simplify } from './typeFest';
|
|
54
|
-
import { AsyncMapper, AsyncPredicate, BaseDBEntity, CreatedUpdated, CreatedUpdatedId, ObjectWithId, AnyObjectWithId, Saved, Unsaved, UnsavedId, BatchResult, InstanceId, IsoDate, IsoDateString, IsoDateTimeString, KeyValueTuple, Mapper, ObjectMapper, ObjectPredicate, Predicate, PromiseMap, AnyObject, AnyFunction, Reviver, SavedDBEntity, StringMap, UnixTimestampNumber, UnixTimestampMillisNumber, UnixTimestamp, Integer, ValueOf, ValuesOf, AbortableMapper, AbortableAsyncPredicate, AbortableAsyncMapper, AbortablePredicate, END, SKIP, _noop, _objectKeys, _passNothingPredicate, _passthroughMapper, _passthroughPredicate, _passUndefinedMapper, _stringMapEntries, _stringMapValues } from './types';
|
|
55
|
+
import { AsyncMapper, AsyncPredicate, BaseDBEntity, CreatedUpdated, CreatedUpdatedId, ObjectWithId, AnyObjectWithId, Saved, Unsaved, UnsavedId, BatchResult, InstanceId, IsoDate, IsoDateString, IsoDateTimeString, KeyValueTuple, Mapper, ObjectMapper, ObjectPredicate, Predicate, PromiseMap, AnyObject, AnyFunction, Reviver, SavedDBEntity, StringMap, UnixTimestampNumber, UnixTimestampMillisNumber, UnixTimestamp, Integer, ValueOf, ValuesOf, AbortableMapper, AbortableAsyncPredicate, AbortableAsyncMapper, AbortablePredicate, NullishValue, FalsyValue, END, SKIP, _noop, _objectKeys, _passNothingPredicate, _passthroughMapper, _passthroughPredicate, _passUndefinedMapper, _stringMapEntries, _stringMapValues } from './types';
|
|
55
56
|
export * from './unit/size.util';
|
|
56
57
|
import { is } from './vendor/is';
|
|
57
58
|
import { CommonLogLevel, CommonLogFunction, CommonLogger, commonLoggerMinLevel, commonLoggerNoop, commonLogLevelNumber, commonLoggerPipe, commonLoggerPrefix, CommonLogWithLevelFunction, commonLoggerCreate } from './log/commonLogger';
|
|
@@ -68,5 +69,5 @@ import { LocalDateConfig, LocalDateFormatter, LocalDateUnit, LocalDateUnitStrict
|
|
|
68
69
|
import { LocalTimeConfig, LocalTimeFormatter, LocalTimeUnit, LocalTimeComponents, ISODayOfWeek } from './datetime/localTime';
|
|
69
70
|
import { DateIntervalConfig, DateIntervalString } from './datetime/dateInterval';
|
|
70
71
|
import { TimeIntervalConfig, TimeIntervalString } from './datetime/timeInterval';
|
|
71
|
-
export type { DateIntervalConfig, DateIntervalString, TimeIntervalConfig, TimeIntervalString, LocalDateConfig, LocalDateFormatter, LocalDateUnit, LocalDateUnitStrict, Inclusiveness, LocalTimeConfig, LocalTimeFormatter, LocalTimeUnit, ISODayOfWeek, LocalTimeComponents, AbortableMapper, AbortablePredicate, AbortableAsyncPredicate, AbortableAsyncMapper, PQueueCfg, MemoCache, AsyncMemoCache, PromiseDecoratorCfg, PromiseDecoratorResp, ErrorData, ErrorObject, HttpErrorData, HttpErrorResponse, Admin401ErrorData, Admin403ErrorData, StringMap, PromiseMap, AnyObject, AnyFunction, ValuesOf, ValueOf, KeyValueTuple, ObjectMapper, ObjectPredicate, InstanceId, IsoDate, IsoDateString, IsoDateTimeString, Reviver, PMapOptions, Mapper, AsyncMapper, Predicate, AsyncPredicate, BatchResult, DeferredPromise, PRetryOptions, PTimeoutOptions, TryCatchOptions, StringifyAnyOptions, JsonStringifyFunction, Merge, ReadonlyDeep, Promisable, Simplify, ConditionalPick, ConditionalExcept, Class, UnixTimestampNumber, UnixTimestampMillisNumber, UnixTimestamp, Integer, BaseDBEntity, SavedDBEntity, Saved, Unsaved, UnsavedId, CreatedUpdated, CreatedUpdatedId, ObjectWithId, AnyObjectWithId, JsonSchema, JsonSchemaAny, JsonSchemaOneOf, JsonSchemaAllOf, JsonSchemaAnyOf, JsonSchemaNot, JsonSchemaRef, JsonSchemaConst, JsonSchemaEnum, JsonSchemaString, JsonSchemaNumber, JsonSchemaBoolean, JsonSchemaNull, JsonSchemaRootObject, JsonSchemaObject, JsonSchemaArray, JsonSchemaTuple, JsonSchemaBuilder, CommonLogLevel, CommonLogWithLevelFunction, CommonLogFunction, CommonLogger, };
|
|
72
|
+
export type { DateIntervalConfig, DateIntervalString, TimeIntervalConfig, TimeIntervalString, LocalDateConfig, LocalDateFormatter, LocalDateUnit, LocalDateUnitStrict, Inclusiveness, LocalTimeConfig, LocalTimeFormatter, LocalTimeUnit, ISODayOfWeek, LocalTimeComponents, AbortableMapper, AbortablePredicate, AbortableAsyncPredicate, AbortableAsyncMapper, PQueueCfg, MemoCache, AsyncMemoCache, PromiseDecoratorCfg, PromiseDecoratorResp, ErrorData, ErrorObject, HttpErrorData, HttpErrorResponse, Admin401ErrorData, Admin403ErrorData, StringMap, PromiseMap, AnyObject, AnyFunction, ValuesOf, ValueOf, KeyValueTuple, ObjectMapper, ObjectPredicate, InstanceId, IsoDate, IsoDateString, IsoDateTimeString, Reviver, FalsyValue, NullishValue, PMapOptions, Mapper, AsyncMapper, Predicate, AsyncPredicate, BatchResult, DeferredPromise, PRetryOptions, PTimeoutOptions, TryCatchOptions, StringifyAnyOptions, JsonStringifyFunction, Merge, ReadonlyDeep, Promisable, Simplify, ConditionalPick, ConditionalExcept, Class, UnixTimestampNumber, UnixTimestampMillisNumber, UnixTimestamp, Integer, BaseDBEntity, SavedDBEntity, Saved, Unsaved, UnsavedId, CreatedUpdated, CreatedUpdatedId, ObjectWithId, AnyObjectWithId, JsonSchema, JsonSchemaAny, JsonSchemaOneOf, JsonSchemaAllOf, JsonSchemaAnyOf, JsonSchemaNot, JsonSchemaRef, JsonSchemaConst, JsonSchemaEnum, JsonSchemaString, JsonSchemaNumber, JsonSchemaBoolean, JsonSchemaNull, JsonSchemaRootObject, JsonSchemaObject, JsonSchemaArray, JsonSchemaTuple, JsonSchemaBuilder, CommonLogLevel, CommonLogWithLevelFunction, CommonLogFunction, CommonLogger, };
|
|
72
73
|
export { is, _createPromiseDecorator, _stringMapValues, _stringMapEntries, _objectKeys, pMap, _passthroughMapper, _passUndefinedMapper, _passthroughPredicate, _passNothingPredicate, _noop, ErrorMode, pDefer, AggregatedError, pRetry, pRetryFn, pTimeout, pTimeoutFn, _tryCatch, _TryCatch, _stringifyAny, jsonSchema, JsonSchemaAnyBuilder, commonLoggerMinLevel, commonLoggerNoop, commonLogLevelNumber, commonLoggerPipe, commonLoggerPrefix, commonLoggerCreate, PQueue, END, SKIP, };
|
package/dist/index.js
CHANGED
|
@@ -65,6 +65,7 @@ tslib_1.__exportStar(require("./string/string.util"), exports);
|
|
|
65
65
|
const stringifyAny_1 = require("./string/stringifyAny");
|
|
66
66
|
Object.defineProperty(exports, "_stringifyAny", { enumerable: true, get: function () { return stringifyAny_1._stringifyAny; } });
|
|
67
67
|
tslib_1.__exportStar(require("./time/time.util"), exports);
|
|
68
|
+
tslib_1.__exportStar(require("./is.util"), exports);
|
|
68
69
|
const types_1 = require("./types");
|
|
69
70
|
Object.defineProperty(exports, "END", { enumerable: true, get: function () { return types_1.END; } });
|
|
70
71
|
Object.defineProperty(exports, "SKIP", { enumerable: true, get: function () { return types_1.SKIP; } });
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Primitive } from './typeFest';
|
|
2
|
+
import { AnyObject, FalsyValue, NullishValue } from './types';
|
|
3
|
+
declare type Nullish<T> = T extends NullishValue ? T : never;
|
|
4
|
+
declare type Truthy<T> = T extends FalsyValue ? never : T;
|
|
5
|
+
declare type Falsy<T> = T extends FalsyValue ? T : never;
|
|
6
|
+
export declare const _isNull: <T>(v: T) => v is T extends null ? T : never;
|
|
7
|
+
export declare const _isUndefined: <T>(v: T) => v is T extends undefined ? T : never;
|
|
8
|
+
export declare const _isNullish: <T>(v: T) => v is Nullish<T>;
|
|
9
|
+
export declare const _isNotNullish: <T>(v: T) => v is NonNullable<T>;
|
|
10
|
+
/**
|
|
11
|
+
* Same as Boolean, but with correct type output.
|
|
12
|
+
* Related:
|
|
13
|
+
* https://github.com/microsoft/TypeScript/issues/16655
|
|
14
|
+
* https://www.karltarvas.com/2021/03/11/typescript-array-filter-boolean.html
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
*
|
|
18
|
+
* [1, 2, undefined].filter(_isTruthy)
|
|
19
|
+
* // => [1, 2]
|
|
20
|
+
*/
|
|
21
|
+
export declare const _isTruthy: <T>(v: T) => v is Truthy<T>;
|
|
22
|
+
export declare const _isFalsy: <T>(v: T) => v is Falsy<T>;
|
|
23
|
+
/**
|
|
24
|
+
* Returns true if item is Object, not null and not Array.
|
|
25
|
+
*/
|
|
26
|
+
export declare function _isObject(item: any): item is AnyObject;
|
|
27
|
+
export declare function _isPrimitive(v: any): v is Primitive;
|
|
28
|
+
export declare function _isEmptyObject(obj: any): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Object is considered empty if it's one of:
|
|
31
|
+
* undefined
|
|
32
|
+
* null
|
|
33
|
+
* '' (empty string)
|
|
34
|
+
* [] (empty array)
|
|
35
|
+
* {} (empty object)
|
|
36
|
+
* new Map() (empty Map)
|
|
37
|
+
* new Set() (empty Set)
|
|
38
|
+
*/
|
|
39
|
+
export declare function _isEmpty(obj: any): boolean;
|
|
40
|
+
export {};
|
package/dist/is.util.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports._isEmpty = exports._isEmptyObject = exports._isPrimitive = exports._isObject = exports._isFalsy = exports._isTruthy = exports._isNotNullish = exports._isNullish = exports._isUndefined = exports._isNull = void 0;
|
|
4
|
+
const _isNull = (v) => v === null;
|
|
5
|
+
exports._isNull = _isNull;
|
|
6
|
+
const _isUndefined = (v) => typeof v === 'undefined';
|
|
7
|
+
exports._isUndefined = _isUndefined;
|
|
8
|
+
const _isNullish = (v) => typeof v === 'undefined' || v === null;
|
|
9
|
+
exports._isNullish = _isNullish;
|
|
10
|
+
const _isNotNullish = (v) => v !== undefined && v !== null;
|
|
11
|
+
exports._isNotNullish = _isNotNullish;
|
|
12
|
+
/**
|
|
13
|
+
* Same as Boolean, but with correct type output.
|
|
14
|
+
* Related:
|
|
15
|
+
* https://github.com/microsoft/TypeScript/issues/16655
|
|
16
|
+
* https://www.karltarvas.com/2021/03/11/typescript-array-filter-boolean.html
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
*
|
|
20
|
+
* [1, 2, undefined].filter(_isTruthy)
|
|
21
|
+
* // => [1, 2]
|
|
22
|
+
*/
|
|
23
|
+
const _isTruthy = (v) => !!v;
|
|
24
|
+
exports._isTruthy = _isTruthy;
|
|
25
|
+
const _isFalsy = (v) => !v;
|
|
26
|
+
exports._isFalsy = _isFalsy;
|
|
27
|
+
/**
|
|
28
|
+
* Returns true if item is Object, not null and not Array.
|
|
29
|
+
*/
|
|
30
|
+
function _isObject(item) {
|
|
31
|
+
return (typeof item === 'object' && item !== null && !Array.isArray(item)) || false;
|
|
32
|
+
}
|
|
33
|
+
exports._isObject = _isObject;
|
|
34
|
+
function _isPrimitive(v) {
|
|
35
|
+
return (v === null ||
|
|
36
|
+
v === undefined ||
|
|
37
|
+
typeof v === 'number' ||
|
|
38
|
+
typeof v === 'boolean' ||
|
|
39
|
+
typeof v === 'string' ||
|
|
40
|
+
typeof v === 'bigint' ||
|
|
41
|
+
typeof v === 'symbol');
|
|
42
|
+
}
|
|
43
|
+
exports._isPrimitive = _isPrimitive;
|
|
44
|
+
function _isEmptyObject(obj) {
|
|
45
|
+
return obj && obj.constructor === Object && Object.keys(obj).length === 0;
|
|
46
|
+
}
|
|
47
|
+
exports._isEmptyObject = _isEmptyObject;
|
|
48
|
+
/**
|
|
49
|
+
* Object is considered empty if it's one of:
|
|
50
|
+
* undefined
|
|
51
|
+
* null
|
|
52
|
+
* '' (empty string)
|
|
53
|
+
* [] (empty array)
|
|
54
|
+
* {} (empty object)
|
|
55
|
+
* new Map() (empty Map)
|
|
56
|
+
* new Set() (empty Set)
|
|
57
|
+
*/
|
|
58
|
+
function _isEmpty(obj) {
|
|
59
|
+
if (obj === undefined || obj === null)
|
|
60
|
+
return true;
|
|
61
|
+
if (typeof obj === 'string' || Array.isArray(obj)) {
|
|
62
|
+
return obj.length === 0;
|
|
63
|
+
}
|
|
64
|
+
if (obj instanceof Map || obj instanceof Set) {
|
|
65
|
+
return obj.size === 0;
|
|
66
|
+
}
|
|
67
|
+
if (typeof obj === 'object') {
|
|
68
|
+
return Object.keys(obj).length === 0;
|
|
69
|
+
}
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
exports._isEmpty = _isEmpty;
|
|
@@ -19,6 +19,7 @@ export declare const jsonSchema: {
|
|
|
19
19
|
number(): JsonSchemaNumberBuilder;
|
|
20
20
|
integer(): JsonSchemaNumberBuilder;
|
|
21
21
|
unixTimestamp(): JsonSchemaNumberBuilder;
|
|
22
|
+
unixTimestamp2000(): JsonSchemaNumberBuilder;
|
|
22
23
|
string(): JsonSchemaStringBuilder;
|
|
23
24
|
dateString(): JsonSchemaStringBuilder;
|
|
24
25
|
object<T_4 extends AnyObject>(props: { [k in keyof T_4]: JsonSchemaAnyBuilder<T_4[k], JsonSchema<T_4[k]>>; }): JsonSchemaObjectBuilder<T_4>;
|
|
@@ -72,7 +73,9 @@ export declare class JsonSchemaNumberBuilder extends JsonSchemaAnyBuilder<number
|
|
|
72
73
|
float: () => this;
|
|
73
74
|
double: () => this;
|
|
74
75
|
unixTimestamp: () => this;
|
|
76
|
+
unixTimestamp2000: () => this;
|
|
75
77
|
unixTimestampMillis: () => this;
|
|
78
|
+
unixTimestampMillis2000: () => this;
|
|
76
79
|
utcOffset: () => this;
|
|
77
80
|
utcOffsetHours: () => this;
|
|
78
81
|
}
|
|
@@ -50,6 +50,9 @@ exports.jsonSchema = {
|
|
|
50
50
|
unixTimestamp() {
|
|
51
51
|
return new JsonSchemaNumberBuilder().unixTimestamp();
|
|
52
52
|
},
|
|
53
|
+
unixTimestamp2000() {
|
|
54
|
+
return new JsonSchemaNumberBuilder().unixTimestamp2000();
|
|
55
|
+
},
|
|
53
56
|
// string types
|
|
54
57
|
string() {
|
|
55
58
|
return new JsonSchemaStringBuilder();
|
|
@@ -167,7 +170,9 @@ class JsonSchemaNumberBuilder extends JsonSchemaAnyBuilder {
|
|
|
167
170
|
this.float = () => this.format('float');
|
|
168
171
|
this.double = () => this.format('double');
|
|
169
172
|
this.unixTimestamp = () => this.format('unixTimestamp');
|
|
173
|
+
this.unixTimestamp2000 = () => this.format('unixTimestamp2000');
|
|
170
174
|
this.unixTimestampMillis = () => this.format('unixTimestampMillis');
|
|
175
|
+
this.unixTimestampMillis2000 = () => this.format('unixTimestampMillis2000');
|
|
171
176
|
this.utcOffset = () => this.format('utcOffset');
|
|
172
177
|
this.utcOffsetHours = () => this.format('utcOffsetHours');
|
|
173
178
|
}
|
|
@@ -309,8 +314,8 @@ class JsonSchemaObjectBuilder extends JsonSchemaAnyBuilder {
|
|
|
309
314
|
baseDBEntity(idType = 'string') {
|
|
310
315
|
Object.assign(this.schema.properties, {
|
|
311
316
|
id: { type: idType },
|
|
312
|
-
created: { type: 'number', format: '
|
|
313
|
-
updated: { type: 'number', format: '
|
|
317
|
+
created: { type: 'number', format: 'unixTimestamp2000' },
|
|
318
|
+
updated: { type: 'number', format: 'unixTimestamp2000' },
|
|
314
319
|
});
|
|
315
320
|
return this;
|
|
316
321
|
}
|
|
@@ -4,11 +4,11 @@ exports.savedDBEntityJsonSchema = exports.baseDBEntityJsonSchema = void 0;
|
|
|
4
4
|
const jsonSchemaBuilder_1 = require("./jsonSchemaBuilder");
|
|
5
5
|
exports.baseDBEntityJsonSchema = jsonSchemaBuilder_1.jsonSchema.object({
|
|
6
6
|
id: jsonSchemaBuilder_1.jsonSchema.string().optional(),
|
|
7
|
-
created: jsonSchemaBuilder_1.jsonSchema.
|
|
8
|
-
updated: jsonSchemaBuilder_1.jsonSchema.
|
|
7
|
+
created: jsonSchemaBuilder_1.jsonSchema.unixTimestamp2000().optional(),
|
|
8
|
+
updated: jsonSchemaBuilder_1.jsonSchema.unixTimestamp2000().optional(),
|
|
9
9
|
});
|
|
10
10
|
exports.savedDBEntityJsonSchema = jsonSchemaBuilder_1.jsonSchema.object({
|
|
11
11
|
id: jsonSchemaBuilder_1.jsonSchema.string(),
|
|
12
|
-
created: jsonSchemaBuilder_1.jsonSchema.
|
|
13
|
-
updated: jsonSchemaBuilder_1.jsonSchema.
|
|
12
|
+
created: jsonSchemaBuilder_1.jsonSchema.unixTimestamp2000(),
|
|
13
|
+
updated: jsonSchemaBuilder_1.jsonSchema.unixTimestamp2000(),
|
|
14
14
|
});
|
|
@@ -84,23 +84,6 @@ export declare function _objectNullValuesToUndefined<T extends AnyObject>(obj: T
|
|
|
84
84
|
* Deep copy object (by json parse/stringify, since it has unbeatable performance+simplicity combo).
|
|
85
85
|
*/
|
|
86
86
|
export declare function _deepCopy<T>(o: T): T;
|
|
87
|
-
/**
|
|
88
|
-
* Returns true if item is Object, not null and not Array.
|
|
89
|
-
*/
|
|
90
|
-
export declare function _isObject(item: any): item is AnyObject;
|
|
91
|
-
export declare function _isPrimitive(v: any): v is null | undefined | number | boolean | string;
|
|
92
|
-
export declare function _isEmptyObject(obj: any): boolean;
|
|
93
|
-
/**
|
|
94
|
-
* Object is considered empty if it's one of:
|
|
95
|
-
* undefined
|
|
96
|
-
* null
|
|
97
|
-
* '' (empty string)
|
|
98
|
-
* [] (empty array)
|
|
99
|
-
* {} (empty object)
|
|
100
|
-
* new Map() (empty Map)
|
|
101
|
-
* new Set() (empty Set)
|
|
102
|
-
*/
|
|
103
|
-
export declare function _isEmpty(obj: any): boolean;
|
|
104
87
|
/**
|
|
105
88
|
* Returns `undefined` if it's empty (according to `_isEmpty()` specification),
|
|
106
89
|
* otherwise returns the original object.
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports._has = exports._set = exports._get = exports._invertMap = exports._invert = exports._unset = exports._deepTrim = exports._merge = exports._filterEmptyValues = exports._undefinedIfEmpty = exports.
|
|
3
|
+
exports._has = exports._set = exports._get = exports._invertMap = exports._invert = exports._unset = exports._deepTrim = exports._merge = exports._filterEmptyValues = exports._undefinedIfEmpty = exports._deepCopy = exports._objectNullValuesToUndefined = exports._findKeyByValue = exports._mapObject = exports._mapKeys = exports._mapValues = exports._filterObject = exports._filterEmptyArrays = exports._filterUndefinedValues = exports._filterNullishValues = exports._filterFalsyValues = exports._mask = exports._omit = exports._pick = void 0;
|
|
4
|
+
const is_util_1 = require("../is.util");
|
|
4
5
|
/**
|
|
5
6
|
* Returns clone of `obj` with only `props` preserved.
|
|
6
7
|
* Opposite of Omit.
|
|
@@ -164,63 +165,19 @@ function _deepCopy(o) {
|
|
|
164
165
|
return JSON.parse(JSON.stringify(o));
|
|
165
166
|
}
|
|
166
167
|
exports._deepCopy = _deepCopy;
|
|
167
|
-
/**
|
|
168
|
-
* Returns true if item is Object, not null and not Array.
|
|
169
|
-
*/
|
|
170
|
-
function _isObject(item) {
|
|
171
|
-
return (typeof item === 'object' && item !== null && !Array.isArray(item)) || false;
|
|
172
|
-
}
|
|
173
|
-
exports._isObject = _isObject;
|
|
174
|
-
function _isPrimitive(v) {
|
|
175
|
-
return (v === null ||
|
|
176
|
-
v === undefined ||
|
|
177
|
-
typeof v === 'number' ||
|
|
178
|
-
typeof v === 'boolean' ||
|
|
179
|
-
typeof v === 'string');
|
|
180
|
-
}
|
|
181
|
-
exports._isPrimitive = _isPrimitive;
|
|
182
|
-
function _isEmptyObject(obj) {
|
|
183
|
-
return obj && obj.constructor === Object && Object.keys(obj).length === 0;
|
|
184
|
-
}
|
|
185
|
-
exports._isEmptyObject = _isEmptyObject;
|
|
186
|
-
/**
|
|
187
|
-
* Object is considered empty if it's one of:
|
|
188
|
-
* undefined
|
|
189
|
-
* null
|
|
190
|
-
* '' (empty string)
|
|
191
|
-
* [] (empty array)
|
|
192
|
-
* {} (empty object)
|
|
193
|
-
* new Map() (empty Map)
|
|
194
|
-
* new Set() (empty Set)
|
|
195
|
-
*/
|
|
196
|
-
function _isEmpty(obj) {
|
|
197
|
-
if (obj === undefined || obj === null)
|
|
198
|
-
return true;
|
|
199
|
-
if (typeof obj === 'string' || Array.isArray(obj)) {
|
|
200
|
-
return obj.length === 0;
|
|
201
|
-
}
|
|
202
|
-
if (obj instanceof Map || obj instanceof Set) {
|
|
203
|
-
return obj.size === 0;
|
|
204
|
-
}
|
|
205
|
-
if (typeof obj === 'object') {
|
|
206
|
-
return Object.keys(obj).length === 0;
|
|
207
|
-
}
|
|
208
|
-
return false;
|
|
209
|
-
}
|
|
210
|
-
exports._isEmpty = _isEmpty;
|
|
211
168
|
/**
|
|
212
169
|
* Returns `undefined` if it's empty (according to `_isEmpty()` specification),
|
|
213
170
|
* otherwise returns the original object.
|
|
214
171
|
*/
|
|
215
172
|
function _undefinedIfEmpty(obj) {
|
|
216
|
-
return _isEmpty(obj) ? undefined : obj;
|
|
173
|
+
return (0, is_util_1._isEmpty)(obj) ? undefined : obj;
|
|
217
174
|
}
|
|
218
175
|
exports._undefinedIfEmpty = _undefinedIfEmpty;
|
|
219
176
|
/**
|
|
220
177
|
* Filters the object by removing all key-value pairs where Value is Empty (according to _isEmpty() specification).
|
|
221
178
|
*/
|
|
222
179
|
function _filterEmptyValues(obj, mutate = false) {
|
|
223
|
-
return _filterObject(obj, (_k, v) => !_isEmpty(v), mutate);
|
|
180
|
+
return _filterObject(obj, (_k, v) => !(0, is_util_1._isEmpty)(v), mutate);
|
|
224
181
|
}
|
|
225
182
|
exports._filterEmptyValues = _filterEmptyValues;
|
|
226
183
|
/**
|
|
@@ -254,9 +211,9 @@ exports._filterEmptyValues = _filterEmptyValues;
|
|
|
254
211
|
*/
|
|
255
212
|
function _merge(target, ...sources) {
|
|
256
213
|
sources.forEach(source => {
|
|
257
|
-
if (_isObject(source)) {
|
|
214
|
+
if ((0, is_util_1._isObject)(source)) {
|
|
258
215
|
Object.keys(source).forEach(key => {
|
|
259
|
-
if (_isObject(source[key])) {
|
|
216
|
+
if ((0, is_util_1._isObject)(source[key])) {
|
|
260
217
|
if (!target[key])
|
|
261
218
|
Object.assign(target, { [key]: {} });
|
|
262
219
|
_merge(target[key], source[key]);
|
|
@@ -292,7 +249,7 @@ exports._deepTrim = _deepTrim;
|
|
|
292
249
|
// from: https://github.com/jonschlinkert/unset-value
|
|
293
250
|
// mutates obj
|
|
294
251
|
function _unset(obj, prop) {
|
|
295
|
-
if (!_isObject(obj)) {
|
|
252
|
+
if (!(0, is_util_1._isObject)(obj)) {
|
|
296
253
|
return;
|
|
297
254
|
}
|
|
298
255
|
// eslint-disable-next-line no-prototype-builtins
|
|
@@ -305,11 +262,11 @@ function _unset(obj, prop) {
|
|
|
305
262
|
while (segs.length && segs[segs.length - 1].slice(-1) === '\\') {
|
|
306
263
|
last = segs.pop().slice(0, -1) + '.' + last;
|
|
307
264
|
}
|
|
308
|
-
while (segs.length && _isObject(obj)) {
|
|
265
|
+
while (segs.length && (0, is_util_1._isObject)(obj)) {
|
|
309
266
|
const k = (prop = segs.shift());
|
|
310
267
|
obj = obj[k];
|
|
311
268
|
}
|
|
312
|
-
if (!_isObject(obj))
|
|
269
|
+
if (!(0, is_util_1._isObject)(obj))
|
|
313
270
|
return;
|
|
314
271
|
delete obj[last];
|
|
315
272
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports._sortObjectDeep = void 0;
|
|
4
|
-
const
|
|
4
|
+
const __1 = require("..");
|
|
5
5
|
/**
|
|
6
6
|
* based on: https://github.com/IndigoUnited/js-deep-sort-object
|
|
7
7
|
*/
|
|
@@ -11,7 +11,7 @@ function _sortObjectDeep(o) {
|
|
|
11
11
|
// eslint-disable-next-line unicorn/no-array-callback-reference
|
|
12
12
|
return o.map(_sortObjectDeep);
|
|
13
13
|
}
|
|
14
|
-
if ((0,
|
|
14
|
+
if ((0, __1._isObject)(o)) {
|
|
15
15
|
const out = {};
|
|
16
16
|
Object.keys(o)
|
|
17
17
|
.sort((a, b) => a.localeCompare(b))
|
package/dist/types.d.ts
CHANGED
|
@@ -189,3 +189,5 @@ export declare function _stringMapEntries<T>(m: StringMap<T>): [k: string, v: T]
|
|
|
189
189
|
* @experimental
|
|
190
190
|
*/
|
|
191
191
|
export declare function _objectKeys<T extends AnyObject>(obj: T): (keyof T)[];
|
|
192
|
+
export declare type NullishValue = null | undefined;
|
|
193
|
+
export declare type FalsyValue = false | '' | 0 | null | undefined;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { _isNotNullish } from '../is.util';
|
|
1
2
|
/**
|
|
2
3
|
* Creates an array of elements split into groups the length of size. If collection can’t be split evenly, the
|
|
3
4
|
* final chunk will be the remaining elements.
|
|
@@ -191,6 +192,9 @@ export function _intersection(...arrays) {
|
|
|
191
192
|
export function _difference(source, ...diffs) {
|
|
192
193
|
return diffs.reduce((a, b) => a.filter(c => !b.includes(c)), source);
|
|
193
194
|
}
|
|
195
|
+
/**
|
|
196
|
+
* Returns the sum of items, or 0 for empty array.
|
|
197
|
+
*/
|
|
194
198
|
export function _sum(items) {
|
|
195
199
|
return items.reduce((sum, n) => sum + n, 0);
|
|
196
200
|
}
|
|
@@ -252,22 +256,32 @@ export function _lastOrUndefined(array) {
|
|
|
252
256
|
return array[array.length - 1];
|
|
253
257
|
}
|
|
254
258
|
export function _minOrUndefined(array) {
|
|
255
|
-
|
|
259
|
+
const a = array.filter(_isNotNullish);
|
|
260
|
+
if (!a.length)
|
|
256
261
|
return;
|
|
257
|
-
return _min(
|
|
262
|
+
return _min(a);
|
|
258
263
|
}
|
|
264
|
+
/**
|
|
265
|
+
* Filters out nullish values (undefined and null).
|
|
266
|
+
*/
|
|
259
267
|
export function _min(array) {
|
|
260
|
-
|
|
268
|
+
const a = array.filter(_isNotNullish);
|
|
269
|
+
if (!a.length)
|
|
261
270
|
throw new Error('_min called on empty array');
|
|
262
|
-
return
|
|
271
|
+
return a.reduce((min, item) => (min <= item ? min : item));
|
|
263
272
|
}
|
|
264
273
|
export function _maxOrUndefined(array) {
|
|
265
|
-
|
|
274
|
+
const a = array.filter(_isNotNullish);
|
|
275
|
+
if (!a.length)
|
|
266
276
|
return;
|
|
267
|
-
return _max(
|
|
277
|
+
return _max(a);
|
|
268
278
|
}
|
|
279
|
+
/**
|
|
280
|
+
* Filters out nullish values (undefined and null).
|
|
281
|
+
*/
|
|
269
282
|
export function _max(array) {
|
|
270
|
-
|
|
283
|
+
const a = array.filter(_isNotNullish);
|
|
284
|
+
if (!a.length)
|
|
271
285
|
throw new Error('_max called on empty array');
|
|
272
|
-
return
|
|
286
|
+
return a.reduce((max, item) => (max >= item ? max : item));
|
|
273
287
|
}
|
|
@@ -179,11 +179,10 @@ export class LocalTime {
|
|
|
179
179
|
return v === undefined ? this.get('second') : this.set('second', v);
|
|
180
180
|
}
|
|
181
181
|
setComponents(c, mutate = false) {
|
|
182
|
-
var _a;
|
|
183
182
|
const d = mutate ? this.$date : new Date(this.$date);
|
|
184
183
|
// Year, month and day set all-at-once, to avoid 30/31 (and 28/29) mishap
|
|
185
184
|
if (c.day || c.month !== undefined || c.year !== undefined) {
|
|
186
|
-
d.setFullYear(
|
|
185
|
+
d.setFullYear(c.year ?? d.getFullYear(), c.month ? c.month - 1 : d.getMonth(), c.day || d.getDate());
|
|
187
186
|
}
|
|
188
187
|
if (c.hour !== undefined) {
|
|
189
188
|
d.setHours(c.hour);
|
|
@@ -19,7 +19,6 @@ export function _createPromiseDecorator(cfg, decoratorParams = {}) {
|
|
|
19
19
|
const key = String(propertyKey);
|
|
20
20
|
const methodSignature = _getTargetMethodSignature(target, key);
|
|
21
21
|
pd.value = async function (...args) {
|
|
22
|
-
var _a, _b;
|
|
23
22
|
// console.log(`@${cfg.decoratorName} called inside function`)
|
|
24
23
|
const started = Date.now();
|
|
25
24
|
try {
|
|
@@ -47,9 +46,12 @@ export function _createPromiseDecorator(cfg, decoratorParams = {}) {
|
|
|
47
46
|
started,
|
|
48
47
|
};
|
|
49
48
|
if (cfg.thenFn) {
|
|
50
|
-
res = cfg.thenFn(
|
|
49
|
+
res = cfg.thenFn({
|
|
50
|
+
...resp,
|
|
51
|
+
res,
|
|
52
|
+
});
|
|
51
53
|
}
|
|
52
|
-
|
|
54
|
+
cfg.finallyFn?.(resp);
|
|
53
55
|
return res;
|
|
54
56
|
}
|
|
55
57
|
catch (err) {
|
|
@@ -64,10 +66,13 @@ export function _createPromiseDecorator(cfg, decoratorParams = {}) {
|
|
|
64
66
|
};
|
|
65
67
|
let handled = false;
|
|
66
68
|
if (cfg.catchFn) {
|
|
67
|
-
cfg.catchFn(
|
|
69
|
+
cfg.catchFn({
|
|
70
|
+
...resp,
|
|
71
|
+
err,
|
|
72
|
+
});
|
|
68
73
|
handled = true;
|
|
69
74
|
}
|
|
70
|
-
|
|
75
|
+
cfg.finallyFn?.(resp);
|
|
71
76
|
if (!handled) {
|
|
72
77
|
throw err; // rethrow
|
|
73
78
|
}
|
|
@@ -105,5 +105,10 @@ export function _debounce(func, wait, opt = {}) {
|
|
|
105
105
|
return debounced;
|
|
106
106
|
}
|
|
107
107
|
export function _throttle(func, wait, opt = {}) {
|
|
108
|
-
return _debounce(func, wait,
|
|
108
|
+
return _debounce(func, wait, {
|
|
109
|
+
leading: true,
|
|
110
|
+
trailing: true,
|
|
111
|
+
...opt,
|
|
112
|
+
maxWait: wait,
|
|
113
|
+
});
|
|
109
114
|
}
|