@noah-libjs/utils 0.0.2 → 0.0.3
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/helper.d.ts +1 -2
- package/dist/index.js +1215 -92
- package/dist/moment-help.d.ts +5 -5
- package/dist/small-fn.d.ts +3 -1
- package/dist/types.d.ts +824 -0
- package/package.json +6 -4
package/dist/index.js
CHANGED
|
@@ -1,18 +1,24 @@
|
|
|
1
|
-
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
2
|
-
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
|
-
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
4
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
5
|
-
import
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
4
|
+
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
5
|
+
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
6
|
+
import _inherits from "@babel/runtime/helpers/inherits";
|
|
7
|
+
import _wrapNativeSuper from "@babel/runtime/helpers/wrapNativeSuper";
|
|
6
8
|
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
9
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
10
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
7
11
|
import _typeof from "@babel/runtime/helpers/typeof";
|
|
8
12
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
9
13
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
10
|
-
|
|
14
|
+
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
15
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
11
16
|
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
|
|
12
17
|
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
13
18
|
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
19
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
14
20
|
import dayjs from 'dayjs';
|
|
15
|
-
export {
|
|
21
|
+
export { default as dayjs } from 'dayjs';
|
|
16
22
|
var isSymbol = function isSymbol(value) {
|
|
17
23
|
return !!value && value.constructor === Symbol;
|
|
18
24
|
};
|
|
@@ -29,6 +35,12 @@ var isFunction = function isFunction(value) {
|
|
|
29
35
|
var isString = function isString(value) {
|
|
30
36
|
return typeof value === "string" || value instanceof String;
|
|
31
37
|
};
|
|
38
|
+
var isInt = function isInt(value) {
|
|
39
|
+
return isNumber(value) && value % 1 === 0;
|
|
40
|
+
};
|
|
41
|
+
var isFloat = function isFloat(value) {
|
|
42
|
+
return isNumber(value) && value % 1 !== 0;
|
|
43
|
+
};
|
|
32
44
|
var isNumber = function isNumber(value) {
|
|
33
45
|
try {
|
|
34
46
|
return Number(value) === value;
|
|
@@ -36,6 +48,29 @@ var isNumber = function isNumber(value) {
|
|
|
36
48
|
return false;
|
|
37
49
|
}
|
|
38
50
|
};
|
|
51
|
+
var isDate = function isDate(value) {
|
|
52
|
+
return Object.prototype.toString.call(value) === "[object Date]";
|
|
53
|
+
};
|
|
54
|
+
var isPromise = function isPromise(value) {
|
|
55
|
+
if (!value) return false;
|
|
56
|
+
if (!value.then) return false;
|
|
57
|
+
if (!isFunction(value.then)) return false;
|
|
58
|
+
return true;
|
|
59
|
+
};
|
|
60
|
+
var isEmpty = function isEmpty(value) {
|
|
61
|
+
if (value === true || value === false) return true;
|
|
62
|
+
if (value === null || value === void 0) return true;
|
|
63
|
+
if (isNumber(value)) return value === 0;
|
|
64
|
+
if (isDate(value)) return isNaN(value.getTime());
|
|
65
|
+
if (isFunction(value)) return false;
|
|
66
|
+
if (isSymbol(value)) return false;
|
|
67
|
+
var length = value.length;
|
|
68
|
+
if (isNumber(length)) return length === 0;
|
|
69
|
+
var size = value.size;
|
|
70
|
+
if (isNumber(size)) return size === 0;
|
|
71
|
+
var keys = Object.keys(value).length;
|
|
72
|
+
return keys === 0;
|
|
73
|
+
};
|
|
39
74
|
var _isEqual = function isEqual(x, y) {
|
|
40
75
|
if (Object.is(x, y)) return true;
|
|
41
76
|
if (x instanceof Date && y instanceof Date) {
|
|
@@ -56,6 +91,142 @@ var _isEqual = function isEqual(x, y) {
|
|
|
56
91
|
}
|
|
57
92
|
return true;
|
|
58
93
|
};
|
|
94
|
+
var group = function group(array, getGroupId) {
|
|
95
|
+
return array.reduce(function (acc, item) {
|
|
96
|
+
var groupId = getGroupId(item);
|
|
97
|
+
if (!acc[groupId]) acc[groupId] = [];
|
|
98
|
+
acc[groupId].push(item);
|
|
99
|
+
return acc;
|
|
100
|
+
}, {});
|
|
101
|
+
};
|
|
102
|
+
function zip() {
|
|
103
|
+
for (var _len = arguments.length, arrays = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
104
|
+
arrays[_key] = arguments[_key];
|
|
105
|
+
}
|
|
106
|
+
if (!arrays || !arrays.length) return [];
|
|
107
|
+
return new Array(Math.max.apply(Math, _toConsumableArray(arrays.map(function (_ref) {
|
|
108
|
+
var length = _ref.length;
|
|
109
|
+
return length;
|
|
110
|
+
})))).fill([]).map(function (_, idx) {
|
|
111
|
+
return arrays.map(function (array) {
|
|
112
|
+
return array[idx];
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
function zipToObject(keys, values) {
|
|
117
|
+
if (!keys || !keys.length) {
|
|
118
|
+
return {};
|
|
119
|
+
}
|
|
120
|
+
var getValue = isFunction(values) ? values : isArray(values) ? function (_k, i) {
|
|
121
|
+
return values[i];
|
|
122
|
+
} : function (_k, _i) {
|
|
123
|
+
return values;
|
|
124
|
+
};
|
|
125
|
+
return keys.reduce(function (acc, key, idx) {
|
|
126
|
+
acc[key] = getValue(key, idx);
|
|
127
|
+
return acc;
|
|
128
|
+
}, {});
|
|
129
|
+
}
|
|
130
|
+
var boil = function boil(array, compareFunc) {
|
|
131
|
+
var _array$length;
|
|
132
|
+
if (!array || ((_array$length = array.length) !== null && _array$length !== void 0 ? _array$length : 0) === 0) return null;
|
|
133
|
+
return array.reduce(compareFunc);
|
|
134
|
+
};
|
|
135
|
+
function sum(array, fn) {
|
|
136
|
+
return (array || []).reduce(function (acc, item) {
|
|
137
|
+
return acc + (fn ? fn(item) : item);
|
|
138
|
+
}, 0);
|
|
139
|
+
}
|
|
140
|
+
var first = function first(array) {
|
|
141
|
+
var defaultValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : void 0;
|
|
142
|
+
return (array === null || array === void 0 ? void 0 : array.length) > 0 ? array[0] : defaultValue;
|
|
143
|
+
};
|
|
144
|
+
var last = function last(array) {
|
|
145
|
+
var defaultValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : void 0;
|
|
146
|
+
return (array === null || array === void 0 ? void 0 : array.length) > 0 ? array[array.length - 1] : defaultValue;
|
|
147
|
+
};
|
|
148
|
+
var sort = function sort(array, getter) {
|
|
149
|
+
var desc = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
150
|
+
if (!array) return [];
|
|
151
|
+
var asc = function asc(a, b) {
|
|
152
|
+
return getter(a) - getter(b);
|
|
153
|
+
};
|
|
154
|
+
var dsc = function dsc(a, b) {
|
|
155
|
+
return getter(b) - getter(a);
|
|
156
|
+
};
|
|
157
|
+
return array.slice().sort(desc === true ? dsc : asc);
|
|
158
|
+
};
|
|
159
|
+
var alphabetical = function alphabetical(array, getter) {
|
|
160
|
+
var dir = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "asc";
|
|
161
|
+
if (!array) return [];
|
|
162
|
+
var asc = function asc(a, b) {
|
|
163
|
+
return "".concat(getter(a)).localeCompare(getter(b));
|
|
164
|
+
};
|
|
165
|
+
var dsc = function dsc(a, b) {
|
|
166
|
+
return "".concat(getter(b)).localeCompare(getter(a));
|
|
167
|
+
};
|
|
168
|
+
return array.slice().sort(dir === "desc" ? dsc : asc);
|
|
169
|
+
};
|
|
170
|
+
var counting = function counting(list2, identity) {
|
|
171
|
+
if (!list2) return {};
|
|
172
|
+
return list2.reduce(function (acc, item) {
|
|
173
|
+
var _acc$id;
|
|
174
|
+
var id = identity(item);
|
|
175
|
+
acc[id] = ((_acc$id = acc[id]) !== null && _acc$id !== void 0 ? _acc$id : 0) + 1;
|
|
176
|
+
return acc;
|
|
177
|
+
}, {});
|
|
178
|
+
};
|
|
179
|
+
var replace = function replace(list2, newItem, match) {
|
|
180
|
+
if (!list2) return [];
|
|
181
|
+
if (newItem === void 0) return _toConsumableArray(list2);
|
|
182
|
+
for (var idx = 0; idx < list2.length; idx++) {
|
|
183
|
+
var item = list2[idx];
|
|
184
|
+
if (match(item, idx)) {
|
|
185
|
+
return [].concat(_toConsumableArray(list2.slice(0, idx)), [newItem], _toConsumableArray(list2.slice(idx + 1, list2.length)));
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return _toConsumableArray(list2);
|
|
189
|
+
};
|
|
190
|
+
var objectify = function objectify(array, getKey) {
|
|
191
|
+
var getValue = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function (item) {
|
|
192
|
+
return item;
|
|
193
|
+
};
|
|
194
|
+
return array.reduce(function (acc, item) {
|
|
195
|
+
acc[getKey(item)] = getValue(item);
|
|
196
|
+
return acc;
|
|
197
|
+
}, {});
|
|
198
|
+
};
|
|
199
|
+
var select = function select(array, mapper, condition) {
|
|
200
|
+
if (!array) return [];
|
|
201
|
+
return array.reduce(function (acc, item, index) {
|
|
202
|
+
if (!condition(item, index)) return acc;
|
|
203
|
+
acc.push(mapper(item, index));
|
|
204
|
+
return acc;
|
|
205
|
+
}, []);
|
|
206
|
+
};
|
|
207
|
+
function max(array, getter) {
|
|
208
|
+
var get = getter !== null && getter !== void 0 ? getter : function (v) {
|
|
209
|
+
return v;
|
|
210
|
+
};
|
|
211
|
+
return boil(array, function (a, b) {
|
|
212
|
+
return get(a) > get(b) ? a : b;
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
function min(array, getter) {
|
|
216
|
+
var get = getter !== null && getter !== void 0 ? getter : function (v) {
|
|
217
|
+
return v;
|
|
218
|
+
};
|
|
219
|
+
return boil(array, function (a, b) {
|
|
220
|
+
return get(a) < get(b) ? a : b;
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
var cluster = function cluster(list2) {
|
|
224
|
+
var size = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2;
|
|
225
|
+
var clusterCount = Math.ceil(list2.length / size);
|
|
226
|
+
return new Array(clusterCount).fill(null).map(function (_c, i) {
|
|
227
|
+
return list2.slice(i * size, i * size + size);
|
|
228
|
+
});
|
|
229
|
+
};
|
|
59
230
|
var unique = function unique(array, toKey) {
|
|
60
231
|
var valueMap = array.reduce(function (acc, item) {
|
|
61
232
|
var key = toKey ? toKey(item) : item;
|
|
@@ -65,60 +236,765 @@ var unique = function unique(array, toKey) {
|
|
|
65
236
|
}, {});
|
|
66
237
|
return Object.values(valueMap);
|
|
67
238
|
};
|
|
68
|
-
|
|
69
|
-
var
|
|
70
|
-
|
|
239
|
+
function range(startOrLength, end) {
|
|
240
|
+
var valueOrMapper = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function (i) {
|
|
241
|
+
return i;
|
|
242
|
+
};
|
|
243
|
+
var step = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1;
|
|
244
|
+
return /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
245
|
+
var mapper, start, _final, i;
|
|
71
246
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
72
247
|
while (1) switch (_context.prev = _context.next) {
|
|
248
|
+
case 0:
|
|
249
|
+
mapper = isFunction(valueOrMapper) ? valueOrMapper : function () {
|
|
250
|
+
return valueOrMapper;
|
|
251
|
+
};
|
|
252
|
+
start = end ? startOrLength : 0;
|
|
253
|
+
_final = end !== null && end !== void 0 ? end : startOrLength;
|
|
254
|
+
i = start;
|
|
255
|
+
case 4:
|
|
256
|
+
if (!(i <= _final)) {
|
|
257
|
+
_context.next = 12;
|
|
258
|
+
break;
|
|
259
|
+
}
|
|
260
|
+
_context.next = 7;
|
|
261
|
+
return mapper(i);
|
|
262
|
+
case 7:
|
|
263
|
+
if (!(i + step > _final)) {
|
|
264
|
+
_context.next = 9;
|
|
265
|
+
break;
|
|
266
|
+
}
|
|
267
|
+
return _context.abrupt("break", 12);
|
|
268
|
+
case 9:
|
|
269
|
+
i += step;
|
|
270
|
+
_context.next = 4;
|
|
271
|
+
break;
|
|
272
|
+
case 12:
|
|
273
|
+
case "end":
|
|
274
|
+
return _context.stop();
|
|
275
|
+
}
|
|
276
|
+
}, _callee);
|
|
277
|
+
})();
|
|
278
|
+
}
|
|
279
|
+
var list = function list(startOrLength, end, valueOrMapper, step) {
|
|
280
|
+
return Array.from(range(startOrLength, end, valueOrMapper, step));
|
|
281
|
+
};
|
|
282
|
+
var flat = function flat(lists) {
|
|
283
|
+
return lists.reduce(function (acc, list2) {
|
|
284
|
+
acc.push.apply(acc, _toConsumableArray(list2));
|
|
285
|
+
return acc;
|
|
286
|
+
}, []);
|
|
287
|
+
};
|
|
288
|
+
var intersects = function intersects(listA, listB, identity) {
|
|
289
|
+
if (!listA || !listB) return false;
|
|
290
|
+
var ident = identity !== null && identity !== void 0 ? identity : function (x) {
|
|
291
|
+
return x;
|
|
292
|
+
};
|
|
293
|
+
var dictB = listB.reduce(function (acc, item) {
|
|
294
|
+
acc[ident(item)] = true;
|
|
295
|
+
return acc;
|
|
296
|
+
}, {});
|
|
297
|
+
return listA.some(function (value) {
|
|
298
|
+
return dictB[ident(value)];
|
|
299
|
+
});
|
|
300
|
+
};
|
|
301
|
+
var fork = function fork(list2, condition) {
|
|
302
|
+
if (!list2) return [[], []];
|
|
303
|
+
return list2.reduce(function (acc, item) {
|
|
304
|
+
var _acc = _slicedToArray(acc, 2),
|
|
305
|
+
a = _acc[0],
|
|
306
|
+
b = _acc[1];
|
|
307
|
+
if (condition(item)) {
|
|
308
|
+
return [[].concat(_toConsumableArray(a), [item]), b];
|
|
309
|
+
} else {
|
|
310
|
+
return [a, [].concat(_toConsumableArray(b), [item])];
|
|
311
|
+
}
|
|
312
|
+
}, [[], []]);
|
|
313
|
+
};
|
|
314
|
+
var merge = function merge(root, others, matcher) {
|
|
315
|
+
if (!others && !root) return [];
|
|
316
|
+
if (!others) return root;
|
|
317
|
+
if (!root) return [];
|
|
318
|
+
if (!matcher) return root;
|
|
319
|
+
return root.reduce(function (acc, r) {
|
|
320
|
+
var matched = others.find(function (o) {
|
|
321
|
+
return matcher(r) === matcher(o);
|
|
322
|
+
});
|
|
323
|
+
if (matched) acc.push(matched);else acc.push(r);
|
|
324
|
+
return acc;
|
|
325
|
+
}, []);
|
|
326
|
+
};
|
|
327
|
+
var replaceOrAppend = function replaceOrAppend(list2, newItem, match) {
|
|
328
|
+
if (!list2 && !newItem) return [];
|
|
329
|
+
if (!newItem) return _toConsumableArray(list2);
|
|
330
|
+
if (!list2) return [newItem];
|
|
331
|
+
for (var idx = 0; idx < list2.length; idx++) {
|
|
332
|
+
var item = list2[idx];
|
|
333
|
+
if (match(item, idx)) {
|
|
334
|
+
return [].concat(_toConsumableArray(list2.slice(0, idx)), [newItem], _toConsumableArray(list2.slice(idx + 1, list2.length)));
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
return [].concat(_toConsumableArray(list2), [newItem]);
|
|
338
|
+
};
|
|
339
|
+
var toggle = function toggle(list2, item, toKey, options) {
|
|
340
|
+
var _options$strategy;
|
|
341
|
+
if (!list2 && !item) return [];
|
|
342
|
+
if (!list2) return [item];
|
|
343
|
+
if (!item) return _toConsumableArray(list2);
|
|
344
|
+
var matcher = toKey ? function (x, idx) {
|
|
345
|
+
return toKey(x, idx) === toKey(item, idx);
|
|
346
|
+
} : function (x) {
|
|
347
|
+
return x === item;
|
|
348
|
+
};
|
|
349
|
+
var existing = list2.find(matcher);
|
|
350
|
+
if (existing) return list2.filter(function (x, idx) {
|
|
351
|
+
return !matcher(x, idx);
|
|
352
|
+
});
|
|
353
|
+
var strategy = (_options$strategy = options === null || options === void 0 ? void 0 : options.strategy) !== null && _options$strategy !== void 0 ? _options$strategy : "append";
|
|
354
|
+
if (strategy === "append") return [].concat(_toConsumableArray(list2), [item]);
|
|
355
|
+
return [item].concat(_toConsumableArray(list2));
|
|
356
|
+
};
|
|
357
|
+
var sift = function sift(list2) {
|
|
358
|
+
var _list2$filter;
|
|
359
|
+
return (_list2$filter = list2 === null || list2 === void 0 ? void 0 : list2.filter(function (x) {
|
|
360
|
+
return !!x;
|
|
361
|
+
})) !== null && _list2$filter !== void 0 ? _list2$filter : [];
|
|
362
|
+
};
|
|
363
|
+
var iterate = function iterate(count, func, initValue) {
|
|
364
|
+
var value = initValue;
|
|
365
|
+
for (var i = 1; i <= count; i++) {
|
|
366
|
+
value = func(value, i);
|
|
367
|
+
}
|
|
368
|
+
return value;
|
|
369
|
+
};
|
|
370
|
+
var diff = function diff(root, other) {
|
|
371
|
+
var identity = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function (t) {
|
|
372
|
+
return t;
|
|
373
|
+
};
|
|
374
|
+
if (!(root !== null && root !== void 0 && root.length) && !(other !== null && other !== void 0 && other.length)) return [];
|
|
375
|
+
if ((root === null || root === void 0 ? void 0 : root.length) === void 0) return _toConsumableArray(other);
|
|
376
|
+
if (!(other !== null && other !== void 0 && other.length)) return _toConsumableArray(root);
|
|
377
|
+
var bKeys = other.reduce(function (acc, item) {
|
|
378
|
+
acc[identity(item)] = true;
|
|
379
|
+
return acc;
|
|
380
|
+
}, {});
|
|
381
|
+
return root.filter(function (a) {
|
|
382
|
+
return !bKeys[identity(a)];
|
|
383
|
+
});
|
|
384
|
+
};
|
|
385
|
+
function shift(arr, n) {
|
|
386
|
+
if (arr.length === 0) return arr;
|
|
387
|
+
var shiftNumber = n % arr.length;
|
|
388
|
+
if (shiftNumber === 0) return arr;
|
|
389
|
+
return [].concat(_toConsumableArray(arr.slice(-shiftNumber, arr.length)), _toConsumableArray(arr.slice(0, -shiftNumber)));
|
|
390
|
+
}
|
|
391
|
+
var reduce = /*#__PURE__*/function () {
|
|
392
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(array, asyncReducer, initValue) {
|
|
393
|
+
var initProvided, iter, value, _iterator, _step, _step$value, i, item;
|
|
394
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
395
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
396
|
+
case 0:
|
|
397
|
+
initProvided = initValue !== void 0;
|
|
398
|
+
if (!(!initProvided && (array === null || array === void 0 ? void 0 : array.length) < 1)) {
|
|
399
|
+
_context2.next = 3;
|
|
400
|
+
break;
|
|
401
|
+
}
|
|
402
|
+
throw new Error("Cannot reduce empty array with no init value");
|
|
403
|
+
case 3:
|
|
404
|
+
iter = initProvided ? array : array.slice(1);
|
|
405
|
+
value = initProvided ? initValue : array[0];
|
|
406
|
+
_iterator = _createForOfIteratorHelper(iter.entries());
|
|
407
|
+
_context2.prev = 6;
|
|
408
|
+
_iterator.s();
|
|
409
|
+
case 8:
|
|
410
|
+
if ((_step = _iterator.n()).done) {
|
|
411
|
+
_context2.next = 15;
|
|
412
|
+
break;
|
|
413
|
+
}
|
|
414
|
+
_step$value = _slicedToArray(_step.value, 2), i = _step$value[0], item = _step$value[1];
|
|
415
|
+
_context2.next = 12;
|
|
416
|
+
return asyncReducer(value, item, i);
|
|
417
|
+
case 12:
|
|
418
|
+
value = _context2.sent;
|
|
419
|
+
case 13:
|
|
420
|
+
_context2.next = 8;
|
|
421
|
+
break;
|
|
422
|
+
case 15:
|
|
423
|
+
_context2.next = 20;
|
|
424
|
+
break;
|
|
425
|
+
case 17:
|
|
426
|
+
_context2.prev = 17;
|
|
427
|
+
_context2.t0 = _context2["catch"](6);
|
|
428
|
+
_iterator.e(_context2.t0);
|
|
429
|
+
case 20:
|
|
430
|
+
_context2.prev = 20;
|
|
431
|
+
_iterator.f();
|
|
432
|
+
return _context2.finish(20);
|
|
433
|
+
case 23:
|
|
434
|
+
return _context2.abrupt("return", value);
|
|
435
|
+
case 24:
|
|
436
|
+
case "end":
|
|
437
|
+
return _context2.stop();
|
|
438
|
+
}
|
|
439
|
+
}, _callee2, null, [[6, 17, 20, 23]]);
|
|
440
|
+
}));
|
|
441
|
+
return function reduce(_x, _x2, _x3) {
|
|
442
|
+
return _ref2.apply(this, arguments);
|
|
443
|
+
};
|
|
444
|
+
}();
|
|
445
|
+
var map = /*#__PURE__*/function () {
|
|
446
|
+
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(array, asyncMapFunc) {
|
|
447
|
+
var result, index, _iterator2, _step2, value, newValue;
|
|
448
|
+
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
449
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
73
450
|
case 0:
|
|
74
451
|
if (array) {
|
|
75
|
-
|
|
452
|
+
_context3.next = 2;
|
|
76
453
|
break;
|
|
77
454
|
}
|
|
78
|
-
return
|
|
455
|
+
return _context3.abrupt("return", []);
|
|
79
456
|
case 2:
|
|
80
457
|
result = [];
|
|
81
458
|
index = 0;
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
459
|
+
_iterator2 = _createForOfIteratorHelper(array);
|
|
460
|
+
_context3.prev = 5;
|
|
461
|
+
_iterator2.s();
|
|
85
462
|
case 7:
|
|
86
|
-
if ((
|
|
87
|
-
|
|
463
|
+
if ((_step2 = _iterator2.n()).done) {
|
|
464
|
+
_context3.next = 15;
|
|
88
465
|
break;
|
|
89
466
|
}
|
|
90
|
-
value =
|
|
91
|
-
|
|
467
|
+
value = _step2.value;
|
|
468
|
+
_context3.next = 11;
|
|
92
469
|
return asyncMapFunc(value, index++);
|
|
93
470
|
case 11:
|
|
94
|
-
newValue =
|
|
471
|
+
newValue = _context3.sent;
|
|
95
472
|
result.push(newValue);
|
|
96
473
|
case 13:
|
|
97
|
-
|
|
474
|
+
_context3.next = 7;
|
|
98
475
|
break;
|
|
99
476
|
case 15:
|
|
100
|
-
|
|
477
|
+
_context3.next = 20;
|
|
101
478
|
break;
|
|
102
479
|
case 17:
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
480
|
+
_context3.prev = 17;
|
|
481
|
+
_context3.t0 = _context3["catch"](5);
|
|
482
|
+
_iterator2.e(_context3.t0);
|
|
106
483
|
case 20:
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
return
|
|
484
|
+
_context3.prev = 20;
|
|
485
|
+
_iterator2.f();
|
|
486
|
+
return _context3.finish(20);
|
|
110
487
|
case 23:
|
|
111
|
-
return
|
|
488
|
+
return _context3.abrupt("return", result);
|
|
112
489
|
case 24:
|
|
113
490
|
case "end":
|
|
114
|
-
return
|
|
491
|
+
return _context3.stop();
|
|
492
|
+
}
|
|
493
|
+
}, _callee3, null, [[5, 17, 20, 23]]);
|
|
494
|
+
}));
|
|
495
|
+
return function map(_x4, _x5) {
|
|
496
|
+
return _ref3.apply(this, arguments);
|
|
497
|
+
};
|
|
498
|
+
}();
|
|
499
|
+
var defer = /*#__PURE__*/function () {
|
|
500
|
+
var _ref4 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4(func) {
|
|
501
|
+
var callbacks, register, _yield$tryit, _yield$tryit2, err, response, _i2, _callbacks, _callbacks$_i, fn, rethrow, _yield$tryit3, _yield$tryit4, rethrown;
|
|
502
|
+
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
503
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
504
|
+
case 0:
|
|
505
|
+
callbacks = [];
|
|
506
|
+
register = function register(fn, options) {
|
|
507
|
+
var _options$rethrow;
|
|
508
|
+
return callbacks.push({
|
|
509
|
+
fn: fn,
|
|
510
|
+
rethrow: (_options$rethrow = options === null || options === void 0 ? void 0 : options.rethrow) !== null && _options$rethrow !== void 0 ? _options$rethrow : false
|
|
511
|
+
});
|
|
512
|
+
};
|
|
513
|
+
_context4.next = 4;
|
|
514
|
+
return tryit(func)(register);
|
|
515
|
+
case 4:
|
|
516
|
+
_yield$tryit = _context4.sent;
|
|
517
|
+
_yield$tryit2 = _slicedToArray(_yield$tryit, 2);
|
|
518
|
+
err = _yield$tryit2[0];
|
|
519
|
+
response = _yield$tryit2[1];
|
|
520
|
+
_i2 = 0, _callbacks = callbacks;
|
|
521
|
+
case 9:
|
|
522
|
+
if (!(_i2 < _callbacks.length)) {
|
|
523
|
+
_context4.next = 21;
|
|
524
|
+
break;
|
|
525
|
+
}
|
|
526
|
+
_callbacks$_i = _callbacks[_i2], fn = _callbacks$_i.fn, rethrow = _callbacks$_i.rethrow;
|
|
527
|
+
_context4.next = 13;
|
|
528
|
+
return tryit(fn)(err);
|
|
529
|
+
case 13:
|
|
530
|
+
_yield$tryit3 = _context4.sent;
|
|
531
|
+
_yield$tryit4 = _slicedToArray(_yield$tryit3, 1);
|
|
532
|
+
rethrown = _yield$tryit4[0];
|
|
533
|
+
if (!(rethrown && rethrow)) {
|
|
534
|
+
_context4.next = 18;
|
|
535
|
+
break;
|
|
536
|
+
}
|
|
537
|
+
throw rethrown;
|
|
538
|
+
case 18:
|
|
539
|
+
_i2++;
|
|
540
|
+
_context4.next = 9;
|
|
541
|
+
break;
|
|
542
|
+
case 21:
|
|
543
|
+
if (!err) {
|
|
544
|
+
_context4.next = 23;
|
|
545
|
+
break;
|
|
546
|
+
}
|
|
547
|
+
throw err;
|
|
548
|
+
case 23:
|
|
549
|
+
return _context4.abrupt("return", response);
|
|
550
|
+
case 24:
|
|
551
|
+
case "end":
|
|
552
|
+
return _context4.stop();
|
|
115
553
|
}
|
|
116
|
-
},
|
|
554
|
+
}, _callee4);
|
|
117
555
|
}));
|
|
118
|
-
return function
|
|
119
|
-
return
|
|
556
|
+
return function defer(_x6) {
|
|
557
|
+
return _ref4.apply(this, arguments);
|
|
120
558
|
};
|
|
121
559
|
}();
|
|
560
|
+
var AggregateError = /*#__PURE__*/function (_Error) {
|
|
561
|
+
function AggregateError() {
|
|
562
|
+
var _errors$find$name, _errors$find, _errors$find$stack, _errors$find2;
|
|
563
|
+
var _this;
|
|
564
|
+
var errors = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
565
|
+
_classCallCheck(this, AggregateError);
|
|
566
|
+
_this = _callSuper(this, AggregateError);
|
|
567
|
+
var name = (_errors$find$name = (_errors$find = errors.find(function (e) {
|
|
568
|
+
return e.name;
|
|
569
|
+
})) === null || _errors$find === void 0 ? void 0 : _errors$find.name) !== null && _errors$find$name !== void 0 ? _errors$find$name : "";
|
|
570
|
+
_this.name = "AggregateError(".concat(name, "...)");
|
|
571
|
+
_this.message = "AggregateError with ".concat(errors.length, " errors");
|
|
572
|
+
_this.stack = (_errors$find$stack = (_errors$find2 = errors.find(function (e) {
|
|
573
|
+
return e.stack;
|
|
574
|
+
})) === null || _errors$find2 === void 0 ? void 0 : _errors$find2.stack) !== null && _errors$find$stack !== void 0 ? _errors$find$stack : _this.stack;
|
|
575
|
+
_this.errors = errors;
|
|
576
|
+
return _this;
|
|
577
|
+
}
|
|
578
|
+
_inherits(AggregateError, _Error);
|
|
579
|
+
return _createClass(AggregateError);
|
|
580
|
+
}(/*#__PURE__*/_wrapNativeSuper(Error));
|
|
581
|
+
var parallel = /*#__PURE__*/function () {
|
|
582
|
+
var _ref5 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee6(limit, array, func) {
|
|
583
|
+
var work, processor, queues, itemResults, _fork, _fork2, errors, results;
|
|
584
|
+
return _regeneratorRuntime.wrap(function _callee6$(_context6) {
|
|
585
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
586
|
+
case 0:
|
|
587
|
+
work = array.map(function (item, index) {
|
|
588
|
+
return {
|
|
589
|
+
index: index,
|
|
590
|
+
item: item
|
|
591
|
+
};
|
|
592
|
+
});
|
|
593
|
+
processor = /*#__PURE__*/function () {
|
|
594
|
+
var _ref6 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee5(res) {
|
|
595
|
+
var results2, next, _yield$tryit5, _yield$tryit6, error, result;
|
|
596
|
+
return _regeneratorRuntime.wrap(function _callee5$(_context5) {
|
|
597
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
598
|
+
case 0:
|
|
599
|
+
results2 = [];
|
|
600
|
+
case 1:
|
|
601
|
+
if (!true) {
|
|
602
|
+
_context5.next = 14;
|
|
603
|
+
break;
|
|
604
|
+
}
|
|
605
|
+
next = work.pop();
|
|
606
|
+
if (next) {
|
|
607
|
+
_context5.next = 5;
|
|
608
|
+
break;
|
|
609
|
+
}
|
|
610
|
+
return _context5.abrupt("return", res(results2));
|
|
611
|
+
case 5:
|
|
612
|
+
_context5.next = 7;
|
|
613
|
+
return tryit(func)(next.item);
|
|
614
|
+
case 7:
|
|
615
|
+
_yield$tryit5 = _context5.sent;
|
|
616
|
+
_yield$tryit6 = _slicedToArray(_yield$tryit5, 2);
|
|
617
|
+
error = _yield$tryit6[0];
|
|
618
|
+
result = _yield$tryit6[1];
|
|
619
|
+
results2.push({
|
|
620
|
+
error: error,
|
|
621
|
+
result: result,
|
|
622
|
+
index: next.index
|
|
623
|
+
});
|
|
624
|
+
_context5.next = 1;
|
|
625
|
+
break;
|
|
626
|
+
case 14:
|
|
627
|
+
case "end":
|
|
628
|
+
return _context5.stop();
|
|
629
|
+
}
|
|
630
|
+
}, _callee5);
|
|
631
|
+
}));
|
|
632
|
+
return function processor(_x10) {
|
|
633
|
+
return _ref6.apply(this, arguments);
|
|
634
|
+
};
|
|
635
|
+
}();
|
|
636
|
+
queues = list(1, limit).map(function () {
|
|
637
|
+
return new Promise(processor);
|
|
638
|
+
});
|
|
639
|
+
_context6.next = 5;
|
|
640
|
+
return Promise.all(queues);
|
|
641
|
+
case 5:
|
|
642
|
+
itemResults = _context6.sent;
|
|
643
|
+
_fork = fork(sort(itemResults.flat(), function (r) {
|
|
644
|
+
return r.index;
|
|
645
|
+
}), function (x) {
|
|
646
|
+
return !!x.error;
|
|
647
|
+
}), _fork2 = _slicedToArray(_fork, 2), errors = _fork2[0], results = _fork2[1];
|
|
648
|
+
if (!(errors.length > 0)) {
|
|
649
|
+
_context6.next = 9;
|
|
650
|
+
break;
|
|
651
|
+
}
|
|
652
|
+
throw new AggregateError(errors.map(function (error) {
|
|
653
|
+
return error.error;
|
|
654
|
+
}));
|
|
655
|
+
case 9:
|
|
656
|
+
return _context6.abrupt("return", results.map(function (r) {
|
|
657
|
+
return r.result;
|
|
658
|
+
}));
|
|
659
|
+
case 10:
|
|
660
|
+
case "end":
|
|
661
|
+
return _context6.stop();
|
|
662
|
+
}
|
|
663
|
+
}, _callee6);
|
|
664
|
+
}));
|
|
665
|
+
return function parallel(_x7, _x8, _x9) {
|
|
666
|
+
return _ref5.apply(this, arguments);
|
|
667
|
+
};
|
|
668
|
+
}();
|
|
669
|
+
function all(_x11) {
|
|
670
|
+
return _all.apply(this, arguments);
|
|
671
|
+
}
|
|
672
|
+
function _all() {
|
|
673
|
+
_all = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee10(promises) {
|
|
674
|
+
var entries, results, exceptions;
|
|
675
|
+
return _regeneratorRuntime.wrap(function _callee10$(_context10) {
|
|
676
|
+
while (1) switch (_context10.prev = _context10.next) {
|
|
677
|
+
case 0:
|
|
678
|
+
entries = isArray(promises) ? promises.map(function (p) {
|
|
679
|
+
return [null, p];
|
|
680
|
+
}) : Object.entries(promises);
|
|
681
|
+
_context10.next = 3;
|
|
682
|
+
return Promise.all(entries.map(function (_ref19) {
|
|
683
|
+
var _ref20 = _slicedToArray(_ref19, 2),
|
|
684
|
+
key = _ref20[0],
|
|
685
|
+
value = _ref20[1];
|
|
686
|
+
return value.then(function (result) {
|
|
687
|
+
return {
|
|
688
|
+
result: result,
|
|
689
|
+
exc: null,
|
|
690
|
+
key: key
|
|
691
|
+
};
|
|
692
|
+
})["catch"](function (exc) {
|
|
693
|
+
return {
|
|
694
|
+
result: null,
|
|
695
|
+
exc: exc,
|
|
696
|
+
key: key
|
|
697
|
+
};
|
|
698
|
+
});
|
|
699
|
+
}));
|
|
700
|
+
case 3:
|
|
701
|
+
results = _context10.sent;
|
|
702
|
+
exceptions = results.filter(function (r) {
|
|
703
|
+
return r.exc;
|
|
704
|
+
});
|
|
705
|
+
if (!(exceptions.length > 0)) {
|
|
706
|
+
_context10.next = 7;
|
|
707
|
+
break;
|
|
708
|
+
}
|
|
709
|
+
throw new AggregateError(exceptions.map(function (e) {
|
|
710
|
+
return e.exc;
|
|
711
|
+
}));
|
|
712
|
+
case 7:
|
|
713
|
+
if (!isArray(promises)) {
|
|
714
|
+
_context10.next = 9;
|
|
715
|
+
break;
|
|
716
|
+
}
|
|
717
|
+
return _context10.abrupt("return", results.map(function (r) {
|
|
718
|
+
return r.result;
|
|
719
|
+
}));
|
|
720
|
+
case 9:
|
|
721
|
+
return _context10.abrupt("return", results.reduce(function (acc, item) {
|
|
722
|
+
return _objectSpread(_objectSpread({}, acc), {}, _defineProperty({}, item.key, item.result));
|
|
723
|
+
}, {}));
|
|
724
|
+
case 10:
|
|
725
|
+
case "end":
|
|
726
|
+
return _context10.stop();
|
|
727
|
+
}
|
|
728
|
+
}, _callee10);
|
|
729
|
+
}));
|
|
730
|
+
return _all.apply(this, arguments);
|
|
731
|
+
}
|
|
732
|
+
var retry = /*#__PURE__*/function () {
|
|
733
|
+
var _ref7 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee7(options, func) {
|
|
734
|
+
var _options$times, _options$backoff;
|
|
735
|
+
var times, delay, backoff, _iterator3, _step3, i, _yield$tryit7, _yield$tryit8, err, result;
|
|
736
|
+
return _regeneratorRuntime.wrap(function _callee7$(_context7) {
|
|
737
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
738
|
+
case 0:
|
|
739
|
+
times = (_options$times = options === null || options === void 0 ? void 0 : options.times) !== null && _options$times !== void 0 ? _options$times : 3;
|
|
740
|
+
delay = options === null || options === void 0 ? void 0 : options.delay;
|
|
741
|
+
backoff = (_options$backoff = options === null || options === void 0 ? void 0 : options.backoff) !== null && _options$backoff !== void 0 ? _options$backoff : null;
|
|
742
|
+
_iterator3 = _createForOfIteratorHelper(range(1, times));
|
|
743
|
+
_context7.prev = 4;
|
|
744
|
+
_iterator3.s();
|
|
745
|
+
case 6:
|
|
746
|
+
if ((_step3 = _iterator3.n()).done) {
|
|
747
|
+
_context7.next = 28;
|
|
748
|
+
break;
|
|
749
|
+
}
|
|
750
|
+
i = _step3.value;
|
|
751
|
+
_context7.next = 10;
|
|
752
|
+
return tryit(func)(function (err2) {
|
|
753
|
+
throw {
|
|
754
|
+
_exited: err2
|
|
755
|
+
};
|
|
756
|
+
});
|
|
757
|
+
case 10:
|
|
758
|
+
_yield$tryit7 = _context7.sent;
|
|
759
|
+
_yield$tryit8 = _slicedToArray(_yield$tryit7, 2);
|
|
760
|
+
err = _yield$tryit8[0];
|
|
761
|
+
result = _yield$tryit8[1];
|
|
762
|
+
if (err) {
|
|
763
|
+
_context7.next = 16;
|
|
764
|
+
break;
|
|
765
|
+
}
|
|
766
|
+
return _context7.abrupt("return", result);
|
|
767
|
+
case 16:
|
|
768
|
+
if (!err._exited) {
|
|
769
|
+
_context7.next = 18;
|
|
770
|
+
break;
|
|
771
|
+
}
|
|
772
|
+
throw err._exited;
|
|
773
|
+
case 18:
|
|
774
|
+
if (!(i === times)) {
|
|
775
|
+
_context7.next = 20;
|
|
776
|
+
break;
|
|
777
|
+
}
|
|
778
|
+
throw err;
|
|
779
|
+
case 20:
|
|
780
|
+
if (!delay) {
|
|
781
|
+
_context7.next = 23;
|
|
782
|
+
break;
|
|
783
|
+
}
|
|
784
|
+
_context7.next = 23;
|
|
785
|
+
return sleep(delay);
|
|
786
|
+
case 23:
|
|
787
|
+
if (!backoff) {
|
|
788
|
+
_context7.next = 26;
|
|
789
|
+
break;
|
|
790
|
+
}
|
|
791
|
+
_context7.next = 26;
|
|
792
|
+
return sleep(backoff(i));
|
|
793
|
+
case 26:
|
|
794
|
+
_context7.next = 6;
|
|
795
|
+
break;
|
|
796
|
+
case 28:
|
|
797
|
+
_context7.next = 33;
|
|
798
|
+
break;
|
|
799
|
+
case 30:
|
|
800
|
+
_context7.prev = 30;
|
|
801
|
+
_context7.t0 = _context7["catch"](4);
|
|
802
|
+
_iterator3.e(_context7.t0);
|
|
803
|
+
case 33:
|
|
804
|
+
_context7.prev = 33;
|
|
805
|
+
_iterator3.f();
|
|
806
|
+
return _context7.finish(33);
|
|
807
|
+
case 36:
|
|
808
|
+
return _context7.abrupt("return", void 0);
|
|
809
|
+
case 37:
|
|
810
|
+
case "end":
|
|
811
|
+
return _context7.stop();
|
|
812
|
+
}
|
|
813
|
+
}, _callee7, null, [[4, 30, 33, 36]]);
|
|
814
|
+
}));
|
|
815
|
+
return function retry(_x12, _x13) {
|
|
816
|
+
return _ref7.apply(this, arguments);
|
|
817
|
+
};
|
|
818
|
+
}();
|
|
819
|
+
var sleep = function sleep(milliseconds) {
|
|
820
|
+
return new Promise(function (res) {
|
|
821
|
+
return setTimeout(res, milliseconds);
|
|
822
|
+
});
|
|
823
|
+
};
|
|
824
|
+
var tryit = function tryit(func) {
|
|
825
|
+
return function () {
|
|
826
|
+
try {
|
|
827
|
+
var result = func.apply(void 0, arguments);
|
|
828
|
+
if (isPromise(result)) {
|
|
829
|
+
return result.then(function (value) {
|
|
830
|
+
return [void 0, value];
|
|
831
|
+
})["catch"](function (err) {
|
|
832
|
+
return [err, void 0];
|
|
833
|
+
});
|
|
834
|
+
}
|
|
835
|
+
return [void 0, result];
|
|
836
|
+
} catch (err) {
|
|
837
|
+
return [err, void 0];
|
|
838
|
+
}
|
|
839
|
+
};
|
|
840
|
+
};
|
|
841
|
+
var guard = function guard(func, shouldGuard) {
|
|
842
|
+
var _guard = function _guard(err) {
|
|
843
|
+
if (shouldGuard && !shouldGuard(err)) throw err;
|
|
844
|
+
return void 0;
|
|
845
|
+
};
|
|
846
|
+
var isPromise2 = function isPromise2(result) {
|
|
847
|
+
return result instanceof Promise;
|
|
848
|
+
};
|
|
849
|
+
try {
|
|
850
|
+
var result = func();
|
|
851
|
+
return isPromise2(result) ? result["catch"](_guard) : result;
|
|
852
|
+
} catch (err) {
|
|
853
|
+
return _guard(err);
|
|
854
|
+
}
|
|
855
|
+
};
|
|
856
|
+
function chain() {
|
|
857
|
+
for (var _len2 = arguments.length, funcs = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
858
|
+
funcs[_key2] = arguments[_key2];
|
|
859
|
+
}
|
|
860
|
+
return function () {
|
|
861
|
+
return funcs.slice(1).reduce(function (acc, fn) {
|
|
862
|
+
return fn(acc);
|
|
863
|
+
}, funcs[0].apply(funcs, arguments));
|
|
864
|
+
};
|
|
865
|
+
}
|
|
866
|
+
function compose() {
|
|
867
|
+
for (var _len3 = arguments.length, funcs = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
868
|
+
funcs[_key3] = arguments[_key3];
|
|
869
|
+
}
|
|
870
|
+
return funcs.reverse().reduce(function (acc, fn) {
|
|
871
|
+
return fn(acc);
|
|
872
|
+
});
|
|
873
|
+
}
|
|
874
|
+
var partial = function partial(fn) {
|
|
875
|
+
for (var _len4 = arguments.length, args = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
|
|
876
|
+
args[_key4 - 1] = arguments[_key4];
|
|
877
|
+
}
|
|
878
|
+
return function () {
|
|
879
|
+
for (var _len5 = arguments.length, rest = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
|
|
880
|
+
rest[_key5] = arguments[_key5];
|
|
881
|
+
}
|
|
882
|
+
return fn.apply(void 0, [].concat(args, rest));
|
|
883
|
+
};
|
|
884
|
+
};
|
|
885
|
+
var partob = function partob(fn, argobj) {
|
|
886
|
+
return function (restobj) {
|
|
887
|
+
return fn(_objectSpread(_objectSpread({}, argobj), restobj));
|
|
888
|
+
};
|
|
889
|
+
};
|
|
890
|
+
var proxied = function proxied(handler) {
|
|
891
|
+
return new Proxy({}, {
|
|
892
|
+
get: function get(target, propertyName) {
|
|
893
|
+
return handler(propertyName);
|
|
894
|
+
}
|
|
895
|
+
});
|
|
896
|
+
};
|
|
897
|
+
var memoize = function memoize(cache, func, keyFunc, ttl) {
|
|
898
|
+
return function callWithMemo() {
|
|
899
|
+
for (var _len6 = arguments.length, args = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
|
|
900
|
+
args[_key6] = arguments[_key6];
|
|
901
|
+
}
|
|
902
|
+
var key = keyFunc ? keyFunc.apply(void 0, args) : JSON.stringify({
|
|
903
|
+
args: args
|
|
904
|
+
});
|
|
905
|
+
var existing = cache[key];
|
|
906
|
+
if (existing !== void 0) {
|
|
907
|
+
if (!existing.exp) return existing.value;
|
|
908
|
+
if (existing.exp > new Date().getTime()) {
|
|
909
|
+
return existing.value;
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
var result = func.apply(void 0, args);
|
|
913
|
+
cache[key] = {
|
|
914
|
+
exp: ttl ? new Date().getTime() + ttl : null,
|
|
915
|
+
value: result
|
|
916
|
+
};
|
|
917
|
+
return result;
|
|
918
|
+
};
|
|
919
|
+
};
|
|
920
|
+
var memo = function memo(func) {
|
|
921
|
+
var _options$key, _options$ttl;
|
|
922
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
923
|
+
return memoize({}, func, (_options$key = options.key) !== null && _options$key !== void 0 ? _options$key : null, (_options$ttl = options.ttl) !== null && _options$ttl !== void 0 ? _options$ttl : null);
|
|
924
|
+
};
|
|
925
|
+
var debounce = function debounce(_ref8, func) {
|
|
926
|
+
var delay = _ref8.delay;
|
|
927
|
+
var timer = void 0;
|
|
928
|
+
var active = true;
|
|
929
|
+
var debounced = function debounced() {
|
|
930
|
+
for (var _len7 = arguments.length, args = new Array(_len7), _key7 = 0; _key7 < _len7; _key7++) {
|
|
931
|
+
args[_key7] = arguments[_key7];
|
|
932
|
+
}
|
|
933
|
+
if (active) {
|
|
934
|
+
clearTimeout(timer);
|
|
935
|
+
timer = setTimeout(function () {
|
|
936
|
+
active && func.apply(void 0, args);
|
|
937
|
+
timer = void 0;
|
|
938
|
+
}, delay);
|
|
939
|
+
} else {
|
|
940
|
+
func.apply(void 0, args);
|
|
941
|
+
}
|
|
942
|
+
};
|
|
943
|
+
debounced.isPending = function () {
|
|
944
|
+
return timer !== void 0;
|
|
945
|
+
};
|
|
946
|
+
debounced.cancel = function () {
|
|
947
|
+
active = false;
|
|
948
|
+
};
|
|
949
|
+
debounced.flush = function () {
|
|
950
|
+
return func.apply(void 0, arguments);
|
|
951
|
+
};
|
|
952
|
+
return debounced;
|
|
953
|
+
};
|
|
954
|
+
var throttle = function throttle(_ref9, func) {
|
|
955
|
+
var interval = _ref9.interval;
|
|
956
|
+
var ready = true;
|
|
957
|
+
var timer = void 0;
|
|
958
|
+
var throttled = function throttled() {
|
|
959
|
+
if (!ready) return;
|
|
960
|
+
func.apply(void 0, arguments);
|
|
961
|
+
ready = false;
|
|
962
|
+
timer = setTimeout(function () {
|
|
963
|
+
ready = true;
|
|
964
|
+
timer = void 0;
|
|
965
|
+
}, interval);
|
|
966
|
+
};
|
|
967
|
+
throttled.isThrottled = function () {
|
|
968
|
+
return timer !== void 0;
|
|
969
|
+
};
|
|
970
|
+
return throttled;
|
|
971
|
+
};
|
|
972
|
+
var callable = function callable(obj, fn) {
|
|
973
|
+
var FUNC = function FUNC() {};
|
|
974
|
+
return new Proxy(Object.assign(FUNC, obj), {
|
|
975
|
+
get: function get(target, key) {
|
|
976
|
+
return target[key];
|
|
977
|
+
},
|
|
978
|
+
set: function set(target, key, value) {
|
|
979
|
+
target[key] = value;
|
|
980
|
+
return true;
|
|
981
|
+
},
|
|
982
|
+
apply: function apply(target, self, args) {
|
|
983
|
+
return fn(Object.assign({}, target)).apply(void 0, _toConsumableArray(args));
|
|
984
|
+
}
|
|
985
|
+
});
|
|
986
|
+
};
|
|
987
|
+
function inRange(number, start, end) {
|
|
988
|
+
var isTypeSafe = typeof number === "number" && typeof start === "number" && (typeof end === "undefined" || typeof end === "number");
|
|
989
|
+
if (!isTypeSafe) {
|
|
990
|
+
return false;
|
|
991
|
+
}
|
|
992
|
+
if (typeof end === "undefined") {
|
|
993
|
+
end = start;
|
|
994
|
+
start = 0;
|
|
995
|
+
}
|
|
996
|
+
return number >= Math.min(start, end) && number < Math.max(start, end);
|
|
997
|
+
}
|
|
122
998
|
var toFloat = function toFloat(value, defaultValue) {
|
|
123
999
|
var def = defaultValue === void 0 ? 0 : defaultValue;
|
|
124
1000
|
if (value === null || value === void 0) {
|
|
@@ -135,6 +1011,28 @@ var toInt = function toInt(value, defaultValue) {
|
|
|
135
1011
|
var result = parseInt(value);
|
|
136
1012
|
return isNaN(result) ? def : result;
|
|
137
1013
|
};
|
|
1014
|
+
var shake = function shake(obj) {
|
|
1015
|
+
var filter = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (x) {
|
|
1016
|
+
return x === void 0;
|
|
1017
|
+
};
|
|
1018
|
+
if (!obj) return {};
|
|
1019
|
+
var keys2 = Object.keys(obj);
|
|
1020
|
+
return keys2.reduce(function (acc, key) {
|
|
1021
|
+
if (filter(obj[key])) {
|
|
1022
|
+
return acc;
|
|
1023
|
+
} else {
|
|
1024
|
+
acc[key] = obj[key];
|
|
1025
|
+
return acc;
|
|
1026
|
+
}
|
|
1027
|
+
}, {});
|
|
1028
|
+
};
|
|
1029
|
+
var mapKeys = function mapKeys(obj, mapFunc) {
|
|
1030
|
+
var keys2 = Object.keys(obj);
|
|
1031
|
+
return keys2.reduce(function (acc, key) {
|
|
1032
|
+
acc[mapFunc(key, obj[key])] = obj[key];
|
|
1033
|
+
return acc;
|
|
1034
|
+
}, {});
|
|
1035
|
+
};
|
|
138
1036
|
var mapValues = function mapValues(obj, mapFunc) {
|
|
139
1037
|
var keys2 = Object.keys(obj);
|
|
140
1038
|
return keys2.reduce(function (acc, key) {
|
|
@@ -144,10 +1042,10 @@ var mapValues = function mapValues(obj, mapFunc) {
|
|
|
144
1042
|
};
|
|
145
1043
|
var mapEntries = function mapEntries(obj, toEntry) {
|
|
146
1044
|
if (!obj) return {};
|
|
147
|
-
return Object.entries(obj).reduce(function (acc,
|
|
148
|
-
var
|
|
149
|
-
key =
|
|
150
|
-
value =
|
|
1045
|
+
return Object.entries(obj).reduce(function (acc, _ref10) {
|
|
1046
|
+
var _ref11 = _slicedToArray(_ref10, 2),
|
|
1047
|
+
key = _ref11[0],
|
|
1048
|
+
value = _ref11[1];
|
|
151
1049
|
var _toEntry = toEntry(key, value),
|
|
152
1050
|
_toEntry2 = _slicedToArray(_toEntry, 2),
|
|
153
1051
|
newKey = _toEntry2[0],
|
|
@@ -156,6 +1054,24 @@ var mapEntries = function mapEntries(obj, toEntry) {
|
|
|
156
1054
|
return acc;
|
|
157
1055
|
}, {});
|
|
158
1056
|
};
|
|
1057
|
+
var invert = function invert(obj) {
|
|
1058
|
+
if (!obj) return {};
|
|
1059
|
+
var keys2 = Object.keys(obj);
|
|
1060
|
+
return keys2.reduce(function (acc, key) {
|
|
1061
|
+
acc[obj[key]] = key;
|
|
1062
|
+
return acc;
|
|
1063
|
+
}, {});
|
|
1064
|
+
};
|
|
1065
|
+
var lowerize = function lowerize(obj) {
|
|
1066
|
+
return mapKeys(obj, function (k) {
|
|
1067
|
+
return k.toLowerCase();
|
|
1068
|
+
});
|
|
1069
|
+
};
|
|
1070
|
+
var upperize = function upperize(obj) {
|
|
1071
|
+
return mapKeys(obj, function (k) {
|
|
1072
|
+
return k.toUpperCase();
|
|
1073
|
+
});
|
|
1074
|
+
};
|
|
159
1075
|
var clone = function clone(obj) {
|
|
160
1076
|
if (isPrimitive(obj)) {
|
|
161
1077
|
return obj;
|
|
@@ -169,6 +1085,15 @@ var clone = function clone(obj) {
|
|
|
169
1085
|
});
|
|
170
1086
|
return newObj;
|
|
171
1087
|
};
|
|
1088
|
+
var listify = function listify(obj, toItem) {
|
|
1089
|
+
if (!obj) return [];
|
|
1090
|
+
var entries = Object.entries(obj);
|
|
1091
|
+
if (entries.length === 0) return [];
|
|
1092
|
+
return entries.reduce(function (acc, entry) {
|
|
1093
|
+
acc.push(toItem(entry[0], entry[1]));
|
|
1094
|
+
return acc;
|
|
1095
|
+
}, []);
|
|
1096
|
+
};
|
|
172
1097
|
var pick = function pick(obj, keys2) {
|
|
173
1098
|
if (!obj) return {};
|
|
174
1099
|
return keys2.reduce(function (acc, key) {
|
|
@@ -187,11 +1112,11 @@ var omit = function omit(obj, keys2) {
|
|
|
187
1112
|
var get = function get(value, path, defaultValue) {
|
|
188
1113
|
var segments = path.split(/[\.\[\]]/g);
|
|
189
1114
|
var current = value;
|
|
190
|
-
var
|
|
191
|
-
|
|
1115
|
+
var _iterator4 = _createForOfIteratorHelper(segments),
|
|
1116
|
+
_step4;
|
|
192
1117
|
try {
|
|
193
|
-
for (
|
|
194
|
-
var key =
|
|
1118
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
1119
|
+
var key = _step4.value;
|
|
195
1120
|
if (current === null) return defaultValue;
|
|
196
1121
|
if (current === void 0) return defaultValue;
|
|
197
1122
|
var dequoted = key.replace(/['"]/g, "");
|
|
@@ -199,9 +1124,9 @@ var get = function get(value, path, defaultValue) {
|
|
|
199
1124
|
current = current[dequoted];
|
|
200
1125
|
}
|
|
201
1126
|
} catch (err) {
|
|
202
|
-
|
|
1127
|
+
_iterator4.e(err);
|
|
203
1128
|
} finally {
|
|
204
|
-
|
|
1129
|
+
_iterator4.f();
|
|
205
1130
|
}
|
|
206
1131
|
if (current === void 0) return defaultValue;
|
|
207
1132
|
return current;
|
|
@@ -226,14 +1151,27 @@ var set = function set(initial, path, value) {
|
|
|
226
1151
|
_set2(cloned);
|
|
227
1152
|
return cloned;
|
|
228
1153
|
};
|
|
1154
|
+
var _assign = function assign(initial, override) {
|
|
1155
|
+
var _ref12;
|
|
1156
|
+
if (!initial || !override) return (_ref12 = initial !== null && initial !== void 0 ? initial : override) !== null && _ref12 !== void 0 ? _ref12 : {};
|
|
1157
|
+
return Object.entries(_objectSpread(_objectSpread({}, initial), override)).reduce(function (acc, _ref13) {
|
|
1158
|
+
var _ref14 = _slicedToArray(_ref13, 2),
|
|
1159
|
+
key = _ref14[0],
|
|
1160
|
+
value = _ref14[1];
|
|
1161
|
+
return _objectSpread(_objectSpread({}, acc), {}, _defineProperty({}, key, function () {
|
|
1162
|
+
if (isObject(initial[key])) return _assign(initial[key], value);
|
|
1163
|
+
return value;
|
|
1164
|
+
}()));
|
|
1165
|
+
}, {});
|
|
1166
|
+
};
|
|
229
1167
|
var keys = function keys(value) {
|
|
230
1168
|
if (!value) return [];
|
|
231
1169
|
var _getKeys = function getKeys(nested, paths) {
|
|
232
1170
|
if (isObject(nested)) {
|
|
233
|
-
return Object.entries(nested).flatMap(function (
|
|
234
|
-
var
|
|
235
|
-
k =
|
|
236
|
-
v =
|
|
1171
|
+
return Object.entries(nested).flatMap(function (_ref15) {
|
|
1172
|
+
var _ref16 = _slicedToArray(_ref15, 2),
|
|
1173
|
+
k = _ref16[0],
|
|
1174
|
+
v = _ref16[1];
|
|
237
1175
|
return _getKeys(v, [].concat(_toConsumableArray(paths), [k]));
|
|
238
1176
|
});
|
|
239
1177
|
}
|
|
@@ -246,6 +1184,177 @@ var keys = function keys(value) {
|
|
|
246
1184
|
};
|
|
247
1185
|
return _getKeys(value, []);
|
|
248
1186
|
};
|
|
1187
|
+
var crush = function crush(value) {
|
|
1188
|
+
if (!value) return {};
|
|
1189
|
+
return objectify(keys(value), function (k) {
|
|
1190
|
+
return k;
|
|
1191
|
+
}, function (k) {
|
|
1192
|
+
return get(value, k);
|
|
1193
|
+
});
|
|
1194
|
+
};
|
|
1195
|
+
var construct = function construct(obj) {
|
|
1196
|
+
if (!obj) return {};
|
|
1197
|
+
return Object.keys(obj).reduce(function (acc, path) {
|
|
1198
|
+
return set(acc, path, obj[path]);
|
|
1199
|
+
}, {});
|
|
1200
|
+
};
|
|
1201
|
+
var random = function random(min, max) {
|
|
1202
|
+
return Math.floor(Math.random() * (max - min + 1) + min);
|
|
1203
|
+
};
|
|
1204
|
+
var draw = function draw(array) {
|
|
1205
|
+
var max = array.length;
|
|
1206
|
+
if (max === 0) {
|
|
1207
|
+
return null;
|
|
1208
|
+
}
|
|
1209
|
+
var index = random(0, max - 1);
|
|
1210
|
+
return array[index];
|
|
1211
|
+
};
|
|
1212
|
+
var shuffle = function shuffle(array) {
|
|
1213
|
+
return array.map(function (a) {
|
|
1214
|
+
return {
|
|
1215
|
+
rand: Math.random(),
|
|
1216
|
+
value: a
|
|
1217
|
+
};
|
|
1218
|
+
}).sort(function (a, b) {
|
|
1219
|
+
return a.rand - b.rand;
|
|
1220
|
+
}).map(function (a) {
|
|
1221
|
+
return a.value;
|
|
1222
|
+
});
|
|
1223
|
+
};
|
|
1224
|
+
var uid = function uid(length) {
|
|
1225
|
+
var specials = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "";
|
|
1226
|
+
var characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" + specials;
|
|
1227
|
+
return iterate(length, function (acc) {
|
|
1228
|
+
return acc + characters.charAt(random(0, characters.length - 1));
|
|
1229
|
+
}, "");
|
|
1230
|
+
};
|
|
1231
|
+
var series = function series(items) {
|
|
1232
|
+
var toKey = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (item) {
|
|
1233
|
+
return "".concat(item);
|
|
1234
|
+
};
|
|
1235
|
+
var _items$reduce = items.reduce(function (acc, item, idx) {
|
|
1236
|
+
return {
|
|
1237
|
+
indexesByKey: _objectSpread(_objectSpread({}, acc.indexesByKey), {}, _defineProperty({}, toKey(item), idx)),
|
|
1238
|
+
itemsByIndex: _objectSpread(_objectSpread({}, acc.itemsByIndex), {}, _defineProperty({}, idx, item))
|
|
1239
|
+
};
|
|
1240
|
+
}, {
|
|
1241
|
+
indexesByKey: {},
|
|
1242
|
+
itemsByIndex: {}
|
|
1243
|
+
}),
|
|
1244
|
+
indexesByKey = _items$reduce.indexesByKey,
|
|
1245
|
+
itemsByIndex = _items$reduce.itemsByIndex;
|
|
1246
|
+
var min = function min(a, b) {
|
|
1247
|
+
return indexesByKey[toKey(a)] < indexesByKey[toKey(b)] ? a : b;
|
|
1248
|
+
};
|
|
1249
|
+
var max = function max(a, b) {
|
|
1250
|
+
return indexesByKey[toKey(a)] > indexesByKey[toKey(b)] ? a : b;
|
|
1251
|
+
};
|
|
1252
|
+
var first = function first() {
|
|
1253
|
+
return itemsByIndex[0];
|
|
1254
|
+
};
|
|
1255
|
+
var last = function last() {
|
|
1256
|
+
return itemsByIndex[items.length - 1];
|
|
1257
|
+
};
|
|
1258
|
+
var next = function next(current, defaultValue) {
|
|
1259
|
+
var _ref17, _itemsByIndex;
|
|
1260
|
+
return (_ref17 = (_itemsByIndex = itemsByIndex[indexesByKey[toKey(current)] + 1]) !== null && _itemsByIndex !== void 0 ? _itemsByIndex : defaultValue) !== null && _ref17 !== void 0 ? _ref17 : first();
|
|
1261
|
+
};
|
|
1262
|
+
var previous = function previous(current, defaultValue) {
|
|
1263
|
+
var _ref18, _itemsByIndex2;
|
|
1264
|
+
return (_ref18 = (_itemsByIndex2 = itemsByIndex[indexesByKey[toKey(current)] - 1]) !== null && _itemsByIndex2 !== void 0 ? _itemsByIndex2 : defaultValue) !== null && _ref18 !== void 0 ? _ref18 : last();
|
|
1265
|
+
};
|
|
1266
|
+
var spin = function spin(current, num) {
|
|
1267
|
+
if (num === 0) return current;
|
|
1268
|
+
var abs = Math.abs(num);
|
|
1269
|
+
var rel = abs > items.length ? abs % items.length : abs;
|
|
1270
|
+
return list(0, rel - 1).reduce(function (acc) {
|
|
1271
|
+
return num > 0 ? next(acc) : previous(acc);
|
|
1272
|
+
}, current);
|
|
1273
|
+
};
|
|
1274
|
+
return {
|
|
1275
|
+
min: min,
|
|
1276
|
+
max: max,
|
|
1277
|
+
first: first,
|
|
1278
|
+
last: last,
|
|
1279
|
+
next: next,
|
|
1280
|
+
previous: previous,
|
|
1281
|
+
spin: spin
|
|
1282
|
+
};
|
|
1283
|
+
};
|
|
1284
|
+
var capitalize = function capitalize(str) {
|
|
1285
|
+
if (!str || str.length === 0) return "";
|
|
1286
|
+
var lower = str.toLowerCase();
|
|
1287
|
+
return lower.substring(0, 1).toUpperCase() + lower.substring(1, lower.length);
|
|
1288
|
+
};
|
|
1289
|
+
var camel = function camel(str) {
|
|
1290
|
+
var _str$replace$split$ma, _str$replace;
|
|
1291
|
+
var parts = (_str$replace$split$ma = str === null || str === void 0 || (_str$replace = str.replace(/([A-Z])+/g, capitalize)) === null || _str$replace === void 0 ? void 0 : _str$replace.split(/(?=[A-Z])|[\.\-\s_]/).map(function (x) {
|
|
1292
|
+
return x.toLowerCase();
|
|
1293
|
+
})) !== null && _str$replace$split$ma !== void 0 ? _str$replace$split$ma : [];
|
|
1294
|
+
if (parts.length === 0) return "";
|
|
1295
|
+
if (parts.length === 1) return parts[0];
|
|
1296
|
+
return parts.reduce(function (acc, part) {
|
|
1297
|
+
return "".concat(acc).concat(part.charAt(0).toUpperCase()).concat(part.slice(1));
|
|
1298
|
+
});
|
|
1299
|
+
};
|
|
1300
|
+
var snake = function snake(str, options) {
|
|
1301
|
+
var _str$replace$split$ma2;
|
|
1302
|
+
var parts = (_str$replace$split$ma2 = str === null || str === void 0 ? void 0 : str.replace(/([A-Z])+/g, capitalize).split(/(?=[A-Z])|[\.\-\s_]/).map(function (x) {
|
|
1303
|
+
return x.toLowerCase();
|
|
1304
|
+
})) !== null && _str$replace$split$ma2 !== void 0 ? _str$replace$split$ma2 : [];
|
|
1305
|
+
if (parts.length === 0) return "";
|
|
1306
|
+
if (parts.length === 1) return parts[0];
|
|
1307
|
+
var result = parts.reduce(function (acc, part) {
|
|
1308
|
+
return "".concat(acc, "_").concat(part.toLowerCase());
|
|
1309
|
+
});
|
|
1310
|
+
return (options === null || options === void 0 ? void 0 : options.splitOnNumber) === false ? result : result.replace(/([A-Za-z]{1}[0-9]{1})/, function (val) {
|
|
1311
|
+
return "".concat(val[0], "_").concat(val[1]);
|
|
1312
|
+
});
|
|
1313
|
+
};
|
|
1314
|
+
var dash = function dash(str) {
|
|
1315
|
+
var _str$replace$split$ma3, _str$replace2;
|
|
1316
|
+
var parts = (_str$replace$split$ma3 = str === null || str === void 0 || (_str$replace2 = str.replace(/([A-Z])+/g, capitalize)) === null || _str$replace2 === void 0 ? void 0 : _str$replace2.split(/(?=[A-Z])|[\.\-\s_]/).map(function (x) {
|
|
1317
|
+
return x.toLowerCase();
|
|
1318
|
+
})) !== null && _str$replace$split$ma3 !== void 0 ? _str$replace$split$ma3 : [];
|
|
1319
|
+
if (parts.length === 0) return "";
|
|
1320
|
+
if (parts.length === 1) return parts[0];
|
|
1321
|
+
return parts.reduce(function (acc, part) {
|
|
1322
|
+
return "".concat(acc, "-").concat(part.toLowerCase());
|
|
1323
|
+
});
|
|
1324
|
+
};
|
|
1325
|
+
var pascal = function pascal(str) {
|
|
1326
|
+
var _str$split$map;
|
|
1327
|
+
var parts = (_str$split$map = str === null || str === void 0 ? void 0 : str.split(/[\.\-\s_]/).map(function (x) {
|
|
1328
|
+
return x.toLowerCase();
|
|
1329
|
+
})) !== null && _str$split$map !== void 0 ? _str$split$map : [];
|
|
1330
|
+
if (parts.length === 0) return "";
|
|
1331
|
+
return parts.map(function (str2) {
|
|
1332
|
+
return str2.charAt(0).toUpperCase() + str2.slice(1);
|
|
1333
|
+
}).join("");
|
|
1334
|
+
};
|
|
1335
|
+
var title = function title(str) {
|
|
1336
|
+
if (!str) return "";
|
|
1337
|
+
return str.split(/(?=[A-Z])|[\.\-\s_]/).map(function (s) {
|
|
1338
|
+
return s.trim();
|
|
1339
|
+
}).filter(function (s) {
|
|
1340
|
+
return !!s;
|
|
1341
|
+
}).map(function (s) {
|
|
1342
|
+
return capitalize(s.toLowerCase());
|
|
1343
|
+
}).join(" ");
|
|
1344
|
+
};
|
|
1345
|
+
var template = function template(str, data) {
|
|
1346
|
+
var regex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : /\{\{(.+?)\}\}/g;
|
|
1347
|
+
return Array.from(str.matchAll(regex)).reduce(function (acc, match) {
|
|
1348
|
+
return acc.replace(match[0], data[match[1]]);
|
|
1349
|
+
}, str);
|
|
1350
|
+
};
|
|
1351
|
+
var trim = function trim(str) {
|
|
1352
|
+
var charsToTrim = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : " ";
|
|
1353
|
+
if (!str) return "";
|
|
1354
|
+
var toTrim = charsToTrim.replace(/[\W]{1}/g, "\\$&");
|
|
1355
|
+
var regex = new RegExp("^[".concat(toTrim, "]+|[").concat(toTrim, "]+$"), "g");
|
|
1356
|
+
return str.replace(regex, "");
|
|
1357
|
+
};
|
|
249
1358
|
var symbolProto = Symbol ? Symbol.prototype : undefined;
|
|
250
1359
|
var symbolToString = symbolProto ? symbolProto.toString : undefined;
|
|
251
1360
|
var INFINITY = 1 / 0;
|
|
@@ -368,11 +1477,10 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
368
1477
|
var e = new Error(message);
|
|
369
1478
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
370
1479
|
};
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
}
|
|
1480
|
+
|
|
1481
|
+
// export function sleep(sec: number) {
|
|
1482
|
+
// return new Promise<void>((resolve) => setTimeout(resolve, sec * 1000))
|
|
1483
|
+
// }
|
|
376
1484
|
function getSearchParamsValue(key) {
|
|
377
1485
|
var _a, _b;
|
|
378
1486
|
var url = new URL(location.toString());
|
|
@@ -484,8 +1592,8 @@ function copyText(text) {
|
|
|
484
1592
|
return res;
|
|
485
1593
|
}
|
|
486
1594
|
function safeExec(fn) {
|
|
487
|
-
for (var
|
|
488
|
-
args[
|
|
1595
|
+
for (var _len8 = arguments.length, args = new Array(_len8 > 1 ? _len8 - 1 : 0), _key8 = 1; _key8 < _len8; _key8++) {
|
|
1596
|
+
args[_key8 - 1] = arguments[_key8];
|
|
489
1597
|
}
|
|
490
1598
|
return isFunction(fn) ? fn.apply(void 0, args) : null;
|
|
491
1599
|
}
|
|
@@ -495,12 +1603,15 @@ function safeGetFromFuncOrData(fn) {
|
|
|
495
1603
|
}
|
|
496
1604
|
function numberLikeCompare(a, b) {
|
|
497
1605
|
if (a === b) return true;
|
|
1606
|
+
if (isString(a) && isString(b)) {
|
|
1607
|
+
return a === b;
|
|
1608
|
+
}
|
|
498
1609
|
if (isNil(a) || isNil(b)) return false;
|
|
499
1610
|
if (isObject(a) || isObject(b)) return false;
|
|
500
1611
|
if (isBoolean(a) && !isBoolean(b)) return false;
|
|
501
1612
|
if (isBoolean(b) && !isBoolean(a)) return false;
|
|
502
|
-
if (toInt(a) === toInt(b)) return true;
|
|
503
|
-
if (toFloat(a) === toFloat(b)) return true;
|
|
1613
|
+
if (toInt(a, NaN) === toInt(b, NaN)) return true;
|
|
1614
|
+
if (toFloat(a, NaN) === toFloat(b, NaN)) return true;
|
|
504
1615
|
if (toString(a) === toString(b)) return true;
|
|
505
1616
|
return false;
|
|
506
1617
|
}
|
|
@@ -566,59 +1677,59 @@ function filter_obj_to_url_search(obj) {
|
|
|
566
1677
|
return clone_one;
|
|
567
1678
|
}
|
|
568
1679
|
function safe_async_call(cb) {
|
|
569
|
-
for (var
|
|
570
|
-
args[
|
|
1680
|
+
for (var _len9 = arguments.length, args = new Array(_len9 > 1 ? _len9 - 1 : 0), _key9 = 1; _key9 < _len9; _key9++) {
|
|
1681
|
+
args[_key9 - 1] = arguments[_key9];
|
|
571
1682
|
}
|
|
572
|
-
return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime.mark(function
|
|
573
|
-
return _regeneratorRuntime.wrap(function
|
|
574
|
-
while (1) switch (
|
|
1683
|
+
return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime.mark(function _callee8() {
|
|
1684
|
+
return _regeneratorRuntime.wrap(function _callee8$(_context8) {
|
|
1685
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
575
1686
|
case 0:
|
|
576
1687
|
if (isFunction(cb)) {
|
|
577
|
-
|
|
1688
|
+
_context8.next = 2;
|
|
578
1689
|
break;
|
|
579
1690
|
}
|
|
580
|
-
return
|
|
1691
|
+
return _context8.abrupt("return", null);
|
|
581
1692
|
case 2:
|
|
582
|
-
|
|
1693
|
+
_context8.next = 4;
|
|
583
1694
|
return Promise.resolve(cb.apply(void 0, args));
|
|
584
1695
|
case 4:
|
|
585
|
-
return
|
|
1696
|
+
return _context8.abrupt("return", _context8.sent);
|
|
586
1697
|
case 5:
|
|
587
1698
|
case "end":
|
|
588
|
-
return
|
|
1699
|
+
return _context8.stop();
|
|
589
1700
|
}
|
|
590
|
-
},
|
|
1701
|
+
}, _callee8);
|
|
591
1702
|
}));
|
|
592
1703
|
}
|
|
593
1704
|
window.safe_async_call = safe_async_call;
|
|
594
1705
|
var global_cache_map = {};
|
|
595
1706
|
function cache_fetch(key, cb) {
|
|
596
|
-
return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime.mark(function
|
|
1707
|
+
return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime.mark(function _callee9() {
|
|
597
1708
|
var _a, conf;
|
|
598
|
-
return _regeneratorRuntime.wrap(function
|
|
599
|
-
while (1) switch (
|
|
1709
|
+
return _regeneratorRuntime.wrap(function _callee9$(_context9) {
|
|
1710
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
600
1711
|
case 0:
|
|
601
1712
|
conf = global_cache_map[key] = (_a = global_cache_map[key]) !== null && _a !== void 0 ? _a : {};
|
|
602
1713
|
if (!conf.cache) {
|
|
603
|
-
|
|
1714
|
+
_context9.next = 3;
|
|
604
1715
|
break;
|
|
605
1716
|
}
|
|
606
|
-
return
|
|
1717
|
+
return _context9.abrupt("return", conf.cache);
|
|
607
1718
|
case 3:
|
|
608
1719
|
if (!conf.cache_promise) {
|
|
609
|
-
|
|
1720
|
+
_context9.next = 5;
|
|
610
1721
|
break;
|
|
611
1722
|
}
|
|
612
|
-
return
|
|
1723
|
+
return _context9.abrupt("return", conf.cache_promise);
|
|
613
1724
|
case 5:
|
|
614
|
-
return
|
|
1725
|
+
return _context9.abrupt("return", conf.cache_promise = cb().then(function (r) {
|
|
615
1726
|
return conf.cache = r;
|
|
616
1727
|
}));
|
|
617
1728
|
case 6:
|
|
618
1729
|
case "end":
|
|
619
|
-
return
|
|
1730
|
+
return _context9.stop();
|
|
620
1731
|
}
|
|
621
|
-
},
|
|
1732
|
+
}, _callee9);
|
|
622
1733
|
}));
|
|
623
1734
|
}
|
|
624
1735
|
function speculate_on_display(value) {
|
|
@@ -670,7 +1781,19 @@ function confirm_operation() {
|
|
|
670
1781
|
// '😎'.charCodeAt(0).toString(16) == 'd83d' // UTF-16 码元
|
|
671
1782
|
// '😎'.charCodeAt(1).toString(16) == 'de0e'
|
|
672
1783
|
// '😎'.codePointAt(0)?.toString(16) == '1f60e'// Unicode 码点
|
|
673
|
-
|
|
1784
|
+
function simple_encrypt(data) {
|
|
1785
|
+
if (!data) return null;
|
|
1786
|
+
return JSON.stringify(data).split('').map(function (_, idx) {
|
|
1787
|
+
return ~_.charCodeAt(0) + idx * 119;
|
|
1788
|
+
});
|
|
1789
|
+
}
|
|
1790
|
+
function simple_decrypt(code) {
|
|
1791
|
+
if (!code) return null;
|
|
1792
|
+
var str = expect_array(code).map(function (_, idx) {
|
|
1793
|
+
return String.fromCharCode(~(_ - idx * 119));
|
|
1794
|
+
}).join('');
|
|
1795
|
+
return safe_json_parse(str);
|
|
1796
|
+
}
|
|
674
1797
|
function getFn(format) {
|
|
675
1798
|
return Object.assign(function (s) {
|
|
676
1799
|
if (isFunction(s === null || s === void 0 ? void 0 : s.format)) {
|
|
@@ -751,8 +1874,8 @@ var MyLog = /*#__PURE__*/function () {
|
|
|
751
1874
|
var _a;
|
|
752
1875
|
var fn = (_a = MyLog._handler) === null || _a === void 0 ? void 0 : _a[type];
|
|
753
1876
|
if (!fn || !isFunction(fn)) return;
|
|
754
|
-
for (var
|
|
755
|
-
msg[
|
|
1877
|
+
for (var _len10 = arguments.length, msg = new Array(_len10 > 1 ? _len10 - 1 : 0), _key10 = 1; _key10 < _len10; _key10++) {
|
|
1878
|
+
msg[_key10 - 1] = arguments[_key10];
|
|
756
1879
|
}
|
|
757
1880
|
fn.apply(void 0, ["%c ".concat(this.env, " %c ").concat(formatDateTime(), " "), "padding: 1px; border-radius:3px 0 0 3px; color: #fff; background: ".concat(colorMap[type], ";"), "padding: 1px; border-radius: 0 3px 3px 0; color: #fff; background: #606060;"].concat(msg));
|
|
758
1881
|
}
|
|
@@ -767,24 +1890,24 @@ var MyLog = /*#__PURE__*/function () {
|
|
|
767
1890
|
}, {
|
|
768
1891
|
key: "log",
|
|
769
1892
|
value: function log() {
|
|
770
|
-
for (var
|
|
771
|
-
msg[
|
|
1893
|
+
for (var _len11 = arguments.length, msg = new Array(_len11), _key11 = 0; _key11 < _len11; _key11++) {
|
|
1894
|
+
msg[_key11] = arguments[_key11];
|
|
772
1895
|
}
|
|
773
1896
|
this._logMsg.apply(this, ['log'].concat(msg));
|
|
774
1897
|
}
|
|
775
1898
|
}, {
|
|
776
1899
|
key: "warn",
|
|
777
1900
|
value: function warn() {
|
|
778
|
-
for (var
|
|
779
|
-
msg[
|
|
1901
|
+
for (var _len12 = arguments.length, msg = new Array(_len12), _key12 = 0; _key12 < _len12; _key12++) {
|
|
1902
|
+
msg[_key12] = arguments[_key12];
|
|
780
1903
|
}
|
|
781
1904
|
this._logMsg.apply(this, ['warn'].concat(msg));
|
|
782
1905
|
}
|
|
783
1906
|
}, {
|
|
784
1907
|
key: "error",
|
|
785
1908
|
value: function error() {
|
|
786
|
-
for (var
|
|
787
|
-
msg[
|
|
1909
|
+
for (var _len13 = arguments.length, msg = new Array(_len13), _key13 = 0; _key13 < _len13; _key13++) {
|
|
1910
|
+
msg[_key13] = arguments[_key13];
|
|
788
1911
|
}
|
|
789
1912
|
this._logMsg.apply(this, ['error'].concat(msg));
|
|
790
1913
|
}
|
|
@@ -839,18 +1962,18 @@ var EventEmitter = /*#__PURE__*/function () {
|
|
|
839
1962
|
}, {
|
|
840
1963
|
key: "on_rm",
|
|
841
1964
|
value: function on_rm(event, listener) {
|
|
842
|
-
var
|
|
1965
|
+
var _this2 = this;
|
|
843
1966
|
// this.off(event, listener)
|
|
844
1967
|
this.addListener(event, listener);
|
|
845
1968
|
return function () {
|
|
846
|
-
|
|
1969
|
+
_this2.off(event, listener);
|
|
847
1970
|
};
|
|
848
1971
|
}
|
|
849
1972
|
}, {
|
|
850
1973
|
key: "emit",
|
|
851
1974
|
value: function emit(event) {
|
|
852
|
-
for (var
|
|
853
|
-
args[
|
|
1975
|
+
for (var _len14 = arguments.length, args = new Array(_len14 > 1 ? _len14 - 1 : 0), _key14 = 1; _key14 < _len14; _key14++) {
|
|
1976
|
+
args[_key14 - 1] = arguments[_key14];
|
|
854
1977
|
}
|
|
855
1978
|
var existing = this.events[event];
|
|
856
1979
|
// EventEmitter.logger.log({ event, args })
|
|
@@ -887,10 +2010,10 @@ var EventEmitter = /*#__PURE__*/function () {
|
|
|
887
2010
|
}, {
|
|
888
2011
|
key: "once",
|
|
889
2012
|
value: function once(event, listener) {
|
|
890
|
-
var
|
|
2013
|
+
var _this3 = this;
|
|
891
2014
|
var _fn = function fn() {
|
|
892
2015
|
listener.apply(void 0, arguments);
|
|
893
|
-
|
|
2016
|
+
_this3.off(event, _fn);
|
|
894
2017
|
};
|
|
895
2018
|
this.on(event, _fn);
|
|
896
2019
|
return this;
|
|
@@ -948,4 +2071,4 @@ Object.defineProperty(EventEmitter, "logger", {
|
|
|
948
2071
|
writable: true,
|
|
949
2072
|
value: new MyLog('EventEmitter')
|
|
950
2073
|
});
|
|
951
|
-
export { EventEmitter, MyLog, base64ToBinary, base64_to_image, cache_fetch, charToUTF8, charToUnicode, clone, cloneDeep, confirm_operation, copyText, dayjs_quarter, downloadFile, expect_array, filter_obj_to_url_search, formatDate, formatDateTime, formatDateTimeNoSecond, formatTime, gen_encoded_char_svg, get, getFilledArray, getFuckTimeInterval, getFutureDate, getMomentObj, getMomentRange, getSearchParamsAll, getSearchParamsValue, image_to_base64, isArray, isBoolean, _isEqual as isEqual, isFunction, isMoment, isNil, isNull, isNumber, isObject, isObjectLike, isString, isSymbol, keys, map, mapEntries, mapValues, numberLikeCompare, omit, pick, randomHex, random_word, safeExec, safeGetFromFuncOrData, safe_async_call, safe_json_parse, safe_json_parse_arr, safe_json_stringify, safe_number_parse, scrollIntoView, set, sleep, speculate_on_display, toFloat, toInt, toString, unicodeToChar, unicode_to_UTF8, unique, uuid, warpBase64Type };
|
|
2074
|
+
export { EventEmitter, MyLog, all, alphabetical, _assign as assign, base64ToBinary, base64_to_image, boil, cache_fetch, callable, camel, capitalize, chain, charToUTF8, charToUnicode, clone, cloneDeep, cluster, compose, confirm_operation, construct, copyText, counting, crush, dash, dayjs_quarter, debounce, defer, diff, downloadFile, draw, expect_array, filter_obj_to_url_search, first, flat, fork, formatDate, formatDateTime, formatDateTimeNoSecond, formatTime, gen_encoded_char_svg, get, getFilledArray, getFuckTimeInterval, getFutureDate, getMomentObj, getMomentRange, getSearchParamsAll, getSearchParamsValue, group, guard, image_to_base64, inRange, intersects, invert, isArray, isBoolean, isDate, isEmpty, _isEqual as isEqual, isFloat, isFunction, isInt, isMoment, isNil, isNull, isNumber, isObject, isObjectLike, isPrimitive, isPromise, isString, isSymbol, iterate, keys, last, list, listify, lowerize, map, mapEntries, mapKeys, mapValues, max, memo, merge, min, numberLikeCompare, objectify, omit, parallel, partial, partob, pascal, pick, proxied, random, randomHex, random_word, range, reduce, replace, replaceOrAppend, retry, safeExec, safeGetFromFuncOrData, safe_async_call, safe_json_parse, safe_json_parse_arr, safe_json_stringify, safe_number_parse, scrollIntoView, select, series, set, shake, shift, shuffle, sift, simple_decrypt, simple_encrypt, sleep, snake, sort, speculate_on_display, sum, template, throttle, title, toFloat, toInt, toString, toggle, trim, tryit as try, tryit, uid, unicodeToChar, unicode_to_UTF8, unique, upperize, uuid, warpBase64Type, zip, zipToObject };
|