@naturalcycles/js-lib 14.42.1 → 14.46.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/CHANGELOG.md +28 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +7 -3
- package/dist/json-schema/from-data/generateJsonSchemaFromData.d.ts +7 -0
- package/dist/json-schema/from-data/generateJsonSchemaFromData.js +90 -0
- package/dist/json-schema/jsonSchema.model.d.ts +7 -0
- package/dist/json-schema/jsonSchemaBuilder.d.ts +3 -0
- package/dist/json-schema/jsonSchemaBuilder.js +9 -0
- package/dist/string/stringifyAny.d.ts +1 -1
- package/dist/string/stringifyAny.js +1 -1
- package/dist/typeFest.d.ts +16 -0
- package/dist/vendor/is.d.ts +224 -0
- package/dist/vendor/is.js +466 -0
- package/dist-esm/array/array.util.js +0 -1
- package/dist-esm/array/range.js +0 -1
- package/dist-esm/decorators/createPromiseDecorator.js +0 -1
- package/dist-esm/decorators/debounce.decorator.js +0 -1
- package/dist-esm/decorators/debounce.js +0 -1
- package/dist-esm/decorators/decorator.util.js +0 -1
- package/dist-esm/decorators/logMethod.decorator.js +0 -1
- package/dist-esm/decorators/memo.decorator.js +0 -1
- package/dist-esm/decorators/memo.util.js +0 -1
- package/dist-esm/decorators/memoFn.js +0 -1
- package/dist-esm/decorators/memoSimple.decorator.js +0 -1
- package/dist-esm/decorators/retry.decorator.js +0 -1
- package/dist-esm/decorators/timeout.decorator.js +0 -1
- package/dist-esm/error/app.error.js +0 -1
- package/dist-esm/error/assert.js +0 -1
- package/dist-esm/error/error.model.js +0 -1
- package/dist-esm/error/error.util.js +0 -1
- package/dist-esm/error/errorMode.js +0 -1
- package/dist-esm/error/http.error.js +0 -1
- package/dist-esm/error/try.js +0 -1
- package/dist-esm/error/tryCatch.js +0 -1
- package/dist-esm/index.js +3 -2
- package/dist-esm/json-schema/from-data/generateJsonSchemaFromData.js +86 -0
- package/dist-esm/json-schema/jsonSchema.cnst.js +0 -1
- package/dist-esm/json-schema/jsonSchema.model.js +0 -1
- package/dist-esm/json-schema/jsonSchema.util.js +0 -1
- package/dist-esm/json-schema/jsonSchemaBuilder.js +9 -1
- package/dist-esm/json-schema/jsonSchemas.js +0 -1
- package/dist-esm/lodash.types.js +0 -1
- package/dist-esm/math/math.util.js +0 -1
- package/dist-esm/math/sma.js +0 -1
- package/dist-esm/number/createDeterministicRandom.js +0 -1
- package/dist-esm/number/number.util.js +0 -1
- package/dist-esm/object/deepEquals.js +0 -1
- package/dist-esm/object/object.util.js +0 -1
- package/dist-esm/object/sortObject.js +0 -1
- package/dist-esm/object/sortObjectDeep.js +0 -1
- package/dist-esm/promise/AggregatedError.js +0 -1
- package/dist-esm/promise/pBatch.js +0 -1
- package/dist-esm/promise/pDefer.js +0 -1
- package/dist-esm/promise/pDelay.js +0 -1
- package/dist-esm/promise/pFilter.js +0 -1
- package/dist-esm/promise/pHang.js +0 -1
- package/dist-esm/promise/pMap.js +0 -1
- package/dist-esm/promise/pProps.js +0 -1
- package/dist-esm/promise/pRetry.js +0 -1
- package/dist-esm/promise/pState.js +0 -1
- package/dist-esm/promise/pTimeout.js +0 -1
- package/dist-esm/promise/pTuple.js +0 -1
- package/dist-esm/string/case.js +0 -1
- package/dist-esm/string/json.util.js +0 -1
- package/dist-esm/string/lodash/unicodeWords.js +0 -1
- package/dist-esm/string/lodash/words.js +0 -1
- package/dist-esm/string/string.util.js +0 -1
- package/dist-esm/string/stringifyAny.js +1 -2
- package/dist-esm/time/time.util.js +0 -1
- package/dist-esm/typeFest.js +0 -1
- package/dist-esm/types.js +0 -1
- package/dist-esm/unit/size.util.js +0 -1
- package/dist-esm/vendor/is.js +463 -0
- package/package.json +2 -1
- package/src/index.ts +4 -0
- package/src/json-schema/from-data/generateJsonSchemaFromData.ts +120 -0
- package/src/json-schema/jsonSchema.model.ts +8 -0
- package/src/json-schema/jsonSchemaBuilder.ts +16 -10
- package/src/string/stringifyAny.ts +2 -2
- package/src/typeFest.ts +30 -0
- package/src/vendor/is.ts +837 -0
- package/dist-esm/array/array.util.js.map +0 -1
- package/dist-esm/array/range.js.map +0 -1
- package/dist-esm/decorators/createPromiseDecorator.js.map +0 -1
- package/dist-esm/decorators/debounce.decorator.js.map +0 -1
- package/dist-esm/decorators/debounce.js.map +0 -1
- package/dist-esm/decorators/decorator.util.js.map +0 -1
- package/dist-esm/decorators/logMethod.decorator.js.map +0 -1
- package/dist-esm/decorators/memo.decorator.js.map +0 -1
- package/dist-esm/decorators/memo.util.js.map +0 -1
- package/dist-esm/decorators/memoFn.js.map +0 -1
- package/dist-esm/decorators/memoSimple.decorator.js.map +0 -1
- package/dist-esm/decorators/retry.decorator.js.map +0 -1
- package/dist-esm/decorators/timeout.decorator.js.map +0 -1
- package/dist-esm/error/app.error.js.map +0 -1
- package/dist-esm/error/assert.js.map +0 -1
- package/dist-esm/error/error.model.js.map +0 -1
- package/dist-esm/error/error.util.js.map +0 -1
- package/dist-esm/error/errorMode.js.map +0 -1
- package/dist-esm/error/http.error.js.map +0 -1
- package/dist-esm/error/try.js.map +0 -1
- package/dist-esm/error/tryCatch.js.map +0 -1
- package/dist-esm/index.js.map +0 -1
- package/dist-esm/json-schema/jsonSchema.cnst.js.map +0 -1
- package/dist-esm/json-schema/jsonSchema.model.js.map +0 -1
- package/dist-esm/json-schema/jsonSchema.util.js.map +0 -1
- package/dist-esm/json-schema/jsonSchemaBuilder.js.map +0 -1
- package/dist-esm/json-schema/jsonSchemas.js.map +0 -1
- package/dist-esm/lodash.types.js.map +0 -1
- package/dist-esm/math/math.util.js.map +0 -1
- package/dist-esm/math/sma.js.map +0 -1
- package/dist-esm/number/createDeterministicRandom.js.map +0 -1
- package/dist-esm/number/number.util.js.map +0 -1
- package/dist-esm/object/deepEquals.js.map +0 -1
- package/dist-esm/object/object.util.js.map +0 -1
- package/dist-esm/object/sortObject.js.map +0 -1
- package/dist-esm/object/sortObjectDeep.js.map +0 -1
- package/dist-esm/promise/AggregatedError.js.map +0 -1
- package/dist-esm/promise/pBatch.js.map +0 -1
- package/dist-esm/promise/pDefer.js.map +0 -1
- package/dist-esm/promise/pDelay.js.map +0 -1
- package/dist-esm/promise/pFilter.js.map +0 -1
- package/dist-esm/promise/pHang.js.map +0 -1
- package/dist-esm/promise/pMap.js.map +0 -1
- package/dist-esm/promise/pProps.js.map +0 -1
- package/dist-esm/promise/pRetry.js.map +0 -1
- package/dist-esm/promise/pState.js.map +0 -1
- package/dist-esm/promise/pTimeout.js.map +0 -1
- package/dist-esm/promise/pTuple.js.map +0 -1
- package/dist-esm/string/case.js.map +0 -1
- package/dist-esm/string/json.util.js.map +0 -1
- package/dist-esm/string/lodash/unicodeWords.js.map +0 -1
- package/dist-esm/string/lodash/words.js.map +0 -1
- package/dist-esm/string/string.util.js.map +0 -1
- package/dist-esm/string/stringifyAny.js.map +0 -1
- package/dist-esm/time/time.util.js.map +0 -1
- package/dist-esm/typeFest.js.map +0 -1
- package/dist-esm/types.js.map +0 -1
- package/dist-esm/unit/size.util.js.map +0 -1
|
@@ -0,0 +1,466 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/// <reference lib="es2018"/>
|
|
3
|
+
/// <reference lib="dom"/>
|
|
4
|
+
/// <reference types="node"/>
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.assert = exports.AssertionTypeDescription = exports.is = void 0;
|
|
7
|
+
const typedArrayTypeNames = [
|
|
8
|
+
'Int8Array',
|
|
9
|
+
'Uint8Array',
|
|
10
|
+
'Uint8ClampedArray',
|
|
11
|
+
'Int16Array',
|
|
12
|
+
'Uint16Array',
|
|
13
|
+
'Int32Array',
|
|
14
|
+
'Uint32Array',
|
|
15
|
+
'Float32Array',
|
|
16
|
+
'Float64Array',
|
|
17
|
+
'BigInt64Array',
|
|
18
|
+
'BigUint64Array',
|
|
19
|
+
];
|
|
20
|
+
function isTypedArrayName(name) {
|
|
21
|
+
return typedArrayTypeNames.includes(name);
|
|
22
|
+
}
|
|
23
|
+
const objectTypeNames = [
|
|
24
|
+
'Function',
|
|
25
|
+
'Generator',
|
|
26
|
+
'AsyncGenerator',
|
|
27
|
+
'GeneratorFunction',
|
|
28
|
+
'AsyncGeneratorFunction',
|
|
29
|
+
'AsyncFunction',
|
|
30
|
+
'Observable',
|
|
31
|
+
'Array',
|
|
32
|
+
'Buffer',
|
|
33
|
+
'Object',
|
|
34
|
+
'RegExp',
|
|
35
|
+
'Date',
|
|
36
|
+
'Error',
|
|
37
|
+
'Map',
|
|
38
|
+
'Set',
|
|
39
|
+
'WeakMap',
|
|
40
|
+
'WeakSet',
|
|
41
|
+
'ArrayBuffer',
|
|
42
|
+
'SharedArrayBuffer',
|
|
43
|
+
'DataView',
|
|
44
|
+
'Promise',
|
|
45
|
+
'URL',
|
|
46
|
+
'FormData',
|
|
47
|
+
'URLSearchParams',
|
|
48
|
+
'HTMLElement',
|
|
49
|
+
...typedArrayTypeNames,
|
|
50
|
+
];
|
|
51
|
+
function isObjectTypeName(name) {
|
|
52
|
+
return objectTypeNames.includes(name);
|
|
53
|
+
}
|
|
54
|
+
const primitiveTypeNames = [
|
|
55
|
+
'null',
|
|
56
|
+
'undefined',
|
|
57
|
+
'string',
|
|
58
|
+
'number',
|
|
59
|
+
'bigint',
|
|
60
|
+
'boolean',
|
|
61
|
+
'symbol',
|
|
62
|
+
];
|
|
63
|
+
function isPrimitiveTypeName(name) {
|
|
64
|
+
return primitiveTypeNames.includes(name);
|
|
65
|
+
}
|
|
66
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
67
|
+
function isOfType(type) {
|
|
68
|
+
return (value) => typeof value === type;
|
|
69
|
+
}
|
|
70
|
+
const { toString } = Object.prototype;
|
|
71
|
+
const getObjectType = (value) => {
|
|
72
|
+
const objectTypeName = toString.call(value).slice(8, -1);
|
|
73
|
+
if (/HTML\w+Element/.test(objectTypeName) && is.domElement(value)) {
|
|
74
|
+
return 'HTMLElement';
|
|
75
|
+
}
|
|
76
|
+
if (isObjectTypeName(objectTypeName)) {
|
|
77
|
+
return objectTypeName;
|
|
78
|
+
}
|
|
79
|
+
return undefined;
|
|
80
|
+
};
|
|
81
|
+
const isObjectOfType = (type) => (value) => getObjectType(value) === type;
|
|
82
|
+
function is(value) {
|
|
83
|
+
if (value === null) {
|
|
84
|
+
return 'null';
|
|
85
|
+
}
|
|
86
|
+
switch (typeof value) {
|
|
87
|
+
case 'undefined':
|
|
88
|
+
return 'undefined';
|
|
89
|
+
case 'string':
|
|
90
|
+
return 'string';
|
|
91
|
+
case 'number':
|
|
92
|
+
return 'number';
|
|
93
|
+
case 'boolean':
|
|
94
|
+
return 'boolean';
|
|
95
|
+
case 'function':
|
|
96
|
+
return 'Function';
|
|
97
|
+
case 'bigint':
|
|
98
|
+
return 'bigint';
|
|
99
|
+
case 'symbol':
|
|
100
|
+
return 'symbol';
|
|
101
|
+
default:
|
|
102
|
+
}
|
|
103
|
+
if (is.observable(value)) {
|
|
104
|
+
return 'Observable';
|
|
105
|
+
}
|
|
106
|
+
if (is.array(value)) {
|
|
107
|
+
return 'Array';
|
|
108
|
+
}
|
|
109
|
+
if (is.buffer(value)) {
|
|
110
|
+
return 'Buffer';
|
|
111
|
+
}
|
|
112
|
+
const tagType = getObjectType(value);
|
|
113
|
+
if (tagType) {
|
|
114
|
+
return tagType;
|
|
115
|
+
}
|
|
116
|
+
if (value instanceof String ||
|
|
117
|
+
value instanceof Boolean ||
|
|
118
|
+
value instanceof Number) {
|
|
119
|
+
throw new TypeError("Please don't use object wrappers for primitive types");
|
|
120
|
+
}
|
|
121
|
+
return 'Object';
|
|
122
|
+
}
|
|
123
|
+
exports.is = is;
|
|
124
|
+
is.undefined = isOfType('undefined');
|
|
125
|
+
is.string = isOfType('string');
|
|
126
|
+
const isNumberType = isOfType('number');
|
|
127
|
+
is.number = (value) => isNumberType(value) && !is.nan(value);
|
|
128
|
+
is.bigint = isOfType('bigint');
|
|
129
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
130
|
+
is.function_ = isOfType('function');
|
|
131
|
+
is.null_ = (value) => value === null;
|
|
132
|
+
is.class_ = (value) => is.function_(value) && value.toString().startsWith('class ');
|
|
133
|
+
is.boolean = (value) => value === true || value === false;
|
|
134
|
+
is.symbol = isOfType('symbol');
|
|
135
|
+
is.numericString = (value) => is.string(value) && !is.emptyStringOrWhitespace(value) && !Number.isNaN(Number(value));
|
|
136
|
+
is.array = (value, assertion) => {
|
|
137
|
+
if (!Array.isArray(value)) {
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
if (!is.function_(assertion)) {
|
|
141
|
+
return true;
|
|
142
|
+
}
|
|
143
|
+
return value.every(assertion);
|
|
144
|
+
};
|
|
145
|
+
is.buffer = (value) => value?.constructor?.isBuffer?.(value) ?? false;
|
|
146
|
+
is.nullOrUndefined = (value) => is.null_(value) || is.undefined(value);
|
|
147
|
+
is.object = (value) => !is.null_(value) && (typeof value === 'object' || is.function_(value));
|
|
148
|
+
is.iterable = (value) => is.function_(value?.[Symbol.iterator]);
|
|
149
|
+
is.asyncIterable = (value) => is.function_(value?.[Symbol.asyncIterator]);
|
|
150
|
+
is.generator = (value) => is.iterable(value) && is.function_(value.next) && is.function_(value.throw);
|
|
151
|
+
is.asyncGenerator = (value) => is.asyncIterable(value) && is.function_(value.next) && is.function_(value.throw);
|
|
152
|
+
is.nativePromise = (value) => isObjectOfType('Promise')(value);
|
|
153
|
+
const hasPromiseAPI = (value) => is.function_(value?.then) && is.function_(value?.catch);
|
|
154
|
+
is.promise = (value) => is.nativePromise(value) || hasPromiseAPI(value);
|
|
155
|
+
is.generatorFunction = isObjectOfType('GeneratorFunction');
|
|
156
|
+
is.asyncGeneratorFunction = (value) => getObjectType(value) === 'AsyncGeneratorFunction';
|
|
157
|
+
is.asyncFunction = (value) => getObjectType(value) === 'AsyncFunction';
|
|
158
|
+
// eslint-disable-next-line no-prototype-builtins, @typescript-eslint/ban-types
|
|
159
|
+
is.boundFunction = (value) => is.function_(value) && !value.hasOwnProperty('prototype');
|
|
160
|
+
is.regExp = isObjectOfType('RegExp');
|
|
161
|
+
is.date = isObjectOfType('Date');
|
|
162
|
+
is.error = isObjectOfType('Error');
|
|
163
|
+
is.map = (value) => isObjectOfType('Map')(value);
|
|
164
|
+
is.set = (value) => isObjectOfType('Set')(value);
|
|
165
|
+
is.weakMap = (value) => isObjectOfType('WeakMap')(value);
|
|
166
|
+
is.weakSet = (value) => isObjectOfType('WeakSet')(value);
|
|
167
|
+
is.int8Array = isObjectOfType('Int8Array');
|
|
168
|
+
is.uint8Array = isObjectOfType('Uint8Array');
|
|
169
|
+
is.uint8ClampedArray = isObjectOfType('Uint8ClampedArray');
|
|
170
|
+
is.int16Array = isObjectOfType('Int16Array');
|
|
171
|
+
is.uint16Array = isObjectOfType('Uint16Array');
|
|
172
|
+
is.int32Array = isObjectOfType('Int32Array');
|
|
173
|
+
is.uint32Array = isObjectOfType('Uint32Array');
|
|
174
|
+
is.float32Array = isObjectOfType('Float32Array');
|
|
175
|
+
is.float64Array = isObjectOfType('Float64Array');
|
|
176
|
+
is.bigInt64Array = isObjectOfType('BigInt64Array');
|
|
177
|
+
is.bigUint64Array = isObjectOfType('BigUint64Array');
|
|
178
|
+
is.arrayBuffer = isObjectOfType('ArrayBuffer');
|
|
179
|
+
is.sharedArrayBuffer = isObjectOfType('SharedArrayBuffer');
|
|
180
|
+
is.dataView = isObjectOfType('DataView');
|
|
181
|
+
is.directInstanceOf = (instance, class_) => Object.getPrototypeOf(instance) === class_.prototype;
|
|
182
|
+
is.urlInstance = (value) => isObjectOfType('URL')(value);
|
|
183
|
+
is.urlString = (value) => {
|
|
184
|
+
if (!is.string(value)) {
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
try {
|
|
188
|
+
new URL(value); // eslint-disable-line no-new
|
|
189
|
+
return true;
|
|
190
|
+
}
|
|
191
|
+
catch {
|
|
192
|
+
return false;
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
// TODO: Use the `not` operator with a type guard here when it's available.
|
|
196
|
+
// Example: `is.truthy = (value: unknown): value is (not false | not 0 | not '' | not undefined | not null) => Boolean(value);`
|
|
197
|
+
is.truthy = (value) => Boolean(value);
|
|
198
|
+
// Example: `is.falsy = (value: unknown): value is (not true | 0 | '' | undefined | null) => Boolean(value);`
|
|
199
|
+
is.falsy = (value) => !value;
|
|
200
|
+
is.nan = (value) => Number.isNaN(value);
|
|
201
|
+
is.primitive = (value) => is.null_(value) || isPrimitiveTypeName(typeof value);
|
|
202
|
+
is.integer = (value) => Number.isInteger(value);
|
|
203
|
+
is.safeInteger = (value) => Number.isSafeInteger(value);
|
|
204
|
+
is.plainObject = (value) => {
|
|
205
|
+
// From: https://github.com/sindresorhus/is-plain-obj/blob/main/index.js
|
|
206
|
+
if (toString.call(value) !== '[object Object]') {
|
|
207
|
+
return false;
|
|
208
|
+
}
|
|
209
|
+
const prototype = Object.getPrototypeOf(value);
|
|
210
|
+
return prototype === null || prototype === Object.getPrototypeOf({});
|
|
211
|
+
};
|
|
212
|
+
is.typedArray = (value) => isTypedArrayName(getObjectType(value));
|
|
213
|
+
const isValidLength = (value) => is.safeInteger(value) && value >= 0;
|
|
214
|
+
is.arrayLike = (value) => !is.nullOrUndefined(value) &&
|
|
215
|
+
!is.function_(value) &&
|
|
216
|
+
isValidLength(value.length);
|
|
217
|
+
is.inRange = (value, range) => {
|
|
218
|
+
if (is.number(range)) {
|
|
219
|
+
return value >= Math.min(0, range) && value <= Math.max(range, 0);
|
|
220
|
+
}
|
|
221
|
+
if (is.array(range) && range.length === 2) {
|
|
222
|
+
return value >= Math.min(...range) && value <= Math.max(...range);
|
|
223
|
+
}
|
|
224
|
+
throw new TypeError(`Invalid range: ${JSON.stringify(range)}`);
|
|
225
|
+
};
|
|
226
|
+
const NODE_TYPE_ELEMENT = 1;
|
|
227
|
+
const DOM_PROPERTIES_TO_CHECK = [
|
|
228
|
+
'innerHTML',
|
|
229
|
+
'ownerDocument',
|
|
230
|
+
'style',
|
|
231
|
+
'attributes',
|
|
232
|
+
'nodeValue',
|
|
233
|
+
];
|
|
234
|
+
is.domElement = (value) => {
|
|
235
|
+
return (is.object(value) &&
|
|
236
|
+
value.nodeType === NODE_TYPE_ELEMENT &&
|
|
237
|
+
is.string(value.nodeName) &&
|
|
238
|
+
!is.plainObject(value) &&
|
|
239
|
+
DOM_PROPERTIES_TO_CHECK.every(property => property in value));
|
|
240
|
+
};
|
|
241
|
+
is.observable = (value) => {
|
|
242
|
+
if (!value) {
|
|
243
|
+
return false;
|
|
244
|
+
}
|
|
245
|
+
if (value === value[Symbol.observable]?.()) {
|
|
246
|
+
return true;
|
|
247
|
+
}
|
|
248
|
+
if (value === value['@@observable']?.()) {
|
|
249
|
+
return true;
|
|
250
|
+
}
|
|
251
|
+
return false;
|
|
252
|
+
};
|
|
253
|
+
is.nodeStream = (value) => is.object(value) && is.function_(value.pipe) && !is.observable(value);
|
|
254
|
+
is.infinite = (value) => value === Infinity || value === -Infinity;
|
|
255
|
+
const isAbsoluteMod2 = (remainder) => (value) => is.integer(value) && Math.abs(value % 2) === remainder;
|
|
256
|
+
is.evenInteger = isAbsoluteMod2(0);
|
|
257
|
+
is.oddInteger = isAbsoluteMod2(1);
|
|
258
|
+
is.emptyArray = (value) => is.array(value) && value.length === 0;
|
|
259
|
+
is.nonEmptyArray = (value) => is.array(value) && value.length > 0;
|
|
260
|
+
is.emptyString = (value) => is.string(value) && value.length === 0;
|
|
261
|
+
// TODO: Use `not ''` when the `not` operator is available.
|
|
262
|
+
is.nonEmptyString = (value) => is.string(value) && value.length > 0;
|
|
263
|
+
const isWhiteSpaceString = (value) => is.string(value) && !/\S/.test(value);
|
|
264
|
+
is.emptyStringOrWhitespace = (value) => is.emptyString(value) || isWhiteSpaceString(value);
|
|
265
|
+
is.emptyObject = (value) => is.object(value) && !is.map(value) && !is.set(value) && Object.keys(value).length === 0;
|
|
266
|
+
// TODO: Use `not` operator here to remove `Map` and `Set` from type guard:
|
|
267
|
+
// - https://github.com/Microsoft/TypeScript/pull/29317
|
|
268
|
+
is.nonEmptyObject = (value) => is.object(value) && !is.map(value) && !is.set(value) && Object.keys(value).length > 0;
|
|
269
|
+
is.emptySet = (value) => is.set(value) && value.size === 0;
|
|
270
|
+
is.nonEmptySet = (value) => is.set(value) && value.size > 0;
|
|
271
|
+
is.emptyMap = (value) => is.map(value) && value.size === 0;
|
|
272
|
+
is.nonEmptyMap = (value) => is.map(value) && value.size > 0;
|
|
273
|
+
// `PropertyKey` is any value that can be used as an object key (string, number, or symbol)
|
|
274
|
+
is.propertyKey = (value) => is.any([is.string, is.number, is.symbol], value);
|
|
275
|
+
is.formData = (value) => isObjectOfType('FormData')(value);
|
|
276
|
+
is.urlSearchParams = (value) => isObjectOfType('URLSearchParams')(value);
|
|
277
|
+
const predicateOnArray = (method, predicate, values) => {
|
|
278
|
+
if (!is.function_(predicate)) {
|
|
279
|
+
throw new TypeError(`Invalid predicate: ${JSON.stringify(predicate)}`);
|
|
280
|
+
}
|
|
281
|
+
if (values.length === 0) {
|
|
282
|
+
throw new TypeError('Invalid number of values');
|
|
283
|
+
}
|
|
284
|
+
return method.call(values, predicate);
|
|
285
|
+
};
|
|
286
|
+
is.any = (predicate, ...values) => {
|
|
287
|
+
const predicates = is.array(predicate) ? predicate : [predicate];
|
|
288
|
+
return predicates.some(singlePredicate => predicateOnArray(Array.prototype.some, singlePredicate, values));
|
|
289
|
+
};
|
|
290
|
+
is.all = (predicate, ...values) => predicateOnArray(Array.prototype.every, predicate, values);
|
|
291
|
+
const assertType = (condition, description, value, options = {}) => {
|
|
292
|
+
if (!condition) {
|
|
293
|
+
const { multipleValues } = options;
|
|
294
|
+
const valuesMessage = multipleValues
|
|
295
|
+
? `received values of types ${[
|
|
296
|
+
...new Set(value.map(singleValue => `\`${is(singleValue)}\``)),
|
|
297
|
+
].join(', ')}`
|
|
298
|
+
: `received value of type \`${is(value)}\``;
|
|
299
|
+
throw new TypeError(`Expected value which is \`${description}\`, ${valuesMessage}.`);
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
var AssertionTypeDescription;
|
|
303
|
+
(function (AssertionTypeDescription) {
|
|
304
|
+
AssertionTypeDescription["class_"] = "Class";
|
|
305
|
+
AssertionTypeDescription["numericString"] = "string with a number";
|
|
306
|
+
AssertionTypeDescription["nullOrUndefined"] = "null or undefined";
|
|
307
|
+
AssertionTypeDescription["iterable"] = "Iterable";
|
|
308
|
+
AssertionTypeDescription["asyncIterable"] = "AsyncIterable";
|
|
309
|
+
AssertionTypeDescription["nativePromise"] = "native Promise";
|
|
310
|
+
AssertionTypeDescription["urlString"] = "string with a URL";
|
|
311
|
+
AssertionTypeDescription["truthy"] = "truthy";
|
|
312
|
+
AssertionTypeDescription["falsy"] = "falsy";
|
|
313
|
+
AssertionTypeDescription["nan"] = "NaN";
|
|
314
|
+
AssertionTypeDescription["primitive"] = "primitive";
|
|
315
|
+
AssertionTypeDescription["integer"] = "integer";
|
|
316
|
+
AssertionTypeDescription["safeInteger"] = "integer";
|
|
317
|
+
AssertionTypeDescription["plainObject"] = "plain object";
|
|
318
|
+
AssertionTypeDescription["arrayLike"] = "array-like";
|
|
319
|
+
AssertionTypeDescription["typedArray"] = "TypedArray";
|
|
320
|
+
AssertionTypeDescription["domElement"] = "HTMLElement";
|
|
321
|
+
AssertionTypeDescription["nodeStream"] = "Node.js Stream";
|
|
322
|
+
AssertionTypeDescription["infinite"] = "infinite number";
|
|
323
|
+
AssertionTypeDescription["emptyArray"] = "empty array";
|
|
324
|
+
AssertionTypeDescription["nonEmptyArray"] = "non-empty array";
|
|
325
|
+
AssertionTypeDescription["emptyString"] = "empty string";
|
|
326
|
+
AssertionTypeDescription["nonEmptyString"] = "non-empty string";
|
|
327
|
+
AssertionTypeDescription["emptyStringOrWhitespace"] = "empty string or whitespace";
|
|
328
|
+
AssertionTypeDescription["emptyObject"] = "empty object";
|
|
329
|
+
AssertionTypeDescription["nonEmptyObject"] = "non-empty object";
|
|
330
|
+
AssertionTypeDescription["emptySet"] = "empty set";
|
|
331
|
+
AssertionTypeDescription["nonEmptySet"] = "non-empty set";
|
|
332
|
+
AssertionTypeDescription["emptyMap"] = "empty map";
|
|
333
|
+
AssertionTypeDescription["nonEmptyMap"] = "non-empty map";
|
|
334
|
+
AssertionTypeDescription["evenInteger"] = "even integer";
|
|
335
|
+
AssertionTypeDescription["oddInteger"] = "odd integer";
|
|
336
|
+
AssertionTypeDescription["directInstanceOf"] = "T";
|
|
337
|
+
AssertionTypeDescription["inRange"] = "in range";
|
|
338
|
+
AssertionTypeDescription["any"] = "predicate returns truthy for any value";
|
|
339
|
+
AssertionTypeDescription["all"] = "predicate returns truthy for all values";
|
|
340
|
+
})(AssertionTypeDescription = exports.AssertionTypeDescription || (exports.AssertionTypeDescription = {}));
|
|
341
|
+
exports.assert = {
|
|
342
|
+
// Unknowns.
|
|
343
|
+
undefined: (value) => assertType(is.undefined(value), 'undefined', value),
|
|
344
|
+
string: (value) => assertType(is.string(value), 'string', value),
|
|
345
|
+
number: (value) => assertType(is.number(value), 'number', value),
|
|
346
|
+
bigint: (value) => assertType(is.bigint(value), 'bigint', value),
|
|
347
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
348
|
+
function_: (value) => assertType(is.function_(value), 'Function', value),
|
|
349
|
+
null_: (value) => assertType(is.null_(value), 'null', value),
|
|
350
|
+
class_: (value) => assertType(is.class_(value), AssertionTypeDescription.class_, value),
|
|
351
|
+
boolean: (value) => assertType(is.boolean(value), 'boolean', value),
|
|
352
|
+
symbol: (value) => assertType(is.symbol(value), 'symbol', value),
|
|
353
|
+
numericString: (value) => assertType(is.numericString(value), AssertionTypeDescription.numericString, value),
|
|
354
|
+
array: (value, assertion) => {
|
|
355
|
+
const assert = assertType;
|
|
356
|
+
assert(is.array(value), 'Array', value);
|
|
357
|
+
if (assertion) {
|
|
358
|
+
value.forEach(assertion);
|
|
359
|
+
}
|
|
360
|
+
},
|
|
361
|
+
buffer: (value) => assertType(is.buffer(value), 'Buffer', value),
|
|
362
|
+
nullOrUndefined: (value) => assertType(is.nullOrUndefined(value), AssertionTypeDescription.nullOrUndefined, value),
|
|
363
|
+
object: (value) => assertType(is.object(value), 'Object', value),
|
|
364
|
+
iterable: (value) => assertType(is.iterable(value), AssertionTypeDescription.iterable, value),
|
|
365
|
+
asyncIterable: (value) => assertType(is.asyncIterable(value), AssertionTypeDescription.asyncIterable, value),
|
|
366
|
+
generator: (value) => assertType(is.generator(value), 'Generator', value),
|
|
367
|
+
asyncGenerator: (value) => assertType(is.asyncGenerator(value), 'AsyncGenerator', value),
|
|
368
|
+
nativePromise: (value) => assertType(is.nativePromise(value), AssertionTypeDescription.nativePromise, value),
|
|
369
|
+
promise: (value) => assertType(is.promise(value), 'Promise', value),
|
|
370
|
+
generatorFunction: (value) => assertType(is.generatorFunction(value), 'GeneratorFunction', value),
|
|
371
|
+
asyncGeneratorFunction: (value) => assertType(is.asyncGeneratorFunction(value), 'AsyncGeneratorFunction', value),
|
|
372
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
373
|
+
asyncFunction: (value) => assertType(is.asyncFunction(value), 'AsyncFunction', value),
|
|
374
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
375
|
+
boundFunction: (value) => assertType(is.boundFunction(value), 'Function', value),
|
|
376
|
+
regExp: (value) => assertType(is.regExp(value), 'RegExp', value),
|
|
377
|
+
date: (value) => assertType(is.date(value), 'Date', value),
|
|
378
|
+
error: (value) => assertType(is.error(value), 'Error', value),
|
|
379
|
+
map: (value) => assertType(is.map(value), 'Map', value),
|
|
380
|
+
set: (value) => assertType(is.set(value), 'Set', value),
|
|
381
|
+
weakMap: (value) => assertType(is.weakMap(value), 'WeakMap', value),
|
|
382
|
+
weakSet: (value) => assertType(is.weakSet(value), 'WeakSet', value),
|
|
383
|
+
int8Array: (value) => assertType(is.int8Array(value), 'Int8Array', value),
|
|
384
|
+
uint8Array: (value) => assertType(is.uint8Array(value), 'Uint8Array', value),
|
|
385
|
+
uint8ClampedArray: (value) => assertType(is.uint8ClampedArray(value), 'Uint8ClampedArray', value),
|
|
386
|
+
int16Array: (value) => assertType(is.int16Array(value), 'Int16Array', value),
|
|
387
|
+
uint16Array: (value) => assertType(is.uint16Array(value), 'Uint16Array', value),
|
|
388
|
+
int32Array: (value) => assertType(is.int32Array(value), 'Int32Array', value),
|
|
389
|
+
uint32Array: (value) => assertType(is.uint32Array(value), 'Uint32Array', value),
|
|
390
|
+
float32Array: (value) => assertType(is.float32Array(value), 'Float32Array', value),
|
|
391
|
+
float64Array: (value) => assertType(is.float64Array(value), 'Float64Array', value),
|
|
392
|
+
bigInt64Array: (value) => assertType(is.bigInt64Array(value), 'BigInt64Array', value),
|
|
393
|
+
bigUint64Array: (value) => assertType(is.bigUint64Array(value), 'BigUint64Array', value),
|
|
394
|
+
arrayBuffer: (value) => assertType(is.arrayBuffer(value), 'ArrayBuffer', value),
|
|
395
|
+
sharedArrayBuffer: (value) => assertType(is.sharedArrayBuffer(value), 'SharedArrayBuffer', value),
|
|
396
|
+
dataView: (value) => assertType(is.dataView(value), 'DataView', value),
|
|
397
|
+
urlInstance: (value) => assertType(is.urlInstance(value), 'URL', value),
|
|
398
|
+
urlString: (value) => assertType(is.urlString(value), AssertionTypeDescription.urlString, value),
|
|
399
|
+
truthy: (value) => assertType(is.truthy(value), AssertionTypeDescription.truthy, value),
|
|
400
|
+
falsy: (value) => assertType(is.falsy(value), AssertionTypeDescription.falsy, value),
|
|
401
|
+
nan: (value) => assertType(is.nan(value), AssertionTypeDescription.nan, value),
|
|
402
|
+
primitive: (value) => assertType(is.primitive(value), AssertionTypeDescription.primitive, value),
|
|
403
|
+
integer: (value) => assertType(is.integer(value), AssertionTypeDescription.integer, value),
|
|
404
|
+
safeInteger: (value) => assertType(is.safeInteger(value), AssertionTypeDescription.safeInteger, value),
|
|
405
|
+
plainObject: (value) => assertType(is.plainObject(value), AssertionTypeDescription.plainObject, value),
|
|
406
|
+
typedArray: (value) => assertType(is.typedArray(value), AssertionTypeDescription.typedArray, value),
|
|
407
|
+
arrayLike: (value) => assertType(is.arrayLike(value), AssertionTypeDescription.arrayLike, value),
|
|
408
|
+
domElement: (value) => assertType(is.domElement(value), AssertionTypeDescription.domElement, value),
|
|
409
|
+
observable: (value) => assertType(is.observable(value), 'Observable', value),
|
|
410
|
+
nodeStream: (value) => assertType(is.nodeStream(value), AssertionTypeDescription.nodeStream, value),
|
|
411
|
+
infinite: (value) => assertType(is.infinite(value), AssertionTypeDescription.infinite, value),
|
|
412
|
+
emptyArray: (value) => assertType(is.emptyArray(value), AssertionTypeDescription.emptyArray, value),
|
|
413
|
+
nonEmptyArray: (value) => assertType(is.nonEmptyArray(value), AssertionTypeDescription.nonEmptyArray, value),
|
|
414
|
+
emptyString: (value) => assertType(is.emptyString(value), AssertionTypeDescription.emptyString, value),
|
|
415
|
+
nonEmptyString: (value) => assertType(is.nonEmptyString(value), AssertionTypeDescription.nonEmptyString, value),
|
|
416
|
+
emptyStringOrWhitespace: (value) => assertType(is.emptyStringOrWhitespace(value), AssertionTypeDescription.emptyStringOrWhitespace, value),
|
|
417
|
+
emptyObject: (value) => assertType(is.emptyObject(value), AssertionTypeDescription.emptyObject, value),
|
|
418
|
+
nonEmptyObject: (value) => assertType(is.nonEmptyObject(value), AssertionTypeDescription.nonEmptyObject, value),
|
|
419
|
+
emptySet: (value) => assertType(is.emptySet(value), AssertionTypeDescription.emptySet, value),
|
|
420
|
+
nonEmptySet: (value) => assertType(is.nonEmptySet(value), AssertionTypeDescription.nonEmptySet, value),
|
|
421
|
+
emptyMap: (value) => assertType(is.emptyMap(value), AssertionTypeDescription.emptyMap, value),
|
|
422
|
+
nonEmptyMap: (value) => assertType(is.nonEmptyMap(value), AssertionTypeDescription.nonEmptyMap, value),
|
|
423
|
+
propertyKey: (value) => assertType(is.propertyKey(value), 'PropertyKey', value),
|
|
424
|
+
formData: (value) => assertType(is.formData(value), 'FormData', value),
|
|
425
|
+
urlSearchParams: (value) => assertType(is.urlSearchParams(value), 'URLSearchParams', value),
|
|
426
|
+
// Numbers.
|
|
427
|
+
evenInteger: (value) => assertType(is.evenInteger(value), AssertionTypeDescription.evenInteger, value),
|
|
428
|
+
oddInteger: (value) => assertType(is.oddInteger(value), AssertionTypeDescription.oddInteger, value),
|
|
429
|
+
// Two arguments.
|
|
430
|
+
directInstanceOf: (instance, class_) => assertType(is.directInstanceOf(instance, class_), AssertionTypeDescription.directInstanceOf, instance),
|
|
431
|
+
inRange: (value, range) => assertType(is.inRange(value, range), AssertionTypeDescription.inRange, value),
|
|
432
|
+
// Variadic functions.
|
|
433
|
+
any: (predicate, ...values) => {
|
|
434
|
+
return assertType(is.any(predicate, ...values), AssertionTypeDescription.any, values, {
|
|
435
|
+
multipleValues: true,
|
|
436
|
+
});
|
|
437
|
+
},
|
|
438
|
+
all: (predicate, ...values) => assertType(is.all(predicate, ...values), AssertionTypeDescription.all, values, {
|
|
439
|
+
multipleValues: true,
|
|
440
|
+
}),
|
|
441
|
+
};
|
|
442
|
+
// Some few keywords are reserved, but we'll populate them for Node.js users
|
|
443
|
+
// See https://github.com/Microsoft/TypeScript/issues/2536
|
|
444
|
+
Object.defineProperties(is, {
|
|
445
|
+
class: {
|
|
446
|
+
value: is.class_,
|
|
447
|
+
},
|
|
448
|
+
function: {
|
|
449
|
+
value: is.function_,
|
|
450
|
+
},
|
|
451
|
+
null: {
|
|
452
|
+
value: is.null_,
|
|
453
|
+
},
|
|
454
|
+
});
|
|
455
|
+
Object.defineProperties(exports.assert, {
|
|
456
|
+
class: {
|
|
457
|
+
value: exports.assert.class_,
|
|
458
|
+
},
|
|
459
|
+
function: {
|
|
460
|
+
value: exports.assert.function_,
|
|
461
|
+
},
|
|
462
|
+
null: {
|
|
463
|
+
value: exports.assert.null_,
|
|
464
|
+
},
|
|
465
|
+
});
|
|
466
|
+
// export {Class, TypedArray, ObservableLike, Primitive} from './types';
|
package/dist-esm/array/range.js
CHANGED
|
@@ -107,4 +107,3 @@ export function _debounce(func, wait, opt = {}) {
|
|
|
107
107
|
export function _throttle(func, wait, opt = {}) {
|
|
108
108
|
return _debounce(func, wait, Object.assign(Object.assign({ leading: true, trailing: true }, opt), { maxWait: wait }));
|
|
109
109
|
}
|
|
110
|
-
//# sourceMappingURL=debounce.js.map
|
package/dist-esm/error/assert.js
CHANGED
|
@@ -80,4 +80,3 @@ export function _isHttpErrorObject(o) {
|
|
|
80
80
|
export function _isErrorObject(o) {
|
|
81
81
|
return (typeof (o === null || o === void 0 ? void 0 : o.name) === 'string' && typeof (o === null || o === void 0 ? void 0 : o.message) === 'string' && typeof (o === null || o === void 0 ? void 0 : o.data) === 'object');
|
|
82
82
|
}
|
|
83
|
-
//# sourceMappingURL=error.util.js.map
|
package/dist-esm/error/try.js
CHANGED
package/dist-esm/index.js
CHANGED
|
@@ -16,6 +16,7 @@ import { ErrorMode } from './error/errorMode';
|
|
|
16
16
|
import { HttpError } from './error/http.error';
|
|
17
17
|
import { _try } from './error/try';
|
|
18
18
|
import { _TryCatch, _tryCatch } from './error/tryCatch';
|
|
19
|
+
import { generateJsonSchemaFromData } from './json-schema/from-data/generateJsonSchemaFromData';
|
|
19
20
|
import { JSON_SCHEMA_ORDER } from './json-schema/jsonSchema.cnst';
|
|
20
21
|
import { mergeJsonSchemaObjects } from './json-schema/jsonSchema.util';
|
|
21
22
|
import { jsonSchema, JsonSchemaAnyBuilder, } from './json-schema/jsonSchemaBuilder';
|
|
@@ -46,5 +47,5 @@ import { _stringifyAny } from './string/stringifyAny';
|
|
|
46
47
|
import { _ms, _since } from './time/time.util';
|
|
47
48
|
import { _noop, _objectKeys, _passNothingPredicate, _passthroughMapper, _passthroughPredicate, _passUndefinedMapper, _stringMapEntries, _stringMapValues, } from './types';
|
|
48
49
|
import { _gb, _hb, _kb, _mb } from './unit/size.util';
|
|
49
|
-
|
|
50
|
-
|
|
50
|
+
import { is } from './vendor/is';
|
|
51
|
+
export { is, _Memo, _memoFn, _LogMethod, _getArgsSignature, _createPromiseDecorator, AppError, HttpError, AssertionError, _isErrorObject, _isHttpErrorObject, _isHttpErrorResponse, _assert, _assertEquals, _assertDeepEquals, _assertIsError, _assertIsString, _assertIsNumber, _assertTypeOf, _randomInt, _createDeterministicRandom, _inRange, _stringMapValues, _stringMapEntries, _objectKeys, _capitalize, _upperFirst, _lowerFirst, _split, _removeWhitespace, _substringBefore, _substringBeforeLast, _substringAfter, _substringAfterLast, _substringBetweenLast, _replaceAll, _nl2br, _truncate, _truncateMiddle, _pick, _omit, _filterFalsyValues, _filterUndefinedValues, _filterNullishValues, _filterEmptyArrays, _filterEmptyValues, _filterObject, _undefinedIfEmpty, _isObject, _isPrimitive, _mapKeys, _mapValues, _mapObject, _objectNullValuesToUndefined, _deepEquals, _deepCopy, _isEmptyObject, _isEmpty, _merge, _deepTrim, _sortObjectDeep, _sortObject, _get, _set, _has, _unset, _mask, _invert, _invertMap, _by, _groupBy, _sortBy, _sortNumbers, _toFixed, _toPrecision, _round, _findLast, _takeWhile, _takeRightWhile, _dropWhile, _dropRightWhile, _countBy, _intersection, _difference, _shuffle, _mapToObject, _findKeyByValue, _anyToError, _anyToErrorObject, _errorToErrorObject, _errorObjectToAppError, _range, _uniq, _uniqBy, _flatten, _flattenDeep, _chunk, SimpleMovingAverage, _average, _averageWeighted, _percentile, _median, _debounce, _throttle, _Debounce, _Throttle, pMap, _passthroughMapper, _passUndefinedMapper, _passthroughPredicate, _passNothingPredicate, _noop, pBatch, ErrorMode, pFilter, pProps, pDelay, pDefer, pHang, pState, AggregatedError, pRetry, pTimeout, pTuple, _Retry, _Timeout, _tryCatch, _TryCatch, _try, _jsonParseIfPossible, _stringifyAny, _ms, _since, _hb, _gb, _mb, _kb, _snakeCase, _camelCase, _kebabCase, _sum, _sumBy, _clamp, _last, mergeJsonSchemaObjects, jsonSchema, JsonSchemaAnyBuilder, JSON_SCHEMA_ORDER, generateJsonSchemaFromData, };
|