util-helpers 4.13.1 → 4.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (174) hide show
  1. package/README.md +16 -6
  2. package/dist/util-helpers.js +935 -536
  3. package/dist/util-helpers.js.map +1 -1
  4. package/dist/util-helpers.min.js +1 -1
  5. package/dist/util-helpers.min.js.map +1 -1
  6. package/esm/blobToDataURL.js +2 -4
  7. package/esm/bytesToSize.js +13 -5
  8. package/esm/calculateCursorPosition.js +7 -12
  9. package/esm/dataURLToBlob.js +2 -5
  10. package/esm/divide.js +9 -13
  11. package/esm/findTreeNode.js +66 -0
  12. package/esm/findTreeSelect.js +80 -0
  13. package/esm/formatBankCard.js +11 -11
  14. package/esm/formatMobile.js +11 -14
  15. package/esm/formatMoney.js +24 -35
  16. package/esm/index.js +9 -4
  17. package/esm/isBankCard.js +9 -13
  18. package/esm/isBusinessLicense.js +19 -20
  19. package/esm/isChinese.js +6 -6
  20. package/esm/isEmail.js +3 -3
  21. package/esm/isHMCard.js +3 -3
  22. package/esm/isIPv4.js +3 -3
  23. package/esm/isIPv6.js +3 -3
  24. package/esm/isIdCard.js +9 -17
  25. package/esm/isMobile.js +3 -3
  26. package/esm/isPassport.js +3 -3
  27. package/esm/isPassword.js +6 -7
  28. package/esm/isPostcode.js +3 -3
  29. package/esm/isPromiseLike.js +0 -2
  30. package/esm/isQQ.js +3 -3
  31. package/esm/isSocialCreditCode.js +29 -28
  32. package/esm/isSwiftCode.js +1 -2
  33. package/esm/isTWCard.js +6 -7
  34. package/esm/isTelephone.js +3 -3
  35. package/esm/isUrl.js +7 -3
  36. package/esm/isVehicle.js +3 -3
  37. package/esm/isWX.js +3 -3
  38. package/esm/listToTree.js +122 -0
  39. package/esm/minus.js +7 -11
  40. package/esm/normalizeString.js +1 -3
  41. package/esm/numberToChinese.js +43 -52
  42. package/esm/padZero.js +1 -5
  43. package/esm/parseIdCard.js +27 -23
  44. package/esm/plus.js +7 -11
  45. package/esm/randomString.js +2 -8
  46. package/esm/replaceChar.js +11 -16
  47. package/esm/round.js +4 -5
  48. package/esm/safeDate.js +5 -7
  49. package/esm/setDataURLPrefix.js +0 -1
  50. package/esm/strlen.js +1 -5
  51. package/esm/times.js +7 -11
  52. package/esm/transformFieldNames.doc.js +34 -0
  53. package/esm/transformFieldNames.js +98 -0
  54. package/esm/transformFieldNames.type.js +19 -0
  55. package/esm/treeToList.js +88 -0
  56. package/esm/utils/config.js +4 -4
  57. package/esm/utils/constants.js +2 -2
  58. package/esm/utils/convertToString.js +1 -2
  59. package/esm/utils/devWarn.js +1 -3
  60. package/esm/utils/math.util.js +20 -29
  61. package/esm/utils/type/index.js +1 -1
  62. package/esm/utils/type/isArguments.js +1 -2
  63. package/esm/utils/type/isArray.js +1 -2
  64. package/esm/utils/type/isBoolean.js +1 -2
  65. package/esm/utils/type/isDate.js +1 -2
  66. package/esm/utils/type/isError.js +1 -2
  67. package/esm/utils/type/isFunction.js +1 -2
  68. package/esm/utils/type/isMap.js +1 -2
  69. package/esm/utils/type/isNaN.js +1 -2
  70. package/esm/utils/type/isNil.js +1 -2
  71. package/esm/utils/type/isNull.js +0 -1
  72. package/esm/utils/type/isNumber.js +1 -2
  73. package/esm/utils/type/isObject.js +0 -3
  74. package/esm/utils/type/isRegExp.js +1 -2
  75. package/esm/utils/type/isSet.js +1 -2
  76. package/esm/utils/type/isString.js +1 -2
  77. package/esm/utils/type/isSymbol.js +1 -2
  78. package/esm/utils/type/isType.js +1 -2
  79. package/esm/utils/type/isUndefined.js +0 -1
  80. package/esm/utils/type/isWeakMap.js +1 -2
  81. package/esm/utils/type/isWeakSet.js +1 -2
  82. package/esm/validatePassword.js +27 -50
  83. package/esm/waitTime.js +0 -1
  84. package/lib/blobToDataURL.js +2 -5
  85. package/lib/bytesToSize.js +13 -6
  86. package/lib/calculateCursorPosition.js +4 -13
  87. package/lib/dataURLToBlob.js +2 -6
  88. package/lib/divide.js +8 -22
  89. package/lib/findTreeNode.js +76 -0
  90. package/lib/findTreeSelect.js +86 -0
  91. package/lib/formatBankCard.js +10 -13
  92. package/lib/formatMobile.js +10 -16
  93. package/lib/formatMoney.js +25 -47
  94. package/lib/index.js +115 -126
  95. package/lib/isBankCard.js +7 -15
  96. package/lib/isBusinessLicense.js +17 -22
  97. package/lib/isChinese.js +6 -9
  98. package/lib/isEmail.js +1 -5
  99. package/lib/isHMCard.js +1 -5
  100. package/lib/isIPv4.js +1 -5
  101. package/lib/isIPv6.js +1 -5
  102. package/lib/isIdCard.js +7 -19
  103. package/lib/isMobile.js +1 -5
  104. package/lib/isPassport.js +1 -5
  105. package/lib/isPassword.js +5 -9
  106. package/lib/isPostcode.js +1 -5
  107. package/lib/isPromiseLike.js +1 -4
  108. package/lib/isQQ.js +1 -5
  109. package/lib/isSocialCreditCode.js +27 -30
  110. package/lib/isSwiftCode.js +1 -5
  111. package/lib/isTWCard.js +4 -9
  112. package/lib/isTelephone.js +1 -5
  113. package/lib/isUrl.js +5 -5
  114. package/lib/isVehicle.js +1 -5
  115. package/lib/isWX.js +1 -5
  116. package/lib/listToTree.js +131 -0
  117. package/lib/minus.js +6 -20
  118. package/lib/normalizeString.js +0 -6
  119. package/lib/numberToChinese.js +41 -55
  120. package/lib/padZero.js +0 -7
  121. package/lib/parseIdCard.js +30 -29
  122. package/lib/plus.js +6 -20
  123. package/lib/randomString.js +2 -8
  124. package/lib/replaceChar.js +10 -18
  125. package/lib/round.js +3 -9
  126. package/lib/safeDate.js +4 -13
  127. package/lib/setDataURLPrefix.js +0 -2
  128. package/lib/strlen.js +0 -7
  129. package/lib/times.js +6 -18
  130. package/lib/transformFieldNames.doc.js +41 -0
  131. package/lib/transformFieldNames.js +104 -0
  132. package/lib/transformFieldNames.type.js +5 -0
  133. package/lib/treeToList.js +96 -0
  134. package/lib/utils/config.js +6 -6
  135. package/lib/utils/constants.js +2 -2
  136. package/lib/utils/convertToString.js +0 -4
  137. package/lib/utils/devWarn.js +0 -4
  138. package/lib/utils/math.util.js +23 -45
  139. package/lib/utils/type/index.js +20 -39
  140. package/lib/utils/type/isArguments.js +0 -4
  141. package/lib/utils/type/isArray.js +0 -4
  142. package/lib/utils/type/isBoolean.js +0 -4
  143. package/lib/utils/type/isDate.js +0 -4
  144. package/lib/utils/type/isError.js +0 -4
  145. package/lib/utils/type/isFunction.js +0 -4
  146. package/lib/utils/type/isMap.js +0 -4
  147. package/lib/utils/type/isNaN.js +0 -4
  148. package/lib/utils/type/isNil.js +0 -5
  149. package/lib/utils/type/isNull.js +0 -2
  150. package/lib/utils/type/isNumber.js +0 -4
  151. package/lib/utils/type/isObject.js +1 -5
  152. package/lib/utils/type/isRegExp.js +0 -4
  153. package/lib/utils/type/isSet.js +0 -4
  154. package/lib/utils/type/isString.js +0 -4
  155. package/lib/utils/type/isSymbol.js +0 -4
  156. package/lib/utils/type/isType.js +1 -2
  157. package/lib/utils/type/isUndefined.js +0 -2
  158. package/lib/utils/type/isWeakMap.js +0 -4
  159. package/lib/utils/type/isWeakSet.js +0 -4
  160. package/lib/validatePassword.js +27 -53
  161. package/lib/waitTime.js +0 -2
  162. package/package.json +6 -5
  163. package/types/bytesToSize.d.ts +9 -1
  164. package/types/findTreeNode.d.ts +26 -0
  165. package/types/findTreeSelect.d.ts +26 -0
  166. package/types/formatBankCard.d.ts +3 -3
  167. package/types/formatMobile.d.ts +4 -4
  168. package/types/index.d.ts +5 -0
  169. package/types/isIdCard.d.ts +2 -0
  170. package/types/isUrl.d.ts +2 -0
  171. package/types/listToTree.d.ts +41 -0
  172. package/types/transformFieldNames.d.ts +34 -0
  173. package/types/transformFieldNames.type.d.ts +2 -0
  174. package/types/treeToList.d.ts +20 -0
