util-helpers 4.16.1 → 4.17.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 (260) hide show
  1. package/README.md +3 -1
  2. package/dist/util-helpers.js +1542 -4040
  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/ajax.js +50 -146
  7. package/esm/blobToDataURL.js +4 -34
  8. package/esm/bytesToSize.js +12 -37
  9. package/esm/calculateCursorPosition.js +30 -52
  10. package/esm/dataURLToBlob.js +14 -28
  11. package/esm/divide.js +24 -48
  12. package/esm/download.js +83 -164
  13. package/esm/fileReader.js +18 -64
  14. package/esm/filterTree.js +25 -57
  15. package/esm/findTreeNode.js +39 -69
  16. package/esm/findTreeNodes.js +35 -68
  17. package/esm/findTreeSelect.js +38 -76
  18. package/esm/formatBankCard.js +13 -43
  19. package/esm/formatMobile.js +17 -43
  20. package/esm/formatMoney.js +59 -139
  21. package/esm/index.js +55 -130
  22. package/esm/isBankCard.js +22 -57
  23. package/esm/isBusinessLicense.js +32 -78
  24. package/esm/isChinese.js +23 -66
  25. package/esm/isEmail.js +6 -21
  26. package/esm/isHMCard.js +5 -28
  27. package/esm/isIPv4.js +5 -22
  28. package/esm/isIPv6.js +5 -36
  29. package/esm/isIdCard.js +27 -66
  30. package/esm/isMobile.js +5 -20
  31. package/esm/isPassport.js +5 -22
  32. package/esm/isPassword.js +7 -48
  33. package/esm/isPostcode.js +5 -20
  34. package/esm/isPromiseLike.js +3 -18
  35. package/esm/isQQ.js +5 -20
  36. package/esm/isSocialCreditCode.js +28 -83
  37. package/esm/isSwiftCode.js +6 -25
  38. package/esm/isTWCard.js +11 -37
  39. package/esm/isTelephone.js +6 -27
  40. package/esm/isUrl.js +5 -44
  41. package/esm/isVehicle.js +5 -28
  42. package/esm/isWX.js +5 -20
  43. package/esm/listToTree.js +51 -122
  44. package/esm/minus.js +21 -39
  45. package/esm/normalizeString.js +8 -29
  46. package/esm/numberToChinese.js +96 -215
  47. package/esm/padZero.js +14 -36
  48. package/esm/parseIdCard.js +64 -132
  49. package/esm/plus.js +21 -39
  50. package/esm/randomString.js +13 -45
  51. package/esm/replaceChar.js +27 -77
  52. package/esm/round.js +14 -31
  53. package/esm/safeDate.js +12 -55
  54. package/esm/setDataURLPrefix.js +6 -29
  55. package/esm/strlen.js +14 -30
  56. package/esm/times.js +24 -42
  57. package/esm/transformFieldNames.js +37 -95
  58. package/esm/treeToList.js +25 -86
  59. package/esm/utils/config.js +4 -14
  60. package/esm/utils/constants.js +4 -4
  61. package/esm/utils/convertToString.js +4 -9
  62. package/esm/utils/devWarn.js +11 -11
  63. package/esm/utils/math.util.js +95 -181
  64. package/esm/utils/type/isBlob.js +4 -24
  65. package/esm/utils/type/isNaN.js +4 -19
  66. package/esm/utils/type/isNil.js +5 -13
  67. package/esm/utils/type/isNull.js +3 -18
  68. package/esm/utils/type/isNumber.js +4 -28
  69. package/esm/utils/type/isObject.js +4 -23
  70. package/esm/utils/type/isString.js +4 -19
  71. package/esm/utils/type/isSymbol.js +4 -19
  72. package/esm/utils/type/isType.js +3 -12
  73. package/esm/utils/type/isUndefined.js +3 -21
  74. package/esm/validatePassword.js +86 -237
  75. package/esm/waitTime.js +7 -26
  76. package/lib/ajax.js +51 -152
  77. package/lib/blobToDataURL.js +5 -40
  78. package/lib/bytesToSize.js +13 -43
  79. package/lib/calculateCursorPosition.js +31 -58
  80. package/lib/dataURLToBlob.js +15 -34
  81. package/lib/divide.js +26 -60
  82. package/lib/download.js +85 -169
  83. package/lib/fileReader.js +19 -70
  84. package/lib/filterTree.js +27 -66
  85. package/lib/findTreeNode.js +40 -77
  86. package/lib/findTreeNodes.js +36 -76
  87. package/lib/findTreeSelect.js +40 -82
  88. package/lib/formatBankCard.js +15 -50
  89. package/lib/formatMobile.js +19 -50
  90. package/lib/formatMoney.js +60 -150
  91. package/lib/index.js +117 -395
  92. package/lib/isBankCard.js +24 -64
  93. package/lib/isBusinessLicense.js +34 -85
  94. package/lib/isChinese.js +24 -73
  95. package/lib/isEmail.js +7 -27
  96. package/lib/isHMCard.js +7 -35
  97. package/lib/isIPv4.js +7 -29
  98. package/lib/isIPv6.js +7 -43
  99. package/lib/isIdCard.js +29 -73
  100. package/lib/isMobile.js +7 -27
  101. package/lib/isPassport.js +7 -29
  102. package/lib/isPassword.js +9 -55
  103. package/lib/isPostcode.js +7 -27
  104. package/lib/isPromiseLike.js +4 -24
  105. package/lib/isQQ.js +7 -27
  106. package/lib/isSocialCreditCode.js +30 -90
  107. package/lib/isSwiftCode.js +7 -32
  108. package/lib/isTWCard.js +13 -44
  109. package/lib/isTelephone.js +7 -33
  110. package/lib/isUrl.js +6 -50
  111. package/lib/isVehicle.js +7 -35
  112. package/lib/isWX.js +7 -27
  113. package/lib/listToTree.js +53 -131
  114. package/lib/minus.js +23 -51
  115. package/lib/normalizeString.js +10 -36
  116. package/lib/numberToChinese.js +98 -222
  117. package/lib/padZero.js +16 -43
  118. package/lib/parseIdCard.js +65 -138
  119. package/lib/plus.js +23 -51
  120. package/lib/randomString.js +14 -51
  121. package/lib/replaceChar.js +28 -83
  122. package/lib/round.js +15 -37
  123. package/lib/safeDate.js +13 -63
  124. package/lib/setDataURLPrefix.js +7 -35
  125. package/lib/strlen.js +16 -37
  126. package/lib/times.js +26 -53
  127. package/lib/transformFieldNames.js +38 -101
  128. package/lib/treeToList.js +27 -94
  129. package/lib/utils/config.js +6 -23
  130. package/lib/utils/constants.js +3 -11
  131. package/lib/utils/convertToString.js +6 -16
  132. package/lib/utils/devWarn.js +13 -17
  133. package/lib/utils/math.util.js +95 -185
  134. package/lib/utils/type/isBlob.js +6 -31
  135. package/lib/utils/type/isNaN.js +6 -26
  136. package/lib/utils/type/isNil.js +7 -20
  137. package/lib/utils/type/isNull.js +4 -24
  138. package/lib/utils/type/isNumber.js +6 -35
  139. package/lib/utils/type/isObject.js +5 -29
  140. package/lib/utils/type/isString.js +6 -26
  141. package/lib/utils/type/isSymbol.js +6 -26
  142. package/lib/utils/type/isType.js +4 -18
  143. package/lib/utils/type/isUndefined.js +4 -27
  144. package/lib/validatePassword.js +87 -244
  145. package/lib/waitTime.js +8 -32
  146. package/package.json +30 -34
  147. package/types/ajax.d.ts +38 -95
  148. package/types/blobToDataURL.d.ts +2 -2
  149. package/types/bytesToSize.d.ts +7 -6
  150. package/types/calculateCursorPosition.d.ts +10 -9
  151. package/types/dataURLToBlob.d.ts +5 -5
  152. package/types/divide.d.ts +2 -2
  153. package/types/download.d.ts +22 -38
  154. package/types/fileReader.d.ts +35 -2
  155. package/types/filterTree.d.ts +6 -7
  156. package/types/findTreeNode.d.ts +5 -7
  157. package/types/findTreeNodes.d.ts +5 -7
  158. package/types/findTreeSelect.d.ts +5 -7
  159. package/types/formatBankCard.d.ts +8 -5
  160. package/types/formatMobile.d.ts +7 -4
  161. package/types/formatMoney.d.ts +8 -7
  162. package/types/index.d.ts +125 -55
  163. package/types/isBankCard.d.ts +9 -8
  164. package/types/isBusinessLicense.d.ts +8 -5
  165. package/types/isChinese.d.ts +9 -8
  166. package/types/isEmail.d.ts +1 -1
  167. package/types/isHMCard.d.ts +2 -2
  168. package/types/isIPv4.d.ts +1 -1
  169. package/types/isIPv6.d.ts +1 -1
  170. package/types/isIdCard.d.ts +8 -7
  171. package/types/isMobile.d.ts +1 -1
  172. package/types/isPassport.d.ts +2 -2
  173. package/types/isPassword.d.ts +4 -7
  174. package/types/isPostcode.d.ts +1 -1
  175. package/types/isPromiseLike.d.ts +1 -1
  176. package/types/isQQ.d.ts +1 -1
  177. package/types/isSocialCreditCode.d.ts +8 -5
  178. package/types/isSwiftCode.d.ts +2 -2
  179. package/types/isTWCard.d.ts +6 -5
  180. package/types/isTelephone.d.ts +1 -1
  181. package/types/isUrl.d.ts +2 -2
  182. package/types/isVehicle.d.ts +2 -2
  183. package/types/isWX.d.ts +1 -1
  184. package/types/listToTree.d.ts +12 -12
  185. package/types/minus.d.ts +3 -2
  186. package/types/normalizeString.d.ts +2 -2
  187. package/types/numberToChinese.d.ts +13 -12
  188. package/types/padZero.d.ts +2 -2
  189. package/types/parseIdCard.d.ts +17 -56
  190. package/types/plus.d.ts +3 -2
  191. package/types/randomString.d.ts +2 -2
  192. package/types/replaceChar.d.ts +15 -11
  193. package/types/round.d.ts +2 -2
  194. package/types/safeDate.d.ts +24 -2
  195. package/types/setDataURLPrefix.d.ts +5 -5
  196. package/types/strlen.d.ts +1 -1
  197. package/types/times.d.ts +3 -2
  198. package/types/transformFieldNames.d.ts +12 -10
  199. package/types/treeToList.d.ts +1 -1
  200. package/types/utils/config.d.ts +6 -5
  201. package/types/utils/constants.d.ts +2 -2
  202. package/types/utils/convertToString.d.ts +1 -1
  203. package/types/utils/devWarn.d.ts +1 -1
  204. package/types/utils/math.util.d.ts +15 -9
  205. package/types/utils/type/index.d.ts +7 -0
  206. package/types/utils/type/isArguments.d.ts +1 -1
  207. package/types/utils/type/isArray.d.ts +1 -1
  208. package/types/utils/type/isArrayBuffer.d.ts +1 -1
  209. package/types/utils/type/isBlob.d.ts +1 -1
  210. package/types/utils/type/isBoolean.d.ts +1 -1
  211. package/types/utils/type/isDate.d.ts +1 -1
  212. package/types/utils/type/isError.d.ts +1 -1
  213. package/types/utils/type/isFunction.d.ts +1 -1
  214. package/types/utils/type/isMap.d.ts +1 -1
  215. package/types/utils/type/isNaN.d.ts +1 -1
  216. package/types/utils/type/isNil.d.ts +1 -1
  217. package/types/utils/type/isNull.d.ts +1 -1
  218. package/types/utils/type/isNumber.d.ts +1 -1
  219. package/types/utils/type/isObject.d.ts +1 -1
  220. package/types/utils/type/isRegExp.d.ts +1 -1
  221. package/types/utils/type/isSet.d.ts +1 -1
  222. package/types/utils/type/isString.d.ts +1 -1
  223. package/types/utils/type/isSymbol.d.ts +1 -1
  224. package/types/utils/type/isType.d.ts +1 -1
  225. package/types/utils/type/isUndefined.d.ts +1 -1
  226. package/types/utils/type/isWeakMap.d.ts +1 -1
  227. package/types/utils/type/isWeakSet.d.ts +1 -1
  228. package/types/validatePassword.d.ts +17 -48
  229. package/types/waitTime.d.ts +2 -2
  230. package/esm/interface.doc.js +0 -125
  231. package/esm/interface.type.js +0 -17
  232. package/esm/utils/type/index.js +0 -29
  233. package/esm/utils/type/isArguments.js +0 -22
  234. package/esm/utils/type/isArray.js +0 -22
  235. package/esm/utils/type/isArrayBuffer.js +0 -25
  236. package/esm/utils/type/isBoolean.js +0 -22
  237. package/esm/utils/type/isDate.js +0 -22
  238. package/esm/utils/type/isError.js +0 -22
  239. package/esm/utils/type/isFunction.js +0 -22
  240. package/esm/utils/type/isMap.js +0 -22
  241. package/esm/utils/type/isRegExp.js +0 -22
  242. package/esm/utils/type/isSet.js +0 -22
  243. package/esm/utils/type/isWeakMap.js +0 -22
  244. package/esm/utils/type/isWeakSet.js +0 -22
  245. package/lib/interface.doc.js +0 -127
  246. package/lib/interface.type.js +0 -5
  247. package/lib/utils/type/index.js +0 -146
  248. package/lib/utils/type/isArguments.js +0 -29
  249. package/lib/utils/type/isArray.js +0 -29
  250. package/lib/utils/type/isArrayBuffer.js +0 -32
  251. package/lib/utils/type/isBoolean.js +0 -29
  252. package/lib/utils/type/isDate.js +0 -29
  253. package/lib/utils/type/isError.js +0 -29
  254. package/lib/utils/type/isFunction.js +0 -29
  255. package/lib/utils/type/isMap.js +0 -29
  256. package/lib/utils/type/isRegExp.js +0 -29
  257. package/lib/utils/type/isSet.js +0 -29
  258. package/lib/utils/type/isWeakMap.js +0 -29
  259. package/lib/utils/type/isWeakSet.js +0 -29
  260. package/types/interface.type.d.ts +0 -2
