@noah-libjs/utils 0.0.2 → 0.0.4

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/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 _slicedToArray from "@babel/runtime/helpers/slicedToArray";
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
- import _regeneratorRuntime from "@babel/runtime/regenerator";
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 { Dayjs, default as dayjs } from 'dayjs';
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
- var map = /*#__PURE__*/function () {
69
- var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(array, asyncMapFunc) {
70
- var result, index, _iterator, _step, value, newValue;
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
- _context.next = 2;
452
+ _context3.next = 2;
76
453
  break;
77
454
  }
78
- return _context.abrupt("return", []);
455
+ return _context3.abrupt("return", []);
79
456
  case 2:
80
457
  result = [];
81
458
  index = 0;
82
- _iterator = _createForOfIteratorHelper(array);
83
- _context.prev = 5;
84
- _iterator.s();
459
+ _iterator2 = _createForOfIteratorHelper(array);
460
+ _context3.prev = 5;
461
+ _iterator2.s();
85
462
  case 7:
86
- if ((_step = _iterator.n()).done) {
87
- _context.next = 15;
463
+ if ((_step2 = _iterator2.n()).done) {
464
+ _context3.next = 15;
88
465
  break;
89
466
  }
90
- value = _step.value;
91
- _context.next = 11;
467
+ value = _step2.value;
468
+ _context3.next = 11;
92
469
  return asyncMapFunc(value, index++);
93
470
  case 11:
94
- newValue = _context.sent;
471
+ newValue = _context3.sent;
95
472
  result.push(newValue);
96
473
  case 13:
97
- _context.next = 7;
474
+ _context3.next = 7;
98
475
  break;
99
476
  case 15:
100
- _context.next = 20;
477
+ _context3.next = 20;
101
478
  break;
102
479
  case 17:
103
- _context.prev = 17;
104
- _context.t0 = _context["catch"](5);
105
- _iterator.e(_context.t0);
480
+ _context3.prev = 17;
481
+ _context3.t0 = _context3["catch"](5);
482
+ _iterator2.e(_context3.t0);
106
483
  case 20:
107
- _context.prev = 20;
108
- _iterator.f();
109
- return _context.finish(20);
484
+ _context3.prev = 20;
485
+ _iterator2.f();
486
+ return _context3.finish(20);
110
487
  case 23:
111
- return _context.abrupt("return", result);
488
+ return _context3.abrupt("return", result);
112
489
  case 24:
113
490
  case "end":
114
- return _context.stop();
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();
553
+ }
554
+ }, _callee4);
555
+ }));
556
+ return function defer(_x6) {
557
+ return _ref4.apply(this, arguments);
558
+ };
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 _callee11(promises) {
674
+ var entries, results, exceptions;
675
+ return _regeneratorRuntime.wrap(function _callee11$(_context11) {
676
+ while (1) switch (_context11.prev = _context11.next) {
677
+ case 0:
678
+ entries = isArray(promises) ? promises.map(function (p) {
679
+ return [null, p];
680
+ }) : Object.entries(promises);
681
+ _context11.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 = _context11.sent;
702
+ exceptions = results.filter(function (r) {
703
+ return r.exc;
704
+ });
705
+ if (!(exceptions.length > 0)) {
706
+ _context11.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
+ _context11.next = 9;
715
+ break;
716
+ }
717
+ return _context11.abrupt("return", results.map(function (r) {
718
+ return r.result;
719
+ }));
720
+ case 9:
721
+ return _context11.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 _context11.stop();
727
+ }
728
+ }, _callee11);
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();
115
812
  }
116
- }, _callee, null, [[5, 17, 20, 23]]);
813
+ }, _callee7, null, [[4, 30, 33, 36]]);
117
814
  }));
118
- return function map(_x, _x2) {
119
- return _ref.apply(this, arguments);
815
+ return function retry(_x12, _x13) {
816
+ return _ref7.apply(this, arguments);
120
817
  };
121
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, _ref2) {
148
- var _ref3 = _slicedToArray(_ref2, 2),
149
- key = _ref3[0],
150
- value = _ref3[1];
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) {
@@ -184,14 +1109,14 @@ var omit = function omit(obj, keys2) {
184
1109
  return acc;
185
1110
  }, _objectSpread({}, obj));
186
1111
  };
