util-helpers 4.16.2 → 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 (259) hide show
  1. package/dist/util-helpers.js +1542 -4040
  2. package/dist/util-helpers.js.map +1 -1
  3. package/dist/util-helpers.min.js +1 -1
  4. package/dist/util-helpers.min.js.map +1 -1
  5. package/esm/ajax.js +50 -146
  6. package/esm/blobToDataURL.js +4 -34
  7. package/esm/bytesToSize.js +12 -37
  8. package/esm/calculateCursorPosition.js +30 -52
  9. package/esm/dataURLToBlob.js +14 -28
  10. package/esm/divide.js +24 -48
  11. package/esm/download.js +83 -164
  12. package/esm/fileReader.js +18 -64
  13. package/esm/filterTree.js +25 -55
  14. package/esm/findTreeNode.js +39 -67
  15. package/esm/findTreeNodes.js +35 -66
  16. package/esm/findTreeSelect.js +38 -74
  17. package/esm/formatBankCard.js +13 -43
  18. package/esm/formatMobile.js +17 -43
  19. package/esm/formatMoney.js +59 -139
  20. package/esm/index.js +55 -130
  21. package/esm/isBankCard.js +22 -57
  22. package/esm/isBusinessLicense.js +32 -78
  23. package/esm/isChinese.js +23 -66
  24. package/esm/isEmail.js +6 -21
  25. package/esm/isHMCard.js +5 -28
  26. package/esm/isIPv4.js +5 -22
  27. package/esm/isIPv6.js +5 -36
  28. package/esm/isIdCard.js +27 -66
  29. package/esm/isMobile.js +5 -20
  30. package/esm/isPassport.js +5 -22
  31. package/esm/isPassword.js +7 -48
  32. package/esm/isPostcode.js +5 -20
  33. package/esm/isPromiseLike.js +3 -18
  34. package/esm/isQQ.js +5 -20
  35. package/esm/isSocialCreditCode.js +28 -83
  36. package/esm/isSwiftCode.js +6 -25
  37. package/esm/isTWCard.js +11 -37
  38. package/esm/isTelephone.js +6 -27
  39. package/esm/isUrl.js +5 -44
  40. package/esm/isVehicle.js +5 -28
  41. package/esm/isWX.js +5 -20
  42. package/esm/listToTree.js +51 -120
  43. package/esm/minus.js +21 -39
  44. package/esm/normalizeString.js +8 -29
  45. package/esm/numberToChinese.js +96 -215
  46. package/esm/padZero.js +14 -36
  47. package/esm/parseIdCard.js +64 -129
  48. package/esm/plus.js +21 -39
  49. package/esm/randomString.js +13 -45
  50. package/esm/replaceChar.js +27 -77
  51. package/esm/round.js +14 -31
  52. package/esm/safeDate.js +12 -55
  53. package/esm/setDataURLPrefix.js +6 -29
  54. package/esm/strlen.js +14 -30
  55. package/esm/times.js +24 -42
  56. package/esm/transformFieldNames.js +37 -93
  57. package/esm/treeToList.js +25 -84
  58. package/esm/utils/config.js +4 -14
  59. package/esm/utils/constants.js +4 -4
  60. package/esm/utils/convertToString.js +4 -9
  61. package/esm/utils/devWarn.js +11 -11
  62. package/esm/utils/math.util.js +95 -181
  63. package/esm/utils/type/isBlob.js +4 -24
  64. package/esm/utils/type/isNaN.js +4 -19
  65. package/esm/utils/type/isNil.js +5 -13
  66. package/esm/utils/type/isNull.js +3 -18
  67. package/esm/utils/type/isNumber.js +4 -28
  68. package/esm/utils/type/isObject.js +4 -23
  69. package/esm/utils/type/isString.js +4 -19
  70. package/esm/utils/type/isSymbol.js +4 -19
  71. package/esm/utils/type/isType.js +3 -12
  72. package/esm/utils/type/isUndefined.js +3 -21
  73. package/esm/validatePassword.js +86 -237
  74. package/esm/waitTime.js +7 -26
  75. package/lib/ajax.js +51 -152
  76. package/lib/blobToDataURL.js +5 -40
  77. package/lib/bytesToSize.js +13 -43
  78. package/lib/calculateCursorPosition.js +32 -58
  79. package/lib/dataURLToBlob.js +15 -34
  80. package/lib/divide.js +26 -60
  81. package/lib/download.js +85 -169
  82. package/lib/fileReader.js +19 -70
  83. package/lib/filterTree.js +27 -66
  84. package/lib/findTreeNode.js +40 -77
  85. package/lib/findTreeNodes.js +36 -76
  86. package/lib/findTreeSelect.js +40 -82
  87. package/lib/formatBankCard.js +15 -50
  88. package/lib/formatMobile.js +19 -50
  89. package/lib/formatMoney.js +60 -150
  90. package/lib/index.js +117 -395
  91. package/lib/isBankCard.js +24 -64
  92. package/lib/isBusinessLicense.js +34 -85
  93. package/lib/isChinese.js +24 -73
  94. package/lib/isEmail.js +7 -27
  95. package/lib/isHMCard.js +7 -35
  96. package/lib/isIPv4.js +7 -29
  97. package/lib/isIPv6.js +7 -43
  98. package/lib/isIdCard.js +29 -73
  99. package/lib/isMobile.js +7 -27
  100. package/lib/isPassport.js +7 -29
  101. package/lib/isPassword.js +9 -55
  102. package/lib/isPostcode.js +7 -27
  103. package/lib/isPromiseLike.js +4 -24
  104. package/lib/isQQ.js +7 -27
  105. package/lib/isSocialCreditCode.js +30 -90
  106. package/lib/isSwiftCode.js +7 -32
  107. package/lib/isTWCard.js +13 -44
  108. package/lib/isTelephone.js +7 -33
  109. package/lib/isUrl.js +6 -49
  110. package/lib/isVehicle.js +7 -35
  111. package/lib/isWX.js +7 -27
  112. package/lib/listToTree.js +53 -131
  113. package/lib/minus.js +23 -51
  114. package/lib/normalizeString.js +10 -36
  115. package/lib/numberToChinese.js +98 -222
  116. package/lib/padZero.js +16 -43
  117. package/lib/parseIdCard.js +65 -138
  118. package/lib/plus.js +23 -51
  119. package/lib/randomString.js +14 -51
  120. package/lib/replaceChar.js +28 -83
  121. package/lib/round.js +15 -37
  122. package/lib/safeDate.js +13 -63
  123. package/lib/setDataURLPrefix.js +7 -35
  124. package/lib/strlen.js +16 -37
  125. package/lib/times.js +26 -53
  126. package/lib/transformFieldNames.js +38 -101
  127. package/lib/treeToList.js +27 -94
  128. package/lib/utils/config.js +6 -23
  129. package/lib/utils/constants.js +3 -11
  130. package/lib/utils/convertToString.js +6 -16
  131. package/lib/utils/devWarn.js +13 -17
  132. package/lib/utils/math.util.js +95 -185
  133. package/lib/utils/type/isBlob.js +6 -31
  134. package/lib/utils/type/isNaN.js +6 -26
  135. package/lib/utils/type/isNil.js +7 -20
  136. package/lib/utils/type/isNull.js +4 -24
  137. package/lib/utils/type/isNumber.js +6 -35
  138. package/lib/utils/type/isObject.js +5 -29
  139. package/lib/utils/type/isString.js +6 -26
  140. package/lib/utils/type/isSymbol.js +6 -26
  141. package/lib/utils/type/isType.js +4 -18
  142. package/lib/utils/type/isUndefined.js +4 -27
  143. package/lib/validatePassword.js +87 -244
  144. package/lib/waitTime.js +8 -32
  145. package/package.json +21 -25
  146. package/types/ajax.d.ts +38 -95
  147. package/types/blobToDataURL.d.ts +2 -2
  148. package/types/bytesToSize.d.ts +7 -6
  149. package/types/calculateCursorPosition.d.ts +10 -9
  150. package/types/dataURLToBlob.d.ts +5 -5
  151. package/types/divide.d.ts +2 -2
  152. package/types/download.d.ts +22 -38
  153. package/types/fileReader.d.ts +35 -2
  154. package/types/filterTree.d.ts +6 -7
  155. package/types/findTreeNode.d.ts +5 -7
  156. package/types/findTreeNodes.d.ts +5 -7
  157. package/types/findTreeSelect.d.ts +5 -7
  158. package/types/formatBankCard.d.ts +8 -5
  159. package/types/formatMobile.d.ts +7 -4
  160. package/types/formatMoney.d.ts +8 -7
  161. package/types/index.d.ts +125 -55
  162. package/types/isBankCard.d.ts +9 -8
  163. package/types/isBusinessLicense.d.ts +8 -5
  164. package/types/isChinese.d.ts +9 -8
  165. package/types/isEmail.d.ts +1 -1
  166. package/types/isHMCard.d.ts +2 -2
  167. package/types/isIPv4.d.ts +1 -1
  168. package/types/isIPv6.d.ts +1 -1
  169. package/types/isIdCard.d.ts +8 -7
  170. package/types/isMobile.d.ts +1 -1
  171. package/types/isPassport.d.ts +2 -2
  172. package/types/isPassword.d.ts +4 -7
  173. package/types/isPostcode.d.ts +1 -1
  174. package/types/isPromiseLike.d.ts +1 -1
  175. package/types/isQQ.d.ts +1 -1
  176. package/types/isSocialCreditCode.d.ts +8 -5
  177. package/types/isSwiftCode.d.ts +2 -2
  178. package/types/isTWCard.d.ts +6 -5
  179. package/types/isTelephone.d.ts +1 -1
  180. package/types/isUrl.d.ts +2 -2
  181. package/types/isVehicle.d.ts +2 -2
  182. package/types/isWX.d.ts +1 -1
  183. package/types/listToTree.d.ts +12 -12
  184. package/types/minus.d.ts +3 -2
  185. package/types/normalizeString.d.ts +2 -2
  186. package/types/numberToChinese.d.ts +13 -12
  187. package/types/padZero.d.ts +2 -2
  188. package/types/parseIdCard.d.ts +17 -56
  189. package/types/plus.d.ts +3 -2
  190. package/types/randomString.d.ts +2 -2
  191. package/types/replaceChar.d.ts +15 -11
  192. package/types/round.d.ts +2 -2
  193. package/types/safeDate.d.ts +24 -2
  194. package/types/setDataURLPrefix.d.ts +5 -5
  195. package/types/strlen.d.ts +1 -1
  196. package/types/times.d.ts +3 -2
  197. package/types/transformFieldNames.d.ts +12 -10
  198. package/types/treeToList.d.ts +1 -1
  199. package/types/utils/config.d.ts +6 -5
  200. package/types/utils/constants.d.ts +2 -2
  201. package/types/utils/convertToString.d.ts +1 -1
  202. package/types/utils/devWarn.d.ts +1 -1
  203. package/types/utils/math.util.d.ts +15 -9
  204. package/types/utils/type/index.d.ts +7 -0
  205. package/types/utils/type/isArguments.d.ts +1 -1
  206. package/types/utils/type/isArray.d.ts +1 -1
  207. package/types/utils/type/isArrayBuffer.d.ts +1 -1
  208. package/types/utils/type/isBlob.d.ts +1 -1
  209. package/types/utils/type/isBoolean.d.ts +1 -1
  210. package/types/utils/type/isDate.d.ts +1 -1
  211. package/types/utils/type/isError.d.ts +1 -1
  212. package/types/utils/type/isFunction.d.ts +1 -1
  213. package/types/utils/type/isMap.d.ts +1 -1
  214. package/types/utils/type/isNaN.d.ts +1 -1
  215. package/types/utils/type/isNil.d.ts +1 -1
  216. package/types/utils/type/isNull.d.ts +1 -1
  217. package/types/utils/type/isNumber.d.ts +1 -1
  218. package/types/utils/type/isObject.d.ts +1 -1
  219. package/types/utils/type/isRegExp.d.ts +1 -1
  220. package/types/utils/type/isSet.d.ts +1 -1
  221. package/types/utils/type/isString.d.ts +1 -1
  222. package/types/utils/type/isSymbol.d.ts +1 -1
  223. package/types/utils/type/isType.d.ts +1 -1
  224. package/types/utils/type/isUndefined.d.ts +1 -1
  225. package/types/utils/type/isWeakMap.d.ts +1 -1
  226. package/types/utils/type/isWeakSet.d.ts +1 -1
  227. package/types/validatePassword.d.ts +17 -48
  228. package/types/waitTime.d.ts +2 -2
  229. package/esm/interface.doc.js +0 -125
  230. package/esm/interface.type.js +0 -17
  231. package/esm/utils/type/index.js +0 -29
  232. package/esm/utils/type/isArguments.js +0 -22
  233. package/esm/utils/type/isArray.js +0 -22
  234. package/esm/utils/type/isArrayBuffer.js +0 -25
  235. package/esm/utils/type/isBoolean.js +0 -22
  236. package/esm/utils/type/isDate.js +0 -22
  237. package/esm/utils/type/isError.js +0 -22
  238. package/esm/utils/type/isFunction.js +0 -22
  239. package/esm/utils/type/isMap.js +0 -22
  240. package/esm/utils/type/isRegExp.js +0 -22
  241. package/esm/utils/type/isSet.js +0 -22
  242. package/esm/utils/type/isWeakMap.js +0 -22
  243. package/esm/utils/type/isWeakSet.js +0 -22
  244. package/lib/interface.doc.js +0 -127
  245. package/lib/interface.type.js +0 -5
  246. package/lib/utils/type/index.js +0 -146
  247. package/lib/utils/type/isArguments.js +0 -29
  248. package/lib/utils/type/isArray.js +0 -29
  249. package/lib/utils/type/isArrayBuffer.js +0 -32
  250. package/lib/utils/type/isBoolean.js +0 -29
  251. package/lib/utils/type/isDate.js +0 -29
  252. package/lib/utils/type/isError.js +0 -29
  253. package/lib/utils/type/isFunction.js +0 -29
  254. package/lib/utils/type/isMap.js +0 -29
  255. package/lib/utils/type/isRegExp.js +0 -29
  256. package/lib/utils/type/isSet.js +0 -29
  257. package/lib/utils/type/isWeakMap.js +0 -29
  258. package/lib/utils/type/isWeakSet.js +0 -29
  259. package/types/interface.type.d.ts +0 -2
