@wzyjs/utils 0.2.36 → 0.2.37

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.
Files changed (81) hide show
  1. package/dist/ai/302/axios.d.ts +2 -0
  2. package/dist/ai/302/chat/index.d.ts +1 -0
  3. package/dist/ai/302/image/index.d.ts +1 -0
  4. package/dist/ai/302/image/midjourney.d.ts +2 -0
  5. package/dist/ai/302/index.d.ts +2 -0
  6. package/dist/ai/index.d.ts +3 -0
  7. package/dist/ai/keling/axios.d.ts +2 -0
  8. package/dist/ai/keling/index.d.ts +8 -0
  9. package/dist/ai/keling/utils.d.ts +4 -0
  10. package/dist/ai/midjourney/index.d.ts +1 -0
  11. package/dist/ai/midjourney/utils.d.ts +12 -0
  12. package/dist/browser/download.d.ts +1 -0
  13. package/dist/browser/element.d.ts +6 -0
  14. package/dist/browser/index.d.ts +8 -0
  15. package/dist/browser/other.d.ts +2 -0
  16. package/dist/browser/style.d.ts +10 -0
  17. package/dist/browser.cjs.js +21010 -0
  18. package/dist/browser.esm.js +21007 -0
  19. package/dist/common/antd.d.ts +11 -0
  20. package/dist/common/array.d.ts +3 -0
  21. package/dist/common/image.d.ts +1 -0
  22. package/dist/common/index.d.ts +13 -0
  23. package/dist/common/location.d.ts +8 -0
  24. package/dist/common/number.d.ts +5 -0
  25. package/dist/common/object.d.ts +10 -0
  26. package/dist/common/other.d.ts +4 -0
  27. package/dist/common/promise.d.ts +5 -0
  28. package/dist/common/string.d.ts +22 -0
  29. package/dist/node/file/index.d.ts +2 -0
  30. package/dist/node/index.d.ts +4 -0
  31. package/dist/node/mail/index.d.ts +1 -0
  32. package/dist/node/oss/index.d.ts +9 -0
  33. package/dist/node.cjs.js +97007 -0
  34. package/dist/{cjs/node.d.ts → node.d.ts} +1 -0
  35. package/dist/node.esm.js +96989 -0
  36. package/package.json +27 -25
  37. package/dist/cjs/browser/element.js +0 -59
  38. package/dist/cjs/browser/index.js +0 -66
  39. package/dist/cjs/browser/initHttpClient.js +0 -62
  40. package/dist/cjs/browser/other.js +0 -35
  41. package/dist/cjs/browser/style.js +0 -81
  42. package/dist/cjs/browser.js +0 -25
  43. package/dist/cjs/common/array.js +0 -68
  44. package/dist/cjs/common/classs.js +0 -36
  45. package/dist/cjs/common/dayjs.js +0 -70
  46. package/dist/cjs/common/index.d.ts +0 -13
  47. package/dist/cjs/common/index.js +0 -106
  48. package/dist/cjs/common/number.js +0 -69
  49. package/dist/cjs/common/object.js +0 -65
  50. package/dist/cjs/common/other.js +0 -129
  51. package/dist/cjs/common/string.js +0 -190
  52. package/dist/cjs/node/file/index.js +0 -58
  53. package/dist/cjs/node/index.js +0 -48
  54. package/dist/cjs/node/jsonFile/index.js +0 -75
  55. package/dist/cjs/node/mail/index.js +0 -67
  56. package/dist/cjs/node.js +0 -25
  57. package/dist/esm/browser/element.js +0 -43
  58. package/dist/esm/browser/index.js +0 -16
  59. package/dist/esm/browser/initHttpClient.js +0 -67
  60. package/dist/esm/browser/other.js +0 -28
  61. package/dist/esm/browser/style.js +0 -55
  62. package/dist/esm/browser.d.ts +0 -2
  63. package/dist/esm/browser.js +0 -2
  64. package/dist/esm/common/array.js +0 -65
  65. package/dist/esm/common/classs.js +0 -33
  66. package/dist/esm/common/dayjs.d.ts +0 -19
  67. package/dist/esm/common/dayjs.js +0 -29
  68. package/dist/esm/common/index.d.ts +0 -13
  69. package/dist/esm/common/index.js +0 -14
  70. package/dist/esm/common/number.js +0 -52
  71. package/dist/esm/common/object.js +0 -84
  72. package/dist/esm/common/other.js +0 -167
  73. package/dist/esm/common/string.js +0 -180
  74. package/dist/esm/node/file/index.js +0 -52
  75. package/dist/esm/node/index.js +0 -4
  76. package/dist/esm/node/jsonFile/index.js +0 -101
  77. package/dist/esm/node/mail/index.js +0 -48
  78. package/dist/esm/node.d.ts +0 -2
  79. package/dist/esm/node.js +0 -2
  80. /package/dist/{cjs/browser.d.ts → browser.d.ts} +0 -0
  81. /package/dist/{cjs/common → common}/dayjs.d.ts +0 -0