187
- var get = function get(value, path, defaultValue) {
1112
+ var get$1 = function get$1(value, path, defaultValue) {
188
1113
  var segments = path.split(/[\.\[\]]/g);
189
1114
  var current = value;
190
- var _iterator2 = _createForOfIteratorHelper(segments),
191
- _step2;
1115
+ var _iterator4 = _createForOfIteratorHelper(segments),
1116
+ _step4;
192
1117
  try {
193
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
194
- var key = _step2.value;
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
- _iterator2.e(err);
1127
+ _iterator4.e(err);
203
1128
  } finally {
204
- _iterator2.f();
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 (_ref4) {
234
- var _ref5 = _slicedToArray(_ref4, 2),
235
- k = _ref5[0],
236
- v = _ref5[1];
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,186 @@ 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$1(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
+ };
1358
+ function get(value, path, defaultValue) {
1359
+ //@ts-ignore
1360
+ var direct_value = value === null || value === void 0 ? void 0 : value[path];
1361
+ if (direct_value) return direct_value;
1362
+ return get$1(value, path, defaultValue);
1363
+ }
1364
+ function identity(value) {
1365
+ return value;
1366
+ }
249
1367
  var symbolProto = Symbol ? Symbol.prototype : undefined;
250
1368
  var symbolToString = symbolProto ? symbolProto.toString : undefined;
251
1369
  var INFINITY = 1 / 0;
@@ -258,6 +1376,11 @@ function isObjectLike(value) {
258
1376
  function isNull(value) {
259
1377
  return value === null;
260
1378
  }
1379
+ function size(value) {
1380
+ if (isString(value) || isArray(value)) return value.length;
1381
+ if (isObject(value)) return Object.keys(value).length;
1382
+ return 0;
1383
+ }
261
1384
  function isNil(value) {
262
1385
  return value == null;
263
1386
  }
@@ -308,6 +1431,9 @@ function safe_json_parse(str) {
308
1431
  }
309
1432
  }
310
1433
  function safe_json_stringify(obj) {
1434
+ if (isString(obj) && safe_json_parse(obj)) {
1435
+ return obj;
1436
+ }
311
1437
  return JSON.stringify(obj);
312
1438
  }
313
1439
  function safe_json_parse_arr(str) {
@@ -368,11 +1494,10 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
368
1494
  var e = new Error(message);
369
1495
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
370
1496
  };
371
- function sleep(sec) {
372
- return new Promise(function (resolve) {
373
- return setTimeout(resolve, sec * 1000);
374
- });
375
- }
1497
+
1498
+ // export function sleep(sec: number) {
1499
+ // return new Promise<void>((resolve) => setTimeout(resolve, sec * 1000))
1500
+ // }
376
1501
  function getSearchParamsValue(key) {
377
1502
  var _a, _b;
378
1503
  var url = new URL(location.toString());
@@ -385,6 +1510,20 @@ function getSearchParamsAll(url) {
385
1510
  }, {}) : {};
386
1511
  return searchParams;
387
1512
  }
1513
+ function setSearchParamsValue(key, value) {
1514
+ var _a;
1515
+ var url = new URL(location.toString());
1516
+ (_a = url === null || url === void 0 ? void 0 : url.searchParams) === null || _a === void 0 ? void 0 : _a.set(key, "".concat(value));
1517
+ return url;
1518
+ }
1519
+ function setSearchParamsAll(data) {
1520
+ var _url = new URL(location.href);
1521
+ Object.keys(data).forEach(function (k) {
1522
+ var _a;
1523
+ (_a = _url === null || _url === void 0 ? void 0 : _url.searchParams) === null || _a === void 0 ? void 0 : _a.set(k, "".concat(data[k]));
1524
+ });
1525
+ return _url;
1526
+ }
388
1527
  function scrollIntoView(symbol) {
389
1528
  var finder = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : document.querySelector.bind(document);
390
1529
  var dom = finder(symbol);
@@ -480,12 +1619,11 @@ function copyText(text) {
480
1619
  textareaC.select();
481
1620
  var res = document.execCommand('copy');
482
1621
  document.body.removeChild(textareaC);
483
- console.log("复制成功");
484
1622
  return res;
485
1623
  }
486
1624
  function safeExec(fn) {
487
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
488
- args[_key - 1] = arguments[_key];
1625
+ for (var _len8 = arguments.length, args = new Array(_len8 > 1 ? _len8 - 1 : 0), _key8 = 1; _key8 < _len8; _key8++) {
1626
+ args[_key8 - 1] = arguments[_key8];
489
1627
  }
490
1628
  return isFunction(fn) ? fn.apply(void 0, args) : null;
491
1629
  }
@@ -495,12 +1633,15 @@ function safeGetFromFuncOrData(fn) {
495
1633
  }
496
1634
  function numberLikeCompare(a, b) {
497
1635
  if (a === b) return true;
1636
+ if (isString(a) && isString(b)) {
1637
+ return a === b;
1638
+ }
498
1639
  if (isNil(a) || isNil(b)) return false;
499
1640
  if (isObject(a) || isObject(b)) return false;
500
1641
  if (isBoolean(a) && !isBoolean(b)) return false;
501
1642
  if (isBoolean(b) && !isBoolean(a)) return false;
502
- if (toInt(a) === toInt(b)) return true;
503
- if (toFloat(a) === toFloat(b)) return true;
1643
+ if (toInt(a, NaN) === toInt(b, NaN)) return true;
1644
+ if (toFloat(a, NaN) === toFloat(b, NaN)) return true;
504
1645
  if (toString(a) === toString(b)) return true;
505
1646
  return false;
506
1647
  }
@@ -521,7 +1662,11 @@ function safe_number_parse(value) {
521
1662
  return isNaN(rawParse) ? defaultValue : rawParse;
522
1663
  }
523
1664
  function expect_array(value) {
524
- if (!Array.isArray(value)) return [];
1665
+ var default_v = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
1666
+ if (!Array.isArray(value)) {
1667
+ if (Array.isArray(default_v)) return default_v;
1668
+ return [];
1669
+ }
525
1670
  return value;
526
1671
  }
527
1672
  // 生成包含字符的 svg 转义字符串
@@ -566,59 +1711,59 @@ function filter_obj_to_url_search(obj) {
566
1711
  return clone_one;
567
1712
  }
568
1713
  function safe_async_call(cb) {
569
- for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
570
- args[_key2 - 1] = arguments[_key2];
1714
+ for (var _len9 = arguments.length, args = new Array(_len9 > 1 ? _len9 - 1 : 0), _key9 = 1; _key9 < _len9; _key9++) {
1715
+ args[_key9 - 1] = arguments[_key9];
571
1716
  }
572
- return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
573
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
574
- while (1) switch (_context2.prev = _context2.next) {
1717
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime.mark(function _callee8() {
1718
+ return _regeneratorRuntime.wrap(function _callee8$(_context8) {
1719
+ while (1) switch (_context8.prev = _context8.next) {
575
1720
  case 0:
576
1721
  if (isFunction(cb)) {
577
- _context2.next = 2;
1722
+ _context8.next = 2;
578
1723
  break;
579
1724
  }
580
- return _context2.abrupt("return", null);
1725
+ return _context8.abrupt("return", null);
581
1726
  case 2:
582
- _context2.next = 4;
1727
+ _context8.next = 4;
583
1728
  return Promise.resolve(cb.apply(void 0, args));
584
1729
  case 4:
585
- return _context2.abrupt("return", _context2.sent);
1730
+ return _context8.abrupt("return", _context8.sent);
586
1731
  case 5:
587
1732
  case "end":
588
- return _context2.stop();
1733
+ return _context8.stop();
589
1734
  }
590
- }, _callee2);
1735
+ }, _callee8);
591
1736
  }));
592
1737
  }
593
1738
  window.safe_async_call = safe_async_call;
594
1739
  var global_cache_map = {};
595
1740
  function cache_fetch(key, cb) {
596
- return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
1741
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime.mark(function _callee9() {
597
1742
  var _a, conf;
598
- return _regeneratorRuntime.wrap(function _callee3$(_context3) {
599
- while (1) switch (_context3.prev = _context3.next) {
1743
+ return _regeneratorRuntime.wrap(function _callee9$(_context9) {
1744
+ while (1) switch (_context9.prev = _context9.next) {
600
1745
  case 0:
601
1746
  conf = global_cache_map[key] = (_a = global_cache_map[key]) !== null && _a !== void 0 ? _a : {};
602
1747
  if (!conf.cache) {
603
- _context3.next = 3;
1748
+ _context9.next = 3;
604
1749
  break;
605
1750
  }
606
- return _context3.abrupt("return", conf.cache);
1751
+ return _context9.abrupt("return", conf.cache);
607
1752
  case 3:
608
1753
  if (!conf.cache_promise) {
609
- _context3.next = 5;
1754
+ _context9.next = 5;
610
1755
  break;
611
1756
  }
612
- return _context3.abrupt("return", conf.cache_promise);
1757
+ return _context9.abrupt("return", conf.cache_promise);
613
1758
  case 5:
614
- return _context3.abrupt("return", conf.cache_promise = cb().then(function (r) {
1759
+ return _context9.abrupt("return", conf.cache_promise = cb().then(function (r) {
615
1760
  return conf.cache = r;
616
1761
  }));
617
1762
  case 6:
618
1763
  case "end":
619
- return _context3.stop();
1764
+ return _context9.stop();
620
1765
  }
621
- }, _callee3);
1766
+ }, _callee9);
622
1767
  }));
623
1768
  }
624
1769
  function speculate_on_display(value) {
@@ -670,16 +1815,42 @@ function confirm_operation() {
670
1815
  // '😎'.charCodeAt(0).toString(16) == 'd83d' // UTF-16 码元
671
1816
  // '😎'.charCodeAt(1).toString(16) == 'de0e'
672
1817
  // '😎'.codePointAt(0)?.toString(16) == '1f60e'// Unicode 码点
673
-
1818
+ function simple_encrypt(data) {
1819
+ if (!data) return null;
1820
+ return JSON.stringify(data).split('').map(function (_, idx) {
1821
+ return ~_.charCodeAt(0) + idx * 119;
1822
+ });
1823
+ }
1824
+ function simple_decrypt(code) {
1825
+ if (!code) return null;
1826
+ var str = expect_array(code).map(function (_, idx) {
1827
+ return String.fromCharCode(~(_ - idx * 119));
1828
+ }).join('');
1829
+ return safe_json_parse(str);
1830
+ }
1831
+ function simple_encrypt_str(data) {
1832
+ if (!data || !isString(data)) return null;
1833
+ return data.split('').map(function (_, idx) {
1834
+ return ~_.charCodeAt(0) + idx * 119;
1835
+ }).join('@@');
1836
+ }
1837
+ function simple_decrypt_str(code) {
1838
+ if (!code || !isString(code)) return null;
1839
+ var str = code.split('@@').map(function (_, idx) {
1840
+ return String.fromCharCode(~(+_ - idx * 119));
1841
+ }).join('');
1842
+ return str;
1843
+ }
674
1844
  function getFn(format) {
675
- return Object.assign(function (s) {
1845
+ function f(s) {
676
1846
  if (isFunction(s === null || s === void 0 ? void 0 : s.format)) {
677
1847
  var res = s.format(format);
678
1848
  if (isString(res)) return res;
679
1849
  }
680
1850
  var a = dayjs(s);
681
1851
  return a.isValid() ? a.format(format) : null;
682
- }, {
1852
+ }
1853
+ return Object.assign(f, {
683
1854
  format: format
684
1855
  });
685
1856
  }
@@ -690,21 +1861,67 @@ var formatDate = getFn('YYYY-MM-DD');
690
1861
  var formatDateTime = getFn('YYYY-MM-DD HH:mm:ss');
691
1862
  var formatDateTimeNoSecond = getFn('YYYY-MM-DD HH:mm');
692
1863
  var formatTime = getFn('HH:mm:ss');
1864
+ function start() {
1865
+ var m = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : dayjs;
1866
+ return m().set('hour', 0).set('minute', 0).set('second', 0);
1867
+ }
1868
+ function end() {
1869
+ var m = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : dayjs;
1870
+ return m().set('hour', 23).set('minute', 59).set('second', 59);
1871
+ }
693
1872
  function getMomentRange() {
694
1873
  var m = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : dayjs;
695
1874
  return {
696
- 昨天: [m().add(-1, 'day'), m().add(-1, 'day')],
697
- 今天: [m(), m()],
698
- 明天: [m().add(1, 'day'), m().add(1, 'day')],
699
- 上周: [m().add(-1, 'week').startOf('week'), m().add(-1, 'week').endOf('week')],
700
- 这周: [m().startOf('week'), m().endOf('week')],
701
- 下周: [m().add(1, 'week').startOf('week'), m().add(1, 'week').endOf('week')],
702
- 上月: [m().add(-1, 'month').startOf('month'), m().add(-1, 'month').endOf('month')],
703
- 这月: [m().startOf('month'), m().endOf('month')],
704
- 下月: [m().add(1, 'month').startOf('month'), m().add(1, 'month').endOf('month')],
705
- 今年: [m().startOf('year'), m().endOf('year')]
1875
+ 昨天: [start(m).add(-1, 'day'), end(m).add(-1, 'day')],
1876
+ 今天: [start(m), end(m)],
1877
+ 明天: [start(m).add(1, 'day'), end(m).add(1, 'day')],
1878
+ 上周: [start(m).add(-1, 'week').startOf('week'), end(m).add(-1, 'week').endOf('week')],
1879
+ // 这周: [start(m).startOf('week'), end(m).endOf('week')] as DT,
1880
+ 近一周: [start(m).add(-1, 'week').add(1, 'day'), end(m)],
1881
+ 下周: [start(m).add(1, 'week').startOf('week'), end(m).add(1, 'week').endOf('week')],
1882
+ 上月: [start(m).add(-1, 'month').startOf('month'), end(m).add(-1, 'month').endOf('month')],
1883
+ // 这月: [start(m).startOf('month'), end(m).endOf('month')] as DT,
1884
+ 近一月: [start(m).add(-1, 'month').add(1, 'day'), end(m)],
1885
+ 下月: [start(m).add(1, 'month').startOf('month'), end(m).add(1, 'month').endOf('month')],
1886
+ 近一年: [start(m).add(-1, 'year').add(1, 'day'), end(m)]
706
1887
  };
707
1888
  }
1889
+ function presets_date() {
1890
+ return [{
1891
+ label: '一月前',
1892
+ value: start().add(-1, 'month')
1893
+ }, {
1894
+ label: '一周前',
1895
+ value: start().add(-1, 'week')
1896
+ }, {
1897
+ label: '一天前',
1898
+ value: start().add(-1, 'day')
1899
+ }, {
1900
+ label: '一天后',
1901
+ value: start().add(1, 'day')
1902
+ }, {
1903
+ label: '两天后',
1904
+ value: start().add(2, 'day')
1905
+ }, {
1906
+ label: '三天后',
1907
+ value: start().add(3, 'day')
1908
+ }, {
1909
+ label: '一周后',
1910
+ value: start().add(1, 'week')
1911
+ }, {
1912
+ label: '两周后',
1913
+ value: start().add(2, 'week')
1914
+ }, {
1915
+ label: '一月后',
1916
+ value: start().add(1, 'month')
1917
+ }, {
1918
+ label: '两月后',
1919
+ value: start().add(2, 'month')
1920
+ }, {
1921
+ label: '半年后',
1922
+ value: start().add(6, 'month')
1923
+ }];
1924
+ }
708
1925
  function isMoment(m) {
709
1926
  return isFunction(m.format);
710
1927
  }
@@ -727,6 +1944,10 @@ function dayjs_quarter(input, which_quarter) {
727
1944
  return [input, currentQuarter];
728
1945
  }
729
1946
  }
1947
+ function diff_between(a, b, unit) {
1948
+ var _float = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
1949
+ return dayjs(a).diff(dayjs(b), unit, _float);
1950
+ }
730
1951
  var colorMap = {
731
1952
  'log': '#1475b2',
732
1953
  'warn': '#f89c1e',
@@ -751,8 +1972,8 @@ var MyLog = /*#__PURE__*/function () {
751
1972
  var _a;
752
1973
  var fn = (_a = MyLog._handler) === null || _a === void 0 ? void 0 : _a[type];
753
1974
  if (!fn || !isFunction(fn)) return;
754
- for (var _len3 = arguments.length, msg = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
755
- msg[_key3 - 1] = arguments[_key3];
1975
+ for (var _len10 = arguments.length, msg = new Array(_len10 > 1 ? _len10 - 1 : 0), _key10 = 1; _key10 < _len10; _key10++) {
1976
+ msg[_key10 - 1] = arguments[_key10];
756
1977
  }
757
1978
  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
1979
  }
@@ -767,24 +1988,24 @@ var MyLog = /*#__PURE__*/function () {
767
1988
  }, {
768
1989
  key: "log",
769
1990
  value: function log() {
770
- for (var _len4 = arguments.length, msg = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
771
- msg[_key4] = arguments[_key4];
1991
+ for (var _len11 = arguments.length, msg = new Array(_len11), _key11 = 0; _key11 < _len11; _key11++) {
1992
+ msg[_key11] = arguments[_key11];
772
1993
  }
773
1994
  this._logMsg.apply(this, ['log'].concat(msg));
774
1995
  }
775
1996
  }, {
776
1997
  key: "warn",
777
1998
  value: function warn() {
778
- for (var _len5 = arguments.length, msg = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
779
- msg[_key5] = arguments[_key5];
1999
+ for (var _len12 = arguments.length, msg = new Array(_len12), _key12 = 0; _key12 < _len12; _key12++) {
2000
+ msg[_key12] = arguments[_key12];
780
2001
  }
781
2002
  this._logMsg.apply(this, ['warn'].concat(msg));
782
2003
  }
783
2004
  }, {
784
2005
  key: "error",
785
2006
  value: function error() {
786
- for (var _len6 = arguments.length, msg = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
787
- msg[_key6] = arguments[_key6];
2007
+ for (var _len13 = arguments.length, msg = new Array(_len13), _key13 = 0; _key13 < _len13; _key13++) {
2008
+ msg[_key13] = arguments[_key13];
788
2009
  }
789
2010
  this._logMsg.apply(this, ['error'].concat(msg));
790
2011
  }
@@ -839,18 +2060,18 @@ var EventEmitter = /*#__PURE__*/function () {
839
2060
  }, {
840
2061
  key: "on_rm",
841
2062
  value: function on_rm(event, listener) {
842
- var _this = this;
2063
+ var _this2 = this;
843
2064
  // this.off(event, listener)
844
2065
  this.addListener(event, listener);
845
2066
  return function () {
846
- _this.off(event, listener);
2067
+ _this2.off(event, listener);
847
2068
  };
848
2069
  }
849
2070
  }, {
850
2071
  key: "emit",
851
2072
  value: function emit(event) {
852
- for (var _len7 = arguments.length, args = new Array(_len7 > 1 ? _len7 - 1 : 0), _key7 = 1; _key7 < _len7; _key7++) {
853
- args[_key7 - 1] = arguments[_key7];
2073
+ for (var _len14 = arguments.length, args = new Array(_len14 > 1 ? _len14 - 1 : 0), _key14 = 1; _key14 < _len14; _key14++) {
2074
+ args[_key14 - 1] = arguments[_key14];
854
2075
  }
855
2076
  var existing = this.events[event];
856
2077
  // EventEmitter.logger.log({ event, args })
@@ -887,10 +2108,10 @@ var EventEmitter = /*#__PURE__*/function () {
887
2108
  }, {
888
2109
  key: "once",
889
2110
  value: function once(event, listener) {
890
- var _this2 = this;
2111
+ var _this3 = this;
891
2112
  var _fn = function fn() {
892
2113
  listener.apply(void 0, arguments);
893
- _this2.off(event, _fn);
2114
+ _this3.off(event, _fn);
894
2115
  };
895
2116
  this.on(event, _fn);
896
2117
  return this;
@@ -948,4 +2169,307 @@ Object.defineProperty(EventEmitter, "logger", {
948
2169
  writable: true,
949
2170
  value: new MyLog('EventEmitter')
950
2171
  });
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 };
2172
+ var EMPTY_PLACEHOLDER = '-';
2173
+ var TOKEN_KEY = 'Σ(っ °Д °;)っ';
2174
+ var ARG_URS1_KEY = 'usr1';
2175
+ var ARG_URS2_KEY = 'usr2';
2176
+ var noop = function noop() {};
2177
+ var ROMAN_NUMERALS = {
2178
+ 1: 'Ⅰ',
2179
+ 2: 'Ⅱ',
2180
+ 3: 'Ⅲ',
2181
+ 4: 'Ⅳ',
2182
+ 5: 'Ⅴ',
2183
+ 6: 'Ⅵ',
2184
+ 7: 'Ⅶ',
2185
+ 8: 'Ⅷ',
2186
+ 9: 'Ⅷ',
2187
+ 10: 'Ⅹ'
2188
+ };
2189
+ var selectOptionMap = {};
2190
+ var REGE_AutoComplete = /\<(.*)\>a$/;
2191
+ var REGE_MyCheckbox = /\<(.*)\>c$/;
2192
+ var REGE_MySelect = /\<(.*)\>s$/;
2193
+ var REGE_EXCLUSIVE = /^(.*)\<(.*)\>(.*)#$/;
2194
+ var optionKey其他 = 99;
2195
+ var optionKey不详 = 100;
2196
+ var optionKey否 = 0;
2197
+ var defalutSp = [{
2198
+ label: '不详',
2199
+ value: optionKey不详
2200
+ }, {
2201
+ label: '其他',
2202
+ value: optionKey其他,
2203
+ inputType: 'MyInput'
2204
+ }, {
2205
+ label: '其它',
2206
+ value: optionKey其他,
2207
+ inputType: 'MyInput'
2208
+ }, {
2209
+ label: '无',
2210
+ value: optionKey否,
2211
+ exclusive: true
2212
+ }, {
2213
+ label: '否',
2214
+ value: optionKey否,
2215
+ exclusive: true
2216
+ }];
2217
+ function _getSimpleOptions(_arr) {
2218
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2219
+ var arr = parseList(_arr);
2220
+ var _options$sp = options.sp,
2221
+ sp = _options$sp === void 0 ? [] : _options$sp,
2222
+ _options$start = options.start,
2223
+ start = _options$start === void 0 ? 1 : _options$start,
2224
+ _options$useDefault = options.useDefault,
2225
+ useDefault = _options$useDefault === void 0 ? true : _options$useDefault,
2226
+ useString = options.useString;
2227
+ var index = start;
2228
+ var opt = arr.map(function (_label, idx) {
2229
+ var _a, _b;
2230
+ var preset = presetInput(_label);
2231
+ var label = (_a = preset.label) !== null && _a !== void 0 ? _a : _label;
2232
+ var _defaultSpItem = useDefault ? defalutSp.find(function (s) {
2233
+ return label === s.label;
2234
+ }) : null;
2235
+ var _spItem = sp.find(function (s) {
2236
+ return label === s.label;
2237
+ });
2238
+ var spItem = (_b = _spItem !== null && _spItem !== void 0 ? _spItem : _defaultSpItem) !== null && _b !== void 0 ? _b : {};
2239
+ if (spItem.value && useString) {
2240
+ spItem.value = spItem.value.toString();
2241
+ }
2242
+ var _value = _defaultSpItem ? index : index++;
2243
+ return Object.assign({
2244
+ label: label,
2245
+ value: useString ? _value.toString() : _value,
2246
+ inputType: preset.inputType,
2247
+ props: preset.props,
2248
+ exclusive: preset.exclusive,
2249
+ parentheses: preset.parentheses,
2250
+ prefix: preset.prefix,
2251
+ suffix: preset.suffix
2252
+ }, spItem);
2253
+ });
2254
+ return opt;
2255
+ }
2256
+ function getSimpleOptions(_arr) {
2257
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2258
+ var ret = typeof _arr === 'function' ? function () {
2259
+ return _getSimpleOptions(_arr(), options);
2260
+ } : _getSimpleOptions(_arr, options);
2261
+ return ret;
2262
+ }
2263
+ function _getSameOptions(_arr) {
2264
+ var arr = parseList(_arr);
2265
+ return arr.map(function (label) {
2266
+ return {
2267
+ label: label,
2268
+ value: label
2269
+ };
2270
+ });
2271
+ }
2272
+ function getSameOptions(_arr) {
2273
+ var ret = typeof _arr === 'function' ? function () {
2274
+ return _getSameOptions(_arr());
2275
+ } : _getSameOptions(_arr);
2276
+ return ret;
2277
+ }
2278
+ function getDualModeOptions(arr, options) {
2279
+ return [getSimpleOptions(arr, options), getSameOptions(arr)];
2280
+ }
2281
+ function parseList(arr) {
2282
+ if (!arr) return [];
2283
+ var _arr = [];
2284
+ var split1 = [];
2285
+ if (Array.isArray(arr)) {
2286
+ _arr = arr;
2287
+ } else if ((split1 = arr.split(',')) && split1.length > 1) {
2288
+ _arr = split1;
2289
+ } else if ((split1 = arr.split('、')) && split1.length > 1) {
2290
+ _arr = split1;
2291
+ }
2292
+ return _arr;
2293
+ }
2294
+ function presetInput(_label) {
2295
+ if (!_label) return {
2296
+ label: _label
2297
+ };
2298
+ var withInput = (_label === null || _label === void 0 ? void 0 : _label.endsWith('|i')) || (_label === null || _label === void 0 ? void 0 : _label.endsWith('i'));
2299
+ if (withInput) {
2300
+ return {
2301
+ inputType: 'Input',
2302
+ label: _label.slice(0, -1)
2303
+ };
2304
+ }
2305
+ var useAuto = REGE_AutoComplete.exec(_label);
2306
+ if (useAuto) {
2307
+ return {
2308
+ inputType: 'MA',
2309
+ label: _label.slice(0, useAuto.index),
2310
+ props: {
2311
+ options: useAuto[1]
2312
+ }
2313
+ };
2314
+ }
2315
+ var useCheckbox = REGE_MyCheckbox.exec(_label);
2316
+ if (useCheckbox) {
2317
+ var config = useCheckbox[1];
2318
+ var arr = config.split('|');
2319
+ var options = arr[0];
2320
+ var marshal = arr[1] ? Number(arr[1]) : undefined;
2321
+ var type = arr[2] || undefined;
2322
+ return {
2323
+ inputType: 'MC',
2324
+ label: _label.slice(0, useCheckbox.index),
2325
+ props: {
2326
+ options: options,
2327
+ marshal: marshal,
2328
+ type: type
2329
+ }
2330
+ };
2331
+ }
2332
+ var useSelect = REGE_MySelect.exec(_label);
2333
+ if (useSelect) {
2334
+ var _config = useSelect[1];
2335
+ var _arr2 = _config.split('|');
2336
+ var _options = _arr2[0];
2337
+ var _marshal = _arr2[1] ? Number(_arr2[1]) : undefined;
2338
+ var mode = _arr2[2] || undefined;
2339
+ return {
2340
+ inputType: 'MS',
2341
+ label: _label.slice(0, useSelect.index),
2342
+ props: {
2343
+ options: _options,
2344
+ marshal: _marshal,
2345
+ mode: mode
2346
+ }
2347
+ };
2348
+ }
2349
+ // 文字<exclusive|parentheses|prefix|suffix>MyInput#
2350
+ var useExclusive = REGE_EXCLUSIVE.exec(_label);
2351
+ if (useExclusive) {
2352
+ var label = useExclusive[1];
2353
+ var _config2 = useExclusive[2];
2354
+ var _arr3 = _config2.split('|');
2355
+ var inputType = useExclusive[3];
2356
+ var exclusive = _arr3[0] ? Boolean(_arr3[0]) : undefined;
2357
+ var parentheses = _arr3[1] ? Boolean(_arr3[1]) : undefined;
2358
+ var prefix = _arr3[2];
2359
+ var suffix = _arr3[3];
2360
+ // mchcLogger.log('useExclusive', { useExclusive, exclusive, parentheses, prefix, suffix, inputType, label, _label })
2361
+ return {
2362
+ exclusive: exclusive,
2363
+ parentheses: parentheses,
2364
+ prefix: prefix,
2365
+ suffix: suffix,
2366
+ inputType: inputType,
2367
+ label: label
2368
+ };
2369
+ }
2370
+ return {
2371
+ label: _label
2372
+ };
2373
+ }
2374
+ function safe_fetch_options(cb) {
2375
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime.mark(function _callee10() {
2376
+ var arr;
2377
+ return _regeneratorRuntime.wrap(function _callee10$(_context10) {
2378
+ while (1) switch (_context10.prev = _context10.next) {
2379
+ case 0:
2380
+ _context10.next = 2;
2381
+ return safe_async_call(cb);
2382
+ case 2:
2383
+ arr = _context10.sent;
2384
+ return _context10.abrupt("return", expect_array(arr));
2385
+ case 4:
2386
+ case "end":
2387
+ return _context10.stop();
2388
+ }
2389
+ }, _callee10);
2390
+ }));
2391
+ }
2392
+ function getPresetOptions(key) {
2393
+ var pure = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
2394
+ var _a, _b;
2395
+ var options = (_b = (_a = selectOptionMap[key]) === null || _a === void 0 ? void 0 : _a.call(selectOptionMap)) !== null && _b !== void 0 ? _b : [];
2396
+ return pure ? options.map(function (_) {
2397
+ return Object.assign(Object.assign({}, _), {
2398
+ inputType: undefined
2399
+ });
2400
+ }) : options;
2401
+ }
2402
+ function getOptionLabel(k, value) {
2403
+ var defaultLabel = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
2404
+ var _a, _b, _c, _d;
2405
+ var options = (_b = (_a = selectOptionMap[k]) === null || _a === void 0 ? void 0 : _a.call(selectOptionMap)) !== null && _b !== void 0 ? _b : [];
2406
+ return (_d = (_c = options.find(function (_) {
2407
+ return _.value === value;
2408
+ })) === null || _c === void 0 ? void 0 : _c.label) !== null && _d !== void 0 ? _d : defaultLabel;
2409
+ }
2410
+ function getOptionValue(k, label) {
2411
+ var _a, _b, _c;
2412
+ var options = (_b = (_a = selectOptionMap[k]) === null || _a === void 0 ? void 0 : _a.call(selectOptionMap)) !== null && _b !== void 0 ? _b : [];
2413
+ return (_c = options.find(function (_) {
2414
+ return _.label === label;
2415
+ })) === null || _c === void 0 ? void 0 : _c.value;
2416
+ }
2417
+ // merge options
2418
+ function merge_preset_options(ops) {
2419
+ Object.assign(selectOptionMap, ops);
2420
+ }
2421
+ var dic_map = {};
2422
+ function getDictionaries() {
2423
+ return dic_map;
2424
+ }
2425
+ /**
2426
+ *
2427
+ * @param value 枚举值value
2428
+ * @param type string 字典类型
2429
+ */
2430
+ function getDictionariesEnumerations(type) {
2431
+ var _a;
2432
+ var dictionaries = getDictionaries();
2433
+ var object = dictionaries === null || dictionaries === void 0 ? void 0 : dictionaries[type];
2434
+ if (!object) {
2435
+ console.warn("\u5B57\u5178 ".concat(type, " \u4E0D\u5B58\u5728!"));
2436
+ return [];
2437
+ }
2438
+ var enumerations = (_a = object === null || object === void 0 ? void 0 : object.enumerations) !== null && _a !== void 0 ? _a : [];
2439
+ return enumerations;
2440
+ }
2441
+ /**
2442
+ *
2443
+ * @param value 枚举值value
2444
+ * @param type string 字典类型
2445
+ */
2446
+ function getDictionaryLabel(type, value) {
2447
+ var enumerations = getDictionariesEnumerations(type);
2448
+ var item = enumerations.find(function (_) {
2449
+ return _.value === +value;
2450
+ });
2451
+ if (!item) {
2452
+ return null;
2453
+ }
2454
+ return item.label;
2455
+ }
2456
+ /**
2457
+ *
2458
+ * @param label 枚举值value
2459
+ * @param type string 字典类型
2460
+ */
2461
+ function getDictionaryValue(type, label) {
2462
+ var enumerations = getDictionariesEnumerations(type);
2463
+ var item = enumerations.find(function (_) {
2464
+ return _.label === label;
2465
+ });
2466
+ if (!item) {
2467
+ return null;
2468
+ }
2469
+ return item.value;
2470
+ }
2471
+ // merge dic
2472
+ function merge_dict(ops) {
2473
+ Object.assign(dic_map, ops);
2474
+ }
2475
+ export { ARG_URS1_KEY, ARG_URS2_KEY, EMPTY_PLACEHOLDER, EventEmitter, MyLog, ROMAN_NUMERALS, TOKEN_KEY, 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, diff_between, downloadFile, draw, expect_array, filter_obj_to_url_search, first, flat, fork, formatDate, formatDateTime, formatDateTimeNoSecond, formatTime, gen_encoded_char_svg, get, getDictionaries, getDictionariesEnumerations, getDictionaryLabel, getDictionaryValue, getDualModeOptions, getFilledArray, getFuckTimeInterval, getFutureDate, getMomentObj, getMomentRange, getOptionLabel, getOptionValue, getPresetOptions, getSameOptions, getSearchParamsAll, getSearchParamsValue, getSimpleOptions, group, guard, identity, 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, merge_dict, merge_preset_options, min, noop, numberLikeCompare, objectify, omit, optionKey不详, optionKey其他, optionKey否, parallel, partial, partob, pascal, pick, presets_date, proxied, random, randomHex, random_word, range, reduce, replace, replaceOrAppend, retry, safeExec, safeGetFromFuncOrData, safe_async_call, safe_fetch_options, safe_json_parse, safe_json_parse_arr, safe_json_stringify, safe_number_parse, scrollIntoView, select, series, set, setSearchParamsAll, setSearchParamsValue, shake, shift, shuffle, sift, simple_decrypt, simple_decrypt_str, simple_encrypt, simple_encrypt_str, size, 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 };