@@ -1,52 +1,17 @@
1
- "use strict";
1
+ 'use strict';
2
2
 
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports["default"] = void 0;
7
- var _normalizeString = _interopRequireDefault(require("./normalizeString"));
8
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
9
- /**
10
- * 格式化银行卡号
11
- *
12
- * @static
13
- * @alias module:Processor.formatBankCard
14
- * @since 1.1.0
15
- * @param {string} bankCardNo 要处理的字符串
16
- * @param {Object} [options] 配置项
17
- * @param {string} [options.spaceMark=' '] 间隔字符
18
- * @param {number} [options.length=4] 间隔长度
19
- * @returns {string} 格式化的银行卡号
20
- * @example
21
- *
22
- * // 19位银行卡
23
- * formatBankCard('6228480402564890018'); // 6228 4804 0256 4890 018
24
- *
25
- * // 16位银行卡
26
- * formatBankCard('6228480402564890'); // 6228 4804 0256 4890
27
- *
28
- * // 脱敏银行卡
29
- * formatBankCard('6228********890'); // 6228 **** **** 890
30
- *
31
- * // 16位银行卡,"-"间隔
32
- * formatBankCard('6228480402564890', {spaceMark: '-'}); // 6228-4804-0256-4890
33
- *
34
- */
35
- function formatBankCard() {
36
- var bankCardNo = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
37
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
38
- // @ts-ignore
39
- // TODO 下个版本废弃 char
40
- var _options$char = options["char"],
41
- _char = _options$char === void 0 ? ' ' : _options$char,
42
- _options$length = options.length,
43
- length = _options$length === void 0 ? 4 : _options$length;
44
- var realSpaceMark = 'spaceMark' in options ? options.spaceMark : _char;
45
- var reg = new RegExp("(.{".concat(length, "})"), 'g');
46
- var regChar = new RegExp("".concat(realSpaceMark), 'g');
47
- var realValue = (0, _normalizeString["default"])(bankCardNo).replace(regChar, '');
48
- var str = realValue.replace(reg, "$1".concat(realSpaceMark));
49
- return realValue.length % length === 0 ? str.substring(0, str.length - 1) : str;
3
+ var normalizeString = require('./normalizeString.js');
4
+
5
+ function formatBankCard(bankCardNo, options) {
6
+ if (bankCardNo === void 0) { bankCardNo = ''; }
7
+ if (options === void 0) { options = {}; }
8
+ var _a = options.char, char = _a === void 0 ? ' ' : _a, _b = options.length, length = _b === void 0 ? 4 : _b;
9
+ var realSpaceMark = 'spaceMark' in options ? options.spaceMark : char;
10
+ var reg = new RegExp("(.{".concat(length, "})"), 'g');
11
+ var regChar = new RegExp("".concat(realSpaceMark), 'g');
12
+ var realValue = normalizeString(bankCardNo).replace(regChar, '');
13
+ var str = realValue.replace(reg, "$1".concat(realSpaceMark));
14
+ return realValue.length % length === 0 ? str.substring(0, str.length - 1) : str;
50
15
  }
51
- var _default = formatBankCard;
52
- exports["default"] = _default;
16
+
17
+ module.exports = formatBankCard;
@@ -1,52 +1,21 @@
1
- "use strict";
1
+ 'use strict';
2
2
 
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports["default"] = void 0;
7
- var _normalizeString = _interopRequireDefault(require("./normalizeString"));
8
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
9
- /**
10
- * 格式化手机号码
11
- *
12
- * @static
13
- * @alias module:Processor.formatMobile
14
- * @since 4.5.0
15
- * @param {string} mobileNo 手机号码
16
- * @param {object} [options] 配置项
17
- * @param {string} [options.spaceMark=' '] 间隔字符
18
- * @returns {string} 格式化后的手机号码
19
- * @example
20
- *
21
- * formatMobile('13345678900'); // 133 4567 8900
22
- * formatMobile('13345678900', { spaceMark: '-' }); // 133-4567-8900
23
- *
24
- * // 脱敏手机号码
25
- * formatMobile('133****1234'); // 133 **** 1234
26
- * formatMobile('133****1234', { spaceMark: '-' }); // 133-****-1234
27
- *
28
- * // 手机号码位数不够
29
- * formatMobile('133'); // 133
30
- * formatMobile('133456'); // 133 456
31
- * formatMobile('13345678'); // 133 4567 8
32
- *
33
- */
34
- function formatMobile(mobileNo) {
35
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
36
- // @ts-ignore
37
- // TODO 下个版本废弃 char
38
- var _options$char = options["char"],
39
- _char = _options$char === void 0 ? ' ' : _options$char;
40
- var realSpaceMark = 'spaceMark' in options ? options.spaceMark : _char;
41
- var regChar = new RegExp(realSpaceMark, 'g');
42
- var realValue = (0, _normalizeString["default"])(mobileNo).replace(regChar, '').substring(0, 11);
43
- if (realValue.length > 7) {
44
- return realValue.replace(/^(...)(....)/g, "$1".concat(realSpaceMark, "$2").concat(realSpaceMark));
45
- }
46
- if (realValue.length > 3) {
47
- return realValue.replace(/^(...)/g, "$1".concat(realSpaceMark));
48
- }
49
- return realValue;
3
+ var normalizeString = require('./normalizeString.js');
4
+
5
+ function formatMobile(mobileNo, options) {
6
+ if (mobileNo === void 0) { mobileNo = ''; }
7
+ if (options === void 0) { options = {}; }
8
+ var _a = options.char, char = _a === void 0 ? ' ' : _a;
9
+ var realSpaceMark = 'spaceMark' in options ? options.spaceMark : char;
10
+ var regChar = new RegExp(realSpaceMark, 'g');
11
+ var realValue = normalizeString(mobileNo).replace(regChar, '').substring(0, 11);
12
+ if (realValue.length > 7) {
13
+ return realValue.replace(/^(...)(....)/g, "$1".concat(realSpaceMark, "$2").concat(realSpaceMark));
14
+ }
15
+ if (realValue.length > 3) {
16
+ return realValue.replace(/^(...)/g, "$1".concat(realSpaceMark));
17
+ }
18
+ return realValue;
50
19
  }
51
- var _default = formatMobile;
52
- exports["default"] = _default;
20
+
21
+ module.exports = formatMobile;
@@ -1,159 +1,69 @@
1
- "use strict";
1
+ 'use strict';
2
2
 
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports["default"] = void 0;
7
- var _math = require("./utils/math.util");
8
- var _isNaN = _interopRequireDefault(require("./utils/type/isNaN"));
9
- var _devWarn = _interopRequireDefault(require("./utils/devWarn"));
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
11
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
12
- 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."); }
13
- 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); }
14
- 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; }
15
- 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; } }
16
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
17
- var reg = /^[+-]?\d*\.?\d*$/;
3
+ var tslib = require('tslib');
4
+ var math_util = require('./utils/math.util.js');
5
+ var isNaN = require('./utils/type/isNaN.js');
6
+ var devWarn = require('./utils/devWarn.js');
18
7
 