package/lib/plus.js CHANGED
@@ -4,25 +4,15 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports["default"] = void 0;
7
-
8
7
  var _math = require("./utils/math.util");
9
-
10
8
  var _times = _interopRequireDefault(require("./times"));
11
-
12
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
13
-
14
10
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
15
-
16
11
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
17
-
18
12
  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); }
19
-
20
13
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
21
-
22
14
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
23
-
24
15
  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; }
25
-
26
16
  /**
27
17
  * 精确加法,支持多个数相加,加数默认为 0 。
28
18
  *
@@ -42,27 +32,23 @@ function plus() {
42
32
  for (var _len = arguments.length, nums = new Array(_len), _key = 0; _key < _len; _key++) {
43
33
  nums[_key] = arguments[_key];
44
34
  }
45
-
46
35
  var num1 = nums[0],
47
- _nums$ = nums[1],
48
- num2 = _nums$ === void 0 ? 0 : _nums$,
49
- rest = nums.slice(2);
50
-
36
+ _nums$ = nums[1],
37
+ num2 = _nums$ === void 0 ? 0 : _nums$,
38
+ rest = nums.slice(2);
51
39
  if (rest.length > 0) {
52
40
  return plus.apply(void 0, [plus(num1, num2)].concat(_toConsumableArray(rest)));
53
41
  }
54
-
55
42
  num1 = (0, _math.transformEffectiveNumber)(num1);
56
- num2 = (0, _math.transformEffectiveNumber)(num2); // 兼容处理,如果参数包含无效数值时,返回 NaN
57
- // @ts-ignore
43
+ num2 = (0, _math.transformEffectiveNumber)(num2);
58
44
 
45
+ // 兼容处理,如果参数包含无效数值时,返回 NaN
46
+ // @ts-ignore
59
47
  if (isNaN(num1) || isNaN(num2)) {
60
48
  return Number.NaN;
61
49
  }
62
-
63
50
  var baseNum = Math.pow(10, Math.max((0, _math.digitLength)(num1), (0, _math.digitLength)(num2)));
64
51
  return ((0, _times["default"])(num1, baseNum) + (0, _times["default"])(num2, baseNum)) / baseNum;
65
52
  }
66
-
67
53
  var _default = plus;
68
54
  exports["default"] = _default;
@@ -7,6 +7,7 @@ exports["default"] = void 0;
7
7
  var numberChars = '0123456789';
8
8
  var letterChars = 'abcdefghijklmnopqrstuvwxyz';
9
9
  var defaultChars = numberChars + letterChars + letterChars.toUpperCase();
10
+
10
11
  /**
11
12
  * @private
12
13
  * @param {number} [len=0] 长度
@@ -14,19 +15,17 @@ var defaultChars = numberChars + letterChars + letterChars.toUpperCase();
14
15
  * @param {string} [prefix=''] 前缀部分,不计入长度
15
16
  * @returns {string}
16
17
  */
