util-helpers 4.15.3 → 4.16.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/README.md +6 -5
- package/dist/util-helpers.js +491 -73
- 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 +149 -0
- package/esm/blobToDataURL.js +9 -13
- package/esm/calculateCursorPosition.js +2 -2
- package/esm/dataURLToBlob.js +7 -6
- package/esm/download.js +171 -0
- package/esm/fileReader.js +67 -0
- package/esm/index.js +6 -3
- package/esm/interface.doc.js +125 -0
- package/esm/isBankCard.js +1 -1
- package/esm/isBusinessLicense.js +1 -1
- package/esm/isChinese.js +3 -3
- package/esm/isHMCard.js +1 -1
- package/esm/isIdCard.js +2 -2
- package/esm/isPassport.js +1 -1
- package/esm/isPassword.js +2 -2
- package/esm/isSocialCreditCode.js +1 -1
- package/esm/isSwiftCode.js +1 -1
- package/esm/isTWCard.js +1 -1
- package/esm/isUrl.js +1 -1
- package/esm/isVehicle.js +1 -1
- package/esm/normalizeString.js +1 -1
- package/esm/numberToChinese.js +3 -2
- package/esm/parseIdCard.js +2 -2
- package/esm/safeDate.js +27 -10
- package/esm/setDataURLPrefix.js +2 -2
- package/esm/transformFieldNames.js +2 -3
- package/esm/utils/config.js +1 -1
- package/esm/utils/type/index.js +3 -1
- package/esm/utils/type/isArrayBuffer.js +25 -0
- package/esm/utils/type/isBlob.js +27 -0
- package/esm/validatePassword.js +1 -1
- package/lib/ajax.js +156 -0
- package/lib/blobToDataURL.js +9 -13
- package/lib/calculateCursorPosition.js +2 -2
- package/lib/dataURLToBlob.js +7 -6
- package/lib/download.js +176 -0
- package/lib/fileReader.js +74 -0
- package/lib/index.js +22 -1
- package/lib/interface.doc.js +127 -0
- package/lib/isBankCard.js +1 -1
- package/lib/isBusinessLicense.js +1 -1
- package/lib/isChinese.js +3 -3
- package/lib/isHMCard.js +1 -1
- package/lib/isIdCard.js +2 -2
- package/lib/isPassport.js +1 -1
- package/lib/isPassword.js +2 -2
- package/lib/isSocialCreditCode.js +1 -1
- package/lib/isSwiftCode.js +1 -1
- package/lib/isTWCard.js +1 -1
- package/lib/isUrl.js +1 -1
- package/lib/isVehicle.js +1 -1
- package/lib/normalizeString.js +1 -1
- package/lib/numberToChinese.js +3 -2
- package/lib/parseIdCard.js +2 -2
- package/lib/safeDate.js +28 -11
- package/lib/setDataURLPrefix.js +2 -2
- package/lib/transformFieldNames.js +1 -1
- package/lib/utils/config.js +1 -1
- package/lib/utils/type/index.js +14 -0
- package/lib/utils/type/isArrayBuffer.js +32 -0
- package/lib/utils/type/isBlob.js +34 -0
- package/lib/validatePassword.js +1 -1
- package/package.json +2 -2
- package/types/ajax.d.ts +121 -0
- package/types/blobToDataURL.d.ts +6 -2
- package/types/calculateCursorPosition.d.ts +2 -2
- package/types/dataURLToBlob.d.ts +1 -1
- package/types/download.d.ts +78 -0
- package/types/fileReader.d.ts +3 -0
- package/types/index.d.ts +4 -1
- package/types/isBankCard.d.ts +1 -1
- package/types/isBusinessLicense.d.ts +1 -1
- package/types/isChinese.d.ts +3 -3
- package/types/isHMCard.d.ts +1 -1
- package/types/isIdCard.d.ts +2 -2
- package/types/isPassport.d.ts +1 -1
- package/types/isPassword.d.ts +2 -2
- package/types/isSocialCreditCode.d.ts +1 -1
- package/types/isSwiftCode.d.ts +1 -1
- package/types/isTWCard.d.ts +1 -1
- package/types/isUrl.d.ts +1 -1
- package/types/isVehicle.d.ts +1 -1
- package/types/normalizeString.d.ts +1 -1
- package/types/numberToChinese.d.ts +3 -2
- package/types/parseIdCard.d.ts +3 -3
- package/types/safeDate.d.ts +3 -23
- package/types/setDataURLPrefix.d.ts +2 -2
- package/types/transformFieldNames.d.ts +2 -2
- package/types/utils/type/index.d.ts +21 -19
- package/types/utils/type/isArrayBuffer.d.ts +21 -0
- package/types/utils/type/isBlob.d.ts +23 -0
- package/types/validatePassword.d.ts +1 -1
- package/esm/transformFieldNames.doc.js +0 -35
- package/lib/transformFieldNames.doc.js +0 -42
- /package/esm/{transformFieldNames.type.js → interface.type.js} +0 -0
- /package/lib/{transformFieldNames.type.js → interface.type.js} +0 -0
- /package/types/{transformFieldNames.type.d.ts → interface.type.d.ts} +0 -0
package/lib/download.js
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
var _dataURLToBlob = _interopRequireDefault(require("./dataURLToBlob"));
|
|
8
|
+
var _isUrl = _interopRequireDefault(require("./isUrl"));
|
|
9
|
+
var _ajax = _interopRequireDefault(require("./ajax"));
|
|
10
|
+
var _type = require("./utils/type");
|
|
11
|
+
var _isPromiseLike = _interopRequireDefault(require("./isPromiseLike"));
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
13
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
14
|
+
/**
|
|
15
|
+
* 下载文件
|
|
16
|
+
*
|
|
17
|
+
* @param {string} blobUrl blob 地址
|
|
18
|
+
* @param {string} [fileName] 文件名称
|
|
19
|
+
*/
|
|
20
|
+
function saver(blobUrl, fileName) {
|
|
21
|
+
var anchor = document.createElement('a');
|
|
22
|
+
// anchor.href = decodeURIComponent(blobUrl);
|
|
23
|
+
anchor.href = blobUrl;
|
|
24
|
+
anchor.style.display = 'none';
|
|
25
|
+
anchor.setAttribute('download', fileName || '');
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* 处理点击事件,防止事件冒泡到 body/html 的点击事件。
|
|
29
|
+
*
|
|
30
|
+
* @param {MouseEvent} e 鼠标事件对象
|
|
31
|
+
*/
|
|
32
|
+
function handleClick(e) {
|
|
33
|
+
e.stopPropagation();
|
|
34
|
+
anchor.removeEventListener('click', handleClick);
|
|
35
|
+
}
|
|
36
|
+
anchor.addEventListener('click', handleClick);
|
|
37
|
+
document.body.appendChild(anchor);
|
|
38
|
+
anchor.click();
|
|
39
|
+
document.body.removeChild(anchor);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @typedef {import('./ajax.js').AjaxOptions} AjaxOptions ajax 配置项
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @callback TransformRequest
|
|
48
|
+
* @param {AjaxOptions} options ajax 配置项
|
|
49
|
+
* @returns {AjaxOptions | Promise<AjaxOptions>}
|
|
50
|
+
*/
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @callback TransformResponse
|
|
54
|
+
* @param {Blob} res 响应的Blob对象。如果你通过 transformRequest 修改了 responseType ,该参数将是该类型响应值。
|
|
55
|
+
* @returns {Blob | Promise<Blob>}
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* @typedef {Object} DownloadOptions 下载配置项
|
|
60
|
+
* @property {string} [options.fileName] 文件名称
|
|
61
|
+
* @property {string} [options.type] MIME 类型
|
|
62
|
+
* @property {'url'|'text'} [options.dataType] 手动设置数据类型,默认会根据传入的数据判断类型,主要是为了区分 url 和 text 。<br/>如果你要下载的文本是 url ,请设置 'text' ;如果你要下载的 url 是绝对/相对路径,请设置 'url' 。
|
|
63
|
+
* @property {TransformRequest} [options.transformRequest] 请求前触发,XHR 对象或配置调整
|
|
64
|
+
* @property {TransformResponse} [options.transformResponse] 请求成功后触发,在传递给 then/catch 前,允许修改响应数据
|
|
65
|
+
*/
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* 下载<br/><br/>
|
|
69
|
+
*
|
|
70
|
+
* <em style="font-weight: bold;">注意:该方法仅适用于浏览器端,兼容 IE10+ 和现代浏览器。</em>
|
|
71
|
+
*
|
|
72
|
+
* @static
|
|
73
|
+
* @alias module:Other.download
|
|
74
|
+
* @since 4.16.0
|
|
75
|
+
* @see {@link https://zh.wikipedia.org/wiki/多用途互聯網郵件擴展|MIME}
|
|
76
|
+
* @see {@link https://9ykc9s.csb.app/|在线示例}
|
|
77
|
+
* @param {string|Blob|ArrayBuffer|Int8Array|Uint8Array|Uint8ClampedArray|Int16Array|Uint16Array|Int32Array|Uint32Array|Float32Array|Float64Array|BigInt64Array|BigUint64Array} data 字符串、blob数据或url地址
|
|
78
|
+
* @param {string|DownloadOptions} [options] 文件名称 或 配置项
|
|
79
|
+
* @returns {Promise<void>}
|
|
80
|
+
* @example
|
|
81
|
+
* // 文本
|
|
82
|
+
* download('hello world', 'text.txt');
|
|
83
|
+
*
|
|
84
|
+
* // 远程文件
|
|
85
|
+
* download('/xxx.jpg', { dataType: 'url' });
|
|
86
|
+
*
|
|
87
|
+
* // blob文件
|
|
88
|
+
* download(new Blob(['hello world']), 'text.txt');
|
|
89
|
+
*
|
|
90
|
+
*/
|
|
91
|
+
function download(data, options) {
|
|
92
|
+
var config = _typeof(options) === 'object' ? options : {};
|
|
93
|
+
if (typeof options === 'string') {
|
|
94
|
+
config.fileName = options;
|
|
95
|
+
}
|
|
96
|
+
var fileName = config.fileName,
|
|
97
|
+
type = config.type,
|
|
98
|
+
dataType = config.dataType,
|
|
99
|
+
transformRequest = config.transformRequest,
|
|
100
|
+
transformResponse = config.transformResponse;
|
|
101
|
+
|
|
102
|
+
/** @type {Blob|undefined} */
|
|
103
|
+
var payload;
|
|
104
|
+
|
|
105
|
+
// dataURLs、blob url、url、string
|
|
106
|
+
if (typeof data === 'string') {
|
|
107
|
+
if (!dataType && /^blob:.*?\/.*/.test(data)) {
|
|
108
|
+
// blob url
|
|
109
|
+
saver(data, fileName);
|
|
110
|
+
return Promise.resolve();
|
|
111
|
+
} else if (!dataType && /^data:([\w+-]+\/[\w+.-]+)?[,;]/.test(data)) {
|
|
112
|
+
// dataURLs
|
|
113
|
+
payload = (0, _dataURLToBlob["default"])(data);
|
|
114
|
+
} else if (dataType === 'url' || !dataType && (0, _isUrl["default"])(data)) {
|
|
115
|
+
// url
|
|
116
|
+
// 包装为异步方法
|
|
117
|
+
/** @type {(opts: AjaxOptions)=>Promise<AjaxOptions>} */
|
|
118
|
+
var asyncTransformRequest = function asyncTransformRequest(opts) {
|
|
119
|
+
// 请求前配置调整
|
|
120
|
+
var tempOptions = typeof transformRequest === 'function' ? transformRequest(opts) : opts;
|
|
121
|
+
// @ts-ignore
|
|
122
|
+
return (0, _isPromiseLike["default"])(tempOptions) ? tempOptions : Promise.resolve(tempOptions);
|
|
123
|
+
};
|
|
124
|
+
/** @type {(res: Blob)=>Promise<Blob>} */
|
|
125
|
+
var asyncTransformResponse = function asyncTransformResponse(res) {
|
|
126
|
+
var tempRes = typeof transformResponse === 'function' ? transformResponse(res) : res;
|
|
127
|
+
// @ts-ignore
|
|
128
|
+
return (0, _isPromiseLike["default"])(tempRes) ? tempRes : Promise.resolve(tempRes);
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
// 此处如果使用 async/await 语法糖,编译后的umd代码过大
|
|
132
|
+
return asyncTransformRequest({
|
|
133
|
+
responseType: 'blob'
|
|
134
|
+
}).then(function (ajaxOptions) {
|
|
135
|
+
return (0, _ajax["default"])(data, ajaxOptions).then(function (e) {
|
|
136
|
+
// @ts-ignore
|
|
137
|
+
return asyncTransformResponse(e.target.response).then(function (res) {
|
|
138
|
+
var currentFileName = fileName || data.split("?")[0].split("#")[0].split("/").pop();
|
|
139
|
+
return download(res, {
|
|
140
|
+
fileName: currentFileName,
|
|
141
|
+
type: type || ((0, _type.isBlob)(res) ? res.type : undefined)
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
} else {
|
|
147
|
+
// string
|
|
148
|
+
payload = new Blob([data], {
|
|
149
|
+
type: type || 'text/plain'
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
} else if ((0, _type.isBlob)(data)) {
|
|
153
|
+
// @ts-ignore
|
|
154
|
+
payload = data;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// html、TypedArray
|
|
158
|
+
if (!(payload instanceof Blob)) {
|
|
159
|
+
payload = new Blob([data], {
|
|
160
|
+
type: type
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// @ts-ignore
|
|
165
|
+
if (navigator.msSaveBlob) {
|
|
166
|
+
// @ts-ignore
|
|
167
|
+
navigator.msSaveBlob(payload, fileName || 'download');
|
|
168
|
+
} else {
|
|
169
|
+
var url = URL.createObjectURL(payload);
|
|
170
|
+
saver(url, fileName);
|
|
171
|
+
URL.revokeObjectURL(url);
|
|
172
|
+
}
|
|
173
|
+
return Promise.resolve();
|
|
174
|
+
}
|
|
175
|
+
var _default = download;
|
|
176
|
+
exports["default"] = _default;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
var FileReaderMethodMap = {
|
|
8
|
+
arrayBuffer: 'readAsArrayBuffer',
|
|
9
|
+
binaryString: 'readAsBinaryString',
|
|
10
|
+
dataURL: 'readAsDataURL',
|
|
11
|
+
text: 'readAsText'
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @overload
|
|
16
|
+
* @param {Blob} blob
|
|
17
|
+
* @param {'arrayBuffer'} type
|
|
18
|
+
* @returns {Promise<ArrayBuffer>}
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @overload
|
|
23
|
+
* @param {Blob} blob
|
|
24
|
+
* @param {'binaryString'|'binaryString'|'dataURL'|'text'} [type='dataURL']
|
|
25
|
+
* @returns {Promise<string>}
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* 读取 Blob 或 File 对象,可以将 Blob 转为 Base64/String/ArrayBuffer<br/><br/>
|
|
30
|
+
*
|
|
31
|
+
* <em style="font-weight: bold;">注意:该方法仅适用于浏览器端。</em>
|
|
32
|
+
*
|
|
33
|
+
* @static
|
|
34
|
+
* @alias module:Processor.fileReader
|
|
35
|
+
* @see {@link https://developer.mozilla.org/zh-CN/docs/Web/API/FileReader|FileReader}
|
|
36
|
+
* @since 4.16.0
|
|
37
|
+
* @param {Blob} blob Blob 或 File 对象
|
|
38
|
+
* @param {'arrayBuffer'|'binaryString'|'dataURL'|'text'} [type='dataURL'] Blob 或 File 对象
|
|
39
|
+
* @returns {Promise<string|ArrayBuffer>} 文件的内容
|
|
40
|
+
* @example
|
|
41
|
+
* const aFileParts = ['<a id="a"><b id="b">hey!</b></a>']; // 一个包含DOMString的数组
|
|
42
|
+
* const htmlBlob = new Blob(aFileParts, { type: 'text/html' }); // 得到 blob
|
|
43
|
+
*
|
|
44
|
+
* fileReader(htmlBlob).then(data=>{
|
|
45
|
+
* console.log(data); // data:text/html;base64,PGEgaWQ9ImEiPjxiIGlkPSJiIj5oZXkhPC9iPjwvYT4=
|
|
46
|
+
* });
|
|
47
|
+
*
|
|
48
|
+
* const textBlob = new Blob(aFileParts, { type: 'text/plain' });
|
|
49
|
+
*
|
|
50
|
+
* fileReader(textBlob, 'text').then(data=>{
|
|
51
|
+
* console.log(data); // <a id="a"><b id="b">hey!</b></a>
|
|
52
|
+
* });
|
|
53
|
+
*/
|
|
54
|
+
function fileReader(blob) {
|
|
55
|
+
var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'dataURL';
|
|
56
|
+
var method = FileReaderMethodMap[type];
|
|
57
|
+
if (!method) {
|
|
58
|
+
method = FileReaderMethodMap.dataURL;
|
|
59
|
+
}
|
|
60
|
+
return new Promise(function (resolve, reject) {
|
|
61
|
+
var reader = new FileReader();
|
|
62
|
+
// @ts-ignore
|
|
63
|
+
reader[method](blob);
|
|
64
|
+
// @ts-ignore
|
|
65
|
+
reader.onload = function () {
|
|
66
|
+
return resolve(reader.result);
|
|
67
|
+
};
|
|
68
|
+
reader.onerror = function (error) {
|
|
69
|
+
return reject(error);
|
|
70
|
+
};
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
var _default = fileReader;
|
|
74
|
+
exports["default"] = _default;
|
package/lib/index.js
CHANGED
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
Object.defineProperty(exports, "ajax", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function get() {
|
|
9
|
+
return _ajax["default"];
|
|
10
|
+
}
|
|
11
|
+
});
|
|
6
12
|
Object.defineProperty(exports, "blobToDataURL", {
|
|
7
13
|
enumerable: true,
|
|
8
14
|
get: function get() {
|
|
@@ -33,6 +39,18 @@ Object.defineProperty(exports, "divide", {
|
|
|
33
39
|
return _divide["default"];
|
|
34
40
|
}
|
|
35
41
|
});
|
|
42
|
+
Object.defineProperty(exports, "download", {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
get: function get() {
|
|
45
|
+
return _download["default"];
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
Object.defineProperty(exports, "fileReader", {
|
|
49
|
+
enumerable: true,
|
|
50
|
+
get: function get() {
|
|
51
|
+
return _fileReader["default"];
|
|
52
|
+
}
|
|
53
|
+
});
|
|
36
54
|
Object.defineProperty(exports, "filterTree", {
|
|
37
55
|
enumerable: true,
|
|
38
56
|
get: function get() {
|
|
@@ -350,6 +368,7 @@ var _numberToChinese = _interopRequireDefault(require("./numberToChinese"));
|
|
|
350
368
|
var _bytesToSize = _interopRequireDefault(require("./bytesToSize"));
|
|
351
369
|
var _parseIdCard = _interopRequireDefault(require("./parseIdCard"));
|
|
352
370
|
var _blobToDataURL = _interopRequireDefault(require("./blobToDataURL"));
|
|
371
|
+
var _fileReader = _interopRequireDefault(require("./fileReader"));
|
|
353
372
|
var _dataURLToBlob = _interopRequireDefault(require("./dataURLToBlob"));
|
|
354
373
|
var _setDataURLPrefix = _interopRequireDefault(require("./setDataURLPrefix"));
|
|
355
374
|
var _normalizeString = _interopRequireDefault(require("./normalizeString"));
|
|
@@ -361,10 +380,12 @@ var _minus = _interopRequireDefault(require("./minus"));
|
|
|
361
380
|
var _times = _interopRequireDefault(require("./times"));
|
|
362
381
|
var _divide = _interopRequireDefault(require("./divide"));
|
|
363
382
|
var _round = _interopRequireDefault(require("./round"));
|
|
364
|
-
var
|
|
383
|
+
var _ajax = _interopRequireDefault(require("./ajax"));
|
|
365
384
|
var _calculateCursorPosition = _interopRequireDefault(require("./calculateCursorPosition"));
|
|
385
|
+
var _download = _interopRequireDefault(require("./download"));
|
|
366
386
|
var _randomString = _interopRequireDefault(require("./randomString"));
|
|
367
387
|
var _strlen = _interopRequireDefault(require("./strlen"));
|
|
388
|
+
var _waitTime = _interopRequireDefault(require("./waitTime"));
|
|
368
389
|
var _transformFieldNames = _interopRequireDefault(require("./transformFieldNames"));
|
|
369
390
|
var _listToTree = _interopRequireDefault(require("./listToTree"));
|
|
370
391
|
var _treeToList = _interopRequireDefault(require("./treeToList"));
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/* eslint-disable no-unused-vars */
|
|
4
|
+
// 该文件用于 jsdoc 生成文件。因为一些 typescript 语法, jsdoc 不支持,导致生成文档报错。
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 转换字段名,返回一个转换字段后的值,不改变原值。
|
|
8
|
+
*
|
|
9
|
+
* @static
|
|
10
|
+
* @alias module:Tree.transformFieldNames
|
|
11
|
+
* @since 4.14.0
|
|
12
|
+
* @param {object[]} data 对象数组。如果是树结构数据,需要指定第三个参数 childrenField
|
|
13
|
+
* @param {object} fieldNames 字段名映射
|
|
14
|
+
* @param {string} [childrenField] 子级数据字段名
|
|
15
|
+
* @param {'spread'|'self'} [nodeAssign='spread'] 节点赋值方式。spread表示使用展开运算符创建新值,self表示使用自身对象。
|
|
16
|
+
* @returns {object[]}
|
|
17
|
+
* @example
|
|
18
|
+
*
|
|
19
|
+
* const options = [{code: '1', name: 'one'},{code:'2', name:'two'}];
|
|
20
|
+
* const newOptions = transformFieldNames(options, {label: 'name', value: 'code'});
|
|
21
|
+
* // [{value: '1', label: 'one'},{value:'2', label:'two'}]
|
|
22
|
+
*
|
|
23
|
+
* // 嵌套数据,指定子级字段名 children
|
|
24
|
+
* const options2 = [{code: '1', name: 'one'},{code:'2', name:'two', children: [{code:'2-1', name:'two-one', children: [{code: '2-1-1', name:'two-one-one'}]}]}];
|
|
25
|
+
* const newOptions2 = transformFieldNames(options2, {label: 'name', value: 'code'}, 'children');
|
|
26
|
+
* // [{value: '1', label: 'one'},{value:'2', label:'two', children: [{value: '2-1', label:'two-one', children: [{value: '2-1-1', label:'two-one-one'}]}]}]
|
|
27
|
+
*
|
|
28
|
+
* const options3 = [{code: '1', name: 'one'},{code:'2', name:'two', childs: [{code:'2-1', name:'two-one'}]}];
|
|
29
|
+
* const newOptions3 = transformFieldNames(options3, {label: 'name', value: 'code'}, 'childs');
|
|
30
|
+
* // [{value: '1', label: 'one'},{value:'2', label:'two', childs: [{value: '2-1', label:'two-one'}]}]
|
|
31
|
+
*
|
|
32
|
+
* // 嵌套数据,并替换子集字段名
|
|
33
|
+
* const newOptions4 = transformFieldNames(options3, {label: 'name', value: 'code', children: 'childs'}, 'childs');
|
|
34
|
+
* // [{value: '1', label: 'one'},{value:'2', label:'two', children: [{value: '2-1', label:'two-one'}]}]
|
|
35
|
+
*/
|
|
36
|
+
function transformFieldNames(data, fieldNames, childrenField) {}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @see {@link https://developer.mozilla.org/zh-CN/docs/Web/API/XMLHttpRequest|XMLHttpRequest}
|
|
40
|
+
* @typedef {Object} AjaxOptions ajax配置项
|
|
41
|
+
* @property {string} [method="get"] 创建请求时使用的方法
|
|
42
|
+
* @property {*} [data=null] 请求体被发送的数据
|
|
43
|
+
* @property {object} [headers] 自定义请求头
|
|
44
|
+
* @property {string} [responseType] 响应类型
|
|
45
|
+
* @property {number} [timeout] 请求超时的毫秒数
|
|
46
|
+
* @property {boolean} [withCredentials=false] 跨域请求时是否需要使用凭证
|
|
47
|
+
* @property {boolean} [async=true] 是否异步执行操作
|
|
48
|
+
* @property {string|null} [user=null] 用户名,用于认证用途
|
|
49
|
+
* @property {string|null} [password=null] 密码,用于认证用途
|
|
50
|
+
* @property {function} [onLoadStart] 接收到响应数据时触发
|
|
51
|
+
* @property {function} [onProgress] 请求接收到更多数据时,周期性地触发
|
|
52
|
+
* @property {function} [onAbort] 当 request 被停止时触发,例如当程序调用 XMLHttpRequest.abort() 时
|
|
53
|
+
* @property {function} [onTimeout] 在预设时间内没有接收到响应时触发
|
|
54
|
+
* @property {function} [onError] 当 request 遭遇错误时触发
|
|
55
|
+
* @property {function} [onLoad] 请求成功完成时触发
|
|
56
|
+
* @property {function} [onLoadEnd] 请求结束时触发,无论请求成功 (load) 还是失败 (abort 或 error)
|
|
57
|
+
*/
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* 请求<br/><br/>
|
|
61
|
+
*
|
|
62
|
+
* <em style="font-weight: bold;">注意:该方法仅适用于浏览器端。</em>
|
|
63
|
+
*
|
|
64
|
+
* @static
|
|
65
|
+
* @alias module:Other.ajax
|
|
66
|
+
* @since 4.16.0
|
|
67
|
+
* @see {@link https://developer.mozilla.org/zh-CN/docs/Web/API/XMLHttpRequest|XMLHttpRequest}
|
|
68
|
+
* @param {string} url 地址
|
|
69
|
+
* @param {AjaxOptions} [options] 配置项
|
|
70
|
+
* @returns {Promise<object>} XHR 事件对象
|
|
71
|
+
* @example
|
|
72
|
+
* ajax('/somefile').then(res=>{
|
|
73
|
+
* // do something
|
|
74
|
+
* });
|
|
75
|
+
*
|
|
76
|
+
* ajax('/api', { method: 'post' }).then(res=>{
|
|
77
|
+
* // do something
|
|
78
|
+
* });
|
|
79
|
+
*/
|
|
80
|
+
function ajax(url, options) {}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* @callback TransformRequest
|
|
84
|
+
* @param {AjaxOptions} options ajax 配置项
|
|
85
|
+
* @returns {AjaxOptions | Promise<AjaxOptions>}
|
|
86
|
+
*/
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* @callback TransformResponse
|
|
90
|
+
* @param {Blob} res 响应的Blob对象。如果你通过 transformRequest 修改了 responseType ,该参数将是该类型响应值。
|
|
91
|
+
* @returns {Blob | Promise<Blob>}
|
|
92
|
+
*/
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* @typedef {Object} DownloadOptions 下载配置项
|
|
96
|
+
* @property {string} [options.fileName] 文件名称
|
|
97
|
+
* @property {string} [options.type] MIME 类型
|
|
98
|
+
* @property {'url'|'text'} [options.dataType] 手动设置数据类型,默认会根据传入的数据判断类型,主要是为了区分 url 和 text 。<br/>如果你要下载的文本是 url ,请设置 'text' ;如果你要下载的 url 是绝对/相对路径,请设置 'url' 。
|
|
99
|
+
* @property {TransformRequest} [options.transformRequest] 请求前触发,XHR 对象或配置调整
|
|
100
|
+
* @property {TransformResponse} [options.transformResponse] 请求成功后触发,在传递给 then/catch 前,允许修改响应数据
|
|
101
|
+
*/
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* 下载<br/><br/>
|
|
105
|
+
*
|
|
106
|
+
* <em style="font-weight: bold;">注意:该方法仅适用于浏览器端,兼容 IE10+ 和现代浏览器。</em>
|
|
107
|
+
*
|
|
108
|
+
* @static
|
|
109
|
+
* @alias module:Other.download
|
|
110
|
+
* @since 4.16.0
|
|
111
|
+
* @see {@link https://zh.wikipedia.org/wiki/多用途互聯網郵件擴展|MIME}
|
|
112
|
+
* @see {@link https://9ykc9s.csb.app/|在线示例}
|
|
113
|
+
* @param {string|Blob|TypedArray} data 字符串、blob数据或url地址
|
|
114
|
+
* @param {string|DownloadOptions} [options] 文件名称 或 配置项
|
|
115
|
+
* @returns {Promise<void>}
|
|
116
|
+
* @example
|
|
117
|
+
* // 文本
|
|
118
|
+
* download('hello world', 'text.txt');
|
|
119
|
+
*
|
|
120
|
+
* // 远程文件
|
|
121
|
+
* download('/xxx.jpg', { dataType: 'url' });
|
|
122
|
+
*
|
|
123
|
+
* // blob文件
|
|
124
|
+
* download(new Blob(['hello world']), 'text.txt');
|
|
125
|
+
*
|
|
126
|
+
*/
|
|
127
|
+
function download(data, fileName, options) {}
|
package/lib/isBankCard.js
CHANGED
|
@@ -34,8 +34,8 @@ function sumCheckCode(numStr) {
|
|
|
34
34
|
*
|
|
35
35
|
* @static
|
|
36
36
|
* @alias module:Validator.isBankCard
|
|
37
|
-
* @see 参考 {@link https://kf.qq.com/faq/170112ABnm6b170112FvquAn.html|常用银行账号位数参考}
|
|
38
37
|
* @since 1.1.0
|
|
38
|
+
* @see {@link https://kf.qq.com/faq/170112ABnm6b170112FvquAn.html|常用银行账号位数参考}
|
|
39
39
|
* @param {*} value 要检测的值
|
|
40
40
|
* @param {Object} [options] 配置项
|
|
41
41
|
* @param {boolean} [options.loose=false] 宽松模式,8~30位数字
|
package/lib/isBusinessLicense.js
CHANGED
|
@@ -44,8 +44,8 @@ function sumCheckCode(preCode) {
|
|
|
44
44
|
*
|
|
45
45
|
* @static
|
|
46
46
|
* @alias module:Validator.isBusinessLicense
|
|
47
|
-
* @see 参考 {@link https://wenku.baidu.com/view/19873704cc1755270722087c.html|GS15—2006 工商行政管理市场主体注册号编制规则}
|
|
48
47
|
* @since 3.5.0
|
|
48
|
+
* @see {@link https://wenku.baidu.com/view/19873704cc1755270722087c.html|GS15—2006 工商行政管理市场主体注册号编制规则}
|
|
49
49
|
* @param {*} value 要检测的值
|
|
50
50
|
* @param {Object} [options] 配置项
|
|
51
51
|
* @param {boolean} [options.checkCode=true] 是否校验最后一位校验码,如果为false,不校验校验位。
|
package/lib/isChinese.js
CHANGED
|
@@ -39,9 +39,9 @@ var supportRegExpUnicode = RegExp.prototype.hasOwnProperty('unicode');
|
|
|
39
39
|
* @static
|
|
40
40
|
* @alias module:Validator.isChinese
|
|
41
41
|
* @since 1.1.0
|
|
42
|
-
* @see
|
|
43
|
-
* @see
|
|
44
|
-
* @see
|
|
42
|
+
* @see {@link http://www.unicode.org/reports/tr38/#BlockListing|4.4 Listing of Characters Covered by the Unihan Database}
|
|
43
|
+
* @see {@link https://zh.wikipedia.org/wiki/Unicode字符平面映射|Unicode字符平面映射}
|
|
44
|
+
* @see {@link https://zh.wikipedia.org/wiki/Unicode區段|Unicode区段}
|
|
45
45
|
* @param {*} value 要检测的值
|
|
46
46
|
* @param {Object} [options] 配置项
|
|
47
47
|
* @param {boolean} [options.loose=false] 宽松模式。如果为true,只要包含中文即为true
|
package/lib/isHMCard.js
CHANGED
|
@@ -15,7 +15,7 @@ var regHMCard = /^[hm]{1}([0-9]{10}|[0-9]{8})$/i;
|
|
|
15
15
|
* @static
|
|
16
16
|
* @alias module:Validator.isHMCard
|
|
17
17
|
* @since 4.0.0
|
|
18
|
-
* @see
|
|
18
|
+
* @see {@link https://zh.wikipedia.org/wiki/港澳居民来往内地通行证|港澳居民来往内地通行证}
|
|
19
19
|
* @param {*} value 要检测的值
|
|
20
20
|
* @returns {boolean} 是否为港澳居民来往内地通行证
|
|
21
21
|
* @example
|
package/lib/isIdCard.js
CHANGED
|
@@ -35,8 +35,8 @@ function check(id) {
|
|
|
35
35
|
* @static
|
|
36
36
|
* @alias module:Validator.isIdCard
|
|
37
37
|
* @since 1.1.0
|
|
38
|
-
* @see
|
|
39
|
-
* @see
|
|
38
|
+
* @see {@link https://zh.wikipedia.org/wiki/中华人民共和国公民身份号码|中华人民共和国公民身份号码}
|
|
39
|
+
* @see {@link https://baike.baidu.com/item/居民身份证号码|居民身份证号码}
|
|
40
40
|
* @param {*} value 要检测的值
|
|
41
41
|
* @param {Object} [options] 配置项
|
|
42
42
|
* @param {boolean} [options.loose=false] 宽松模式,支持15位身份证号码
|
package/lib/isPassport.js
CHANGED
|
@@ -15,8 +15,8 @@ var reg = /^((e[\da-z])|(de)|(se)|(pe)|([khm][\da-z]))[\da-z]{7}$/i;
|
|
|
15
15
|
*
|
|
16
16
|
* @static
|
|
17
17
|
* @alias module:Validator.isPassport
|
|
18
|
-
* @see 参考 {@link https://zh.wikipedia.org/wiki/中华人民共和国护照#个人资料页|中华人民共和国护照#个人资料页}
|
|
19
18
|
* @since 1.1.0
|
|
19
|
+
* @see {@link https://zh.wikipedia.org/wiki/中华人民共和国护照#个人资料页|中华人民共和国护照#个人资料页}
|
|
20
20
|
* @param {*} value 要检测的值
|
|
21
21
|
* @returns {boolean} 值是否为护照号
|
|
22
22
|
* @example
|
package/lib/isPassword.js
CHANGED
|
@@ -11,11 +11,11 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "d
|
|
|
11
11
|
* <p><strong>注意:该校验只校验是否存在不同字符(大小写字母、数字、特殊符号),不判断长度。</strong></p>
|
|
12
12
|
* <p><i>如果需要更细致的验证,请使用 <a href="#.validatePassword">validatePassword</a></i></p>
|
|
13
13
|
*
|
|
14
|
-
* @see 参考 {@link https://baike.baidu.com/item/ASCII#3|ASCII}
|
|
15
14
|
* @static
|
|
16
15
|
* @alias module:Validator.isPassword
|
|
17
|
-
* @since 1.1.0
|
|
18
16
|
* @requires module:Validator.validatePassword
|
|
17
|
+
* @since 1.1.0
|
|
18
|
+
* @see {@link https://baike.baidu.com/item/ASCII#3|ASCII}
|
|
19
19
|
* @param {*} value 要检测的值
|
|
20
20
|
* @param {Object} [options] 配置项
|
|
21
21
|
* @param {number} [options.level=2] 密码强度 1-包含一种字符 2-包含两种字符 3-包含三种字符。(大写字母、小写字母、数字、特殊字符)
|
|
@@ -50,8 +50,8 @@ function sumCheckCode(preCode) {
|
|
|
50
50
|
*
|
|
51
51
|
* @static
|
|
52
52
|
* @alias module:Validator.isSocialCreditCode
|
|
53
|
-
* @see 参考 {@link https://zh.wikisource.org/zh-hans/GB_32100-2015_法人和其他组织统一社会信用代码编码规则|GB 32100-2015 法人和其他组织统一社会信用代码编码规则}
|
|
54
53
|
* @since 1.1.0
|
|
54
|
+
* @see {@link https://zh.wikisource.org/zh-hans/GB_32100-2015_法人和其他组织统一社会信用代码编码规则|GB 32100-2015 法人和其他组织统一社会信用代码编码规则}
|
|
55
55
|
* @param {*} value 要检测的值
|
|
56
56
|
* @param {Object} [options] 配置项
|
|
57
57
|
* @param {boolean} [options.checkCode=true] 是否校验最后一位校验码,如果为false,不校验校验位。
|
package/lib/isSwiftCode.js
CHANGED
|
@@ -13,8 +13,8 @@ var reg = /^[A-Z]{6}[A-Z\d]{2}(?:[A-Z\d]{3})?$/;
|
|
|
13
13
|
*
|
|
14
14
|
* @static
|
|
15
15
|
* @alias module:Validator.isSwiftCode
|
|
16
|
-
* @see 参考 {@link https://zh.wikipedia.org/wiki/ISO_9362|ISO 9362}
|
|
17
16
|
* @since 4.9.0
|
|
17
|
+
* @see {@link https://zh.wikipedia.org/wiki/ISO_9362|ISO 9362}
|
|
18
18
|
* @param {*} value 要检测的值
|
|
19
19
|
* @returns {boolean} 值是否为 Swift Code
|
|
20
20
|
* @example
|
package/lib/isTWCard.js
CHANGED
|
@@ -18,7 +18,7 @@ var singleRegTWCard = /^[\da-z]{10,12}$/i;
|
|
|
18
18
|
* @static
|
|
19
19
|
* @alias module:Validator.isTWCard
|
|
20
20
|
* @since 4.0.0
|
|
21
|
-
* @see
|
|
21
|
+
* @see {@link https://zh.wikipedia.org/wiki/台湾居民来往大陆通行证|台湾居民来往大陆通行证}
|
|
22
22
|
* @param {*} value 要检测的值
|
|
23
23
|
* @param {Object} [options] 配置项
|
|
24
24
|
* @param {boolean} [options.loose=false] 宽松模式。如果为true,表示支持一次性短期通行证
|
package/lib/isUrl.js
CHANGED
|
@@ -30,7 +30,7 @@ var regNonProtocal = new RegExp("^(?:".concat(serverReg, ")(?:").concat(portReg,
|
|
|
30
30
|
* @static
|
|
31
31
|
* @alias module:Validator.isUrl
|
|
32
32
|
* @since 3.4.0
|
|
33
|
-
* @see
|
|
33
|
+
* @see {@link https://zh.wikipedia.org/wiki/统一资源定位符|统一资源定位符}
|
|
34
34
|
* @param {*} value 要检测的值
|
|
35
35
|
* @returns {boolean} 值是否为url
|
|
36
36
|
* @example
|
package/lib/isVehicle.js
CHANGED
|
@@ -14,8 +14,8 @@ var reg = /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕
|
|
|
14
14
|
*
|
|
15
15
|
* @static
|
|
16
16
|
* @alias module:Validator.isVehicle
|
|
17
|
-
* @see 参考 {@link https://baike.baidu.com/item/车牌号|车牌号}
|
|
18
17
|
* @since 1.1.0
|
|
18
|
+
* @see {@link https://baike.baidu.com/item/车牌号|车牌号}
|
|
19
19
|
* @param {*} value 要检测的值
|
|
20
20
|
* @returns {boolean} 值是否为车牌号
|
|
21
21
|
* @example
|
package/lib/normalizeString.js
CHANGED
|
@@ -12,8 +12,8 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "d
|
|
|
12
12
|
*
|
|
13
13
|
* @static
|
|
14
14
|
* @alias module:Processor.normalizeString
|
|
15
|
-
* @see 参考 {@link https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/String#string_instances|String}
|
|
16
15
|
* @since 4.3.0
|
|
16
|
+
* @see {@link https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/String#string_instances|String}
|
|
17
17
|
* @param {*} value 待处理的值
|
|
18
18
|
* @returns {string} 规整化的值
|
|
19
19
|
* @example
|
package/lib/numberToChinese.js
CHANGED
|
@@ -136,8 +136,9 @@ function mapNumberChar(num) {
|
|
|
136
136
|
}
|
|
137
137
|
|
|
138
138
|
/**
|
|
139
|
-
*
|
|
140
|
-
*
|
|
139
|
+
* 数字转中文数字<br/><br/>
|
|
140
|
+
*
|
|
141
|
+
* 如果数字不在安全数字 -9007199254740991~9007199254740991 范围内,处理会有异常。
|
|
141
142
|
*
|
|
142
143
|
* @static
|
|
143
144
|
* @alias module:Processor.numberToChinese
|
package/lib/parseIdCard.js
CHANGED
|
@@ -75,9 +75,9 @@ var Provinces = [
|
|
|
75
75
|
* @static
|
|
76
76
|
* @alias module:Processor.parseIdCard
|
|
77
77
|
* @since 4.0.0
|
|
78
|
-
* @see
|
|
78
|
+
* @see {@link https://baike.baidu.com/item/居民身份证号码|居民身份证号码}
|
|
79
79
|
* @param {string} id 身份证号码,支持15位
|
|
80
|
-
* @returns {null
|
|
80
|
+
* @returns {IdCardInfo | null} 省份、生日、性别,省/市/区/年/月/日/性别编码。如果解析失败将返回 null 。
|
|
81
81
|
* @example
|
|
82
82
|
*
|
|
83
83
|
* parseIdCard('123456789123456'); // null
|