19
- /**
20
- * 检查数字或数字字符串
21
- *
22
- * @private
23
- * @param {string} num
24
- * @returns 是否为数字
25
- */
8
+ var reg = /^[+-]?\d*\.?\d*$/;
26
9
  function checkNumber(num) {
27
- if (!(reg.test(num) || (0, _math.isScientificNumber)(num)) || (0, _isNaN["default"])(num) || typeof num !== 'number' && typeof num !== 'string' || num === '') {
28
- (0, _devWarn["default"])("".concat(num, " invalid parameter."));
29
- return false;
30
- }
31
-
32
- // 数字超限如果不是是字符串,可能有异常
33
- // 如 1111111111111111111111 // => 1.1111111111111111e+21
34
- if (typeof num === 'number') {
35
- (0, _math.checkBoundary)(num);
36
- }
37
- return true;
10
+ if ((typeof num !== 'number' && typeof num !== 'string') || (typeof num === 'number' && isNaN(num)) || (typeof num === 'string' && (!(reg.test(num) || math_util.isScientificNumber(num)) || num === ''))) {
11
+ devWarn("".concat(num, " invalid parameter."));
12
+ return false;
13
+ }
14
+ if (typeof num === 'number') {
15
+ math_util.checkBoundary(num);
16
+ }
17
+ return true;
38
18
  }
