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.
- package/dist/util-helpers.js +1600 -4039
- 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/download.js
CHANGED
|
@@ -1,171 +1,90 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import { __awaiter, __generator } from 'tslib';
|
|
2
|
+
import dataURLToBlob from './dataURLToBlob.js';
|
|
3
|
+
import isUrl from './isUrl.js';
|
|
4
|
+
import ajax from './ajax.js';
|
|
5
|
+
import isBlob from './utils/type/isBlob.js';
|
|
6
|
+
import isPromiseLike from './isPromiseLike.js';
|
|
3
7
|
|
|
4
|
-
import dataURLToBlob from "./dataURLToBlob";
|
|
5
|
-
import isUrl from "./isUrl";
|
|
6
|
-
import ajax from "./ajax";
|
|
7
|
-
import { isBlob } from "./utils/type";
|
|
8
|
-
import isPromiseLike from "./isPromiseLike";
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* 下载文件
|
|
12
|
-
*
|
|
13
|
-
* @param {string} blobUrl blob 地址
|
|
14
|
-
* @param {string} [fileName] 文件名称
|
|
15
|
-
*/
|
|
16
8
|
function saver(blobUrl, fileName) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
anchor.removeEventListener('click', handleClick);
|
|
31
|
-
}
|
|
32
|
-
anchor.addEventListener('click', handleClick);
|
|
33
|
-
document.body.appendChild(anchor);
|
|
34
|
-
anchor.click();
|
|
35
|
-
document.body.removeChild(anchor);
|
|
9
|
+
if (fileName === void 0) { fileName = ''; }
|
|
10
|
+
var anchor = document.createElement('a');
|
|
11
|
+
anchor.href = blobUrl;
|
|
12
|
+
anchor.style.display = 'none';
|
|
13
|
+
anchor.setAttribute('download', fileName);
|
|
14
|
+
function handleClick(e) {
|
|
15
|
+
e.stopPropagation();
|
|
16
|
+
anchor.removeEventListener('click', handleClick);
|
|
17
|
+
}
|
|
18
|
+
anchor.addEventListener('click', handleClick);
|
|
19
|
+
document.body.appendChild(anchor);
|
|
20
|
+
anchor.click();
|
|
21
|
+
document.body.removeChild(anchor);
|
|
36
22
|
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* @typedef {import('./ajax.js').AjaxOptions} AjaxOptions ajax 配置项
|
|
40
|
-
*/
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* @callback TransformRequest
|
|
44
|
-
* @param {AjaxOptions} options ajax 配置项
|
|
45
|
-
* @returns {AjaxOptions | Promise<AjaxOptions>}
|
|
46
|
-
*/
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* @callback TransformResponse
|
|
50
|
-
* @param {Blob} res 响应的Blob对象。如果你通过 transformRequest 修改了 responseType ,该参数将是该类型响应值。
|
|
51
|
-
* @returns {Blob | Promise<Blob>}
|
|
52
|
-
*/
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* @typedef {Object} DownloadOptions 下载配置项
|
|
56
|
-
* @property {string} [options.fileName] 文件名称
|
|
57
|
-
* @property {string} [options.type] MIME 类型
|
|
58
|
-
* @property {'url'|'text'} [options.dataType] 手动设置数据类型,默认会根据传入的数据判断类型,主要是为了区分 url 和 text 。<br/>如果你要下载的文本是 url ,请设置 'text' ;如果你要下载的 url 是绝对/相对路径,请设置 'url' 。
|
|
59
|
-
* @property {TransformRequest} [options.transformRequest] 请求前触发,XHR 对象或配置调整
|
|
60
|
-
* @property {TransformResponse} [options.transformResponse] 请求成功后触发,在传递给 then/catch 前,允许修改响应数据
|
|
61
|
-
*/
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* 下载<br/><br/>
|
|
65
|
-
*
|
|
66
|
-
* <em style="font-weight: bold;">注意:该方法仅适用于浏览器端,兼容 IE10+ 和现代浏览器。</em>
|
|
67
|
-
*
|
|
68
|
-
* @static
|
|
69
|
-
* @alias module:Other.download
|
|
70
|
-
* @since 4.16.0
|
|
71
|
-
* @see {@link https://zh.wikipedia.org/wiki/多用途互聯網郵件擴展|MIME}
|
|
72
|
-
* @see {@link https://9ykc9s.csb.app/|在线示例}
|
|
73
|
-
* @param {string|Blob|ArrayBuffer|Int8Array|Uint8Array|Uint8ClampedArray|Int16Array|Uint16Array|Int32Array|Uint32Array|Float32Array|Float64Array|BigInt64Array|BigUint64Array} data 字符串、blob数据或url地址
|
|
74
|
-
* @param {string|DownloadOptions} [options] 文件名称 或 配置项
|
|
75
|
-
* @returns {Promise<void>}
|
|
76
|
-
* @example
|
|
77
|
-
* // 文本
|
|
78
|
-
* download('hello world', 'text.txt');
|
|
79
|
-
*
|
|
80
|
-
* // 远程文件
|
|
81
|
-
* download('/xxx.jpg', { dataType: 'url' });
|
|
82
|
-
*
|
|
83
|
-
* // blob文件
|
|
84
|
-
* download(new Blob(['hello world']), 'text.txt');
|
|
85
|
-
*
|
|
86
|
-
*/
|
|
87
23
|
function download(data, options) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
24
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
25
|
+
var config, fileName, type, dataType, transformRequest, transformResponse, payload, asyncTransformRequest, asyncTransformResponse, ajaxOptions, ev, res, currentFileName, url;
|
|
26
|
+
return __generator(this, function (_a) {
|
|
27
|
+
switch (_a.label) {
|
|
28
|
+
case 0:
|
|
29
|
+
config = typeof options === 'object' ? options : {};
|
|
30
|
+
if (typeof options === 'string') {
|
|
31
|
+
config.fileName = options;
|
|
32
|
+
}
|
|
33
|
+
fileName = config.fileName, type = config.type, dataType = config.dataType, transformRequest = config.transformRequest, transformResponse = config.transformResponse;
|
|
34
|
+
if (!(typeof data === 'string')) return [3, 8];
|
|
35
|
+
if (!(!dataType && /^blob:.*?\/.*/.test(data))) return [3, 1];
|
|
36
|
+
saver(data, fileName);
|
|
37
|
+
return [2, Promise.resolve()];
|
|
38
|
+
case 1:
|
|
39
|
+
if (!(!dataType && /^data:([\w+-]+\/[\w+.-]+)?[,;]/.test(data))) return [3, 2];
|
|
40
|
+
payload = dataURLToBlob(data);
|
|
41
|
+
return [3, 7];
|
|
42
|
+
case 2:
|
|
43
|
+
if (!(dataType === 'url' || (!dataType && isUrl(data)))) return [3, 6];
|
|
44
|
+
asyncTransformRequest = function (opts) {
|
|
45
|
+
var tempOptions = typeof transformRequest === 'function' ? transformRequest(opts) : opts;
|
|
46
|
+
return isPromiseLike(tempOptions) ? tempOptions : Promise.resolve(tempOptions);
|
|
47
|
+
};
|
|
48
|
+
asyncTransformResponse = function (res) {
|
|
49
|
+
var tempRes = typeof transformResponse === 'function' ? transformResponse(res) : res;
|
|
50
|
+
return isPromiseLike(tempRes) ? tempRes : Promise.resolve(tempRes);
|
|
51
|
+
};
|
|
52
|
+
return [4, asyncTransformRequest({ responseType: 'blob' })];
|
|
53
|
+
case 3:
|
|
54
|
+
ajaxOptions = _a.sent();
|
|
55
|
+
return [4, ajax(data, ajaxOptions)];
|
|
56
|
+
case 4:
|
|
57
|
+
ev = _a.sent();
|
|
58
|
+
return [4, asyncTransformResponse(ev.target.response)];
|
|
59
|
+
case 5:
|
|
60
|
+
res = _a.sent();
|
|
61
|
+
currentFileName = fileName || data.split('?')[0].split('#')[0].split('/').pop();
|
|
62
|
+
return [2, download(res, { fileName: currentFileName, type: type || (isBlob(res) ? res.type : undefined) })];
|
|
63
|
+
case 6:
|
|
64
|
+
payload = new Blob([data], { type: type || 'text/plain' });
|
|
65
|
+
_a.label = 7;
|
|
66
|
+
case 7: return [3, 9];
|
|
67
|
+
case 8:
|
|
68
|
+
if (data instanceof Blob) {
|
|
69
|
+
payload = data;
|
|
70
|
+
}
|
|
71
|
+
_a.label = 9;
|
|
72
|
+
case 9:
|
|
73
|
+
if (!payload) {
|
|
74
|
+
payload = new Blob([data], { type: type });
|
|
75
|
+
}
|
|
76
|
+
if (navigator.msSaveBlob) {
|
|
77
|
+
navigator.msSaveBlob(payload, fileName || 'download');
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
url = URL.createObjectURL(payload);
|
|
81
|
+
saver(url, fileName);
|
|
82
|
+
URL.revokeObjectURL(url);
|
|
83
|
+
}
|
|
84
|
+
return [2, Promise.resolve()];
|
|
85
|
+
}
|
|
140
86
|
});
|
|
141
|
-
});
|
|
142
|
-
} else {
|
|
143
|
-
// string
|
|
144
|
-
payload = new Blob([data], {
|
|
145
|
-
type: type || 'text/plain'
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
} else if (isBlob(data)) {
|
|
149
|
-
// @ts-ignore
|
|
150
|
-
payload = data;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// html、TypedArray
|
|
154
|
-
if (!(payload instanceof Blob)) {
|
|
155
|
-
payload = new Blob([data], {
|
|
156
|
-
type: type
|
|
157
87
|
});
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// @ts-ignore
|
|
161
|
-
if (navigator.msSaveBlob) {
|
|
162
|
-
// @ts-ignore
|
|
163
|
-
navigator.msSaveBlob(payload, fileName || 'download');
|
|
164
|
-
} else {
|
|
165
|
-
var url = URL.createObjectURL(payload);
|
|
166
|
-
saver(url, fileName);
|
|
167
|
-
URL.revokeObjectURL(url);
|
|
168
|
-
}
|
|
169
|
-
return Promise.resolve();
|
|
170
88
|
}
|
|
171
|
-
|
|
89
|
+
|
|
90
|
+
export { download as default };
|
package/esm/fileReader.js
CHANGED
|
@@ -1,67 +1,21 @@
|
|
|
1
1
|
var FileReaderMethodMap = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
arrayBuffer: 'readAsArrayBuffer',
|
|
3
|
+
binaryString: 'readAsBinaryString',
|
|
4
|
+
dataURL: 'readAsDataURL',
|
|
5
|
+
text: 'readAsText'
|
|
6
6
|
};
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
* @returns {Promise<string>}
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* 读取 Blob 或 File 对象,转为 Base64/String/ArrayBuffer<br/><br/>
|
|
24
|
-
*
|
|
25
|
-
* <em style="font-weight: bold;">注意:该方法仅适用于浏览器端。</em>
|
|
26
|
-
*
|
|
27
|
-
* @static
|
|
28
|
-
* @alias module:Processor.fileReader
|
|
29
|
-
* @see {@link https://developer.mozilla.org/zh-CN/docs/Web/API/FileReader|FileReader}
|
|
30
|
-
* @since 4.16.0
|
|
31
|
-
* @param {Blob} blob Blob 或 File 对象
|
|
32
|
-
* @param {'arrayBuffer'|'binaryString'|'dataURL'|'text'} [type='dataURL'] Blob 或 File 对象
|
|
33
|
-
* @returns {Promise<string|ArrayBuffer>} 文件的内容
|
|
34
|
-
* @example
|
|
35
|
-
* const aFileParts = ['<a id="a"><b id="b">hey!</b></a>']; // 一个包含DOMString的数组
|
|
36
|
-
* const htmlBlob = new Blob(aFileParts, { type: 'text/html' }); // 得到 blob
|
|
37
|
-
*
|
|
38
|
-
* fileReader(htmlBlob).then(data=>{
|
|
39
|
-
* console.log(data); // data:text/html;base64,PGEgaWQ9ImEiPjxiIGlkPSJiIj5oZXkhPC9iPjwvYT4=
|
|
40
|
-
* });
|
|
41
|
-
*
|
|
42
|
-
* const textBlob = new Blob(aFileParts, { type: 'text/plain' });
|
|
43
|
-
*
|
|
44
|
-
* fileReader(textBlob, 'text').then(data=>{
|
|
45
|
-
* console.log(data); // <a id="a"><b id="b">hey!</b></a>
|
|
46
|
-
* });
|
|
47
|
-
*/
|
|
48
|
-
function fileReader(blob) {
|
|
49
|
-
var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'dataURL';
|
|
50
|
-
var method = FileReaderMethodMap[type];
|
|
51
|
-
if (!method) {
|
|
52
|
-
method = FileReaderMethodMap.dataURL;
|
|
53
|
-
}
|
|
54
|
-
return new Promise(function (resolve, reject) {
|
|
55
|
-
var reader = new FileReader();
|
|
56
|
-
// @ts-ignore
|
|
57
|
-
reader[method](blob);
|
|
58
|
-
// @ts-ignore
|
|
59
|
-
reader.onload = function () {
|
|
60
|
-
return resolve(reader.result);
|
|
61
|
-
};
|
|
62
|
-
reader.onerror = function (error) {
|
|
63
|
-
return reject(error);
|
|
64
|
-
};
|
|
65
|
-
});
|
|
7
|
+
function fileReader(blob, type) {
|
|
8
|
+
if (type === void 0) { type = 'dataURL'; }
|
|
9
|
+
var method = FileReaderMethodMap[type];
|
|
10
|
+
if (!method) {
|
|
11
|
+
method = FileReaderMethodMap.dataURL;
|
|
12
|
+
}
|
|
13
|
+
return new Promise(function (resolve, reject) {
|
|
14
|
+
var reader = new FileReader();
|
|
15
|
+
reader[method](blob);
|
|
16
|
+
reader.onload = function () { return resolve(reader.result); };
|
|
17
|
+
reader.onerror = function (error) { return reject(error); };
|
|
18
|
+
});
|
|
66
19
|
}
|
|
67
|
-
|
|
20
|
+
|
|
21
|
+
export { fileReader as default };
|
package/esm/filterTree.js
CHANGED
|
@@ -1,59 +1,29 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { __assign } from 'tslib';
|
|
2
|
+
import isObject from './utils/type/isObject.js';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
* @template {any} T
|
|
11
|
-
* @template {(item: T) => boolean} F
|
|
12
|
-
* @param {T[]} tree 树结构数据
|
|
13
|
-
* @param {F} predicate 遍历每一项执行的函数,参数是当前遍历到的节点数据,如果返回 Truthy ,结果将包含该节点
|
|
14
|
-
* @param {string} [childrenField='children'] 子级字段名
|
|
15
|
-
* @param {'spread'|'self'} [nodeAssign='spread'] 节点赋值方式。spread表示使用展开运算符创建新值,self表示使用自身对象。
|
|
16
|
-
* @returns {T[]}
|
|
17
|
-
* @example
|
|
18
|
-
* const menus = [{ "id": "1", "name": "首页", "code": "trade", "pid": null }, { "id": "2", "name": "交易管理", "code": "trade", "pid": null, "children": [{ "id": "3", "name": "交易查询", "code": "trade-1", "pid": "2", "children": [{ "id": "4", "name": "交易查询-查询操作", "code": "trade-1-1", "pid": "3" }] }] }, { "id": "5", "name": "权限管理", "code": "authorization", "pid": null, "children": [{ "id": "6", "name": "角色管理", "code": "authorization-1", "pid": "5" }, { "id": "7", "name": "用户管理", "code": "authorization-2", "pid": "5" }] }];
|
|
19
|
-
*
|
|
20
|
-
* filterTree(menus, item=>item.name.indexOf('管理') > -1);
|
|
21
|
-
* // [{"id":"2","name":"交易管理","code":"trade","pid":null,"children":[]},{"id":"5","name":"权限管理","code":"authorization","pid":null,"children":[{"id":"6","name":"角色管理","code":"authorization-1","pid":"5"},{"id":"7","name":"用户管理","code":"authorization-2","pid":"5"}]}]
|
|
22
|
-
*
|
|
23
|
-
* // 如果某节点被过滤掉,它的子节点也一并抛弃
|
|
24
|
-
* filterTree(menus, item=>item.id === '7');
|
|
25
|
-
* // []
|
|
26
|
-
*
|
|
27
|
-
* filterTree(menus, item=>item.id === 'not found');
|
|
28
|
-
* // []
|
|
29
|
-
*/
|
|
30
|
-
function filterTree(tree, predicate) {
|
|
31
|
-
var childrenField = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'children';
|
|
32
|
-
var nodeAssign = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'spread';
|
|
33
|
-
/** @type {T[]} */
|
|
34
|
-
var result = [];
|
|
35
|
-
if (!Array.isArray(tree)) {
|
|
36
|
-
return result;
|
|
37
|
-
}
|
|
38
|
-
tree.forEach(function (item) {
|
|
39
|
-
var newItem = item;
|
|
40
|
-
if (isObject(item)) {
|
|
41
|
-
// @ts-ignore
|
|
42
|
-
newItem = nodeAssign === 'spread' ? _objectSpread({}, item) : item;
|
|
4
|
+
function filterTree(tree, predicate, childrenField, nodeAssign) {
|
|
5
|
+
if (childrenField === void 0) { childrenField = 'children'; }
|
|
6
|
+
if (nodeAssign === void 0) { nodeAssign = 'spread'; }
|
|
7
|
+
var result = [];
|
|
8
|
+
if (!Array.isArray(tree)) {
|
|
9
|
+
return result;
|
|
43
10
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
var childs = newItem[childrenField];
|
|
49
|
-
if (Array.isArray(childs) && childs.length > 0) {
|
|
50
|
-
// @ts-ignore
|
|
51
|
-
newItem[childrenField] = filterTree(childs, predicate, childrenField, nodeAssign);
|
|
11
|
+
tree.forEach(function (item) {
|
|
12
|
+
var newItem = item;
|
|
13
|
+
if (isObject(item)) {
|
|
14
|
+
newItem = nodeAssign === 'spread' ? __assign({}, item) : item;
|
|
52
15
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
16
|
+
if (predicate(newItem)) {
|
|
17
|
+
if (isObject(newItem)) {
|
|
18
|
+
var childs = newItem[childrenField];
|
|
19
|
+
if (Array.isArray(childs) && childs.length > 0) {
|
|
20
|
+
newItem[childrenField] = filterTree(childs, predicate, childrenField, nodeAssign);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
result.push(newItem);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
return result;
|
|
58
27
|
}
|
|
59
|
-
|
|
28
|
+
|
|
29
|
+
export { filterTree as default };
|
package/esm/findTreeNode.js
CHANGED
|
@@ -1,72 +1,44 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import { isObject } from "./utils/type";
|
|
1
|
+
import { __values, __spreadArray, __read } from 'tslib';
|
|
2
|
+
import isObject from './utils/type/isObject.js';
|
|
4
3
|
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
/** @type {T|undefined} */
|
|
34
|
-
var node;
|
|
35
|
-
if (!Array.isArray(tree)) {
|
|
36
|
-
return node;
|
|
37
|
-
}
|
|
38
|
-
var _iterator = _createForOfIteratorHelper(tree),
|
|
39
|
-
_step;
|
|
40
|
-
try {
|
|
41
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
42
|
-
var item = _step.value;
|
|
43
|
-
stack.push(item);
|
|
44
|
-
while (stack.length) {
|
|
45
|
-
/** @type {T} */
|
|
46
|
-
// @ts-ignore
|
|
47
|
-
var temp = stack.pop();
|
|
48
|
-
if (predicate(temp)) {
|
|
49
|
-
node = temp;
|
|
50
|
-
break;
|
|
4
|
+
function findTreeNode(tree, predicate, childrenField) {
|
|
5
|
+
var e_1, _a;
|
|
6
|
+
if (childrenField === void 0) { childrenField = 'children'; }
|
|
7
|
+
var stack = [];
|
|
8
|
+
var node;
|
|
9
|
+
if (!Array.isArray(tree)) {
|
|
10
|
+
return node;
|
|
11
|
+
}
|
|
12
|
+
try {
|
|
13
|
+
for (var tree_1 = __values(tree), tree_1_1 = tree_1.next(); !tree_1_1.done; tree_1_1 = tree_1.next()) {
|
|
14
|
+
var item = tree_1_1.value;
|
|
15
|
+
stack.push(item);
|
|
16
|
+
while (stack.length) {
|
|
17
|
+
var temp = stack.pop();
|
|
18
|
+
if (predicate(temp)) {
|
|
19
|
+
node = temp;
|
|
20
|
+
break;
|
|
21
|
+
}
|
|
22
|
+
if (isObject(temp)) {
|
|
23
|
+
var childs = temp[childrenField];
|
|
24
|
+
if (Array.isArray(childs) && childs.length > 0) {
|
|
25
|
+
stack.push.apply(stack, __spreadArray([], __read(childs), false));
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (node) {
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
51
32
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
stack.push.apply(stack, _toConsumableArray(childs));
|
|
58
|
-
}
|
|
33
|
+
}
|
|
34
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
35
|
+
finally {
|
|
36
|
+
try {
|
|
37
|
+
if (tree_1_1 && !tree_1_1.done && (_a = tree_1.return)) _a.call(tree_1);
|
|
59
38
|
}
|
|
60
|
-
|
|
61
|
-
if (node) {
|
|
62
|
-
break;
|
|
63
|
-
}
|
|
39
|
+
finally { if (e_1) throw e_1.error; }
|
|
64
40
|
}
|
|
65
|
-
|
|
66
|
-
_iterator.e(err);
|
|
67
|
-
} finally {
|
|
68
|
-
_iterator.f();
|
|
69
|
-
}
|
|
70
|
-
return node;
|
|
41
|
+
return node;
|
|
71
42
|
}
|
|
72
|
-
|
|
43
|
+
|
|
44
|
+
export { findTreeNode as default };
|