util-helpers 4.16.2 → 4.17.1

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 +1600 -4039
  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
package/esm/isWX.js CHANGED
@@ -1,24 +1,9 @@
1
- import normalizeString from './normalizeString';
1
+ import normalizeString from './normalizeString.js';
2
2
 
3
- // 微信号 6至20位,以字母开头,字母,数字,减号(连接符),下划线
4
3
  var reg = /^[a-z]([-_a-z0-9]{5,19})+$/i;
5
-
6
- /**
7
- * 检测值是否为微信号
8
- *
9
- * @static
10
- * @alias module:Validator.isWX
11
- * @since 1.1.0
12
- * @param {*} value 要检测的值
13
- * @returns {boolean} 值是否为微信号
14
- * @example
15
- *
16
- * isWX('a12345'); // true
17
- * isWX('123'); // false
18
- *
19
- */
20
4
  function isWX(value) {
21
- var valueStr = normalizeString(value);
22
- return reg.test(valueStr);
5
+ var valueStr = normalizeString(value);
6
+ return reg.test(valueStr);
23
7
  }
24
- export default isWX;
8
+
9
+ export { isWX as default };
package/esm/listToTree.js CHANGED
@@ -1,127 +1,58 @@
1
- import _objectSpread from "@babel/runtime/helpers/objectSpread2";
2
- import { isObject } from "./utils/type";
1
+ import { __assign } from 'tslib';
2
+ import isObject from './utils/type/isObject.js';
3
3
 
4
- /**
5
- * 递归处理空子级
6
- *
7
- * @private
8
- * @template {Record<string,any>} [T=Record<string,any>]
9
- * @param {T[]} arr 列表数据
10
- * @param {object} [options] 配置项
11
- * @param {string} [options.childrenField='children'] 子级字段名称
12
- * @param {'none'|'null'} [options.emptyChildrenValue='none'] 子级为空时的值,none表示删除该子级,null表示为null,array表示为[]。
13
- */
14
4
  function processEmptyChildren(arr, options) {
15
- var _ref = options || {},
16
- _ref$childrenField = _ref.childrenField,
17
- childrenField = _ref$childrenField === void 0 ? 'children' : _ref$childrenField,
18
- _ref$emptyChildrenVal = _ref.emptyChildrenValue,
19
- emptyChildrenValue = _ref$emptyChildrenVal === void 0 ? 'none' : _ref$emptyChildrenVal;
20
- arr.forEach(function (item) {
21
- // if (isObject(item) && Array.isArray(item[childrenField])) {
22
- if (item[childrenField].length <= 0) {
23
- if (emptyChildrenValue === 'null') {
24
- // @ts-ignore
25
- item[childrenField] = null;
26
- // } else if (emptyChildrenValue === 'none') { // emptyChildrenValue='array' 不会执行该内部方法
27
- } else {
28
- delete item[childrenField];
29
- }
30
- } else {
31
- processEmptyChildren(item[childrenField], options);
32
- }
33
- // }
34
- });
5
+ var _a = options.childrenField, childrenField = _a === void 0 ? 'children' : _a, _b = options.emptyChildrenValue, emptyChildrenValue = _b === void 0 ? 'none' : _b;
6
+ arr.forEach(function (item) {
7
+ if (item[childrenField].length <= 0) {
8
+ if (emptyChildrenValue === 'null') {
9
+ item[childrenField] = null;
10
+ }
11
+ else {
12
+ delete item[childrenField];
13
+ }
14
+ }
15
+ else {
16
+ processEmptyChildren(item[childrenField], options);
17
+ }
18
+ });
35
19
  }
