foreslash 0.1.2 → 0.2.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/lib/index.cmn.cjs +408 -31
- package/lib/index.d.ts +583 -33
- package/lib/index.mjs +380 -32
- package/lib/index.umd.js +408 -31
- package/package.json +3 -2
package/lib/index.cmn.cjs
CHANGED
|
@@ -11,6 +11,48 @@ See the Mulan PSL v2 for more details.
|
|
|
11
11
|
*/
|
|
12
12
|
'use strict';
|
|
13
13
|
|
|
14
|
+
function range(start, end, stepOrOptions) {
|
|
15
|
+
if (!isFinite(start))
|
|
16
|
+
throw new Error('start must be finite');
|
|
17
|
+
if (end == null)
|
|
18
|
+
return range(0, start);
|
|
19
|
+
if (!isFinite(end))
|
|
20
|
+
throw new Error('end must be finite');
|
|
21
|
+
let step = 1;
|
|
22
|
+
let getter = null;
|
|
23
|
+
if (typeof stepOrOptions === 'number') {
|
|
24
|
+
step = stepOrOptions;
|
|
25
|
+
}
|
|
26
|
+
else if (stepOrOptions) {
|
|
27
|
+
const { step: _step } = stepOrOptions;
|
|
28
|
+
if (_step)
|
|
29
|
+
step = _step;
|
|
30
|
+
if ('value' in stepOrOptions)
|
|
31
|
+
getter = () => stepOrOptions.value;
|
|
32
|
+
else if ('getter' in stepOrOptions)
|
|
33
|
+
getter = stepOrOptions.getter;
|
|
34
|
+
}
|
|
35
|
+
if (!isFinite(step))
|
|
36
|
+
throw new Error('step must be finite');
|
|
37
|
+
if (step === 0)
|
|
38
|
+
throw new Error('step must not be 0');
|
|
39
|
+
if ((start > end && step > 0) || (start < end && step < 0))
|
|
40
|
+
step = -step;
|
|
41
|
+
const res = [];
|
|
42
|
+
for (let i = start; step > 0 ? i <= end : i >= end; i += step) {
|
|
43
|
+
res.push(getter ? getter(i, res) : i);
|
|
44
|
+
if (step > 0 ? i + step > end : i + step < end)
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
return res;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function sleep(time = 1000) {
|
|
51
|
+
return new Promise((res) => {
|
|
52
|
+
setTimeout(res, time);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
14
56
|
const isArray = Array.isArray;
|
|
15
57
|
|
|
16
58
|
const object2String = Object.prototype.toString;
|
|
@@ -19,22 +61,19 @@ function getTag(value) {
|
|
|
19
61
|
}
|
|
20
62
|
|
|
21
63
|
function getGlobalThis() {
|
|
22
|
-
if (typeof self !== 'undefined')
|
|
64
|
+
if (typeof self !== 'undefined')
|
|
23
65
|
return self;
|
|
24
|
-
|
|
25
|
-
if (typeof window !== 'undefined') {
|
|
66
|
+
if (typeof window !== 'undefined')
|
|
26
67
|
return window;
|
|
27
|
-
|
|
28
|
-
if (typeof global !== 'undefined') {
|
|
68
|
+
if (typeof global !== 'undefined')
|
|
29
69
|
return global;
|
|
30
|
-
}
|
|
31
70
|
return Function('return this')();
|
|
32
71
|
}
|
|
33
72
|
|
|
34
|
-
const global$
|
|
35
|
-
const ArrayBuffer = global$
|
|
73
|
+
const global$7 = getGlobalThis();
|
|
74
|
+
const ArrayBuffer$1 = global$7.ArrayBuffer;
|
|
36
75
|
function isArrayBuffer(val) {
|
|
37
|
-
return !!ArrayBuffer && val instanceof ArrayBuffer;
|
|
76
|
+
return !!ArrayBuffer$1 && val instanceof ArrayBuffer$1;
|
|
38
77
|
}
|
|
39
78
|
|
|
40
79
|
function isInteger(value) {
|
|
@@ -53,20 +92,36 @@ function isBoolean(value) {
|
|
|
53
92
|
return typeof value === 'boolean';
|
|
54
93
|
}
|
|
55
94
|
|
|
56
|
-
const global$
|
|
57
|
-
const Buffer = global$
|
|
95
|
+
const global$6 = getGlobalThis();
|
|
96
|
+
const Buffer = global$6.Buffer;
|
|
58
97
|
const isBuffer = (Buffer && Buffer.isBuffer) || (() => false);
|
|
59
98
|
|
|
60
|
-
function
|
|
61
|
-
return typeof value === '
|
|
99
|
+
function isObject(value) {
|
|
100
|
+
return typeof value === 'object' && value !== null;
|
|
62
101
|
}
|
|
63
102
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
return !!global$3.Map && value instanceof Map;
|
|
103
|
+
function isDataView(value) {
|
|
104
|
+
return isObject(value) && getTag(value) === 'DataView';
|
|
67
105
|
}
|
|
68
|
-
|
|
69
|
-
|
|
106
|
+
|
|
107
|
+
function isDate(value) {
|
|
108
|
+
return isObject(value) && getTag(value) === 'Date';
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const global$5 = getGlobalThis();
|
|
112
|
+
const File = global$5.File;
|
|
113
|
+
function isFile(value) {
|
|
114
|
+
return !!File && value instanceof File;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const global$4 = getGlobalThis();
|
|
118
|
+
const FormData$1 = global$4.FormData;
|
|
119
|
+
function isFormData(value) {
|
|
120
|
+
return !!FormData$1 && value instanceof FormData$1;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function isFunction(value) {
|
|
124
|
+
return typeof value === 'function';
|
|
70
125
|
}
|
|
71
126
|
|
|
72
127
|
function isNil(value) {
|
|
@@ -79,12 +134,20 @@ function isUndefined(value) {
|
|
|
79
134
|
return value === void 0;
|
|
80
135
|
}
|
|
81
136
|
|
|
82
|
-
function
|
|
83
|
-
return typeof value === '
|
|
137
|
+
function isIterable(value) {
|
|
138
|
+
return !isNil(value) && typeof value[Symbol.iterator] === 'function';
|
|
84
139
|
}
|
|
85
140
|
|
|
86
|
-
|
|
87
|
-
|
|
141
|
+
const global$3 = getGlobalThis();
|
|
142
|
+
function isMap(value) {
|
|
143
|
+
return !!global$3.Map && value instanceof Map;
|
|
144
|
+
}
|
|
145
|
+
function isWeakMap(value) {
|
|
146
|
+
return !!global$3.WeakMap && value instanceof WeakMap;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function isNumber(value) {
|
|
150
|
+
return typeof value === 'number';
|
|
88
151
|
}
|
|
89
152
|
|
|
90
153
|
function isPrimitive(value) {
|
|
@@ -99,6 +162,10 @@ function isPromiseLike(value) {
|
|
|
99
162
|
return isObject(value) && isFunction(value.then);
|
|
100
163
|
}
|
|
101
164
|
|
|
165
|
+
function isRegExp(value) {
|
|
166
|
+
return isObject(value) && getTag(value) === 'RegExp';
|
|
167
|
+
}
|
|
168
|
+
|
|
102
169
|
const global$2 = getGlobalThis();
|
|
103
170
|
function isSet(value) {
|
|
104
171
|
return !!global$2.Set && value instanceof Set;
|
|
@@ -115,6 +182,56 @@ function isSymbol(value) {
|
|
|
115
182
|
return typeof value === 'symbol';
|
|
116
183
|
}
|
|
117
184
|
|
|
185
|
+
const allTypedArrayTags = new Set([
|
|
186
|
+
'Int8Array',
|
|
187
|
+
'Int16Array',
|
|
188
|
+
'Int32Array',
|
|
189
|
+
'Uint8Array',
|
|
190
|
+
'Uint8ClampedArray',
|
|
191
|
+
'Uint16Array',
|
|
192
|
+
'Uint32Array',
|
|
193
|
+
'Float32Array',
|
|
194
|
+
'Float64Array',
|
|
195
|
+
'BigInt64Array',
|
|
196
|
+
'BigUint64Array',
|
|
197
|
+
]);
|
|
198
|
+
function isTypedArray(value) {
|
|
199
|
+
return isObject(value) && allTypedArrayTags.has(getTag(value));
|
|
200
|
+
}
|
|
201
|
+
function isInt8Array(value) {
|
|
202
|
+
return isObject(value) && getTag(value) === 'Int8Array';
|
|
203
|
+
}
|
|
204
|
+
function isInt16Array(value) {
|
|
205
|
+
return isObject(value) && getTag(value) === 'Int16Array';
|
|
206
|
+
}
|
|
207
|
+
function isInt32Array(value) {
|
|
208
|
+
return isObject(value) && getTag(value) === 'Int32Array';
|
|
209
|
+
}
|
|
210
|
+
function isUint8Array(value) {
|
|
211
|
+
return isObject(value) && getTag(value) === 'Uint8Array';
|
|
212
|
+
}
|
|
213
|
+
function isUint8ClampedArray(value) {
|
|
214
|
+
return isObject(value) && getTag(value) === 'Uint8ClampedArray';
|
|
215
|
+
}
|
|
216
|
+
function isUint16Array(value) {
|
|
217
|
+
return isObject(value) && getTag(value) === 'Uint16Array';
|
|
218
|
+
}
|
|
219
|
+
function isUint32Array(value) {
|
|
220
|
+
return isObject(value) && getTag(value) === 'Uint32Array';
|
|
221
|
+
}
|
|
222
|
+
function isFloat32Array(value) {
|
|
223
|
+
return isObject(value) && getTag(value) === 'Float32Array';
|
|
224
|
+
}
|
|
225
|
+
function isFloat64Array(value) {
|
|
226
|
+
return isObject(value) && getTag(value) === 'Float64Array';
|
|
227
|
+
}
|
|
228
|
+
function isBigInt64Array(value) {
|
|
229
|
+
return isObject(value) && getTag(value) === 'BigInt64Array';
|
|
230
|
+
}
|
|
231
|
+
function isBigUint64Array(value) {
|
|
232
|
+
return isObject(value) && getTag(value) === 'BigUint64Array';
|
|
233
|
+
}
|
|
234
|
+
|
|
118
235
|
const global$1 = getGlobalThis();
|
|
119
236
|
function isWrapperObject(value) {
|
|
120
237
|
return (!!value &&
|
|
@@ -141,6 +258,33 @@ function isWrapperBigInt(value) {
|
|
|
141
258
|
return !!global$1.BigInt && value instanceof BigInt;
|
|
142
259
|
}
|
|
143
260
|
|
|
261
|
+
function tryit(fn) {
|
|
262
|
+
return function tryitConvert(...args) {
|
|
263
|
+
try {
|
|
264
|
+
const res = fn.apply(this, args);
|
|
265
|
+
return isPromise(res)
|
|
266
|
+
? res.then((val) => [undefined, val], (err) => [err, undefined])
|
|
267
|
+
: [undefined, res];
|
|
268
|
+
}
|
|
269
|
+
catch (err) {
|
|
270
|
+
return [err, undefined];
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
const noop = function noop() { };
|
|
276
|
+
|
|
277
|
+
function withResolvers(PromiseLike = Promise) {
|
|
278
|
+
let promise;
|
|
279
|
+
let resolve = noop;
|
|
280
|
+
let reject = noop;
|
|
281
|
+
promise = new PromiseLike((res, rej) => {
|
|
282
|
+
resolve = res;
|
|
283
|
+
reject = rej;
|
|
284
|
+
});
|
|
285
|
+
return { promise, resolve, reject };
|
|
286
|
+
}
|
|
287
|
+
|
|
144
288
|
const mimeMap = {
|
|
145
289
|
application: {
|
|
146
290
|
acrobat: ['pdf'],
|
|
@@ -877,6 +1021,63 @@ function _caseConvert(tokens, joiner, handler) {
|
|
|
877
1021
|
.filter((s) => s.length)
|
|
878
1022
|
.join(joiner);
|
|
879
1023
|
}
|
|
1024
|
+
|
|
1025
|
+
function camelCase(str, options) {
|
|
1026
|
+
const { keepLetterCase = false, keepNumber = true } = options || {};
|
|
1027
|
+
let tokens = _splitVar(str);
|
|
1028
|
+
if (!keepNumber)
|
|
1029
|
+
tokens = tokens.filter(({ number }) => !number);
|
|
1030
|
+
return _caseConvert(tokens, '', keepLetterCase
|
|
1031
|
+
? ({ code }, index) => {
|
|
1032
|
+
if (index)
|
|
1033
|
+
return code.slice(0, 1).toUpperCase() + code.slice(1);
|
|
1034
|
+
else
|
|
1035
|
+
return code;
|
|
1036
|
+
}
|
|
1037
|
+
: ({ code }, index) => {
|
|
1038
|
+
if (index)
|
|
1039
|
+
return code.slice(0, 1).toUpperCase() + code.slice(1).toLowerCase();
|
|
1040
|
+
else
|
|
1041
|
+
return code.toLowerCase();
|
|
1042
|
+
});
|
|
1043
|
+
}
|
|
1044
|
+
|
|
1045
|
+
function kebabCase(str, options) {
|
|
1046
|
+
const { keepLetterCase = false, keepNumber = true } = options || {};
|
|
1047
|
+
let tokens = _splitVar(str);
|
|
1048
|
+
if (!keepNumber)
|
|
1049
|
+
tokens = tokens.filter(({ number }) => !number);
|
|
1050
|
+
return _caseConvert(tokens, '-', keepLetterCase ? ({ code }) => code : ({ code }) => code.toLowerCase());
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1053
|
+
function pascalCase(str, options) {
|
|
1054
|
+
const { keepLetterCase = false, keepNumber = true } = options || {};
|
|
1055
|
+
let tokens = _splitVar(str);
|
|
1056
|
+
if (!keepNumber)
|
|
1057
|
+
tokens = tokens.filter(({ number }) => !number);
|
|
1058
|
+
return _caseConvert(tokens, '', keepLetterCase
|
|
1059
|
+
? ({ code }) => code.slice(0, 1).toUpperCase() + code.slice(1)
|
|
1060
|
+
: ({ code }) => code.slice(0, 1).toUpperCase() + code.slice(1).toLowerCase());
|
|
1061
|
+
}
|
|
1062
|
+
|
|
1063
|
+
function snakeCase(str, options) {
|
|
1064
|
+
const { keepLetterCase = false, keepNumber = true } = options || {};
|
|
1065
|
+
let tokens = _splitVar(str);
|
|
1066
|
+
if (!keepNumber)
|
|
1067
|
+
tokens = tokens.filter(({ number }) => !number);
|
|
1068
|
+
return _caseConvert(tokens, '_', keepLetterCase ? ({ code }) => code : ({ code }) => code.toLowerCase());
|
|
1069
|
+
}
|
|
1070
|
+
|
|
1071
|
+
function titleCase(str, options) {
|
|
1072
|
+
const { keepLetterCase = false, keepNumber = true } = options || {};
|
|
1073
|
+
let tokens = _splitVar(str);
|
|
1074
|
+
if (!keepNumber)
|
|
1075
|
+
tokens = tokens.filter(({ number }) => !number);
|
|
1076
|
+
return _caseConvert(tokens, ' ', keepLetterCase
|
|
1077
|
+
? ({ code }) => code.slice(0, 1).toUpperCase() + code.slice(1)
|
|
1078
|
+
: ({ code }) => code.slice(0, 1).toUpperCase() + code.slice(1).toLowerCase());
|
|
1079
|
+
}
|
|
1080
|
+
|
|
880
1081
|
function caseConvert(str, joiner = '', handler) {
|
|
881
1082
|
const hc = handler ? handler : (token) => token.code;
|
|
882
1083
|
return _caseConvert(_splitVar(str), joiner, hc);
|
|
@@ -920,6 +1121,10 @@ function caseSnake(str, keepLetterCase = false, keepNumber = true) {
|
|
|
920
1121
|
return _caseConvert(tokens, '_', keepLetterCase ? ({ code }) => code : ({ code }) => code.toLowerCase());
|
|
921
1122
|
}
|
|
922
1123
|
|
|
1124
|
+
function splitWords(str) {
|
|
1125
|
+
return _splitVar(str).map(({ code }) => code);
|
|
1126
|
+
}
|
|
1127
|
+
|
|
923
1128
|
function compose(...composeFunc) {
|
|
924
1129
|
if (composeFunc.length === 0) {
|
|
925
1130
|
throw new Error('Invalid composeFunc parameter: composeFunc is empty');
|
|
@@ -1100,6 +1305,97 @@ function _cloneSet(obj, map, cloner, ...args) {
|
|
|
1100
1305
|
obj.forEach((item) => res.add(cloner(item, map, ...args)));
|
|
1101
1306
|
return res;
|
|
1102
1307
|
}
|
|
1308
|
+
function _cloneFormData(obj, map, cloner, ...args) {
|
|
1309
|
+
const res = new FormData();
|
|
1310
|
+
map.set(obj, res);
|
|
1311
|
+
obj.forEach((value, key) => {
|
|
1312
|
+
res.append(key, cloner(value, map, ...args));
|
|
1313
|
+
});
|
|
1314
|
+
return res;
|
|
1315
|
+
}
|
|
1316
|
+
function _cloneArrayBuffer(obj, map) {
|
|
1317
|
+
const res = new ArrayBuffer(obj.byteLength);
|
|
1318
|
+
map.set(obj, res);
|
|
1319
|
+
new Uint8Array(res).set(new Uint8Array(obj));
|
|
1320
|
+
return res;
|
|
1321
|
+
}
|
|
1322
|
+
|
|
1323
|
+
function _deepClone(obj, map, options) {
|
|
1324
|
+
if (map.has(obj))
|
|
1325
|
+
return map.get(obj);
|
|
1326
|
+
if (options.customCloner.length) {
|
|
1327
|
+
for (let i = 0; i < options.customCloner.length; i++) {
|
|
1328
|
+
const { cloner, judger } = options.customCloner[i];
|
|
1329
|
+
if (judger(obj)) {
|
|
1330
|
+
const res = cloner(obj, map);
|
|
1331
|
+
map.set(obj, res);
|
|
1332
|
+
return res;
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1335
|
+
}
|
|
1336
|
+
if (!isObject(obj) || isFunction(obj) || isWeakMap(obj) || isWeakSet(obj) || isPromise(obj))
|
|
1337
|
+
return obj;
|
|
1338
|
+
if (isArray(obj))
|
|
1339
|
+
return _cloneArray(obj, map, _deepClone, options);
|
|
1340
|
+
if (isMap(obj))
|
|
1341
|
+
return _cloneMap(obj, map, _deepClone, options);
|
|
1342
|
+
if (isSet(obj))
|
|
1343
|
+
return _cloneSet(obj, map, _deepClone, options);
|
|
1344
|
+
if (isFormData(obj))
|
|
1345
|
+
return _cloneFormData(obj, map, _deepClone, options);
|
|
1346
|
+
let res;
|
|
1347
|
+
if (obj instanceof Date) {
|
|
1348
|
+
res = new Date(obj.valueOf());
|
|
1349
|
+
map.set(obj, res);
|
|
1350
|
+
}
|
|
1351
|
+
else if (obj instanceof RegExp) {
|
|
1352
|
+
res = new RegExp(obj.source, obj.flags);
|
|
1353
|
+
map.set(obj, res);
|
|
1354
|
+
}
|
|
1355
|
+
else if (obj instanceof ArrayBuffer) {
|
|
1356
|
+
res = _cloneArrayBuffer(obj, map);
|
|
1357
|
+
}
|
|
1358
|
+
else if (isTypedArray(obj)) {
|
|
1359
|
+
res = new obj.constructor(_cloneArrayBuffer(obj.buffer, map), obj.byteOffset, obj.length);
|
|
1360
|
+
map.set(obj, res);
|
|
1361
|
+
}
|
|
1362
|
+
else if (obj instanceof DataView) {
|
|
1363
|
+
res = new DataView(map.has(obj.buffer) ? map.get(obj.buffer) : _cloneArrayBuffer(obj.buffer, map), obj.byteOffset, obj.byteLength);
|
|
1364
|
+
map.set(obj, res);
|
|
1365
|
+
}
|
|
1366
|
+
else if (isWrapperObject(obj)) {
|
|
1367
|
+
res = Object(obj.valueOf());
|
|
1368
|
+
map.set(obj, res);
|
|
1369
|
+
}
|
|
1370
|
+
else {
|
|
1371
|
+
res = options.clonePrototype ? Object.create(Object.getPrototypeOf(obj)) : {};
|
|
1372
|
+
map.set(obj, res);
|
|
1373
|
+
Reflect.ownKeys(obj).forEach((key) => {
|
|
1374
|
+
if (!options.cloneSymbol && typeof key === 'symbol')
|
|
1375
|
+
return;
|
|
1376
|
+
if (options.cloneDescriptor) {
|
|
1377
|
+
const val = Object.getOwnPropertyDescriptor(obj, key);
|
|
1378
|
+
if (!val)
|
|
1379
|
+
return;
|
|
1380
|
+
if (val.value)
|
|
1381
|
+
val.value = _deepClone(val.value, map, options);
|
|
1382
|
+
Object.defineProperty(res, key, val);
|
|
1383
|
+
}
|
|
1384
|
+
else {
|
|
1385
|
+
Reflect.set(res, key, _deepClone(Reflect.get(obj, key), map, options));
|
|
1386
|
+
}
|
|
1387
|
+
});
|
|
1388
|
+
}
|
|
1389
|
+
return res;
|
|
1390
|
+
}
|
|
1391
|
+
|
|
1392
|
+
function deepClone(obj, options, map) {
|
|
1393
|
+
if (!isMap(map))
|
|
1394
|
+
map = new Map();
|
|
1395
|
+
const res = _deepClone(obj, map, Object.assign({ cloneSymbol: true, clonePrototype: false, cloneDescriptor: false, customCloner: [] }, options));
|
|
1396
|
+
map.clear();
|
|
1397
|
+
return res;
|
|
1398
|
+
}
|
|
1103
1399
|
|
|
1104
1400
|
function _fastClone(obj, map) {
|
|
1105
1401
|
if (map.has(obj))
|
|
@@ -1112,6 +1408,8 @@ function _fastClone(obj, map) {
|
|
|
1112
1408
|
return _cloneMap(obj, map, _fastClone);
|
|
1113
1409
|
if (isSet(obj))
|
|
1114
1410
|
return _cloneSet(obj, map, _fastClone);
|
|
1411
|
+
if (isFormData(obj))
|
|
1412
|
+
return _cloneFormData(obj, map, _fastClone);
|
|
1115
1413
|
let res;
|
|
1116
1414
|
if (obj instanceof Date) {
|
|
1117
1415
|
res = new Date(obj.valueOf());
|
|
@@ -1140,7 +1438,7 @@ function fastClone(obj, map) {
|
|
|
1140
1438
|
}
|
|
1141
1439
|
|
|
1142
1440
|
function isEmpty(value) {
|
|
1143
|
-
if (value
|
|
1441
|
+
if (value === null || value === undefined)
|
|
1144
1442
|
return true;
|
|
1145
1443
|
if (typeof value !== 'object') {
|
|
1146
1444
|
if (value === '' || value === 0)
|
|
@@ -1150,18 +1448,72 @@ function isEmpty(value) {
|
|
|
1150
1448
|
return false;
|
|
1151
1449
|
}
|
|
1152
1450
|
else {
|
|
1153
|
-
if (isArrayLike(value))
|
|
1451
|
+
if (isArrayLike(value))
|
|
1154
1452
|
return !value.length;
|
|
1155
|
-
}
|
|
1156
1453
|
if (isBuffer(value) || isArrayBuffer(value))
|
|
1157
1454
|
return !value.byteLength;
|
|
1455
|
+
if (isDate(value))
|
|
1456
|
+
return isNaN(value.getTime());
|
|
1158
1457
|
if (isSet(value) || isMap(value))
|
|
1159
1458
|
return !value.size;
|
|
1160
|
-
|
|
1459
|
+
for (const key in value) {
|
|
1460
|
+
if (Object.prototype.hasOwnProperty.call(value, key))
|
|
1461
|
+
return false;
|
|
1462
|
+
}
|
|
1463
|
+
return true;
|
|
1161
1464
|
}
|
|
1162
1465
|
}
|
|
1163
1466
|
|
|
1164
|
-
|
|
1467
|
+
function _getKey(args) {
|
|
1468
|
+
function toString(item) {
|
|
1469
|
+
if (isBigInt(item))
|
|
1470
|
+
return String(item) + 'n';
|
|
1471
|
+
if (isRegExp(item))
|
|
1472
|
+
return 'RegExp' + String(item);
|
|
1473
|
+
if (isDate(item))
|
|
1474
|
+
return 'Date' + item.toISOString();
|
|
1475
|
+
try {
|
|
1476
|
+
return JSON.stringify(item);
|
|
1477
|
+
}
|
|
1478
|
+
catch (e) {
|
|
1479
|
+
return String(item);
|
|
1480
|
+
}
|
|
1481
|
+
}
|
|
1482
|
+
let res = 'ForeSlashMemoKey:[';
|
|
1483
|
+
for (let i = 0; i < args.length; i++) {
|
|
1484
|
+
res += toString(args[i]) + ',';
|
|
1485
|
+
}
|
|
1486
|
+
return res + ']';
|
|
1487
|
+
}
|
|
1488
|
+
function memo(fn, options) {
|
|
1489
|
+
const map = new Map();
|
|
1490
|
+
const getKey = (options === null || options === void 0 ? void 0 : options.getKey) ? options.getKey : _getKey;
|
|
1491
|
+
const setTtl = (options === null || options === void 0 ? void 0 : options.ttl) ? options.ttl : 0;
|
|
1492
|
+
const setCount = (options === null || options === void 0 ? void 0 : options.count) ? options.count : 0;
|
|
1493
|
+
return function (...args) {
|
|
1494
|
+
const key = getKey(args);
|
|
1495
|
+
if (map.has(key)) {
|
|
1496
|
+
const item = map.get(key);
|
|
1497
|
+
const { res, ttl, count } = item;
|
|
1498
|
+
const isValidCache = ttl >= Date.now() && count > 0;
|
|
1499
|
+
item.count -= 1;
|
|
1500
|
+
if (item.count <= 0)
|
|
1501
|
+
map.delete(key);
|
|
1502
|
+
if (ttl < Date.now())
|
|
1503
|
+
map.delete(key);
|
|
1504
|
+
if (isValidCache)
|
|
1505
|
+
return res;
|
|
1506
|
+
}
|
|
1507
|
+
const res = fn.apply(this, args);
|
|
1508
|
+
const memoItem = { res, ttl: Infinity, count: Infinity };
|
|
1509
|
+
if (setCount > 0)
|
|
1510
|
+
memoItem.count = setCount;
|
|
1511
|
+
if (setTtl > 0)
|
|
1512
|
+
memoItem.ttl = Date.now() + setTtl;
|
|
1513
|
+
map.set(key, memoItem);
|
|
1514
|
+
return res;
|
|
1515
|
+
};
|
|
1516
|
+
}
|
|
1165
1517
|
|
|
1166
1518
|
function not(value) {
|
|
1167
1519
|
return !Boolean(value);
|
|
@@ -1195,13 +1547,10 @@ function pipe(...pipeFunc) {
|
|
|
1195
1547
|
};
|
|
1196
1548
|
}
|
|
1197
1549
|
|
|
1198
|
-
function splitWords(str) {
|
|
1199
|
-
return _splitVar(str).map(({ code }) => code);
|
|
1200
|
-
}
|
|
1201
|
-
|
|
1202
1550
|
exports._ = _;
|
|
1203
1551
|
exports.acceptableFileName = acceptableFileName;
|
|
1204
1552
|
exports.acceptableFileType = acceptableFileType;
|
|
1553
|
+
exports.camelCase = camelCase;
|
|
1205
1554
|
exports.caseCamel = caseCamel;
|
|
1206
1555
|
exports.caseConvert = caseConvert;
|
|
1207
1556
|
exports.caseKebab = caseKebab;
|
|
@@ -1209,6 +1558,7 @@ exports.casePascal = casePascal;
|
|
|
1209
1558
|
exports.caseSnake = caseSnake;
|
|
1210
1559
|
exports.compose = compose;
|
|
1211
1560
|
exports.curry = _curryMore;
|
|
1561
|
+
exports.deepClone = deepClone;
|
|
1212
1562
|
exports.fastClone = fastClone;
|
|
1213
1563
|
exports.getAcceptableExtByMIME = getAcceptableExtByMIME;
|
|
1214
1564
|
exports.getAcceptableMIMEByExt = getAcceptableMIMEByExt;
|
|
@@ -1218,11 +1568,23 @@ exports.isArray = isArray;
|
|
|
1218
1568
|
exports.isArrayBuffer = isArrayBuffer;
|
|
1219
1569
|
exports.isArrayLike = isArrayLike;
|
|
1220
1570
|
exports.isBigInt = isBigInt;
|
|
1571
|
+
exports.isBigInt64Array = isBigInt64Array;
|
|
1572
|
+
exports.isBigUint64Array = isBigUint64Array;
|
|
1221
1573
|
exports.isBoolean = isBoolean;
|
|
1222
1574
|
exports.isBuffer = isBuffer;
|
|
1575
|
+
exports.isDataView = isDataView;
|
|
1576
|
+
exports.isDate = isDate;
|
|
1223
1577
|
exports.isEmpty = isEmpty;
|
|
1578
|
+
exports.isFile = isFile;
|
|
1579
|
+
exports.isFloat32Array = isFloat32Array;
|
|
1580
|
+
exports.isFloat64Array = isFloat64Array;
|
|
1581
|
+
exports.isFormData = isFormData;
|
|
1224
1582
|
exports.isFunction = isFunction;
|
|
1583
|
+
exports.isInt16Array = isInt16Array;
|
|
1584
|
+
exports.isInt32Array = isInt32Array;
|
|
1585
|
+
exports.isInt8Array = isInt8Array;
|
|
1225
1586
|
exports.isInteger = isInteger;
|
|
1587
|
+
exports.isIterable = isIterable;
|
|
1226
1588
|
exports.isMap = isMap;
|
|
1227
1589
|
exports.isNil = isNil;
|
|
1228
1590
|
exports.isNull = isNull;
|
|
@@ -1232,9 +1594,15 @@ exports.isPlaceholder = isPlaceholder;
|
|
|
1232
1594
|
exports.isPrimitive = isPrimitive;
|
|
1233
1595
|
exports.isPromise = isPromise;
|
|
1234
1596
|
exports.isPromiseLike = isPromiseLike;
|
|
1597
|
+
exports.isRegExp = isRegExp;
|
|
1235
1598
|
exports.isSet = isSet;
|
|
1236
1599
|
exports.isString = isString;
|
|
1237
1600
|
exports.isSymbol = isSymbol;
|
|
1601
|
+
exports.isTypedArray = isTypedArray;
|
|
1602
|
+
exports.isUint16Array = isUint16Array;
|
|
1603
|
+
exports.isUint32Array = isUint32Array;
|
|
1604
|
+
exports.isUint8Array = isUint8Array;
|
|
1605
|
+
exports.isUint8ClampedArray = isUint8ClampedArray;
|
|
1238
1606
|
exports.isUndefined = isUndefined;
|
|
1239
1607
|
exports.isWeakMap = isWeakMap;
|
|
1240
1608
|
exports.isWeakSet = isWeakSet;
|
|
@@ -1244,8 +1612,11 @@ exports.isWrapperNumber = isWrapperNumber;
|
|
|
1244
1612
|
exports.isWrapperObject = isWrapperObject;
|
|
1245
1613
|
exports.isWrapperString = isWrapperString;
|
|
1246
1614
|
exports.isWrapperSymbol = isWrapperSymbol;
|
|
1615
|
+
exports.kebabCase = kebabCase;
|
|
1616
|
+
exports.memo = memo;
|
|
1247
1617
|
exports.noop = noop;
|
|
1248
1618
|
exports.not = not;
|
|
1619
|
+
exports.pascalCase = pascalCase;
|
|
1249
1620
|
exports.pass = pass;
|
|
1250
1621
|
exports.passWith = passWith;
|
|
1251
1622
|
exports.pipe = pipe;
|
|
@@ -1255,8 +1626,14 @@ exports.randomHexString = randomHexString;
|
|
|
1255
1626
|
exports.randomInt = randomInt;
|
|
1256
1627
|
exports.randomIntFloor = randomIntFloor;
|
|
1257
1628
|
exports.randomString = randomString;
|
|
1629
|
+
exports.range = range;
|
|
1258
1630
|
exports.shuffle = shuffle;
|
|
1631
|
+
exports.sleep = sleep;
|
|
1632
|
+
exports.snakeCase = snakeCase;
|
|
1259
1633
|
exports.splitWords = splitWords;
|
|
1634
|
+
exports.titleCase = titleCase;
|
|
1635
|
+
exports.tryit = tryit;
|
|
1260
1636
|
exports.ulid = ulid;
|
|
1261
1637
|
exports.uuidNil = uuidNil;
|
|
1262
1638
|
exports.uuidV4 = uuidV4;
|
|
1639
|
+
exports.withResolvers = withResolvers;
|