@@ -1,30 +1,7 @@
1
- /**
2
- * 设置 DataURL 前缀、MIME 类型、base64 标识。<br/>
3
- * 如果你需要获取DataURL MIME 类型和数据本身,推荐使用 <a href="https://www.npmjs.com/package/data-urls">data-urls</a>。
4
- *
5
- * @static
6
- * @alias module:Processor.setDataURLPrefix
7
- * @since 4.1.0
8
- * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Basics_of_HTTP/Data_URIs|Data URLs}
9
- * @see {@link https://mimesniff.spec.whatwg.org/#understanding-mime-types|MIME types}
10
- * @param {string} data 数据本身
11
- * @param {string} [mimetype="image/png"] MIME 类型
12
- * @param {boolean} [base64=true] 添加 base64 标识
13
- * @returns {string} DataURL 格式的字符串
14
- * @example
15
- *
16
- * const data = 'PGEgaWQ9ImEiPjxiIGlkPSJiIj5oZXkhPC9iPjwvYT4=';
17
- * setDataURLPrefix(data); // data:image/png;base64,PGEgaWQ9ImEiPjxiIGlkPSJiIj5oZXkhPC9iPjwvYT4=
18
- * setDataURLPrefix(data, 'image/png', false); // data:image/png,PGEgaWQ9ImEiPjxiIGlkPSJiIj5oZXkhPC9iPjwvYT4=
19
- * setDataURLPrefix(data, 'image/jpg'); // data:image/jpg;base64,PGEgaWQ9ImEiPjxiIGlkPSJiIj5oZXkhPC9iPjwvYT4=
20
- * setDataURLPrefix(data, 'text/html'); // data:text/html;base64,PGEgaWQ9ImEiPjxiIGlkPSJiIj5oZXkhPC9iPjwvYT4=
21
- * setDataURLPrefix(data, ''); // data:;base64,PGEgaWQ9ImEiPjxiIGlkPSJiIj5oZXkhPC9iPjwvYT4=
22
- * setDataURLPrefix(data, '', false); // data:,PGEgaWQ9ImEiPjxiIGlkPSJiIj5oZXkhPC9iPjwvYT4=
23
- *
24
- */
25
- function setDataURLPrefix(data) {
26
- var mimetype = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'image/png';
27
- var base64 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
28
- return "data:".concat(mimetype).concat(base64 ? ';base64' : '', ",").concat(data);
1
+ function setDataURLPrefix(data, mimeType, base64) {
2
+ if (mimeType === void 0) { mimeType = 'image/png'; }
3
+ if (base64 === void 0) { base64 = true; }
4
+ return "data:".concat(mimeType).concat(base64 ? ';base64' : '', ",").concat(data);
29
5
  }
30
- export default setDataURLPrefix;
6
+
7
+ export { setDataURLPrefix as default };
package/esm/strlen.js CHANGED
@@ -1,34 +1,18 @@
1
- import normalizeString from './normalizeString';
1
+ import normalizeString from './normalizeString.js';
2
2
 
3
- /**
4
- * 获取字符长度。中文汉字占2个字符,英文占1个字符,特殊如emoji占4个字符。
5
- *
6
- * @static
7
- * @alias module:Other.strlen
8
- * @since 4.10.0
9
- * @param {string} str 字符串
10
- * @returns {number} 字符长度
11
- * @example
12
- *
13
- * strlen('你好a'); // 5
14
- * strlen('你好,世界!'); // 12
15
- * strlen('严両丞丽'); // 8
16
- * strlen('abcde'); // 5
17
- * strlen('𠮷'); // 4
18
- * strlen('🍎'); // 4
19
- *
20
- */
21
3
  function strlen(str) {
22
- var realStr = normalizeString(str);
23
- var len = 0;
24
- for (var i = 0; i < realStr.length; i++) {
25
- var c = realStr.charCodeAt(i);
26
- if (c >= 0x0001 && c <= 0x007e || 0xff60 <= c && c <= 0xff9f) {
27
- len++;
28
- } else {
29
- len += 2;
4
+ var realStr = normalizeString(str);
5
+ var len = 0;
6
+ for (var i = 0; i < realStr.length; i++) {
7
+ var c = realStr.charCodeAt(i);
8
+ if ((c >= 0x0001 && c <= 0x007e) || (0xff60 <= c && c <= 0xff9f)) {
9
+ len++;
10
+ }
11
+ else {
12
+ len += 2;
13
+ }
30
14
  }
31
- }
32
- return len;
15
+ return len;
33
16
  }
34
- export default strlen;
17
+
18
+ export { strlen as default };
package/esm/times.js CHANGED
@@ -1,45 +1,27 @@
1
- import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
- import { digitLength, float2Fixed, checkBoundary, transformEffectiveNumber } from './utils/math.util';
1
+ import { __read, __spreadArray } from 'tslib';
2
+ import { transformEffectiveNumber, float2Fixed, digitLength, checkBoundary } from './utils/math.util.js';
3
+ import _isNaN from './utils/type/isNaN.js';
3
4
 
4
- /**
5
- * 精确乘法,支持多个数相乘,乘数默认为 1 。
6
- *
7
- * @static
8
- * @alias module:Math.times
9
- * @since 3.1.0
10
- * @param {...number|string} nums 相乘的数
11
- * @returns {number} 乘积
12
- * @example
13
- *
14
- * times(3, 0.6); // 1.8
15
- * times(3, 0.6, 2); // 3.6
16
- * times(3, 0.6, 2, 10); // 36
17
- *
18
- */
19
5
  function times() {
20
- for (var _len = arguments.length, nums = new Array(_len), _key = 0; _key < _len; _key++) {
21
- nums[_key] = arguments[_key];
22
- }
23
- var num1 = nums[0],
24
- _nums$ = nums[1],
25
- num2 = _nums$ === void 0 ? 1 : _nums$,
26
- rest = nums.slice(2);
27
- if (rest.length > 0) {
28
- return times.apply(void 0, [times(num1, num2)].concat(_toConsumableArray(rest)));
29
- }
30
- num1 = transformEffectiveNumber(num1);
31
- num2 = transformEffectiveNumber(num2);
32
-
33
- // 兼容处理,如果参数包含无效数值时,返回 NaN
34
- // @ts-ignore
35
- if (isNaN(num1) || isNaN(num2)) {
36
- return Number.NaN;
37
- }
38
- var num1Changed = float2Fixed(num1);
39
- var num2Changed = float2Fixed(num2);
40
- var baseNum = digitLength(num1) + digitLength(num2);
41
- var leftValue = num1Changed * num2Changed;
42
- checkBoundary(leftValue);
43
- return leftValue / Math.pow(10, baseNum);
6
+ var nums = [];
7
+ for (var _i = 0; _i < arguments.length; _i++) {
8
+ nums[_i] = arguments[_i];
9
+ }
10
+ var _a = __read(nums), num1 = _a[0], _b = _a[1], num2 = _b === void 0 ? 1 : _b, rest = _a.slice(2);
11
+ if (rest.length > 0) {
12
+ return times.apply(void 0, __spreadArray([times(num1, num2)], __read(rest), false));
13
+ }
14
+ num1 = transformEffectiveNumber(num1);
15
+ num2 = transformEffectiveNumber(num2);
16
+ if (_isNaN(num1) || _isNaN(num2)) {
17
+ return Number.NaN;
18
+ }
19
+ var num1Changed = float2Fixed(num1);
20
+ var num2Changed = float2Fixed(num2);
21
+ var baseNum = digitLength(num1) + digitLength(num2);
22
+ var leftValue = num1Changed * num2Changed;
23
+ checkBoundary(leftValue);
24
+ return leftValue / Math.pow(10, baseNum);
44
25
  }
45
- export default times;
26
+
27
+ export { times as default };
@@ -1,98 +1,40 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- 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; }
3
- 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; }
4
- // 如果修改文档,请同步修改 interface.doc.js
1
+ import { __assign } from 'tslib';
2
+ import isObject from './utils/type/isObject.js';
5
3
 
