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
package/esm/ajax.js CHANGED
@@ -1,149 +1,53 @@
1
- import _typeof from "@babel/runtime/helpers/typeof";
2
- /**
3
- * @typedef {XMLHttpRequest['onloadstart']} XMLHttpRequestEvent XMLHttpRequest 事件对象
4
- */
5
-
6
- /**
7
- * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/API/XMLHttpRequest|XMLHttpRequest}
8
- * @typedef {Object} AjaxOptions ajax配置项
9
- * @property {string} [method="get"] 创建请求时使用的方法
10
- * @property {Document | XMLHttpRequestBodyInit | null} [data=null] 请求体被发送的数据
11
- * @property {Object.<string, string>} [headers] 自定义请求头
12
- * @property {XMLHttpRequestResponseType} [responseType] 响应类型
13
- * @property {number} [timeout] 请求超时的毫秒数
14
- * @property {boolean} [withCredentials=false] 跨域请求时是否需要使用凭证
15
- * @property {boolean} [async=true] 是否异步执行操作
16
- * @property {string|null} [user=null] 用户名,用于认证用途
17
- * @property {string|null} [password=null] 密码,用于认证用途
18
- * @property {XMLHttpRequestEvent} [onLoadStart] 接收到响应数据时触发
19
- * @property {XMLHttpRequestEvent} [onProgress] 请求接收到更多数据时,周期性地触发
20
- * @property {XMLHttpRequestEvent} [onAbort] 当 request 被停止时触发,例如当程序调用 XMLHttpRequest.abort() 时
21
- * @property {XMLHttpRequestEvent} [onTimeout] 在预设时间内没有接收到响应时触发
22
- * @property {XMLHttpRequestEvent} [onError] 当 request 遭遇错误时触发
23
- * @property {XMLHttpRequestEvent} [onLoad] 请求成功完成时触发
24
- * @property {XMLHttpRequestEvent} [onLoadEnd] 请求结束时触发,无论请求成功 (load) 还是失败 (abort 或 error)
25
- */
26
-
27
- /**
28
- * 请求<br/><br/>
29
- *
30
- * <em style="font-weight: bold;">注意:该方法仅适用于浏览器端。</em>
31
- *
32
- * @static
33
- * @alias module:Other.ajax
34
- * @since 4.16.0
35
- * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/API/XMLHttpRequest|XMLHttpRequest}
36
- * @param {string} url 地址
37
- * @param {AjaxOptions} [options] 配置项
38
- * @returns {Promise<ProgressEvent<EventTarget>>}
39
- * @example
40
- * ajax('/somefile').then(res=>{
41
- * // do something
42
- * });
43
- *
44
- * ajax('/api', { method: 'post' }).then(res=>{
45
- * // do something
46
- * });
47
- */
48
1
  function ajax(url, options) {
49
- var _ref = options || {},
50
- _ref$method = _ref.method,
51
- method = _ref$method === void 0 ? 'get' : _ref$method,
52
- _ref$data = _ref.data,
53
- data = _ref$data === void 0 ? null : _ref$data,
54
- timeout = _ref.timeout,
55
- headers = _ref.headers,
56
- _ref$withCredentials = _ref.withCredentials,
57
- withCredentials = _ref$withCredentials === void 0 ? false : _ref$withCredentials,
58
- _ref$async = _ref.async,
59
- async = _ref$async === void 0 ? true : _ref$async,
60
- _ref$user = _ref.user,
61
- user = _ref$user === void 0 ? null : _ref$user,
62
- _ref$password = _ref.password,
63
- password = _ref$password === void 0 ? null : _ref$password,
64
- responseType = _ref.responseType,
65
- onAbort = _ref.onAbort,
66
- onError = _ref.onError,
67
- onLoad = _ref.onLoad,
68
- onLoadEnd = _ref.onLoadEnd,
69
- onLoadStart = _ref.onLoadStart,
70
- onProgress = _ref.onProgress,
71
- onTimeout = _ref.onTimeout;
72
- return new Promise(function (resolve, reject) {
73
- var xhr = new XMLHttpRequest();
74
- xhr.open(method.toLowerCase(), url, async, user, password);
75
-
76
- // 设置请求超时
77
- if (typeof timeout === 'number' && timeout > 0) {
78
- xhr.timeout = timeout;
79
- }
80
-
81
- // 跨域请求时是否需要使用凭证
82
- xhr.withCredentials = withCredentials;
83
-
84
- // 设置响应类型
85
- if (responseType) {
86
- xhr.responseType = responseType;
87
- }
88
-
89
- // 设置请求头
90
- if (_typeof(headers) === 'object') {
91
- Object.keys(headers).map(function (item) {
92
- xhr.setRequestHeader(item, headers[item]);
93
- });
94
- }
95
-
96
- /**
97
- * 请求成功异步调用
98
- * @param {XMLHttpRequestEvent} [cb] 回调方法
99
- */
100
- var wrapSuccess = function wrapSuccess(cb) {
101
- /**
102
- * 内部方法
103
- * @param {ProgressEvent<EventTarget>} e 事件对象
104
- */
105
- return function (e) {
106
- resolve(e);
107
- cb === null || cb === void 0 ? void 0 : cb.call(xhr, e);
108
- };
109
- };
110
-
111
- /**
112
- * 请求失败(中断/超时/失败)处理
113
- * @param {XMLHttpRequestEvent} [cb] 回调方法
114
- */
115
- var wrapError = function wrapError(cb) {
116
- /**
117
- * 内部方法
118
- * @param {ProgressEvent<EventTarget>} e 事件对象
119
- */
120
- return function (e) {
121
- reject(e);
122
- cb === null || cb === void 0 ? void 0 : cb.call(xhr, e);
123
- };
124
- };
125
-
126
- // 事件处理
127
- /**@type {Object.<keyof XMLHttpRequestEventTargetEventMap, XMLHttpRequestEvent | undefined>} */
128
- var events = {
129
- loadstart: onLoadStart,
130
- progress: onProgress,
131
- abort: wrapError(onAbort),
132
- timeout: wrapError(onTimeout),
133
- error: wrapError(onError),
134
- load: wrapSuccess(onLoad),
135
- loadend: onLoadEnd
136
- };
137
- /**@type {(keyof XMLHttpRequestEventTargetEventMap)[]} */
138
- // @ts-ignore
139
- var eventNames = Object.keys(events);
140
- eventNames.map(function (item) {
141
- var func = events[item];
142
- if (func) {
143
- xhr.addEventListener(item, func);
144
- }
2
+ var _a = options || {}, _b = _a.method, method = _b === void 0 ? 'get' : _b, _c = _a.data, data = _c === void 0 ? null : _c, timeout = _a.timeout, headers = _a.headers, _d = _a.withCredentials, withCredentials = _d === void 0 ? false : _d, _e = _a.async, async = _e === void 0 ? true : _e, _f = _a.user, user = _f === void 0 ? null : _f, _g = _a.password, password = _g === void 0 ? null : _g, responseType = _a.responseType, onReadyStateChange = _a.onReadyStateChange, onLoadStart = _a.onLoadStart, onProgress = _a.onProgress, onAbort = _a.onAbort, onTimeout = _a.onTimeout, onError = _a.onError, onLoad = _a.onLoad, onLoadEnd = _a.onLoadEnd;
3
+ return new Promise(function (resolve, reject) {
4
+ var xhr = new XMLHttpRequest();
5
+ xhr.open(method.toLowerCase(), url, async, user, password);
6
+ if (onReadyStateChange) {
7
+ xhr.onreadystatechange = onReadyStateChange;
8
+ }
9
+ if (typeof timeout === 'number' && timeout > 0) {
10
+ xhr.timeout = timeout;
11
+ }
12
+ xhr.withCredentials = withCredentials;
13
+ if (responseType) {
14
+ xhr.responseType = responseType;
15
+ }
16
+ if (typeof headers === 'object') {
17
+ Object.keys(headers).map(function (item) {
18
+ xhr.setRequestHeader(item, headers[item]);
19
+ });
20
+ }
21
+ var wrapSuccess = function (cb) {
22
+ return function (e) {
23
+ resolve(e);
24
+ cb === null || cb === void 0 ? void 0 : cb.call(xhr, e);
25
+ };
26
+ };
27
+ var wrapError = function (cb) {
28
+ return function (e) {
29
+ reject(e);
30
+ cb === null || cb === void 0 ? void 0 : cb.call(xhr, e);
31
+ };
32
+ };
33
+ var events = {
34
+ loadstart: onLoadStart,
35
+ progress: onProgress,
36
+ abort: wrapError(onAbort),
37
+ timeout: wrapError(onTimeout),
38
+ error: wrapError(onError),
39
+ load: wrapSuccess(onLoad),
40
+ loadend: onLoadEnd
41
+ };
42
+ var eventKeys = Object.keys(events);
43
+ eventKeys.map(function (item) {
44
+ var func = events[item];
45
+ if (func) {
46
+ xhr.addEventListener(item, func);
47
+ }
48
+ });
49
+ xhr.send(data);
145
50
  });
146
- xhr.send(data);
147
- });
148
51
  }
149
- export default ajax;
52
+
53
+ export { ajax as default };
@@ -1,37 +1,7 @@
1
- // file、blob文件如何预览图片?
2
- // 方法1:将file或者blob类型文件转成base64数据,再作为src赋值给img标签
3
- // 方法2:使用 window.URL.createObjectURL(blob) 为blob、file 创建一个指向该参数对象的URL
1
+ import fileReader from './fileReader.js';
4
2
 
5
- import fileReader from "./fileReader";
6
-
7
- /**
8
- * 将 Blob 或 File 对象转成 data:URL 格式的 Base64 字符串<br/><br/>
9
- *
10
- * <em style="font-weight: bold;">注意:该方法仅适用于浏览器端。</em>
11
- *
12
- * @ignore
13
- * @static
14
- * @alias module:Processor.blobToDataURL
15
- * @since 4.1.0
16
- * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/API/FileReader/readAsDataURL|FileReader.readAsDataURL()}
17
- * @deprecated 请使用 `fileReader` 方法
18
- * @param {Blob} blob Blob 或 File 对象
19
- * @returns {Promise<string>} data:URL 格式的 Base64 字符串。
20
- * @example
21
- * const aFileParts = ['<a id="a"><b id="b">hey!</b></a>']; // 一个包含DOMString的数组
22
- * const htmlBlob = new Blob(aFileParts, { type: 'text/html' }); // 得到 blob
23
- *
24
- * blobToDataURL(htmlBlob).then(data=>{
25
- * console.log(data); // data:text/html;base64,PGEgaWQ9ImEiPjxiIGlkPSJiIj5oZXkhPC9iPjwvYT4=
26
- * });
27
- *
28
- * const textBlob = new Blob(aFileParts, { type: 'text/plain' });
29
- *
30
- * blobToDataURL(textBlob).then(data=>{
31
- * console.log(data); // data:text/plain;base64,PGEgaWQ9ImEiPjxiIGlkPSJiIj5oZXkhPC9iPjwvYT4=
32
- * });
33
- */
34
3
  function blobToDataURL(blob) {
35
- return fileReader(blob);
4
+ return fileReader(blob);
36
5
  }
37
- export default blobToDataURL;
6
+
7
+ export { blobToDataURL as default };
@@ -1,38 +1,13 @@
1
- /**
2
- * 字节转换存储单位,保留2位小数点
3
- *
4
- * @static
5
- * @alias module:Processor.bytesToSize
6
- * @since 3.8.0
7
- * @param {number} bytes 字节大小
8
- * @param {Object} [options] 配置项
9
- * @param {string} [options.spaceMark=' '] 间隔字符
10
- * @param {number} [options.precision=2] 精度
11
- * @returns {string} 存储单位值
12
- * @example
13
- *
14
- * bytesToSize(0); // 0 B
15
- * bytesToSize(1024); // 1 KB
16
- * bytesToSize(3.213243*1024*1024); // 3.21 MB
17
- * bytesToSize(1024*1024*1024); // 1 GB
18
- *
19
- * // 自定义间隔符号
20
- * bytesToSize(0, { spaceMark: '' }); // 0B
21
- * bytesToSize(1024, { spaceMark: '' }); // 1KB
22
- *
23
- */
24
- function bytesToSize(bytes) {
25
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
26
- var _options$spaceMark = options.spaceMark,
27
- spaceMark = _options$spaceMark === void 0 ? ' ' : _options$spaceMark,
28
- _options$precision = options.precision,
29
- precision = _options$precision === void 0 ? 2 : _options$precision;
30
- var numBytes = typeof bytes !== 'number' ? Number(bytes) : bytes;
31
- if (numBytes === 0 || isNaN(numBytes)) return "0".concat(spaceMark, "B");
32
- var k = 1024;
33
- // 存储单位
34
- var sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
35
- var i = Math.floor(Math.log(numBytes) / Math.log(k));
36
- return sizes[i] ? "".concat(Number((numBytes / Math.pow(k, i)).toFixed(precision))).concat(spaceMark).concat(sizes[i]) : numBytes + '';
1
+ function bytesToSize(bytes, options) {
2
+ if (options === void 0) { options = {}; }
3
+ var _a = options.spaceMark, spaceMark = _a === void 0 ? ' ' : _a, _b = options.precision, precision = _b === void 0 ? 2 : _b;
4
+ var numBytes = typeof bytes !== 'number' ? Number(bytes) : bytes;
5
+ if (numBytes === 0 || isNaN(numBytes))
6
+ return "0".concat(spaceMark, "B");
7
+ var k = 1024;
8
+ var sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
9
+ var i = Math.floor(Math.log(numBytes) / Math.log(k));
10
+ return sizes[i] ? "".concat(Number((numBytes / Math.pow(k, i)).toFixed(precision))).concat(spaceMark).concat(sizes[i]) : numBytes + '';
37
11
  }
38
- export default bytesToSize;
12
+
13
+ export { bytesToSize as default };
@@ -1,55 +1,33 @@
1
- import normalizeString from './normalizeString';
1
+ import normalizeString from './normalizeString.js';
2
2
 
3
- // ref: https://github.com/ant-design/ant-design-mobile/blob/v2/components/input-item/index.tsx#L240
4
-
5
- /**
6
- * 计算输入框的值格式化后光标位置
7
- *
8
- * @static
9
- * @alias module:Other.calculateCursorPosition
10
- * @since 4.6.0
11
- * @see {@link https://2950v9.csb.app/|h5示例}
12
- * @see {@link https://33ccy9.csb.app/|react示例}
13
- * @param {number} prevPos 赋值前的光标位置,onChange/onInput的光标位置 e.target.selectionEnd
14
- * @param {string} prevCtrlValue 上一个格式化后的值
15
- * @param {string} rawValue 当前输入原值
16
- * @param {string} ctrlValue 当前格式化后的值
17
- * @param {Object} [options] 配置项
18
- * @param {string[]|string} [options.placeholderChar=' '] 占位符
19
- * @param {RegExp} [options.maskReg=/\D/g] 需要遮盖的字符规则。默认去掉非数字,意味着 ctrlValue 需要去掉非数字。
20
- * @param {'mobile'|'bankCard'} [options.type] 格式化类型,内置手机号码和银行卡号特殊处理
21
- * @returns {number} 格式化后的光标位置
22
- */
23
- function calculateCursorPosition(prevPos, prevCtrlValue, rawValue, ctrlValue) {
24
- var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
25
- var _options$placeholderC = options.placeholderChar,
26
- placeholderChar = _options$placeholderC === void 0 ? ' ' : _options$placeholderC,
27
- _options$maskReg = options.maskReg,
28
- maskReg = _options$maskReg === void 0 ? /\D/g : _options$maskReg,
29
- type = options.type;
30
- var realCtrlValue = normalizeString(prevCtrlValue);
31
- var realRawValue = normalizeString(rawValue);
32
- var placeholderChars = Array.isArray(placeholderChar) ? placeholderChar : [placeholderChar];
33
- var editLength = realRawValue.length - realCtrlValue.length;
34
- var isAddition = editLength > 0;
35
- var pos = prevPos;
36
- if (isAddition) {
37
- var additionStr = realRawValue.substring(pos - editLength, pos);
38
- var ctrlCharCount = additionStr.replace(maskReg, '').length;
39
- pos -= editLength - ctrlCharCount;
40
- var placeholderCharCount = 0;
41
- while (ctrlCharCount > 0) {
42
- if (placeholderChars.indexOf(ctrlValue.charAt(pos - ctrlCharCount + placeholderCharCount)) !== -1) {
43
- placeholderCharCount++;
44
- } else {
45
- ctrlCharCount--;
46
- }
3
+ function calculateCursorPosition(prevPos, prevCtrlValue, rawValue, ctrlValue, options) {
4
+ if (options === void 0) { options = {}; }
5
+ var _a = options.placeholderChar, placeholderChar = _a === void 0 ? ' ' : _a, _b = options.maskReg, maskReg = _b === void 0 ? /\D/g : _b, type = options.type;
6
+ var realCtrlValue = normalizeString(prevCtrlValue);
7
+ var realRawValue = normalizeString(rawValue);
8
+ var placeholderChars = Array.isArray(placeholderChar) ? placeholderChar : [placeholderChar];
9
+ var editLength = realRawValue.length - realCtrlValue.length;
10
+ var isAddition = editLength > 0;
11
+ var pos = prevPos;
12
+ if (isAddition) {
13
+ var additionStr = realRawValue.substring(pos - editLength, pos);
14
+ var ctrlCharCount = additionStr.replace(maskReg, '').length;
15
+ pos -= editLength - ctrlCharCount;
16
+ var placeholderCharCount = 0;
17
+ while (ctrlCharCount > 0) {
18
+ if (placeholderChars.indexOf(ctrlValue.charAt(pos - ctrlCharCount + placeholderCharCount)) !== -1) {
19
+ placeholderCharCount++;
20
+ }
21
+ else {
22
+ ctrlCharCount--;
23
+ }
24
+ }
25
+ pos += placeholderCharCount;
26
+ }
27
+ if ((type === 'mobile' && (pos === 4 || pos === 9)) || (type === 'bankCard' && pos > 0 && pos % 5 === 0)) {
28
+ pos -= 1;
47
29
  }
48
- pos += placeholderCharCount;
49
- }
50
- if (type === 'mobile' && (pos === 4 || pos === 9) || type === 'bankCard' && pos > 0 && pos % 5 === 0) {
51
- pos -= 1;
52
- }
53
- return pos;
30
+ return pos;
54
31
  }
55
- export default calculateCursorPosition;
32
+
33
+ export { calculateCursorPosition as default };
@@ -1,29 +1,15 @@
1
- /**
2
- * DataURL 转为 Blob 对象
3
- *
4
- * @static
5
- * @alias module:Processor.dataURLToBlob
6
- * @since 4.1.0
7
- * @see {@link https://developer.mozilla.org/zh-CN/docs/Glossary/Base64|Base64}
8
- * @param {string} dataurl data: 协议的URL
9
- * @returns {Blob} Blob 对象
10
- * @example
11
- * const dataurl = 'data:text/html;base64,PGEgaWQ9ImEiPjxiIGlkPSJiIj5oZXkhPC9iPjwvYT4=';
12
- * dataURLToBlob(dataurl); // Blob {size: 32, type: 'text/html'}
13
- */
14
- function dataURLToBlob(dataurl) {
15
- var parts = dataurl.split(',');
16
- var meta = parts[0].substring(5).split(';');
17
- var type = meta[0];
18
- var decoder = meta.indexOf('base64') !== -1 ? atob : decodeURIComponent;
19
- var bstr = decoder(parts[1]);
20
- var n = bstr.length;
21
- var u8arr = new Uint8Array(n);
22
- while (n--) {
23
- u8arr[n] = bstr.charCodeAt(n);
24
- }
25
- return new Blob([u8arr], {
26
- type: type
27
- });
1
+ function dataURLToBlob(data) {
2
+ var parts = data.split(',');
3
+ var meta = parts[0].substring(5).split(';');
4
+ var type = meta[0];
5
+ var decoder = meta.indexOf('base64') !== -1 ? atob : decodeURIComponent;
6
+ var bstr = decoder(parts[1]);
7
+ var n = bstr.length;
8
+ var u8arr = new Uint8Array(n);
9
+ while (n--) {
10
+ u8arr[n] = bstr.charCodeAt(n);
11
+ }
12
+ return new Blob([u8arr], { type: type });
28
13
  }
29
- export default dataURLToBlob;
14
+
15
+ export { dataURLToBlob as default };
package/esm/divide.js CHANGED
@@ -1,51 +1,27 @@
1
- import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
- import { strip, digitLength, float2Fixed, checkBoundary, transformEffectiveNumber } from './utils/math.util';
3
- import times from './times';
1
+ import { __read, __spreadArray } from 'tslib';
2
+ import { transformEffectiveNumber, float2Fixed, checkBoundary, strip, digitLength } from './utils/math.util.js';
3
+ import times from './times.js';
4
+ import _isNaN from './utils/type/isNaN.js';
4
5
 
5
- /**
6
- * 精确除法,支持多个数相除,除数默认为 1 。
7
- *
8
- * @static
9
- * @alias module:Math.divide
10
- * @since 3.1.0
11
- * @param {...number|string} nums 被除数和除数
12
- * @returns {number} 商数
13
- * @example
14
- *
15
- * divide(1.21); // 1.21 除数默认为 1 ,即 1.21/1 = 1.21
16
- * divide(1.21, 1.1); // 1.1
17
- * divide(1000, 10, 10); // 10
18
- * divide(1000, 10, 10, 10); // 1
19
- *
20
- * divide(); // NaN 如果没有传入参数,被除数默认为 undefined 。 Number(undefined) 转换为 NaN ,NaN/1 = NaN
21
- * divide(null); // 0 Number(null) 转换为 0 , 0/1 = 0
22
- * divide('1.5 ', 0.5); // 3 Number('1.5 ') 转换为 1.5 ,1.5/0.5 = 3
23
- *
24
- */
25
6
  function divide() {
26
- for (var _len = arguments.length, nums = new Array(_len), _key = 0; _key < _len; _key++) {
27
- nums[_key] = arguments[_key];
28
- }
29
- var num1 = nums[0],
30
- _nums$ = nums[1],
31
- num2 = _nums$ === void 0 ? 1 : _nums$,
32
- rest = nums.slice(2);
33
- if (rest.length > 0) {
34
- return divide.apply(void 0, [divide(num1, num2)].concat(_toConsumableArray(rest)));
35
- }
36
- num1 = transformEffectiveNumber(num1);
37
- num2 = transformEffectiveNumber(num2);
38
-
39
- // 兼容处理,如果参数包含无效数值时,返回 NaN
40
- // @ts-ignore
41
- if (isNaN(num1) || isNaN(num2)) {
42
- return Number.NaN;
43
- }
44
- var num1Changed = float2Fixed(num1);
45
- var num2Changed = float2Fixed(num2);
46
- checkBoundary(num1Changed);
47
- checkBoundary(num2Changed);
48
- // fix: 类似 10 ** -4 为 0.00009999999999999999,strip 修正
49
- return times(num1Changed / num2Changed, strip(Math.pow(10, digitLength(num2) - digitLength(num1))));
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 ? 1 : _b, rest = _a.slice(2);
12
+ if (rest.length > 0) {
13
+ return divide.apply(void 0, __spreadArray([divide(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 num1Changed = float2Fixed(num1);
21
+ var num2Changed = float2Fixed(num2);
22
+ checkBoundary(num1Changed);
23
+ checkBoundary(num2Changed);
24
+ return times(num1Changed / num2Changed, strip(Math.pow(10, digitLength(num2) - digitLength(num1))));
50
25
  }
51
- export default divide;
26
+
27
+ export { divide as default };