17
-
18
18
  function internalRandomString() {
19
19
  var len = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
20
20
  var optionalChars = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultChars;
21
21
  var prefix = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
22
-
23
22
  while (len-- > 0) {
24
23
  var r = optionalChars[Math.floor(Math.random() * optionalChars.length)];
25
24
  return internalRandomString(len, optionalChars, prefix + r);
26
25
  }
27
-
28
26
  return prefix;
29
27
  }
28
+
30
29
  /**
31
30
  * 生成随机字符串
32
31
  *
@@ -46,20 +45,15 @@ function internalRandomString() {
46
45
  * randomString(8, 'abcefg'); // bcgcfabg
47
46
  *
48
47
  */
49
-
50
-
51
48
  function randomString() {
52
49
  var len = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
53
50
  var optionalChars = arguments.length > 1 ? arguments[1] : undefined;
54
51
  var realLen = typeof len === 'number' ? len : Number(len);
55
-
56
52
  if (isNaN(realLen)) {
57
53
  realLen = 0;
58
54
  }
59
-
60
55
  var realChars = typeof optionalChars === 'string' && optionalChars ? optionalChars : defaultChars;
61
56
  return internalRandomString(len, realChars);
62
57
  }
63
-
64
58
  var _default = randomString;
65
59
  exports["default"] = _default;
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports["default"] = void 0;
7
-
8
7
  var _normalizeString = _interopRequireDefault(require("./normalizeString"));
