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.
- package/dist/util-helpers.js +1542 -4040
- package/dist/util-helpers.js.map +1 -1
- package/dist/util-helpers.min.js +1 -1
- package/dist/util-helpers.min.js.map +1 -1
- package/esm/ajax.js +50 -146
- package/esm/blobToDataURL.js +4 -34
- package/esm/bytesToSize.js +12 -37
- package/esm/calculateCursorPosition.js +30 -52
- package/esm/dataURLToBlob.js +14 -28
- package/esm/divide.js +24 -48
- package/esm/download.js +83 -164
- package/esm/fileReader.js +18 -64
- package/esm/filterTree.js +25 -55
- package/esm/findTreeNode.js +39 -67
- package/esm/findTreeNodes.js +35 -66
- package/esm/findTreeSelect.js +38 -74
- package/esm/formatBankCard.js +13 -43
- package/esm/formatMobile.js +17 -43
- package/esm/formatMoney.js +59 -139
- package/esm/index.js +55 -130
- package/esm/isBankCard.js +22 -57
- package/esm/isBusinessLicense.js +32 -78
- package/esm/isChinese.js +23 -66
- package/esm/isEmail.js +6 -21
- package/esm/isHMCard.js +5 -28
- package/esm/isIPv4.js +5 -22
- package/esm/isIPv6.js +5 -36
- package/esm/isIdCard.js +27 -66
- package/esm/isMobile.js +5 -20
- package/esm/isPassport.js +5 -22
- package/esm/isPassword.js +7 -48
- package/esm/isPostcode.js +5 -20
- package/esm/isPromiseLike.js +3 -18
- package/esm/isQQ.js +5 -20
- package/esm/isSocialCreditCode.js +28 -83
- package/esm/isSwiftCode.js +6 -25
- package/esm/isTWCard.js +11 -37
- package/esm/isTelephone.js +6 -27
- package/esm/isUrl.js +5 -44
- package/esm/isVehicle.js +5 -28
- package/esm/isWX.js +5 -20
- package/esm/listToTree.js +51 -120
- package/esm/minus.js +21 -39
- package/esm/normalizeString.js +8 -29
- package/esm/numberToChinese.js +96 -215
- package/esm/padZero.js +14 -36
- package/esm/parseIdCard.js +64 -129
- package/esm/plus.js +21 -39
- package/esm/randomString.js +13 -45
- package/esm/replaceChar.js +27 -77
- package/esm/round.js +14 -31
- package/esm/safeDate.js +12 -55
- package/esm/setDataURLPrefix.js +6 -29
- package/esm/strlen.js +14 -30
- package/esm/times.js +24 -42
- package/esm/transformFieldNames.js +37 -93
- package/esm/treeToList.js +25 -84
- package/esm/utils/config.js +4 -14
- package/esm/utils/constants.js +4 -4
- package/esm/utils/convertToString.js +4 -9
- package/esm/utils/devWarn.js +11 -11
- package/esm/utils/math.util.js +95 -181
- package/esm/utils/type/isBlob.js +4 -24
- package/esm/utils/type/isNaN.js +4 -19
- package/esm/utils/type/isNil.js +5 -13
- package/esm/utils/type/isNull.js +3 -18
- package/esm/utils/type/isNumber.js +4 -28
- package/esm/utils/type/isObject.js +4 -23
- package/esm/utils/type/isString.js +4 -19
- package/esm/utils/type/isSymbol.js +4 -19
- package/esm/utils/type/isType.js +3 -12
- package/esm/utils/type/isUndefined.js +3 -21
- package/esm/validatePassword.js +86 -237
- package/esm/waitTime.js +7 -26
- package/lib/ajax.js +51 -152
- package/lib/blobToDataURL.js +5 -40
- package/lib/bytesToSize.js +13 -43
- package/lib/calculateCursorPosition.js +32 -58
- package/lib/dataURLToBlob.js +15 -34
- package/lib/divide.js +26 -60
- package/lib/download.js +85 -169
- package/lib/fileReader.js +19 -70
- package/lib/filterTree.js +27 -66
- package/lib/findTreeNode.js +40 -77
- package/lib/findTreeNodes.js +36 -76
- package/lib/findTreeSelect.js +40 -82
- package/lib/formatBankCard.js +15 -50
- package/lib/formatMobile.js +19 -50
- package/lib/formatMoney.js +60 -150
- package/lib/index.js +117 -395
- package/lib/isBankCard.js +24 -64
- package/lib/isBusinessLicense.js +34 -85
- package/lib/isChinese.js +24 -73
- package/lib/isEmail.js +7 -27
- package/lib/isHMCard.js +7 -35
- package/lib/isIPv4.js +7 -29
- package/lib/isIPv6.js +7 -43
- package/lib/isIdCard.js +29 -73
- package/lib/isMobile.js +7 -27
- package/lib/isPassport.js +7 -29
- package/lib/isPassword.js +9 -55
- package/lib/isPostcode.js +7 -27
- package/lib/isPromiseLike.js +4 -24
- package/lib/isQQ.js +7 -27
- package/lib/isSocialCreditCode.js +30 -90
- package/lib/isSwiftCode.js +7 -32
- package/lib/isTWCard.js +13 -44
- package/lib/isTelephone.js +7 -33
- package/lib/isUrl.js +6 -49
- package/lib/isVehicle.js +7 -35
- package/lib/isWX.js +7 -27
- package/lib/listToTree.js +53 -131
- package/lib/minus.js +23 -51
- package/lib/normalizeString.js +10 -36
- package/lib/numberToChinese.js +98 -222
- package/lib/padZero.js +16 -43
- package/lib/parseIdCard.js +65 -138
- package/lib/plus.js +23 -51
- package/lib/randomString.js +14 -51
- package/lib/replaceChar.js +28 -83
- package/lib/round.js +15 -37
- package/lib/safeDate.js +13 -63
- package/lib/setDataURLPrefix.js +7 -35
- package/lib/strlen.js +16 -37
- package/lib/times.js +26 -53
- package/lib/transformFieldNames.js +38 -101
- package/lib/treeToList.js +27 -94
- package/lib/utils/config.js +6 -23
- package/lib/utils/constants.js +3 -11
- package/lib/utils/convertToString.js +6 -16
- package/lib/utils/devWarn.js +13 -17
- package/lib/utils/math.util.js +95 -185
- package/lib/utils/type/isBlob.js +6 -31
- package/lib/utils/type/isNaN.js +6 -26
- package/lib/utils/type/isNil.js +7 -20
- package/lib/utils/type/isNull.js +4 -24
- package/lib/utils/type/isNumber.js +6 -35
- package/lib/utils/type/isObject.js +5 -29
- package/lib/utils/type/isString.js +6 -26
- package/lib/utils/type/isSymbol.js +6 -26
- package/lib/utils/type/isType.js +4 -18
- package/lib/utils/type/isUndefined.js +4 -27
- package/lib/validatePassword.js +87 -244
- package/lib/waitTime.js +8 -32
- package/package.json +21 -25
- package/types/ajax.d.ts +38 -95
- package/types/blobToDataURL.d.ts +2 -2
- package/types/bytesToSize.d.ts +7 -6
- package/types/calculateCursorPosition.d.ts +10 -9
- package/types/dataURLToBlob.d.ts +5 -5
- package/types/divide.d.ts +2 -2
- package/types/download.d.ts +22 -38
- package/types/fileReader.d.ts +35 -2
- package/types/filterTree.d.ts +6 -7
- package/types/findTreeNode.d.ts +5 -7
- package/types/findTreeNodes.d.ts +5 -7
- package/types/findTreeSelect.d.ts +5 -7
- package/types/formatBankCard.d.ts +8 -5
- package/types/formatMobile.d.ts +7 -4
- package/types/formatMoney.d.ts +8 -7
- package/types/index.d.ts +125 -55
- package/types/isBankCard.d.ts +9 -8
- package/types/isBusinessLicense.d.ts +8 -5
- package/types/isChinese.d.ts +9 -8
- package/types/isEmail.d.ts +1 -1
- package/types/isHMCard.d.ts +2 -2
- package/types/isIPv4.d.ts +1 -1
- package/types/isIPv6.d.ts +1 -1
- package/types/isIdCard.d.ts +8 -7
- package/types/isMobile.d.ts +1 -1
- package/types/isPassport.d.ts +2 -2
- package/types/isPassword.d.ts +4 -7
- package/types/isPostcode.d.ts +1 -1
- package/types/isPromiseLike.d.ts +1 -1
- package/types/isQQ.d.ts +1 -1
- package/types/isSocialCreditCode.d.ts +8 -5
- package/types/isSwiftCode.d.ts +2 -2
- package/types/isTWCard.d.ts +6 -5
- package/types/isTelephone.d.ts +1 -1
- package/types/isUrl.d.ts +2 -2
- package/types/isVehicle.d.ts +2 -2
- package/types/isWX.d.ts +1 -1
- package/types/listToTree.d.ts +12 -12
- package/types/minus.d.ts +3 -2
- package/types/normalizeString.d.ts +2 -2
- package/types/numberToChinese.d.ts +13 -12
- package/types/padZero.d.ts +2 -2
- package/types/parseIdCard.d.ts +17 -56
- package/types/plus.d.ts +3 -2
- package/types/randomString.d.ts +2 -2
- package/types/replaceChar.d.ts +15 -11
- package/types/round.d.ts +2 -2
- package/types/safeDate.d.ts +24 -2
- package/types/setDataURLPrefix.d.ts +5 -5
- package/types/strlen.d.ts +1 -1
- package/types/times.d.ts +3 -2
- package/types/transformFieldNames.d.ts +12 -10
- package/types/treeToList.d.ts +1 -1
- package/types/utils/config.d.ts +6 -5
- package/types/utils/constants.d.ts +2 -2
- package/types/utils/convertToString.d.ts +1 -1
- package/types/utils/devWarn.d.ts +1 -1
- package/types/utils/math.util.d.ts +15 -9
- package/types/utils/type/index.d.ts +7 -0
- package/types/utils/type/isArguments.d.ts +1 -1
- package/types/utils/type/isArray.d.ts +1 -1
- package/types/utils/type/isArrayBuffer.d.ts +1 -1
- package/types/utils/type/isBlob.d.ts +1 -1
- package/types/utils/type/isBoolean.d.ts +1 -1
- package/types/utils/type/isDate.d.ts +1 -1
- package/types/utils/type/isError.d.ts +1 -1
- package/types/utils/type/isFunction.d.ts +1 -1
- package/types/utils/type/isMap.d.ts +1 -1
- package/types/utils/type/isNaN.d.ts +1 -1
- package/types/utils/type/isNil.d.ts +1 -1
- package/types/utils/type/isNull.d.ts +1 -1
- package/types/utils/type/isNumber.d.ts +1 -1
- package/types/utils/type/isObject.d.ts +1 -1
- package/types/utils/type/isRegExp.d.ts +1 -1
- package/types/utils/type/isSet.d.ts +1 -1
- package/types/utils/type/isString.d.ts +1 -1
- package/types/utils/type/isSymbol.d.ts +1 -1
- package/types/utils/type/isType.d.ts +1 -1
- package/types/utils/type/isUndefined.d.ts +1 -1
- package/types/utils/type/isWeakMap.d.ts +1 -1
- package/types/utils/type/isWeakSet.d.ts +1 -1
- package/types/validatePassword.d.ts +17 -48
- package/types/waitTime.d.ts +2 -2
- package/esm/interface.doc.js +0 -125
- package/esm/interface.type.js +0 -17
- package/esm/utils/type/index.js +0 -29
- package/esm/utils/type/isArguments.js +0 -22
- package/esm/utils/type/isArray.js +0 -22
- package/esm/utils/type/isArrayBuffer.js +0 -25
- package/esm/utils/type/isBoolean.js +0 -22
- package/esm/utils/type/isDate.js +0 -22
- package/esm/utils/type/isError.js +0 -22
- package/esm/utils/type/isFunction.js +0 -22
- package/esm/utils/type/isMap.js +0 -22
- package/esm/utils/type/isRegExp.js +0 -22
- package/esm/utils/type/isSet.js +0 -22
- package/esm/utils/type/isWeakMap.js +0 -22
- package/esm/utils/type/isWeakSet.js +0 -22
- package/lib/interface.doc.js +0 -127
- package/lib/interface.type.js +0 -5
- package/lib/utils/type/index.js +0 -146
- package/lib/utils/type/isArguments.js +0 -29
- package/lib/utils/type/isArray.js +0 -29
- package/lib/utils/type/isArrayBuffer.js +0 -32
- package/lib/utils/type/isBoolean.js +0 -29
- package/lib/utils/type/isDate.js +0 -29
- package/lib/utils/type/isError.js +0 -29
- package/lib/utils/type/isFunction.js +0 -29
- package/lib/utils/type/isMap.js +0 -29
- package/lib/utils/type/isRegExp.js +0 -29
- package/lib/utils/type/isSet.js +0 -29
- package/lib/utils/type/isWeakMap.js +0 -29
- package/lib/utils/type/isWeakSet.js +0 -29
- 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
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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
|
-
|
|
52
|
+
|
|
53
|
+
export { ajax as default };
|
package/esm/blobToDataURL.js
CHANGED
|
@@ -1,37 +1,7 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
4
|
+
return fileReader(blob);
|
|
36
5
|
}
|
|
37
|
-
|
|
6
|
+
|
|
7
|
+
export { blobToDataURL as default };
|
package/esm/bytesToSize.js
CHANGED
|
@@ -1,38 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
12
|
+
|
|
13
|
+
export { bytesToSize as default };
|
|
@@ -1,55 +1,33 @@
|
|
|
1
|
-
import normalizeString from './normalizeString';
|
|
1
|
+
import normalizeString from './normalizeString.js';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
|
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
|
-
|
|
32
|
+
|
|
33
|
+
export { calculateCursorPosition as default };
|
package/esm/dataURLToBlob.js
CHANGED
|
@@ -1,29 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
14
|
+
|
|
15
|
+
export { dataURLToBlob as default };
|
package/esm/divide.js
CHANGED
|
@@ -1,51 +1,27 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
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
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
|
|
26
|
+
|
|
27
|
+
export { divide as default };
|