36
-
37
- /**
38
- * 列表数据转树结构
39
- *
40
- * @static
41
- * @alias module:Tree.listToTree
42
- * @since 4.14.0
43
- * @template {Record<string,any>} [T=Record<string,any>]
44
- * @template {*} [R=T&Record<string,any>]
45
- * @param {T[]} list 列表数据
46
- * @param {object} [options] 配置项
47
- * @param {string} [options.keyField='id'] 当前数据的键值字段名称
48
- * @param {string} [options.parentField='pid'] 当前数据的父级字段名称
49
- * @param {string} [options.childrenField='children'] 子级字段名称
50
- * @param {'none'|'null'|'array'} [options.emptyChildrenValue='none'] 子级为空时的值,none表示删除该子级,null表示为null,array表示为[]。
51
- * @param {'spread'|'self'} [options.nodeAssign='spread'] 节点赋值方式。spread表示使用展开运算符创建新值,self表示使用自身对象。
52
- * @returns {R[]} 树结构
53
- * @example
54
- *
55
- * const menus = [
56
- * { id: '1', name: '首页', code: 'trade', pid: null },
57
- * { id: '2', name: '交易管理', code: 'trade', pid: null },
58
- * { id: '3', name: '交易查询', code: 'trade-1', pid: '2' },
59
- * { id: '4', name: '交易查询-查询操作', code: 'trade-1-1', pid: '3' },
60
- * { id: '5', name: '权限管理', code: 'authorization', pid: null },
61
- * { id: '6', name: '角色管理', code: 'authorization-1', pid: '5' },
62
- * { id: '7', name: '用户管理', code: 'authorization-2', pid: '5' }
63
- * ];
64
- * listToTree(menus);
65
- * // [{"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"}]}]
66
- *
67
- * // 自定义子级字段名
68
- * listToTree(basicMenus, { childrenField: 'childs' });
69
- * // [{"id":"1","name":"首页","code":"trade","pid":null},{"id":"2","name":"交易管理","code":"trade","pid":null,"childs":[{"id":"3","name":"交易查询","code":"trade-1","pid":"2","childs":[{"id":"4","name":"交易查询-查询操作","code":"trade-1-1","pid":"3"}]}]},{"id":"5","name":"权限管理","code":"authorization","pid":null,"childs":[{"id":"6","name":"角色管理","code":"authorization-1","pid":"5"},{"id":"7","name":"用户管理","code":"authorization-2","pid":"5"}]}]
70
- *
71
- */
72
20
  function listToTree(list, options) {
73
- var _ref2 = options || {},
74
- _ref2$keyField = _ref2.keyField,
75
- keyField = _ref2$keyField === void 0 ? 'id' : _ref2$keyField,
76
- _ref2$parentField = _ref2.parentField,
77
- parentField = _ref2$parentField === void 0 ? 'pid' : _ref2$parentField,
78
- _ref2$childrenField = _ref2.childrenField,
79
- childrenField = _ref2$childrenField === void 0 ? 'children' : _ref2$childrenField,
80
- _ref2$emptyChildrenVa = _ref2.emptyChildrenValue,
81
- emptyChildrenValue = _ref2$emptyChildrenVa === void 0 ? 'none' : _ref2$emptyChildrenVa,
82
- _ref2$nodeAssign = _ref2.nodeAssign,
83
- nodeAssign = _ref2$nodeAssign === void 0 ? 'spread' : _ref2$nodeAssign;
84
-
85
- /** @type {R[]} */
86
- var tree = [];
87
-
88
- /** @type {Object.<string, T[]>} */
89
- var record = {};
90
- if (!Array.isArray(list)) {
91
- return tree;
92
- }
93
- list.forEach(function (item) {
94
- if (isObject(item)) {
95
- var newItem = nodeAssign === 'spread' ? _objectSpread({}, item) : item;
96
-
97
- /** @type {string} */
98
- var id = newItem[keyField];
99
-
100
- /** @type {string} */
101
- var pid = newItem[parentField];
102
- if (record[id]) {
103
- // @ts-ignore
104
- newItem[childrenField] = record[id];
105
- } else {
106
- // @ts-ignore
107
- newItem[childrenField] = record[id] = [];
108
- }
109
- if (pid) {
110
- if (!record[pid]) {
111
- record[pid] = [newItem];
112
- } else {
113
- record[pid].push(newItem);
21
+ if (options === void 0) { options = {}; }
22
+ var _a = options.keyField, keyField = _a === void 0 ? 'id' : _a, _b = options.parentField, parentField = _b === void 0 ? 'pid' : _b, _c = options.childrenField, childrenField = _c === void 0 ? 'children' : _c, _d = options.emptyChildrenValue, emptyChildrenValue = _d === void 0 ? 'none' : _d, _e = options.nodeAssign, nodeAssign = _e === void 0 ? 'spread' : _e;
23
+ var tree = [];
24
+ var record = {};
25
+ if (!Array.isArray(list)) {
26
+ return tree;
27
+ }
28
+ list.forEach(function (item) {
29
+ if (isObject(item)) {
30
+ var newItem = nodeAssign === 'spread' ? __assign({}, item) : item;
31
+ var id = newItem[keyField];
32
+ var pid = newItem[parentField];
33
+ if (record[id]) {
34
+ newItem[childrenField] = record[id];
35
+ }
36
+ else {
37
+ newItem[childrenField] = record[id] = [];
38
+ }
39
+ if (pid) {
40
+ if (!record[pid]) {
41
+ record[pid] = [newItem];
42
+ }
43
+ else {
44
+ record[pid].push(newItem);
45
+ }
46
+ }
47
+ else {
48
+ tree.push(newItem);
49
+ }
114
50
  }
115
- } else {
116
- // @ts-ignore
117
- tree.push(newItem);
118
- }
51
+ });
52
+ if (emptyChildrenValue !== 'array') {
53
+ processEmptyChildren(tree, options);
119
54
  }
120
- });
121
- if (emptyChildrenValue !== 'array') {
122
- // @ts-ignore
123
- processEmptyChildren(tree, options);
124
- }
125
- return tree;
55
+ return tree;
126
56
  }
127
- export default listToTree;
57
+
58
+ export { listToTree as default };
package/esm/minus.js CHANGED
@@ -1,42 +1,24 @@
1
- import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
- import { digitLength, transformEffectiveNumber } from './utils/math.util';
3
- import times from './times';
1
+ import { __read, __spreadArray } from 'tslib';
2
+ import { transformEffectiveNumber, digitLength } from './utils/math.util.js';
3
+ import times from './times.js';
4
+ import _isNaN from './utils/type/isNaN.js';
4
5
 
5
- /**
6
- * 精确减法,支持多个数相减,减数默认为 0 。
7
- *
8
- * @static
9
- * @alias module:Math.minus
10
- * @since 3.1.0
11
- * @param {...number|string} nums 相减的数
12
- * @returns {number} 差
13
- * @example
14
- *
15
- * minus(1, 0.9); // 0.1
16
- * minus(1, 0.9, 0.02); // 0.08
17
- * minus(1, 0.9, 0.02, 0.08); // 0
18
- *
19
- */
20
6
  function minus() {
21
- for (var _len = arguments.length, nums = new Array(_len), _key = 0; _key < _len; _key++) {
22
- nums[_key] = arguments[_key];
23
- }
24
- var num1 = nums[0],
25
- _nums$ = nums[1],
26
- num2 = _nums$ === void 0 ? 0 : _nums$,
27
- rest = nums.slice(2);
28
- if (rest.length > 0) {
29
- return minus.apply(void 0, [minus(num1, num2)].concat(_toConsumableArray(rest)));
30
- }
31
- num1 = transformEffectiveNumber(num1);
32
- num2 = transformEffectiveNumber(num2);
33
-
34
- // 兼容处理,如果参数包含无效数值时,返回 NaN
35
- // @ts-ignore
36
- if (isNaN(num1) || isNaN(num2)) {
37
- return Number.NaN;
38
- }
39
- var baseNum = Math.pow(10, Math.max(digitLength(num1), digitLength(num2)));
40
- return (times(num1, baseNum) - times(num2, baseNum)) / baseNum;
7
+ var nums = [];
8
+ for (var _i = 0; _i < arguments.length; _i++) {
9
+ nums[_i] = arguments[_i];
10
+ }
11
+ var _a = __read(nums), num1 = _a[0], _b = _a[1], num2 = _b === void 0 ? 0 : _b, rest = _a.slice(2);
12
+ if (rest.length > 0) {
13
+ return minus.apply(void 0, __spreadArray([minus(num1, num2)], __read(rest), false));
14
+ }
15
+ num1 = transformEffectiveNumber(num1);
16
+ num2 = transformEffectiveNumber(num2);
17
+ if (_isNaN(num1) || _isNaN(num2)) {
18
+ return Number.NaN;
19
+ }
20
+ var baseNum = Math.pow(10, Math.max(digitLength(num1), digitLength(num2)));
21
+ return (times(num1, baseNum) - times(num2, baseNum)) / baseNum;
41
22
  }
42
- export default minus;
23
+
24
+ export { minus as default };
@@ -1,32 +1,11 @@
1
- import isNil from './utils/type/isNil';
2
- import convertToString from './utils/convertToString';
1
+ import isNil from './utils/type/isNil.js';
2
+ import convertToString from './utils/convertToString.js';
3
3
 
4
- /**
5
- * 规整化字符串。如果值为 undefined 或 null 将转为空字符串,如果值不是字符串类型将转为字符串。
6
- *
7
- * @static
8
- * @alias module:Processor.normalizeString
9
- * @since 4.3.0
10
- * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/String#string_instances|String}
11
- * @param {*} value 待处理的值
12
- * @returns {string} 规整化的值
13
- * @example
14
- *
15
- * normalizeString(); // ''
16
- * normalizeString(undefined); // ''
17
- * normalizeString(void 0); // ''
18
- * normalizeString(null); // ''
19
- *
20
- * normalizeString(true); // 'true'
21
- * normalizeString(NaN); // 'NaN'
22
- * normalizeString(1); // '1'
23
- * normalizeString('a'); // 'a'
24
- *
25
- */
26
4
  function normalizeString(value) {
27
- if (isNil(value)) {
28
- return '';
29
- }
30
- return convertToString(value);
5
+ if (isNil(value)) {
6
+ return '';
7
+ }
8
+ return convertToString(value);
31
9
  }
32
- export default normalizeString;
10
+
11
+ export { normalizeString as default };
@@ -1,234 +1,115 @@
1
- import { checkBoundary } from './utils/math.util';
2
- import devWarn from './utils/devWarn';
1
+ import { checkBoundary } from './utils/math.util.js';
2
+ import devWarn from './utils/devWarn.js';
3
3
 
4
- // 简体
5
4
  var chnNumberChar = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九'];
6
5
  var chnUnitChar = ['', '十', '百', '千'];
7
-
8
- // 繁体
9
6
  var big5NumberChar = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'];
10
7
  var big5UnitChar = ['', '拾', '佰', '仟'];
11
-
12
- // 数字字符、计数单位
13
-
14
- /**
15
- * @type {string[]}
16
- * @private
17
- */
18
8
  var numberChar;
19
-
20
- /**
21
- * @type {string[]}
22
- * @private
23
- */
24
9
  var unitChar;
25
-
26
- /**
27
- * @type {string[]}
28
- * @private
29
- */
30
10
  var unitSection;
31
-
32
- /**
33
- * 每个小节的内部进行转化
34
- *
35
- * @private
36
- * @param {number} section 数字
37
- * @returns {string} 转化的数字
38
- */
39
11
  function sectionToChinese(section) {
40
- var str = '';
41
- var chnstr = '';
42
- var zero = false; //zero为是否进行补零, 第一次进行取余由于为个位数,默认不补零
43
- var unitPos = 0;
44
- while (section > 0) {
45
- // 对数字取余10,得到的数即为个位数
46
- var v = section % 10;
47
-
48
- //如果数字为零,则对字符串进行补零
49
- if (v == 0) {
50
- if (zero) {
51
- //如果遇到连续多次取余都是0,那么只需补一个零即可
52
- zero = false;
53
- chnstr = numberChar[v] + chnstr;
54
- }
55
- } else {
56
- //第一次取余之后,如果再次取余为零,则需要补零
57
- zero = true;
58
- str = numberChar[v];
59
- str += unitChar[unitPos];
60
- chnstr = str + chnstr;
12
+ var str = '';
13
+ var chnstr = '';
14
+ var zero = false;
15
+ var unitPos = 0;
16
+ while (section > 0) {
17
+ var v = section % 10;
18
+ if (v == 0) {
19
+ if (zero) {
20
+ zero = false;
21
+ chnstr = numberChar[v] + chnstr;
22
+ }
23
+ }
24
+ else {
25
+ zero = true;
26
+ str = numberChar[v];
27
+ str += unitChar[unitPos];
28
+ chnstr = str + chnstr;
29
+ }
30
+ unitPos++;
31
+ section = Math.floor(section / 10);
61
32
  }
62
- unitPos++;
63
- section = Math.floor(section / 10);
64
- }
65
- return chnstr;
33
+ return chnstr;
66
34
  }
67
-
68
- /**
69
- * 转换整数
70
- *
71
- * @private
72
- * @param {number} num 要转换的数字
73
- * @returns {string} 中文数字
74
- */
75
35
  function convertInteger(num) {
76
- var numInt = Math.floor(num);
77
- var unitPos = 0;
78
- var strIns = '';
79
- var chnStr = '';
80
- var needZero = false;
81
- if (numInt === 0) {
82
- return numberChar[0];
83
- }
84
- while (numInt > 0) {
85
- var section = numInt % 10000;
86
- if (needZero) {
87
- chnStr = numberChar[0] + chnStr;
36
+ var numInt = Math.floor(num);
37
+ var unitPos = 0;
38
+ var strIns = '';
39
+ var chnStr = '';
40
+ var needZero = false;
41
+ if (numInt === 0) {
42
+ return numberChar[0];
88
43
  }
89
- strIns = sectionToChinese(section);
90
- strIns += section !== 0 ? unitSection[unitPos] : unitSection[0];
91
- chnStr = strIns + chnStr;
92
- needZero = section < 1000 && section > 0;
93
- numInt = Math.floor(numInt / 10000);
94
- unitPos++;
95
- }
96
- return chnStr;
44
+ while (numInt > 0) {
45
+ var section = numInt % 10000;
46
+ if (needZero) {
47
+ chnStr = numberChar[0] + chnStr;
48
+ }
49
+ strIns = sectionToChinese(section);
50
+ strIns += section !== 0 ? unitSection[unitPos] : unitSection[0];
51
+ chnStr = strIns + chnStr;
52
+ needZero = section < 1000 && section > 0;
53
+ numInt = Math.floor(numInt / 10000);
54
+ unitPos++;
55
+ }
56
+ return chnStr;
97
57
  }
98
-
99
- /**
100
- * 转换小数
101
- *
102
- * @private
103
- * @param {number} num 要转换的数字
104
- */
105
58
  function convertDecimal(num) {
106
- var strNum = num + '';
107
- var index = strNum.indexOf('.');
108
- var ret = '';
109
- if (index > -1) {
110
- var decimalStr = strNum.slice(index + 1);
111
- ret = mapNumberChar(parseInt(decimalStr));
112
- }
113
- return ret;
59
+ var strNum = num + '';
60
+ var index = strNum.indexOf('.');
61
+ var ret = '';
62
+ if (index > -1) {
63
+ var decimalStr = strNum.slice(index + 1);
64
+ ret = mapNumberChar(parseInt(decimalStr));
65
+ }
66
+ return ret;
114
67
  }
115
-
116
- /**
117
- * 映射为中文数字
118
- *
119
- * @private
120
- * @param {number} num 要处理的数字
121
- * @returns {string} 返回中文数字的映射
122
- */
123
68
  function mapNumberChar(num) {
124
- var strNum = num + '';
125
- var ret = '';
126
- for (var i = 0, len = strNum.length; i < len; i++) {
127
- ret += numberChar[parseInt(strNum[i])];
128
- }
129
- return ret;
69
+ var strNum = num + '';
70
+ var ret = '';
71
+ for (var i = 0, len = strNum.length; i < len; i++) {
72
+ ret += numberChar[parseInt(strNum[i])];
73
+ }
74
+ return ret;
130
75
  }
131
-
132
- /**
133
- * 数字转中文数字<br/><br/>
134
- *
135
- * 如果数字不在安全数字 -9007199254740991~9007199254740991 范围内,处理会有异常。
136
- *
137
- * @static
138
- * @alias module:Processor.numberToChinese
139
- * @since 1.2.0
140
- * @param {number} num 数字
141
- * @param {Object} [options] 配置项
142
- * @param {boolean} [options.big5=false] 繁体
143
- * @param {boolean} [options.unit=true] 计数单位
144
- * @param {string} [options.decimal="点"] 中文小数点,繁体字为點
145
- * @param {string} [options.zero="零"] 设置0。常用配置 〇
146
- * @param {string} [options.negative="负"] 负数前面的字
147
- * @param {Object} [options.unitConfig] 节点单位配置
148
- * @param {string} [options.unitConfig.w="万"] 设置计数单位万。常用配置 萬
149
- * @param {string} [options.unitConfig.y="亿"] 设置计数单位亿。常用配置 億
150
- * @returns {string} 中文数字
151
- * @example
152
- *
153
- * numberToChinese(100); // 一百
154
- * numberToChinese(100.3); // 一百点三
155
- * numberToChinese(1234567890); // 一十二亿三千四百五十六万七千八百九十
156
- * numberToChinese(1234567890.11); // 一十二亿三千四百五十六万七千八百九十点一一
157
- *
158
- * // 繁体
159
- * numberToChinese(100, {big5: true}); // 壹佰
160
- * numberToChinese(100.3, {big5: true}); // 壹佰點叁
161
- * numberToChinese(1234567890.11, {big5: true}); // 壹拾贰亿叁仟肆佰伍拾陆万柒仟捌佰玖拾點壹壹
162
- *
163
- * // 不带计数单位
164
- * numberToChinese(1990, {unit: false}); // 一九九零
165
- *
166
- * // 不带计数单位,修改0
167
- * numberToChinese(1990, {unit: false, zero:'〇'}); // 一九九〇
168
- *
169
- */
170
- function numberToChinese(num) {
171
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
172
- var _options$big = options.big5,
173
- big5 = _options$big === void 0 ? false : _options$big,
174
- _options$unit = options.unit,
175
- unit = _options$unit === void 0 ? true : _options$unit,
176
- _options$zero = options.zero,
177
- zero = _options$zero === void 0 ? '' : _options$zero,
178
- _options$negative = options.negative,
179
- negative = _options$negative === void 0 ? '负' : _options$negative,
180
- _options$unitConfig = options.unitConfig,
181
- unitConfig = _options$unitConfig === void 0 ? {} : _options$unitConfig;
182
- var _options$decimal = options.decimal,
183
- decimal = _options$decimal === void 0 ? '' : _options$decimal;
184
-
185
- // 非数字 或 NaN 不处理
186
- if (typeof num !== 'number' || isNaN(num)) {
187
- devWarn("\u53C2\u6570\u9519\u8BEF ".concat(num, "\uFF0C\u8BF7\u4F20\u5165\u6570\u5B57"));
188
- return '';
189
- }
190
-
191
- // 超过安全数字提示
192
- checkBoundary(num);
193
-
194
- // 设置数字字符和计数单位
195
- if (big5) {
196
- numberChar = big5NumberChar.slice();
197
- unitChar = big5UnitChar.slice();
198
- decimal = decimal || '點';
199
- } else {
200
- numberChar = chnNumberChar.slice();
201
- unitChar = chnUnitChar.slice();
202
- decimal = decimal || '点';
203
- }
204
-
205
- // 设置节点计数单位,万、亿、万亿
206
- var unitWan = (unitConfig === null || unitConfig === void 0 ? void 0 : unitConfig.w) || '万';
207
- var unitYi = (unitConfig === null || unitConfig === void 0 ? void 0 : unitConfig.y) || '亿';
208
- var unitWanYi = unitWan + unitYi;
209
- unitSection = ['', unitWan, unitYi, unitWanYi];
210
-
211
- // 设置0
212
- if (zero) {
213
- numberChar[0] = zero;
214
- }
215
-
216
- // 前置字符,负数处理
217
- var preStr = num < 0 ? negative : '';
218
-
219
- // 整数和小数
220
- var chnInteger, chnDecimal;
221
- var numAbs = Math.abs(num);
222
-
223
- // 处理整数
224
- if (unit) {
225
- chnInteger = convertInteger(numAbs);
226
- } else {
227
- chnInteger = mapNumberChar(Math.floor(numAbs));
228
- }
229
-
230
- // 处理小数
231
- chnDecimal = convertDecimal(numAbs);
232
- return chnDecimal ? "".concat(preStr).concat(chnInteger).concat(decimal).concat(chnDecimal) : "".concat(preStr).concat(chnInteger);
76
+ function numberToChinese(num, options) {
77
+ if (options === void 0) { options = {}; }
78
+ var _a = options.big5, big5 = _a === void 0 ? false : _a, _b = options.unit, unit = _b === void 0 ? true : _b, _c = options.zero, zero = _c === void 0 ? '' : _c, _d = options.negative, negative = _d === void 0 ? '负' : _d, _e = options.unitConfig, unitConfig = _e === void 0 ? {} : _e;
79
+ var _f = options.decimal, decimal = _f === void 0 ? '' : _f;
80
+ if (typeof num !== 'number' || isNaN(num)) {
81
+ devWarn("\u53C2\u6570\u9519\u8BEF ".concat(num, "\uFF0C\u8BF7\u4F20\u5165\u6570\u5B57"));
82
+ return '';
83
+ }
84
+ checkBoundary(num);
85
+ if (big5) {
86
+ numberChar = big5NumberChar.slice();
87
+ unitChar = big5UnitChar.slice();
88
+ decimal = decimal || '點';
89
+ }
90
+ else {
91
+ numberChar = chnNumberChar.slice();
92
+ unitChar = chnUnitChar.slice();
93
+ decimal = decimal || '点';
94
+ }
95
+ var unitWan = (unitConfig === null || unitConfig === void 0 ? void 0 : unitConfig.w) || '万';
96
+ var unitYi = (unitConfig === null || unitConfig === void 0 ? void 0 : unitConfig.y) || '亿';
97
+ var unitWanYi = unitWan + unitYi;
98
+ unitSection = ['', unitWan, unitYi, unitWanYi];
99
+ if (zero) {
100
+ numberChar[0] = zero;
101
+ }
102
+ var preStr = num < 0 ? negative : '';
103
+ var chnInteger;
104
+ var numAbs = Math.abs(num);
105
+ if (unit) {
106
+ chnInteger = convertInteger(numAbs);
107
+ }
108
+ else {
109
+ chnInteger = mapNumberChar(Math.floor(numAbs));
110
+ }
111
+ var chnDecimal = convertDecimal(numAbs);
112
+ return chnDecimal ? "".concat(preStr).concat(chnInteger).concat(decimal).concat(chnDecimal) : "".concat(preStr).concat(chnInteger);
233
113
  }
234
- export default numberToChinese;
114
+
115
+ export { numberToChinese as default };