9
-
10
8
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
11
-
12
9
  /**
13
10
  * 替换字符,应用场景如:脱敏
14
11
  *
@@ -49,32 +46,29 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "d
49
46
  */
50
47
  function replaceChar(str) {
51
48
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
52
-
53
49
  var _options$char = options["char"],
54
- _char = _options$char === void 0 ? '*' : _options$char,
55
- exclude = options.exclude;
56
-
50
+ _char = _options$char === void 0 ? '*' : _options$char,
51
+ exclude = options.exclude;
57
52
  var _options$start = options.start,
58
- start = _options$start === void 0 ? 3 : _options$start,
59
- _options$end = options.end,
60
- end = _options$end === void 0 ? -4 : _options$end,
61
- repeat = options.repeat;
53
+ start = _options$start === void 0 ? 3 : _options$start,
54
+ _options$end = options.end,
55
+ end = _options$end === void 0 ? -4 : _options$end,
56
+ repeat = options.repeat;
62
57
  var realStr = (0, _normalizeString["default"])(str);
63
- var strLen = realStr.length; // 开始位置超过str长度
58
+ var strLen = realStr.length;
64
59
 
60
+ // 开始位置超过str长度
65
61
  if (Math.abs(start) >= strLen) {
66
62
  return realStr;
67
63
  }
68
-
69
64
  start = start >= 0 ? start : strLen + start;
70
- end = end >= 0 ? end : strLen + end; // 开始位置大于结束位置
65
+ end = end >= 0 ? end : strLen + end;
71
66
 
67
+ // 开始位置大于结束位置
72
68
  if (start >= end) {
73
69
  return realStr;
74
70
  }
75
-
76
71
  var middleStr = realStr.substring(start, end);
77
-
78
72
  if (exclude) {
79
73
  var reg = new RegExp("[^".concat(exclude, "]"), 'g');
80
74
  middleStr = middleStr.replace(reg, _char);
@@ -82,9 +76,7 @@ function replaceChar(str) {
82
76
  repeat = typeof repeat === 'number' && repeat >= 0 ? repeat : middleStr.length;
83
77
  middleStr = _char.repeat(repeat);
84
78
  }
85
-
86
79
  return realStr.substring(0, start) + middleStr + realStr.substring(end);
87
80
  }
88
-
89
81
  var _default = replaceChar;
90
82
  exports["default"] = _default;
package/lib/round.js CHANGED
@@ -4,15 +4,10 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports["default"] = void 0;
7
-
8
7
  var _divide = _interopRequireDefault(require("./divide"));
9
-
10
8
  var _times = _interopRequireDefault(require("./times"));
11
-
12
9
  var _math = require("./utils/math.util");
13
-
14
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
15
-
16
11
  /**
17
12
  * 四舍五入,支持设置精度
18
13
  *
@@ -31,16 +26,15 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "d
31
26
  */
32
27
  function round(num) {
33
28
  var precision = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
34
- num = (0, _math.transformEffectiveNumber)(num); // 兼容处理,如果参数包含无效数值时,返回 NaN
35
- // @ts-ignore
29
+ num = (0, _math.transformEffectiveNumber)(num);
36
30
 
31
+ // 兼容处理,如果参数包含无效数值时,返回 NaN
32
+ // @ts-ignore
37
33
  if (isNaN(num)) {
38
34
  return Number.NaN;
39
35
  }
40
-
41
36
  var base = Math.pow(10, precision);
42
37
  return (0, _divide["default"])(Math.round((0, _times["default"])(num, base)), base);
43
38
  }
44
-
45
39
  var _default = round;
46
40
  exports["default"] = _default;
package/lib/safeDate.js CHANGED
@@ -4,17 +4,11 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports["default"] = void 0;
7
-
8
7
  var _isNil = _interopRequireDefault(require("./utils/type/isNil"));
9
-
10
8
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
11
-
12
- function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct; } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
13
-
9
+ function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct.bind(); } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
14
10
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
15
-
16
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
17
-
11
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
18
12
  // TODO: 函数重载,类型参照 Date