6
- import { isObject } from './utils/type';
7
-
8
- /**
9
- * 转换字段名,返回一个转换字段后的值,不改变原值。
10
- *
11
- * @static
12
- * @alias module:Processor.transformFieldNames
13
- * @since 4.14.0
14
- * @template {*} D
15
- * @template {Record<string, keyof D>} F
16
- * @template {string} C
17
- * @param {D[]} data 对象数组。如果是树结构数据,需要指定第三个参数 childrenField
18
- * @param {F} fieldNames 字段名映射
19
- * @param {C} [childrenField] 子级数据字段名
20
- * @param {'spread'|'self'} [nodeAssign='spread'] 节点赋值方式。spread表示使用展开运算符创建新值,self表示使用自身对象。
21
- * @returns {import('./interface.type.js').TransformFieldNames<D, F, C>}
22
- * @example
23
- *
24
- * const options = [{code: '1', name: 'one'},{code:'2', name:'two'}];
25
- * const newOptions = transformFieldNames(options, {label: 'name', value: 'code'});
26
- * // [{value: '1', label: 'one'},{value:'2', label:'two'}]
27
- *
28
- * // 嵌套数据,指定子级字段名 children
29
- * 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'}]}]}];
30
- * const newOptions2 = transformFieldNames(options2, {label: 'name', value: 'code'}, 'children');
31
- * // [{value: '1', label: 'one'},{value:'2', label:'two', children: [{value: '2-1', label:'two-one', children: [{value: '2-1-1', label:'two-one-one'}]}]}]
32
- *
33
- * const options3 = [{code: '1', name: 'one'},{code:'2', name:'two', childs: [{code:'2-1', name:'two-one'}]}];
34
- * const newOptions3 = transformFieldNames(options3, {label: 'name', value: 'code'}, 'childs');
35
- * // [{value: '1', label: 'one'},{value:'2', label:'two', childs: [{value: '2-1', label:'two-one'}]}]
36
- *
37
- * // 嵌套数据,并替换子集字段名
38
- * const newOptions4 = transformFieldNames(options3, {label: 'name', value: 'code', children: 'childs'}, 'childs');
39
- * // [{value: '1', label: 'one'},{value:'2', label:'two', children: [{value: '2-1', label:'two-one'}]}]
40
- */
41
- function transformFieldNames(data, fieldNames, childrenField) {
42
- var nodeAssign = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'spread';
43
- if (!Array.isArray(data)) {
44
- return data;
45
- }
46
- if (data.length <= 0) {
47
- // @ts-ignore
48
- return [];
49
- }
50
-
51
- /**
52
- * 递归处理字段名
53
- *
54
- * @param {Array.<object>} arr 列表数据
55
- * @returns {*}
56
- */
57
- function recusion(arr) {
58
- return arr.map(function (item) {
59
- if (!isObject(item)) {
60
- return item;
61
- }
62
- var newItem = nodeAssign === 'spread' ? _objectSpread({}, item) : item;
63
- /** @type {Array.<string>} */
64
- var delKeys = [];
65
-
66
- // 树形数据子节点
67
- // @ts-ignore
68
- if (childrenField && Array.isArray(newItem[childrenField]) && newItem[childrenField].length > 0) {
69
- // @ts-ignore
70
- newItem[childrenField] = recusion(newItem[childrenField].slice());
71
- }
72
-
73
- // 替换字段名
74
- Object.keys(fieldNames).forEach(function (newKey) {
75
- var oldKey = fieldNames[newKey];
76
- if (oldKey in newItem) {
77
- // @ts-ignore
78
- newItem[newKey] = newItem[oldKey];
79
- // @ts-ignore
80
- delKeys.push(oldKey);
81
- }
82
- });
83
-
84
- // 删除旧字段
85
- if (delKeys.length > 0) {
86
- delKeys.forEach(function (delKey) {
87
- // @ts-ignore
88
- delete newItem[delKey];
4
+ function transformFieldNames(data, fieldNames, childrenField, nodeAssign) {
5
+ if (nodeAssign === void 0) { nodeAssign = 'spread'; }
6
+ if (!Array.isArray(data)) {
7
+ return data;
8
+ }
9
+ if (data.length <= 0) {
10
+ return [];
11
+ }
12
+ function recusion(arr) {
13
+ return arr.map(function (item) {
14
+ if (!isObject(item)) {
15
+ return item;
16
+ }
17
+ var newItem = nodeAssign === 'spread' ? __assign({}, item) : item;
18
+ var delKeys = [];
19
+ if (childrenField && Array.isArray(newItem[childrenField]) && newItem[childrenField].length > 0) {
20
+ newItem[childrenField] = recusion(newItem[childrenField].slice());
21
+ }
22
+ Object.keys(fieldNames).forEach(function (newKey) {
23
+ var oldKey = fieldNames[newKey];
24
+ if (oldKey in newItem) {
25
+ newItem[newKey] = newItem[oldKey];
26
+ delKeys.push(oldKey);
27
+ }
28
+ });
29
+ if (delKeys.length > 0) {
30
+ delKeys.forEach(function (delKey) {
31
+ delete newItem[delKey];
32
+ });
33
+ }
34
+ return newItem;
89
35
  });
90
- }
91
- return newItem;
92
- });
93
- }
94
-
95
- // @ts-ignore
96
- return recusion(data.slice());
36
+ }
37
+ return recusion(data.slice());
97
38
  }
98
- export default transformFieldNames;
39
+
40
+ export { transformFieldNames as default };
package/esm/treeToList.js CHANGED
@@ -1,91 +1,30 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- 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; }
3
- 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; }
4
- import { isObject } from "./utils/type";
1
+ import { __assign } from 'tslib';
2
+ import isObject from './utils/type/isObject.js';
5
3
 
6
- /**
7
- * 树结构转列表数据
8
- *
9
- * @static
10
- * @alias module:Tree.treeToList
11
- * @since 4.14.0
12
- * @template {Record<string,any>} T
13
- * @template {keyof T} K
14
- * @template {Omit<T, K>} R
15
- * @param {T[]} tree 列表数据
16
- * @param {K} childrenField 子级字段名称
17
- * @returns {R[]} 列表数据
18
- * @example
19
- * 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" }] }];
20
- *
21
- * treeToList(menus, 'children'));
22
- * // [{"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"}]
23
- */
24
4
  function treeToList(tree, childrenField) {
25
- /** @type {R[]} */
26
- var list = [];
27
- if (!Array.isArray(tree)) {
5
+ var list = [];
6
+ if (!Array.isArray(tree)) {
7
+ return list;
8
+ }
9
+ function recusion(arr) {
10
+ arr.forEach(function (item) {
11
+ if (isObject(item)) {
12
+ var newItem = __assign({}, item);
13
+ list.push(newItem);
14
+ if (newItem[childrenField]) {
15
+ if (Array.isArray(newItem[childrenField]) && newItem[childrenField].length > 0) {
16
+ recusion(newItem[childrenField]);
17
+ }
18
+ delete newItem[childrenField];
19
+ }
20
+ }
21
+ else {
22
+ list.push(item);
23
+ }
24
+ });
25
+ }
26
+ recusion(tree);
28
27
  return list;
29
- }
30
-
31
- /**
32
- * 递归遍历
33
- * @param {T[]} arr 列表数据
34
- */
35
- function recusion(arr) {
36
- arr.forEach(function (item) {
37
- if (isObject(item)) {
38
- var newItem = _objectSpread({}, item);
39
- // @ts-ignore
40
- list.push(newItem);
41
- if (newItem[childrenField]) {
42
- if (Array.isArray(newItem[childrenField]) && newItem[childrenField].length > 0) {
43
- recusion(newItem[childrenField]);
44
- }
45
- delete newItem[childrenField];
46
- }
47
- } else {
48
- // @ts-ignore
49
- list.push(item);
50
- }
51
- });
52
- }
53
- recusion(tree);
54
- return list;
55
28
  }
56
29
 
57
- // function treeToList(tree, childrenField) {
58
- // /** @type {R[]} */
59
- // const list = [];
60
-
61
- // // 深度优先
62
- // /** @type {T[]} */
63
- // const stack = [];
64
- // for (const item of tree) {
65
- // if (isObject(item)) {
66
- // stack.push(item);
67
-
68
- // while (stack.length) {
69
- // /** @type {T} */
70
- // // @ts-ignore
71
- // const temp = stack.shift();
72
-
73
- // // @ts-ignore
74
- // list.push(temp);
75
-
76
- // if (temp[childrenField]) {
77
- // if (Array.isArray(temp[childrenField]) && temp[childrenField].length > 0) {
78
- // stack.push(...temp[childrenField]);
79
- // }
80
- // delete temp[childrenField];
81
- // }
82
- // }
83
- // } else {
84
- // // @ts-ignore
85
- // list.push(item);
86
- // }
87
- // }
88
- // return list;
89
- // }
90
-
91
- export default treeToList;
30
+ export { treeToList as default };
@@ -1,19 +1,9 @@
1
1
  var config = {
2
- // 禁用warning提示
3
- disableWarning: true
2
+ disableWarning: true
4
3
  };
5
-
6
- /**
7
- * 设置禁止warning提示
8
- * @static
9
- * @alias module:Debug.formatBankCard
10
- * @since 3.6.1
11
- * @param {boolean} bool 是否禁止warning提示
12
- */
13
4
  function setDisableWarning(bool) {
14
- config.disableWarning = !!bool;
5
+ config.disableWarning = !!bool;
15
6
  }
7
+ var version = "4.17.0";
16
8
 
17
- // eslint-disable-next-line no-undef
18
- var version = "4.16.1";
19
- export { config, setDisableWarning, version };
9
+ export { config, setDisableWarning, version };
@@ -1,4 +1,4 @@
1
- // 最大安全数字
2
- export var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || 9007199254740991;
3
- // 最小安全数字
4
- export var MIN_SAFE_INTEGER = Number.MIN_SAFE_INTEGER || -9007199254740991;
1
+ var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || 9007199254740991;
2
+ var MIN_SAFE_INTEGER = Number.MIN_SAFE_INTEGER || -9007199254740991;
3
+
4
+ export { MAX_SAFE_INTEGER, MIN_SAFE_INTEGER };
@@ -1,12 +1,7 @@
1
- import isString from './type/isString';
1
+ import isString from './type/isString.js';
2
2
 
3
- /**
4
- * 转换为字符串
5
- *
6
- * @param {*} value 值
7
- * @returns {string} 字符串
8
- */
9
3
  function convertToString(value) {
10
- return isString(value) ? value : String(value);
4
+ return isString(value) ? value : String(value);
11
5
  }
12
- export default convertToString;
6
+
7
+ export { convertToString as default };
@@ -1,14 +1,14 @@
1
- import { config } from './config';
1
+ import { __spreadArray, __read } from 'tslib';
2
+ import { config } from './config.js';
2
3
 
3
- /**
4
- * 打印警告信息
5
- *
6
- * @param {any[]} args 打印的信息
7
- */
8
4
  function devWarn() {
9
- if (!config.disableWarning) {
10
- var _console;
11
- (_console = console).warn.apply(_console, arguments);
12
- }
5
+ var args = [];
6
+ for (var _i = 0; _i < arguments.length; _i++) {
7
+ args[_i] = arguments[_i];
8
+ }
9
+ if (!config.disableWarning) {
10
+ console.warn.apply(console, __spreadArray([], __read(args), false));
11
+ }
13
12
  }
14
- export default devWarn;
13
+
14
+ export { devWarn as default };