39
-
40
- /**
41
- * 格式化整数部分
42
- *
43
- * @private
44
- * @param {string} intStr 数字字符串
45
- * @param {string} thousand 千分位符号
46
- * @returns 格式化后的值
47
- */
48
19
  function formatInt(intStr, thousand) {
49
- var txt = '';
50
- intStr = (0, _math.trimLeftZero)(intStr);
51
- intStr = intStr[0] === '+' ? intStr.substring(1) : intStr; // 去掉+符号
52
- var negativeSymbol = Number(intStr) < 0 ? '-' : '';
53
- var reArr = negativeSymbol ? intStr.substring(1).split('').reverse() : intStr.split('').reverse();
54
- for (var i = 0; i < reArr.length; i++) {
55
- txt += reArr[i] + ((i + 1) % 3 === 0 && i + 1 !== reArr.length ? thousand : '');
56
- }
57
- return negativeSymbol + txt.split('').reverse().join('');
20
+ var txt = '';
21
+ intStr = math_util.trimLeftZero(intStr);
22
+ intStr = intStr[0] === '+' ? intStr.substring(1) : intStr;
23
+ var negativeSymbol = Number(intStr) < 0 ? '-' : '';
24
+ var reArr = negativeSymbol ? intStr.substring(1).split('').reverse() : intStr.split('').reverse();
25
+ for (var i = 0; i < reArr.length; i++) {
26
+ txt += reArr[i] + ((i + 1) % 3 === 0 && i + 1 !== reArr.length ? thousand : '');
27
+ }
28
+ return negativeSymbol + txt.split('').reverse().join('');
58
29
  }