19
13
 
20
14
  /**
@@ -41,19 +35,16 @@ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || func
41
35
  */
42
36
  function safeDate(value) {
43
37
  var safeValue = typeof value === 'string' ? value.replace(/[\\.-]/g, '/') : value;
44
-
45
38
  for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
46
39
  args[_key - 1] = arguments[_key];
47
40
  }
48
-
49
41
  if (args && args.length > 0) {
50
42
  // @ts-ignore
51
43
  return _construct(Date, [safeValue].concat(args));
52
- } // @ts-ignore
53
-
44
+ }
54
45
 
46
+ // @ts-ignore
55
47
  return (0, _isNil["default"])(safeValue) ? new Date() : new Date(safeValue);
56
48
  }
57
-
58
49
  var _default = safeDate;
59
50
  exports["default"] = _default;
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports["default"] = void 0;
7
-
8
7
  /**
9
8
  * 设置 DataURL 前缀、MIME 类型、base64 标识。<br/>
10
9
  * 如果你需要获取DataURL 的 MIME 类型和数据本身,推荐使用 <a href="https://www.npmjs.com/package/data-urls">data-urls</a>。
@@ -34,6 +33,5 @@ function setDataURLPrefix(data) {
34
33
  var base64 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
35
34
  return "data:".concat(mimetype).concat(base64 ? ';base64' : '', ",").concat(data);
36
35
  }
37
-
38
36
  var _default = setDataURLPrefix;
39
37
  exports["default"] = _default;
package/lib/strlen.js CHANGED
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports["default"] = void 0;
7
-
8
7
  var _normalizeString = _interopRequireDefault(require("./normalizeString"));
9
-
10
8
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
11
-
12
9
  /**
13
10
  * 获取字符长度。中文汉字占2个字符,英文占1个字符,特殊如emoji占4个字符。
14
11
  *
@@ -30,19 +27,15 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "d
30
27
  function strlen(str) {
31
28
  var realStr = (0, _normalizeString["default"])(str);
32
29
  var len = 0;
33
-
34
30
  for (var i = 0; i < realStr.length; i++) {
35
31
  var c = realStr.charCodeAt(i);
36
-
37
32
  if (c >= 0x0001 && c <= 0x007e || 0xff60 <= c && c <= 0xff9f) {
38
33
  len++;
39
34
  } else {
40
35
  len += 2;
41
36
  }
42
37
  }
43
-
44
38
  return len;
45
39
  }
46
-
47
40
  var _default = strlen;
48
41
  exports["default"] = _default;
package/lib/times.js CHANGED
@@ -4,21 +4,13 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports["default"] = void 0;
7
-
8
7
  var _math = require("./utils/math.util");
9
-
10
8
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
11
-
12
9
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
13
-
14
10
  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); }
15
-
16
11
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
17
-
18
12
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
19
-
20
13
  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; }
21
-
22
14
  /**
23
15
  * 精确乘法,支持多个数相乘,乘数默认为 1 。
24
16
  *
@@ -38,24 +30,21 @@ function times() {
38
30
  for (var _len = arguments.length, nums = new Array(_len), _key = 0; _key < _len; _key++) {
39
31
  nums[_key] = arguments[_key];
40
32
  }
41
-
42
33
  var num1 = nums[0],
43
- _nums$ = nums[1],
44
- num2 = _nums$ === void 0 ? 1 : _nums$,
45
- rest = nums.slice(2);
46
-
34
+ _nums$ = nums[1],
35
+ num2 = _nums$ === void 0 ? 1 : _nums$,
36
+ rest = nums.slice(2);
47
37
  if (rest.length > 0) {
48
38
  return times.apply(void 0, [times(num1, num2)].concat(_toConsumableArray(rest)));
49
39
  }
50
-
51
40
  num1 = (0, _math.transformEffectiveNumber)(num1);
52
- num2 = (0, _math.transformEffectiveNumber)(num2); // 兼容处理,如果参数包含无效数值时,返回 NaN
53
- // @ts-ignore
41
+ num2 = (0, _math.transformEffectiveNumber)(num2);
54
42
 
43
+ // 兼容处理,如果参数包含无效数值时,返回 NaN
44
+ // @ts-ignore
55
45
  if (isNaN(num1) || isNaN(num2)) {
56
46
  return Number.NaN;
57
47
  }
58
-
59
48
  var num1Changed = (0, _math.float2Fixed)(num1);
60
49
  var num2Changed = (0, _math.float2Fixed)(num2);
61
50
  var baseNum = (0, _math.digitLength)(num1) + (0, _math.digitLength)(num2);
@@ -63,6 +52,5 @@ function times() {
63
52
  (0, _math.checkBoundary)(leftValue);
64
53
  return leftValue / Math.pow(10, baseNum);
65
54
  }
66
-
67
55
  var _default = times;
68
56
  exports["default"] = _default;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = void 0;
7
+ /* eslint-disable no-unused-vars */
8
+ // 该文件用于 jsdoc 生成文件。因为一些 typescript 语法, jsdoc 不支持,导致生成文档报错。
9
+
10
+ /**
11
+ * 转换字段名,返回一个转换字段后的值,不改变原值。
12
+ *
13
+ * @static
14
+ * @alias module:Processor.transformFieldNames
15
+ * @since 4.14.0
16
+ * @param {object[]} data 对象数组。如果是树结构数据,需要指定第三个参数 childrenFieldName
17
+ * @param {object} fieldNames 字段名映射
18
+ * @param {string} [childrenFieldName] 子级数据字段名
19
+ * @returns {object[]}
20
+ * @example
21
+ *
22
+ * const options = [{code: '1', name: 'one'},{code:'2', name:'two'}];
23
+ * const newOptions = transformFieldNames(options, {label: 'name', value: 'code'});
24
+ * // [{value: '1', label: 'one'},{value:'2', label:'two'}]
25
+ *
26
+ * // 嵌套数据,指定子级字段名 children
27
+ * const options2 = [{code: '1', name: 'one'},{code:'2', name:'two', children: [{code:'2-1', name:'two-one', children: [{code: '2-1-1', name:'two-one-one'}]}]}];
28
+ * const newOptions2 = transformFieldNames(options2, {label: 'name', value: 'code'}, 'children');
29
+ * // [{value: '1', label: 'one'},{value:'2', label:'two', children: [{value: '2-1', label:'two-one', children: [{value: '2-1-1', label:'two-one-one'}]}]}]
30
+ *
31
+ * const options3 = [{code: '1', name: 'one'},{code:'2', name:'two', childs: [{code:'2-1', name:'two-one'}]}];
32
+ * const newOptions3 = transformFieldNames(options3, {label: 'name', value: 'code'}, 'childs');
33
+ * // [{value: '1', label: 'one'},{value:'2', label:'two', childs: [{value: '2-1', label:'two-one'}]}]
34
+ *
35
+ * // 嵌套数据,并替换子集字段名
36
+ * const newOptions4 = transformFieldNames(options3, {label: 'name', value: 'code', children: 'childs'}, 'childs');
37
+ * // [{value: '1', label: 'one'},{value:'2', label:'two', children: [{value: '2-1', label:'two-one'}]}]
38
+ */
39
+ function transformFieldNames(data, fieldNames, childrenFieldName) {}
40
+ var _default = transformFieldNames;
41
+ exports["default"] = _default;
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = void 0;
7
+ var _type = require("./utils/type");
8
+ 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); }
9
+ 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; }
10
+ 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; }
11
+ 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; }
12
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
13
+ 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); }
14
+ /**
15
+ * 转换字段名,返回一个转换字段后的值,不改变原值。
16
+ *
17
+ * @static
18
+ * @alias module:Processor.transformFieldNames
19
+ * @since 4.14.0
20
+ * @template {*} D
21
+ * @template {Record<string, keyof D>} F
22
+ * @template {string} C
23
+ * @param {D[]} data 对象数组。如果是树结构数据,需要指定第三个参数 childrenFieldName
24
+ * @param {F} fieldNames 字段名映射
25
+ * @param {C} [childrenFieldName] 子级数据字段名
26
+ * @returns {import('./transformFieldNames.type.js').TransformFieldNames<D, F, C>}
27
+ * @example
28
+ *
29
+ * const options = [{code: '1', name: 'one'},{code:'2', name:'two'}];
30
+ * const newOptions = transformFieldNames(options, {label: 'name', value: 'code'});
31
+ * // [{value: '1', label: 'one'},{value:'2', label:'two'}]
32
+ *
33
+ * // 嵌套数据,指定子级字段名 children
34
+ * const options2 = [{code: '1', name: 'one'},{code:'2', name:'two', children: [{code:'2-1', name:'two-one', children: [{code: '2-1-1', name:'two-one-one'}]}]}];
35
+ * const newOptions2 = transformFieldNames(options2, {label: 'name', value: 'code'}, 'children');
36
+ * // [{value: '1', label: 'one'},{value:'2', label:'two', children: [{value: '2-1', label:'two-one', children: [{value: '2-1-1', label:'two-one-one'}]}]}]
37
+ *
38
+ * const options3 = [{code: '1', name: 'one'},{code:'2', name:'two', childs: [{code:'2-1', name:'two-one'}]}];
39
+ * const newOptions3 = transformFieldNames(options3, {label: 'name', value: 'code'}, 'childs');
40
+ * // [{value: '1', label: 'one'},{value:'2', label:'two', childs: [{value: '2-1', label:'two-one'}]}]
41
+ *
42
+ * // 嵌套数据,并替换子集字段名
43
+ * const newOptions4 = transformFieldNames(options3, {label: 'name', value: 'code', children: 'childs'}, 'childs');
44
+ * // [{value: '1', label: 'one'},{value:'2', label:'two', children: [{value: '2-1', label:'two-one'}]}]
45
+ */
46
+ function transformFieldNames(data, fieldNames, childrenFieldName) {
47
+ if (!Array.isArray(data)) {
48
+ return data;
49
+ }
50
+ if (data.length <= 0) {
51
+ // @ts-ignore
52
+ return [];
53
+ }
54
+
55
+ /**
56
+ * 递归处理字段名
57
+ *
58
+ * @param {Array.<object>} arr 列表数据
59
+ * @returns {*}
60
+ */
61
+ function recusion() {
62
+ var arr = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
63
+ return arr.map(function (item) {
64
+ if (!(0, _type.isObject)(item)) {
65
+ return item;
66
+ }
67
+ var newItem = _objectSpread({}, item);
68
+ /** @type {Array.<string>} */
69
+ var delKeys = [];
70
+
71
+ // 树形数据子节点
72
+ // @ts-ignore
73
+ if (childrenFieldName && Array.isArray(newItem[childrenFieldName]) && newItem[childrenFieldName].length > 0) {
74
+ // @ts-ignore
75
+ newItem[childrenFieldName] = recusion(newItem[childrenFieldName].slice());
76
+ }
77
+
78
+ // 替换字段名
79
+ Object.keys(fieldNames).forEach(function (newKey) {
80
+ var oldKey = fieldNames[newKey];
81
+ if (oldKey in newItem) {
82
+ // @ts-ignore
83
+ newItem[newKey] = newItem[oldKey];
84
+ // @ts-ignore
85
+ delKeys.push(oldKey);
86
+ }
87
+ });
88
+
89
+ // 删除旧字段
90
+ if (delKeys.length > 0) {
91
+ delKeys.forEach(function (delKey) {
92
+ // @ts-ignore
93
+ delete newItem[delKey];
94
+ });
95
+ }
96
+ return newItem;
97
+ });
98
+ }
99
+
100
+ // @ts-ignore
101
+ return recusion(data.slice());
102
+ }
103
+ var _default = transformFieldNames;
104
+ exports["default"] = _default;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = void 0;
7
+ var _type = require("./utils/type");
8
+ 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); }
9
+ 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; }
10
+ 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; }
11
+ 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; }
12
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
13
+ 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); }
14
+ /**
15
+ * 树结构转列表数据
16
+ *
17
+ * @static
18
+ * @alias module:Processor.treeToList
19
+ * @since 4.14.0
20
+ * @template {Record<string,any>} T
21
+ * @template {keyof T} K
22
+ * @template {Omit<T, K>} R
23
+ * @param {T[]} tree 列表数据
24
+ * @param {K} childrenField 子级字段名称
25
+ * @returns {R[]} 列表数据
26
+ * @example
27
+ * const menus = [{ "id": "1", "name": "首页", "code": "trade", "pid": null }, { "id": "2", "name": "交易管理", "code": "trade", "pid": null, "children": [{ "id": "3", "name": "交易查询", "code": "trade-1", "pid": "2", "children": [{ "id": "4", "name": "交易查询-查询操作", "code": "trade-1-1", "pid": "3" }] }] }, { "id": "5", "name": "权限管理", "code": "authorization", "pid": null, "children": [{ "id": "6", "name": "角色管理", "code": "authorization-1", "pid": "5" }, { "id": "7", "name": "用户管理", "code": "authorization-2", "pid": "5" }] }];
28
+ *
29
+ * treeToList(menus, 'children'));
30
+ * // [{"id":"1","name":"首页","code":"trade","pid":null},{"id":"2","name":"交易管理","code":"trade","pid":null},{"id":"3","name":"交易查询","code":"trade-1","pid":"2"},{"id":"4","name":"交易查询-查询操作","code":"trade-1-1","pid":"3"},{"id":"5","name":"权限管理","code":"authorization","pid":null},{"id":"6","name":"角色管理","code":"authorization-1","pid":"5"},{"id":"7","name":"用户管理","code":"authorization-2","pid":"5"}]
31
+ */
32
+ function treeToList(tree, childrenField) {
33
+ /** @type {R[]} */
34
+ var list = [];
35
+
36
+ /**
37
+ * 递归遍历
38
+ * @param {T[]} arr 列表数据
39
+ */
40
+ function recusion(arr) {
41
+ arr.forEach(function (item) {
42
+ if ((0, _type.isObject)(item)) {
43
+ var newItem = _objectSpread({}, item);
44
+ // @ts-ignore
45
+ list.push(newItem);
46
+ if (newItem !== null && newItem !== void 0 && newItem[childrenField]) {
47
+ if (Array.isArray(newItem[childrenField]) && newItem[childrenField].length > 0) {
48
+ recusion(newItem[childrenField]);
49
+ }
50
+ delete newItem[childrenField];
51
+ }
52
+ } else {
53
+ // @ts-ignore
54
+ list.push(item);
55
+ }
56
+ });
57
+ }
58
+ recusion(tree);
59
+ return list;
60
+ }
61
+
62
+ // function treeToList(tree, childrenField) {
63
+ // /** @type {R[]} */
64
+ // const list = [];
65
+
66
+ // // 深度优先
67
+ // /** @type {T[]} */
68
+ // const stack = [];
69
+ // for (const item of tree) {
70
+ // if (isObject(item)) {
71
+ // stack.push(item);
72
+
73
+ // while (stack.length) {
74
+ // /** @type {T} */
75
+ // // @ts-ignore
76
+ // const temp = stack.shift();
77
+
78
+ // // @ts-ignore
79
+ // list.push(temp);
80
+
81
+ // if (temp[childrenField]) {
82
+ // if (Array.isArray(temp[childrenField]) && temp[childrenField].length > 0) {
83
+ // stack.push(...temp[childrenField]);
84
+ // }
85
+ // delete temp[childrenField];
86
+ // }
87
+ // }
88
+ // } else {
89
+ // // @ts-ignore
90
+ // list.push(item);
91
+ // }
92
+ // }
93
+ // return list;
94
+ // }
95
+ var _default = treeToList;
96
+ exports["default"] = _default;
@@ -3,12 +3,14 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.config = void 0;
6
7
  exports.setDisableWarning = setDisableWarning;
