foreslash 0.1.2 → 0.2.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/lib/index.cmn.cjs CHANGED
@@ -11,6 +11,44 @@ See the Mulan PSL v2 for more details.
11
11
  */
12
12
  'use strict';
13
13
 
14
+ function range(start, end, stepOrOptions) {
15
+ let step = 1;
16
+ let getter = null;
17
+ if (typeof stepOrOptions === 'number') {
18
+ step = stepOrOptions;
19
+ }
20
+ else if (stepOrOptions) {
21
+ const { step: _step } = stepOrOptions;
22
+ if (_step)
23
+ step = _step;
24
+ if ('value' in stepOrOptions)
25
+ getter = () => stepOrOptions.value;
26
+ else if ('getter' in stepOrOptions)
27
+ getter = stepOrOptions.getter;
28
+ }
29
+ if (!isFinite(step))
30
+ throw new Error('step must be finite');
31
+ if (step === 0)
32
+ throw new Error('step must not be 0');
33
+ if (!isFinite(start) || !isFinite(end))
34
+ throw new Error('start and end must be finite');
35
+ if ((start > end && step > 0) || (start < end && step < 0))
36
+ step = -step;
37
+ const res = [];
38
+ for (let i = start; step > 0 ? i <= end : i >= end; i += step) {
39
+ res.push(getter ? getter(i, res) : i);
40
+ if (step > 0 ? i + step > end : i + step < end)
41
+ break;
42
+ }
43
+ return res;
44
+ }
45
+
46
+ function sleep(time = 1000) {
47
+ return new Promise((res) => {
48
+ setTimeout(res, time);
49
+ });
50
+ }
51
+
14
52
  const isArray = Array.isArray;
15
53
 
16
54
  const object2String = Object.prototype.toString;
@@ -19,22 +57,19 @@ function getTag(value) {
19
57
  }
20
58
 
21
59
  function getGlobalThis() {
22
- if (typeof self !== 'undefined') {
60
+ if (typeof self !== 'undefined')
23
61
  return self;
24
- }
25
- if (typeof window !== 'undefined') {
62
+ if (typeof window !== 'undefined')
26
63
  return window;
27
- }
28
- if (typeof global !== 'undefined') {
64
+ if (typeof global !== 'undefined')
29
65
  return global;
30
- }
31
66
  return Function('return this')();
32
67
  }
33
68
 
34
- const global$5 = getGlobalThis();
35
- const ArrayBuffer = global$5.ArrayBuffer;
69
+ const global$7 = getGlobalThis();
70
+ const ArrayBuffer$1 = global$7.ArrayBuffer;
36
71
  function isArrayBuffer(val) {
37
- return !!ArrayBuffer && val instanceof ArrayBuffer;
72
+ return !!ArrayBuffer$1 && val instanceof ArrayBuffer$1;
38
73
  }
39
74
 