59
-
60
- /**
61
- * 格式化小数部分,如果使用 toFixed,超大额数字会自动被截断
62
- *
63
- * @private
64
- * @param {string} decStr 小数点部分的字符串
65
- * @param {number} precision 保留位数
66
- * @param {string} decimal 小数点符号
67
- * @returns 格式化后的值
68
- */
69
30
  function formatDec(decStr, precision, decimal) {
70
- if (precision === 0) {
71
- return '';
72
- }
73
- var zero = 0;
74
- var ret = '';
75
- if (decStr && Number(decStr) > 0) {
76
- var tmpNum = parseFloat('0.' + decStr);
77
- ret = tmpNum.toFixed(precision).substring(2);
78
- } else {
79
- ret = zero.toFixed(precision).substring(2);
80
- }
81
- return decimal + ret;
31
+ if (precision === 0) {
32
+ return '';
33
+ }
34
+ var zero = 0;
35
+ var ret = '';
36
+ if (decStr && Number(decStr) > 0) {
37
+ var tmpNum = parseFloat('0.' + decStr);
38
+ ret = tmpNum.toFixed(precision).substring(2);
39
+ }
40
+ else {
41
+ ret = zero.toFixed(precision).substring(2);
42
+ }
43
+ return decimal + ret;
82
44
  }