@@ -1,52 +0,0 @@
1
- // 取指定范围内的随机数
2
- export var getRandomNum = function getRandomNum(min, max) {
3
- return Math.floor(Math.random() * (max - min + 1) + min);
4
- };
5
-
6
- // 指定小数点的位数
7
- export var limitDecimals = function limitDecimals(v) {
8
- var num = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2;
9
- var isForce = arguments.length > 2 ? arguments[2] : undefined;
10
- var value = parseFloat(v);
11
- if (isNaN(value)) {
12
- if (isForce) {
13
- value = 0;
14
- } else {
15
- return '';
16
- }
17
- }
18
- return value.toFixed(num).toString();
19
- };
20
-
21
- // 转换成更易读的尺寸单位
22
- export var getFileSize = function getFileSize(size) {
23
- var d = 'G';
24
- var s = size / 1024 / 1024 / 1024;
25
- if (s < 1) {
26
- d = 'M';
27
- s *= 1024;
28
- }
29
- // @ts-ignore
30
- return "".concat((s.toFixed(1) / 1).toString()).concat(d);
31
- };
32
-
33
- // 校验是否为有效的数值
34
- export var isValidNumber = function isValidNumber(value) {
35
- // 检查是否为数字类型
36
- if (typeof value !== 'number') {
37
- return false;
38
- }
39
-
40
- // 检查是否为 NaN
41
- if (isNaN(value)) {
42
- return false;
43
- }
44
-
45
- // 检查是否为 Infinity 或 -Infinity
46
- if (value === Infinity || value === -Infinity) {
47
- return false;
48
- }
49
-
50
- // 如果以上检查都通过,则是有效的数值
51
- return true;
52
- };
@@ -1,84 +0,0 @@
1
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
5
- function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
6
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
- import { getType, isJson } from "./string";
8
-
9
- // 判断是否有包含指定属性的对象,第三个参数可以指定具体的值
10
- export var findItem = function findItem(list, attr, value) {
11
- return list.find(function (item) {
12
- return value === undefined ? item[attr] : item[attr] === value;
13
- });
14
- };
15
-
16
- // 在数据里深入找指定字段
17
- var findAttr = function findAttr(variable, attr, curPath) {
18
- if (isJson(variable)) {
19
- variable = JSON.parse(variable);
20
- curPath += '.toString()';
21
- }
22
- if (getType(variable) === 'Array') {
23
- for (var index = 0; index < variable.length; index++) {
24
- var res = findAttr(variable[index], attr, curPath + "[".concat(index, "]"));
25
- if (res) {
26
- return res;
27
- }
28
- }
29
- }
30
- if (getType(variable) === 'Object') {
31
- if (variable[attr] !== undefined) {
32
- return curPath + '.' + attr;
33
- }
34
- for (var _key in variable) {
35
- var _res = findAttr(variable[_key], attr, curPath + ".".concat(_key));
36
- if (_res) {
37
- return _res;
38
- }
39
- }
40
- }
41
- };
42
-
43
- // 过滤对象中为undefined的属性
44
- export var filterParams = function filterParams(params) {
45
- return Object.entries(params || {}).reduce(function (obj, _ref) {
46
- var _ref2 = _slicedToArray(_ref, 2),
47
- key = _ref2[0],
48
- value = _ref2[1];
49
- if (value !== undefined) {
50
- obj[key] = value;
51
- }
52
- return obj;
53
- }, {});
54
- };
55
-
56
- // 监听属性
57
- export var watch = {
58
- observe: function observe(obj, key, watchFun) {
59
- // 给该属性设默认值
60
- var val = obj[key];
61
- Object.defineProperty(obj, key, {
62
- configurable: true,
63
- enumerable: true,
64
- set: function set(value) {
65
- obj[key] = value;
66
- // 赋值(set)时,调用对应函数
67
- watchFun(value, val);
68
- },
69
- get: function get() {
70
- return val;
71
- }
72
- });
73
- },
74
- setWatcher: function setWatcher() {
75
- var _this = this;
76
- var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
77
- var watch = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
78
- // 接收index.js传过来的data对象和watch对象
79
- Object.keys(watch).forEach(function (v) {
80
- // 将watch对象内的key遍历
81
- _this.observe(data, v, watch[v]); // 监听data内的v属性,传入watch内对应函数以调用
82
- });
83
- }
84
- };
@@ -1,167 +0,0 @@
1
- function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
- var _excluded = ["current", "pageSize"];
3
- function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
4
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
5
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
6
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
7
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
8
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
9
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
10
- function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
11
- function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
12
- function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
13
- import { pick } from 'lodash';
14
- // 处理 ProTable 参数中的 pagination 和 where 和 sort
15
- export var handleParams = function handleParams(params, sort, filter, additional) {
16
- var _ref = params || {},
17
- _ref$current = _ref.current,
18
- current = _ref$current === void 0 ? 1 : _ref$current,
19
- _ref$pageSize = _ref.pageSize,
20
- pageSize = _ref$pageSize === void 0 ? 10 : _ref$pageSize,
21
- where = _objectWithoutProperties(_ref, _excluded);
22
- var where_ = _objectSpread(_objectSpread(_objectSpread({}, additional || {}), where || {}), filter || {});
23
- var order_ = Object.keys(sort).reduce(function (acc, key) {
24
- var value = sort[key];
25
- if (value === 'ascend') {
26
- acc[key] = 'asc';
27
- } else if (value === 'descend') {
28
- acc[key] = 'desc';
29
- }
30
- return acc;
31
- }, {});
32
- return {
33
- where: Object.keys(where_).length ? where_ : undefined,
34
- order: Object.keys(order_).length ? order_ : undefined,
35
- pagination: {
36
- current: current,
37
- pageSize: pageSize
38
- }
39
- };
40
- };
41
-
42
- // 将 list 的数据处理为 { label: string, value: string }[]
43
- export var handleRes2List = /*#__PURE__*/function () {
44
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(reqPromise) {
45
- var _yield$reqPromise, data;
46
- return _regeneratorRuntime().wrap(function _callee$(_context) {
47
- while (1) switch (_context.prev = _context.next) {
48
- case 0:
49
- _context.next = 2;
50
- return reqPromise();
51
- case 2:
52
- _yield$reqPromise = _context.sent;
53
- data = _yield$reqPromise.data;
54
- return _context.abrupt("return", ((data === null || data === void 0 ? void 0 : data.data) || []).map(function (item) {
55
- return {
56
- label: item.name,
57
- value: item.id || item.key
58
- };
59
- }));
60
- case 5:
61
- case "end":
62
- return _context.stop();
63
- }
64
- }, _callee);
65
- }));
66
- return function handleRes2List(_x) {
67
- return _ref2.apply(this, arguments);
68
- };
69
- }();
70
-
71
- // 计算执行 promise 花费的时间
72
- export var executePromise = /*#__PURE__*/function () {
73
- var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(promise) {
74
- var start, result, time;
75
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
76
- while (1) switch (_context2.prev = _context2.next) {
77
- case 0:
78
- start = Date.now();
79
- _context2.next = 3;
80
- return promise;
81
- case 3:
82
- result = _context2.sent;
83
- time = Date.now() - start;
84
- return _context2.abrupt("return", {
85
- result: result,
86
- time: time
87
- });
88
- case 6:
89
- case "end":
90
- return _context2.stop();
91
- }
92
- }, _callee2);
93
- }));
94
- return function executePromise(_x2) {
95
- return _ref3.apply(this, arguments);
96
- };
97
- }();
98
-
99
- // 地址栏方面的操作
100
- export var locationFn = {
101
- // url地址的query转为query对象
102
- url2Params: function url2Params() {
103
- var url = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : location.href;
104
- url = decodeURIComponent(url);
105
- var jsonList = {};
106
- if (url.indexOf('?') > -1) {
107
- var str = url.slice(url.indexOf('?') + 1);
108
- var strs = str.split('&');
109
- for (var i = 0; i < strs.length; i++) {
110
- jsonList[strs[i].split('=')[0]] = strs[i].split('=')[1]; // 如果出现乱码的话,可以用decodeURI()进行解码
111
- }
112
- }
113
-
114
- return jsonList || {};
115
- },
116
- // 参数对象转换为url
117
- params2Url: function params2Url(params) {
118
- var url = '';
119
- for (var k in params) {
120
- if (k) {
121
- url += "".concat(k, "=").concat(params[k], "&");
122
- }
123
- }
124
- return url.substr(0, url.length - 1);
125
- },
126
- // 设置地址栏参数
127
- setUrlParams: function setUrlParams(key, value, keepName) {
128
- if (key === undefined || value === undefined) return;
129
-
130
- // 给地址栏参数对象添加指定参数
131
- var allParams = locationFn.url2Params();
132
- if (keepName) {
133
- allParams = pick(allParams, keepName) || {};
134
- }
135
- // @ts-ignore
136
- allParams[key] = encodeURIComponent(value);
137
-
138
- // 域名和路径
139
- var url = location.href;
140
- var sliceEnd = url.indexOf('?') === -1 ? url.length : url.indexOf('?');
141
- var domainPath = url.slice(0, sliceEnd);
142
-
143
- // 参数
144
- var params = locationFn.params2Url(allParams);
145
-
146
- // 修改地址栏url
147
- location.replace("".concat(domainPath, "?").concat(params));
148
- },
149
- // 取地址栏的path部分
150
- urlGetPath: function urlGetPath() {
151
- var url = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : location.href;
152
- // 计算要截取的最后一位
153
- var lastIndex = url.indexOf('?');
154
- if (lastIndex === -1) {
155
- lastIndex = url.length;
156
- }
157
- return url.slice(0, lastIndex);
158
- }
159
- };
160
-
161
- // 延迟指定毫秒数
162
- export var delay = function delay() {
163
- var time = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1000;
164
- return new Promise(function (resolve) {
165
- return setTimeout(resolve, time);
166
- });
167
- };
@@ -1,180 +0,0 @@
1
- function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
3
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
5
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
6
- function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
7
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
8
- // 获取字符串中的中文字符串
9
- export var getChineseByStr = function getChineseByStr(str) {
10
- if (!str) {
11
- return '';
12
- }
13
- var match = str.match(/[\u4e00-\u9fa5]/g);
14
- if (!match) {
15
- return '';
16
- }
17
- return match.join('');
18
- };
19
-
20
- // 获取字符串中的长度,中文算 2 个字符
21
- export var getStrLength = function getStrLength(value) {
22
- if (!value) {
23
- return 0;
24
- }
25
- var chineseLength = getChineseByStr(value).length;
26
- return value.length - chineseLength + chineseLength * 2;
27
- };
28
-
29
- // 替换全部指定字符串
30
- export var replaceAll = function replaceAll(str, searchValue, replaceValue) {
31
- if (!str || !searchValue || !replaceValue) {
32
- return str || '';
33
- }
34
- str = str.replace(searchValue, replaceValue);
35
- if (!str.includes(searchValue)) {
36
- return str;
37
- }
38
- return replaceAll(str, searchValue, replaceValue);
39
- };
40
-
41
- // 根据规则替换字符串
42
- export var replaceByRules = function replaceByRules(str, rules) {
43
- rules.forEach(function (_ref) {
44
- var _ref2 = _slicedToArray(_ref, 2),
45
- searchValue = _ref2[0],
46
- replaceValue = _ref2[1];
47
- str = str.replaceAll(searchValue, replaceValue);
48
- });
49
- return str;
50
- };
51
-
52
- // 获取变量的类型
53
- export var getType = function getType(value) {
54
- return Object.prototype.toString.call(value).slice(8, -1);
55
- };
56
-
57
- // 金钱格式化,每三位加,
58
- export var amount = function amount(str) {
59
- var reg = /(?=(?!\b)(\d{3})+$)/g;
60
- return str.replace(reg, ',');
61
- };
62
-
63
- // 更安全的 JSON.parse
64
- export var jsonParse = function jsonParse(value) {
65
- if (_typeof(value) === 'object') {
66
- return value;
67
- }
68
- try {
69
- return JSON.parse(value);
70
- } catch (err) {
71
- return {};
72
- }
73
- };
74
-
75
- // 是否为json对象的字符串
76
- export var isJson = function isJson(str) {
77
- try {
78
- if (getType(JSON.parse(str)) === 'Object') {
79
- return true;
80
- }
81
- } catch (e) {}
82
- return false;
83
- };
84
-
85
- // 将变量转为字符串
86
- export var toString = function toString(value) {
87
- return Object.prototype.toString.call(value).slice(8, -1) === 'object' ? JSON.stringify(value) : String(value);
88
- };
89
-
90
- // 生成随机颜色
91
- export var getRandomColor = function getRandomColor() {
92
- var color = Math.floor(Math.random() * 16777215).toString(16);
93
- if (color.length === 6) {
94
- return color;
95
- } else {
96
- return getRandomColor();
97
- }
98
- };
99
-
100
- // 生成随机字符串
101
- export var getRandomString = function getRandomString() {
102
- var length = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 4;
103
- return Math.random().toString(36).substr(2, length);
104
- };
105
-
106
- // 获取字符串内的中文
107
- export var getChinese = function getChinese(str) {
108
- if (str == null || str === '') {
109
- return '';
110
- }
111
- var res = str.match(/[\u4e00-\u9fa5]/g);
112
- if (!res) {
113
- return '';
114
- }
115
- return res.join('');
116
- };
117
-
118
- // 截取指定两个文本之间的字符串 (不好用)
119
- export var getSliceStr = function getSliceStr(str, before, after) {
120
- return str.slice(str.indexOf(before) + before.length, str.lastIndexOf(after));
121
- };
122
-
123
- // 获取代理后的url
124
- export var getProxyUrl = function getProxyUrl(url) {
125
- var beforeUrl = 'https://1141871752167714.cn-hangzhou.fc.aliyuncs.com/2016-08-15/proxy/a.LATEST/proxy/?url=';
126
- return beforeUrl + url;
127
- };
128
-
129
- // 获取字符串的长度
130
- export var getLength = function getLength(value) {
131
- var chineseLength = getChinese(value).length;
132
- return value.length - chineseLength + chineseLength * 2;
133
- };
134
-
135
- // 获取指定cookie
136
- export var getCookie = function getCookie(name) {
137
- var reg = new RegExp("(^| )".concat(name, "=([^;]*)(;|$)"));
138
- var arr = document.cookie.match(reg);
139
- return arr ? unescape(arr[2]) : null;
140
- };
141
-
142
- // 生成符合数量的字母,例如:3 => ['a', 'b', 'c']
143
- export var generateAlphabetArray = function generateAlphabetArray(n) {
144
- return Array.from({
145
- length: n
146
- }, function (_, i) {
147
- return String.fromCharCode(97 + i);
148
- });
149
- };
150
-
151
- // 计算文本相似度 (Levenshtein 距离算法)
152
- export var levenshteinDistance = function levenshteinDistance(a, b) {
153
- var matrix = [];
154
-
155
- // 初始化矩阵
156
- for (var i = 0; i <= b.length; i++) {
157
- matrix[i] = [i];
158
- }
159
- for (var j = 0; j <= a.length; j++) {
160
- matrix[0][j] = j;
161
- }
162
-
163
- // 填充矩阵
164
- for (var _i2 = 1; _i2 <= b.length; _i2++) {
165
- for (var _j = 1; _j <= a.length; _j++) {
166
- if (b[_i2 - 1] === a[_j - 1]) {
167
- matrix[_i2][_j] = matrix[_i2 - 1][_j - 1];
168
- } else {
169
- matrix[_i2][_j] = Math.min(matrix[_i2 - 1][_j - 1] + 1,
170
- // 替换
171
- matrix[_i2][_j - 1] + 1,
172
- // 插入
173
- matrix[_i2 - 1][_j] + 1 // 删除
174
- );
175
- }
176
- }
177
- }
178
-
179
- return matrix[b.length][a.length];
180
- };
@@ -1,52 +0,0 @@
1
- function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
- function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
3
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
4
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
5
- import fs from 'fs-extra';
6
- export var replaceContentInFile = /*#__PURE__*/function () {
7
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(filePath, targetContent, replacement) {
8
- var data, updatedData;
9
- return _regeneratorRuntime().wrap(function _callee$(_context) {
10
- while (1) switch (_context.prev = _context.next) {
11
- case 0:
12
- _context.prev = 0;
13
- _context.next = 3;
14
- return fs.readFile(filePath, 'utf8');
15
- case 3:
16
- data = _context.sent;
17
- if (!(replacement && data.includes(replacement))) {
18
- _context.next = 7;
19
- break;
20
- }
21
- console.error("\u5DF2\u66FF\u6362\u8FC7\uFF1A".concat(filePath));
22
- return _context.abrupt("return");
23
- case 7:
24
- if (data.includes(targetContent)) {
25
- _context.next = 10;
26
- break;
27
- }
28
- console.error("\u4E0D\u5305\u542B\u76EE\u6807\u5185\u5BB9\uFF1A".concat(targetContent));
29
- throw new Error("\u4E0D\u5305\u542B\u76EE\u6807\u5185\u5BB9\uFF1A".concat(targetContent));
30
- case 10:
31
- updatedData = data.replace(new RegExp(targetContent, 'g'), replacement);
32
- _context.next = 13;
33
- return fs.writeFile(filePath, updatedData, 'utf8');
34
- case 13:
35
- console.log("\u6210\u529F\u66FF\u6362\u6587\u4EF6\u4E2D\u7684\u5185\u5BB9\uFF01");
36
- _context.next = 20;
37
- break;
38
- case 16:
39
- _context.prev = 16;
40
- _context.t0 = _context["catch"](0);
41
- console.error("\u5904\u7406\u6587\u4EF6\u65F6\u53D1\u751F\u9519\u8BEF\uFF1A".concat(_context.t0));
42
- throw _context.t0;
43
- case 20:
44
- case "end":
45
- return _context.stop();
46
- }
47
- }, _callee, null, [[0, 16]]);
48
- }));
49
- return function replaceContentInFile(_x, _x2, _x3) {
50
- return _ref.apply(this, arguments);
51
- };
52
- }();
@@ -1,4 +0,0 @@
1
- export * from "./jsonFile";
2
- export * from "./mail";
3
- export * from "./file";
4
- export { default as DataStore, DataStoreOptions } from 'nedb';