40
75
  function isInteger(value) {
@@ -53,20 +88,36 @@ function isBoolean(value) {
53
88
  return typeof value === 'boolean';
54
89
  }
55
90
 
56
- const global$4 = getGlobalThis();
57
- const Buffer = global$4.Buffer;
91
+ const global$6 = getGlobalThis();
92
+ const Buffer = global$6.Buffer;
58
93
  const isBuffer = (Buffer && Buffer.isBuffer) || (() => false);
59
94
 
60
- function isFunction(value) {
61
- return typeof value === 'function';
95
+ function isObject(value) {
96
+ return typeof value === 'object' && value !== null;
62
97
  }
63
98
 
64
- const global$3 = getGlobalThis();
65
- function isMap(value) {
66
- return !!global$3.Map && value instanceof Map;
99
+ function isDataView(value) {
100
+ return isObject(value) && getTag(value) === 'DataView';
67
101
  }
68
- function isWeakMap(value) {
69
- return !!global$3.WeakMap && value instanceof WeakMap;
102
+
103
+ function isDate(value) {
104
+ return isObject(value) && getTag(value) === 'Date';
105
+ }
106
+
107
+ const global$5 = getGlobalThis();
108
+ const File = global$5.File;
109
+ function isFile(value) {
110
+ return !!File && value instanceof File;
111
+ }
112
+
113
+ const global$4 = getGlobalThis();
114
+ const FormData$1 = global$4.FormData;
115
+ function isFormData(value) {
116
+ return !!FormData$1 && value instanceof FormData$1;
117
+ }
118
+
119
+ function isFunction(value) {
120
+ return typeof value === 'function';
70
121
  }
71
122
 
72
123
  function isNil(value) {
@@ -79,12 +130,20 @@ function isUndefined(value) {
79
130
  return value === void 0;
80
131
  }
81
132
 
82
- function isNumber(value) {
83
- return typeof value === 'number';
133
+ function isIterable(value) {
134
+ return !isNil(value) && typeof value[Symbol.iterator] === 'function';
84
135
  }
85
136
 
86
- function isObject(value) {
87
- return typeof value === 'object' && value !== null;
137
+ const global$3 = getGlobalThis();
138
+ function isMap(value) {
139
+ return !!global$3.Map && value instanceof Map;
140
+ }
141
+ function isWeakMap(value) {
142
+ return !!global$3.WeakMap && value instanceof WeakMap;
143
+ }
144
+
145
+ function isNumber(value) {
146
+ return typeof value === 'number';
88
147
  }
89
148
 
90
149
  function isPrimitive(value) {
@@ -99,6 +158,10 @@ function isPromiseLike(value) {
99
158
  return isObject(value) && isFunction(value.then);
100
159
  }
101
160
 
161
+ function isRegExp(value) {
162
+ return isObject(value) && getTag(value) === 'RegExp';
163
+ }
164
+
102
165
  const global$2 = getGlobalThis();
103
166
  function isSet(value) {
104
167
  return !!global$2.Set && value instanceof Set;
@@ -115,6 +178,56 @@ function isSymbol(value) {
115
178
  return typeof value === 'symbol';
116
179
  }
117
180
 
181
+ const allTypedArrayTags = new Set([
182
+ 'Int8Array',
183
+ 'Int16Array',
184
+ 'Int32Array',
185
+ 'Uint8Array',
186
+ 'Uint8ClampedArray',
187
+ 'Uint16Array',
188
+ 'Uint32Array',
189
+ 'Float32Array',
190
+ 'Float64Array',
191
+ 'BigInt64Array',
192
+ 'BigUint64Array',
193
+ ]);
194
+ function isTypedArray(value) {
195
+ return isObject(value) && allTypedArrayTags.has(getTag(value));
196
+ }
197
+ function isInt8Array(value) {
198
+ return isObject(value) && getTag(value) === 'Int8Array';
199
+ }
200
+ function isInt16Array(value) {
201
+ return isObject(value) && getTag(value) === 'Int16Array';
202
+ }
203
+ function isInt32Array(value) {
204
+ return isObject(value) && getTag(value) === 'Int32Array';
205
+ }
206
+ function isUint8Array(value) {
207
+ return isObject(value) && getTag(value) === 'Uint8Array';
208
+ }
209
+ function isUint8ClampedArray(value) {
210
+ return isObject(value) && getTag(value) === 'Uint8ClampedArray';
211
+ }
212
+ function isUint16Array(value) {
213
+ return isObject(value) && getTag(value) === 'Uint16Array';
214
+ }
215
+ function isUint32Array(value) {
216
+ return isObject(value) && getTag(value) === 'Uint32Array';
217
+ }
218
+ function isFloat32Array(value) {
219
+ return isObject(value) && getTag(value) === 'Float32Array';
220
+ }
221
+ function isFloat64Array(value) {
222
+ return isObject(value) && getTag(value) === 'Float64Array';
223
+ }
224
+ function isBigInt64Array(value) {
225
+ return isObject(value) && getTag(value) === 'BigInt64Array';
226
+ }
227
+ function isBigUint64Array(value) {
228
+ return isObject(value) && getTag(value) === 'BigUint64Array';
229
+ }
230
+
118
231
  const global$1 = getGlobalThis();
119
232
  function isWrapperObject(value) {
120
233
  return (!!value &&
@@ -141,6 +254,33 @@ function isWrapperBigInt(value) {
141
254
  return !!global$1.BigInt && value instanceof BigInt;
142
255
  }
143
256
 
257
+ function tryit(fn) {
258
+ return function tryitConvert(...args) {
259
+ try {
260
+ const res = fn.apply(this, args);
261
+ return isPromise(res)
262
+ ? res.then((val) => [undefined, val], (err) => [err, undefined])
263
+ : [undefined, res];
264
+ }
265
+ catch (err) {
266
+ return [err, undefined];
267
+ }
268
+ };
269
+ }
270
+
271
+ const noop = function noop() { };
272
+
273
+ function withResolvers(PromiseLike = Promise) {
274
+ let promise;
275
+ let resolve = noop;
276
+ let reject = noop;
277
+ promise = new PromiseLike((res, rej) => {
278
+ resolve = res;
279
+ reject = rej;
280
+ });
281
+ return { promise, resolve, reject };
282
+ }
283
+
144
284
  const mimeMap = {
145
285
  application: {
146
286
  acrobat: ['pdf'],
@@ -877,6 +1017,63 @@ function _caseConvert(tokens, joiner, handler) {
877
1017
  .filter((s) => s.length)
878
1018
  .join(joiner);
879
1019
  }
1020
+
1021
+ function camelCase(str, options) {
1022
+ const { keepLetterCase = false, keepNumber = true } = options || {};
1023
+ let tokens = _splitVar(str);
1024
+ if (!keepNumber)
1025
+ tokens = tokens.filter(({ number }) => !number);
1026
+ return _caseConvert(tokens, '', keepLetterCase
1027
+ ? ({ code }, index) => {
1028
+ if (index)
1029
+ return code.slice(0, 1).toUpperCase() + code.slice(1);
1030
+ else
1031
+ return code;
1032
+ }
1033
+ : ({ code }, index) => {
1034
+ if (index)
1035
+ return code.slice(0, 1).toUpperCase() + code.slice(1).toLowerCase();
1036
+ else
1037
+ return code.toLowerCase();
1038
+ });
1039
+ }
1040
+
1041
+ function kebabCase(str, options) {
1042
+ const { keepLetterCase = false, keepNumber = true } = options || {};
1043
+ let tokens = _splitVar(str);
1044
+ if (!keepNumber)
1045
+ tokens = tokens.filter(({ number }) => !number);
1046
+ return _caseConvert(tokens, '-', keepLetterCase ? ({ code }) => code : ({ code }) => code.toLowerCase());
1047
+ }
1048
+
1049
+ function pascalCase(str, options) {
1050
+ const { keepLetterCase = false, keepNumber = true } = options || {};
1051
+ let tokens = _splitVar(str);
1052
+ if (!keepNumber)
1053
+ tokens = tokens.filter(({ number }) => !number);
1054
+ return _caseConvert(tokens, '', keepLetterCase
1055
+ ? ({ code }) => code.slice(0, 1).toUpperCase() + code.slice(1)
1056
+ : ({ code }) => code.slice(0, 1).toUpperCase() + code.slice(1).toLowerCase());
1057
+ }
1058
+
1059
+ function snakeCase(str, options) {
1060
+ const { keepLetterCase = false, keepNumber = true } = options || {};
1061
+ let tokens = _splitVar(str);
1062
+ if (!keepNumber)
1063
+ tokens = tokens.filter(({ number }) => !number);
1064
+ return _caseConvert(tokens, '_', keepLetterCase ? ({ code }) => code : ({ code }) => code.toLowerCase());
1065
+ }
1066
+
1067
+ function titleCase(str, options) {
1068
+ const { keepLetterCase = false, keepNumber = true } = options || {};
1069
+ let tokens = _splitVar(str);
1070
+ if (!keepNumber)
1071
+ tokens = tokens.filter(({ number }) => !number);
1072
+ return _caseConvert(tokens, ' ', keepLetterCase
1073
+ ? ({ code }) => code.slice(0, 1).toUpperCase() + code.slice(1)
1074
+ : ({ code }) => code.slice(0, 1).toUpperCase() + code.slice(1).toLowerCase());
1075
+ }
1076
+
880
1077
  function caseConvert(str, joiner = '', handler) {
881
1078
  const hc = handler ? handler : (token) => token.code;
882
1079
  return _caseConvert(_splitVar(str), joiner, hc);
@@ -920,6 +1117,10 @@ function caseSnake(str, keepLetterCase = false, keepNumber = true) {
920
1117
  return _caseConvert(tokens, '_', keepLetterCase ? ({ code }) => code : ({ code }) => code.toLowerCase());
921
1118
  }
922
1119
 
1120
+ function splitWords(str) {
1121
+ return _splitVar(str).map(({ code }) => code);
1122
+ }
1123
+
923
1124
  function compose(...composeFunc) {
924
1125
  if (composeFunc.length === 0) {
925
1126
  throw new Error('Invalid composeFunc parameter: composeFunc is empty');
@@ -1100,6 +1301,97 @@ function _cloneSet(obj, map, cloner, ...args) {
1100
1301
  obj.forEach((item) => res.add(cloner(item, map, ...args)));
1101
1302
  return res;
1102
1303
  }
1304
+ function _cloneFormData(obj, map, cloner, ...args) {
1305
+ const res = new FormData();
1306
+ map.set(obj, res);
1307
+ obj.forEach((value, key) => {
1308
+ res.append(key, cloner(value, map, ...args));
1309
+ });
1310
+ return res;
1311
+ }
1312
+ function _cloneArrayBuffer(obj, map) {
1313
+ const res = new ArrayBuffer(obj.byteLength);
1314
+ map.set(obj, res);
1315
+ new Uint8Array(res).set(new Uint8Array(obj));
1316
+ return res;
1317
+ }
1318
+
1319
+ function _deepClone(obj, map, options) {
1320
+ if (map.has(obj))
1321
+ return map.get(obj);
1322
+ if (options.customCloner.length) {
1323
+ for (let i = 0; i < options.customCloner.length; i++) {
1324
+ const { cloner, judger } = options.customCloner[i];
1325
+ if (judger(obj)) {
1326
+ const res = cloner(obj, map);
1327
+ map.set(obj, res);
1328
+ return res;
1329
+ }
1330
+ }
1331
+ }
1332
+ if (!isObject(obj) || isFunction(obj) || isWeakMap(obj) || isWeakSet(obj) || isPromise(obj))
1333
+ return obj;
1334
+ if (isArray(obj))
1335
+ return _cloneArray(obj, map, _deepClone, options);
1336
+ if (isMap(obj))
1337
+ return _cloneMap(obj, map, _deepClone, options);
1338
+ if (isSet(obj))
1339
+ return _cloneSet(obj, map, _deepClone, options);
1340
+ if (isFormData(obj))
1341
+ return _cloneFormData(obj, map, _deepClone, options);
1342
+ let res;
1343
+ if (obj instanceof Date) {
1344
+ res = new Date(obj.valueOf());
1345
+ map.set(obj, res);
1346
+ }
1347
+ else if (obj instanceof RegExp) {
1348
+ res = new RegExp(obj.source, obj.flags);
1349
+ map.set(obj, res);
1350
+ }
1351
+ else if (obj instanceof ArrayBuffer) {
1352
+ res = _cloneArrayBuffer(obj, map);
1353
+ }
1354
+ else if (isTypedArray(obj)) {
1355
+ res = new obj.constructor(_cloneArrayBuffer(obj.buffer, map), obj.byteOffset, obj.length);
1356
+ map.set(obj, res);
1357
+ }
1358
+ else if (obj instanceof DataView) {
1359
+ res = new DataView(_cloneArrayBuffer(obj.buffer, map), obj.byteOffset, obj.byteLength);
1360
+ map.set(obj, res);
1361
+ }
1362
+ else if (isWrapperObject(obj)) {
1363
+ res = Object(obj.valueOf());
1364
+ map.set(obj, res);
1365
+ }
1366
+ else {
1367
+ res = options.clonePrototype ? Object.create(Object.getPrototypeOf(obj)) : {};
1368
+ map.set(obj, res);
1369
+ Reflect.ownKeys(obj).forEach((key) => {
1370
+ if (!options.cloneSymbol && typeof key === 'symbol')
1371
+ return;
1372
+ if (options.cloneDescriptor) {
1373
+ const val = Object.getOwnPropertyDescriptor(obj, key);
1374
+ if (!val)
1375
+ return;
1376
+ if (val.value)
1377
+ val.value = _deepClone(val.value, map, options);
1378
+ Object.defineProperty(res, key, val);
1379
+ }
1380
+ else {
1381
+ Reflect.set(res, key, _deepClone(Reflect.get(obj, key), map, options));
1382
+ }
1383
+ });
1384
+ }
1385
+ return res;
1386
+ }
1387
+
1388
+ function deepClone(obj, options, map) {
1389
+ if (!isMap(map))
1390
+ map = new Map();
1391
+ const res = _deepClone(obj, map, Object.assign({ cloneSymbol: true, clonePrototype: false, cloneDescriptor: false, customCloner: [] }, options));
1392
+ map.clear();
1393
+ return res;
1394
+ }
1103
1395
 
1104
1396
  function _fastClone(obj, map) {
1105
1397
  if (map.has(obj))
@@ -1112,6 +1404,8 @@ function _fastClone(obj, map) {
1112
1404
  return _cloneMap(obj, map, _fastClone);
1113
1405
  if (isSet(obj))
1114
1406
  return _cloneSet(obj, map, _fastClone);
1407
+ if (isFormData(obj))
1408
+ return _cloneFormData(obj, map, _fastClone);
1115
1409
  let res;
1116
1410
  if (obj instanceof Date) {
1117
1411
  res = new Date(obj.valueOf());
@@ -1140,7 +1434,7 @@ function fastClone(obj, map) {
1140
1434
  }
1141
1435
 
1142
1436
  function isEmpty(value) {
1143
- if (value == null)
1437
+ if (value === null || value === undefined)
1144
1438
  return true;
1145
1439
  if (typeof value !== 'object') {
1146
1440
  if (value === '' || value === 0)
@@ -1150,19 +1444,18 @@ function isEmpty(value) {
1150
1444
  return false;
1151
1445
  }
1152
1446
  else {
1153
- if (isArrayLike(value)) {
1447
+ if (isArrayLike(value))
1154
1448
  return !value.length;
1155
- }
1156
1449
  if (isBuffer(value) || isArrayBuffer(value))
1157
1450
  return !value.byteLength;
1451
+ if (isDate(value))
1452
+ return isNaN(value.getTime());
1158
1453
  if (isSet(value) || isMap(value))
1159
1454
  return !value.size;
1160
1455
  return !Object.getOwnPropertyNames(value).length;
1161
1456
  }
1162
1457
  }
1163
1458
 
1164
- const noop = function noop() { };
1165
-
1166
1459
  function not(value) {
1167
1460
  return !Boolean(value);
1168
1461
  }
@@ -1195,13 +1488,10 @@ function pipe(...pipeFunc) {
1195
1488
  };
1196
1489
  }
1197
1490
 
1198
- function splitWords(str) {
1199
- return _splitVar(str).map(({ code }) => code);
1200
- }
1201
-
1202
1491
  exports._ = _;
1203
1492
  exports.acceptableFileName = acceptableFileName;
1204
1493
  exports.acceptableFileType = acceptableFileType;
1494
+ exports.camelCase = camelCase;
1205
1495
  exports.caseCamel = caseCamel;
1206
1496
  exports.caseConvert = caseConvert;
1207
1497
  exports.caseKebab = caseKebab;
@@ -1209,6 +1499,7 @@ exports.casePascal = casePascal;
1209
1499
  exports.caseSnake = caseSnake;
1210
1500
  exports.compose = compose;
1211
1501
  exports.curry = _curryMore;
1502
+ exports.deepClone = deepClone;
1212
1503
  exports.fastClone = fastClone;
1213
1504
  exports.getAcceptableExtByMIME = getAcceptableExtByMIME;
1214
1505
  exports.getAcceptableMIMEByExt = getAcceptableMIMEByExt;
@@ -1218,11 +1509,23 @@ exports.isArray = isArray;
1218
1509
  exports.isArrayBuffer = isArrayBuffer;
1219
1510
  exports.isArrayLike = isArrayLike;
1220
1511
  exports.isBigInt = isBigInt;
1512
+ exports.isBigInt64Array = isBigInt64Array;
1513
+ exports.isBigUint64Array = isBigUint64Array;
1221
1514
  exports.isBoolean = isBoolean;
1222
1515
  exports.isBuffer = isBuffer;
1516
+ exports.isDataView = isDataView;
1517
+ exports.isDate = isDate;
1223
1518
  exports.isEmpty = isEmpty;
1519
+ exports.isFile = isFile;
1520
+ exports.isFloat32Array = isFloat32Array;
1521
+ exports.isFloat64Array = isFloat64Array;
1522
+ exports.isFormData = isFormData;
1224
1523
  exports.isFunction = isFunction;
1524
+ exports.isInt16Array = isInt16Array;
1525
+ exports.isInt32Array = isInt32Array;
1526
+ exports.isInt8Array = isInt8Array;
1225
1527
  exports.isInteger = isInteger;
1528
+ exports.isIterable = isIterable;
1226
1529
  exports.isMap = isMap;
1227
1530
  exports.isNil = isNil;
1228
1531
  exports.isNull = isNull;
@@ -1232,9 +1535,15 @@ exports.isPlaceholder = isPlaceholder;
1232
1535
  exports.isPrimitive = isPrimitive;
1233
1536
  exports.isPromise = isPromise;
1234
1537
  exports.isPromiseLike = isPromiseLike;
1538
+ exports.isRegExp = isRegExp;
1235
1539
  exports.isSet = isSet;
1236
1540
  exports.isString = isString;
1237
1541
  exports.isSymbol = isSymbol;
1542
+ exports.isTypedArray = isTypedArray;
1543
+ exports.isUint16Array = isUint16Array;
1544
+ exports.isUint32Array = isUint32Array;
1545
+ exports.isUint8Array = isUint8Array;
1546
+ exports.isUint8ClampedArray = isUint8ClampedArray;
1238
1547
  exports.isUndefined = isUndefined;
1239
1548
  exports.isWeakMap = isWeakMap;
1240
1549
  exports.isWeakSet = isWeakSet;
@@ -1244,8 +1553,10 @@ exports.isWrapperNumber = isWrapperNumber;
1244
1553
  exports.isWrapperObject = isWrapperObject;
1245
1554
  exports.isWrapperString = isWrapperString;
1246
1555
  exports.isWrapperSymbol = isWrapperSymbol;
1556
+ exports.kebabCase = kebabCase;
1247
1557
  exports.noop = noop;
1248
1558
  exports.not = not;
1559
+ exports.pascalCase = pascalCase;
1249
1560
  exports.pass = pass;
1250
1561
  exports.passWith = passWith;
1251
1562
  exports.pipe = pipe;
@@ -1255,8 +1566,14 @@ exports.randomHexString = randomHexString;
1255
1566
  exports.randomInt = randomInt;
1256
1567
  exports.randomIntFloor = randomIntFloor;
1257
1568
  exports.randomString = randomString;
1569
+ exports.range = range;
1258
1570
  exports.shuffle = shuffle;
1571
+ exports.sleep = sleep;
1572
+ exports.snakeCase = snakeCase;
1259
1573
  exports.splitWords = splitWords;
1574
+ exports.titleCase = titleCase;
1575
+ exports.tryit = tryit;
1260
1576
  exports.ulid = ulid;
1261
1577
  exports.uuidNil = uuidNil;
1262
1578
  exports.uuidV4 = uuidV4;
1579
+ exports.withResolvers = withResolvers;