83
-
84
- /**
85
- * 格式化金额
86
- *
87
- * @static
88
- * @alias module:Processor.formatMoney
89
- * @since 1.1.0
90
- * @param {string | number} num 需转换金额 (最大:9007199254740991 最小: -9007199254740991)
91
- * @param {Object} [options] 金额格式化配置
92
- * @param {number} [options.precision=2] 保留位数 (最高:10位)
93
- * @param {string} [options.symbol] 货币符号
94
- * @param {string} [options.thousand=","] 千分位符号
95
- * @param {string} [options.decimal="."] 小数位符号
96
- * @returns {string} 格式化的金额
97
- * @example
98
- *
99
- * // 整数
100
- * formatMoney(1000); // 1,000.00
101
- *
102
- * // 小数(默认保留2位小数)
103
- * formatMoney(3000.03); // 3,000.03
104
- *
105
- * // 保留4位小数
106
- * formatMoney(3000.03, { precision: 4 }); // 3,000.0300
107
- *
108
- * // 保留10位小数
109
- * formatMoney(1500.2, { precision: 10 }); // 1,500.2000000000
110
- *
111
- * // 自定义单位符号
112
- * formatMoney(1000.00, { symbol: '$' }); // $1,000.00
113
- *
114
- * // 自定义千位分割符(默认',')
115
- * formatMoney(1000.00, { thousand: '|' }); // 1|000.00
116
- *
117
- * // 自定义小数位分割符(默认'.')
118
- * formatMoney(1000.00, { decimal: '&' }); // 1,000&00
119
- *
120
- * // 字符串数字
121
- * formatMoney('3000.03', { precision: 4 }); // 3,000.0300
122
- */
123
- var formatMoney = function formatMoney(num) {
124
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
125
- var _options$precision = options.precision,
126
- precision = _options$precision === void 0 ? 2 : _options$precision,
127
- symbol = options.symbol,
128
- _options$thousand = options.thousand,
129
- thousand = _options$thousand === void 0 ? ',' : _options$thousand,
130
- _options$decimal = options.decimal,
131
- decimal = _options$decimal === void 0 ? '.' : _options$decimal;
132
-
133
- // 数字参数不正确,返回空字符串
134
- // @ts-ignore
135
- if (!checkNumber(num)) {
136
- return '';
137
- }
138
-
139
- // 参数规整化
140
- if (typeof precision !== 'number' || (0, _isNaN["default"])(precision) || precision < 0) {
141
- precision = 2;
142
- } else if (precision > 10) {
143
- precision = 10;
144
- }
145
- symbol = typeof symbol === 'string' ? symbol : '';
146
- thousand = typeof thousand === 'string' ? thousand : ',';
147
- decimal = typeof decimal === 'string' ? decimal : '.';
148
-
149
- // 转换数字字符串,支持科学记数法
150
- var strNum = (0, _math.scientificToNumber)(num) + '';
151
- // 整数和小数部分
152
- var _strNum$split = strNum.split('.'),
153
- _strNum$split2 = _slicedToArray(_strNum$split, 2),
154
- intStr = _strNum$split2[0],
155
- decStr = _strNum$split2[1];
156
- return symbol + formatInt(intStr, thousand) + formatDec(decStr, precision, decimal);
45
+ var formatMoney = function (num, options) {
46
+ if (options === void 0) { options = {}; }
47
+ var _a = options.precision, precision = _a === void 0 ? 2 : _a, symbol = options.symbol, _b = options.thousand, thousand = _b === void 0 ? ',' : _b, _c = options.decimal, decimal = _c === void 0 ? '.' : _c;
48
+ if (!checkNumber(num)) {
49
+ return '';
50
+ }
51
+ if (typeof num === 'number' && !isFinite(num)) {
52
+ return num + '';
53
+ }
54
+ if (typeof precision !== 'number' || isNaN(precision) || precision < 0) {
55
+ precision = 2;
56
+ }
57
+ else if (precision > 10) {
58
+ precision = 10;
59
+ }
60
+ symbol = typeof symbol === 'string' ? symbol : '';
61
+ thousand = typeof thousand === 'string' ? thousand : ',';
62
+ decimal = typeof decimal === 'string' ? decimal : '.';
63
+ var strNum = math_util.scientificToNumber(num) + '';
64
+ var _d = tslib.__read(strNum.split('.'), 2), intStr = _d[0], decStr = _d[1];
65
+ return symbol + formatInt(intStr, thousand) + formatDec(decStr, precision, decimal);
157
66
  };
158
- var _default = formatMoney;
159
- exports["default"] = _default;
67
+ var formatMoney$1 = formatMoney;
68
+
69
+ module.exports = formatMoney$1;