7
- exports.version = exports.config = void 0;
8
+ exports.version = void 0;
8
9
  var config = {
9
10
  // 禁用warning提示
10
11
  disableWarning: true
11
12
  };
13
+
12
14
  /**
13
15
  * 设置禁止warning提示
14
16
  * @static
@@ -16,13 +18,11 @@ var config = {
16
18
  * @since 3.6.1
17
19
  * @param {boolean} bool 是否禁止warning提示
18
20
  */
19
-
20
21
  exports.config = config;
21
-
22
22
  function setDisableWarning(bool) {
23
23
  config.disableWarning = !!bool;
24
- } // eslint-disable-next-line no-undef
25
-
24
+ }
26
25
 
27
- var version = "4.13.1";
26
+ // eslint-disable-next-line no-undef
27
+ var version = "4.14.0";
28
28
  exports.version = version;
@@ -5,8 +5,8 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.MIN_SAFE_INTEGER = exports.MAX_SAFE_INTEGER = void 0;
7
7
  // 最大安全数字
8
- var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || 9007199254740991; // 最小安全数字
9
-
8
+ var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || 9007199254740991;
9
+ // 最小安全数字
10
10
  exports.MAX_SAFE_INTEGER = MAX_SAFE_INTEGER;
11
11
  var MIN_SAFE_INTEGER = Number.MIN_SAFE_INTEGER || -9007199254740991;
12
12
  exports.MIN_SAFE_INTEGER = MIN_SAFE_INTEGER;