util-helpers 4.15.2 → 4.16.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/README.md +6 -5
- package/dist/util-helpers.js +887 -479
- 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 +8 -12
- package/esm/dataURLToBlob.js +6 -5
- package/esm/download.js +156 -0
- package/esm/fileReader.js +67 -0
- package/esm/filterTree.js +1 -1
- package/esm/findTreeNode.js +1 -1
- package/esm/findTreeNodes.js +1 -1
- package/esm/findTreeSelect.js +1 -1
- package/esm/index.js +15 -5
- package/esm/interface.doc.js +124 -0
- package/esm/{transformFieldNames.type.js → interface.type.js} +2 -4
- package/esm/listToTree.js +1 -1
- package/esm/numberToChinese.js +3 -2
- package/esm/parseIdCard.js +1 -1
- package/esm/replaceChar.js +11 -7
- package/esm/safeDate.js +26 -9
- package/esm/transformFieldNames.js +2 -3
- package/esm/treeToList.js +1 -1
- 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/lib/ajax.js +156 -0
- package/lib/blobToDataURL.js +8 -12
- package/lib/dataURLToBlob.js +6 -5
- package/lib/download.js +161 -0
- package/lib/fileReader.js +74 -0
- package/lib/filterTree.js +1 -1
- package/lib/findTreeNode.js +1 -1
- package/lib/findTreeNodes.js +1 -1
- package/lib/findTreeSelect.js +1 -1
- package/lib/index.js +26 -5
- package/lib/interface.doc.js +126 -0
- package/lib/listToTree.js +1 -1
- package/lib/numberToChinese.js +3 -2
- package/lib/parseIdCard.js +1 -1
- package/lib/replaceChar.js +11 -7
- package/lib/safeDate.js +27 -10
- package/lib/transformFieldNames.js +1 -1
- package/lib/treeToList.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/package.json +2 -2
- package/types/ajax.d.ts +121 -0
- package/types/blobToDataURL.d.ts +5 -1
- package/types/download.d.ts +77 -0
- package/types/fileReader.d.ts +3 -0
- package/types/filterTree.d.ts +1 -1
- package/types/findTreeNode.d.ts +1 -1
- package/types/findTreeNodes.d.ts +1 -1
- package/types/findTreeSelect.d.ts +1 -1
- package/types/index.d.ts +8 -5
- package/types/{transformFieldNames.type.d.ts → interface.type.d.ts} +1 -1
- package/types/listToTree.d.ts +1 -1
- package/types/numberToChinese.d.ts +3 -2
- package/types/parseIdCard.d.ts +2 -2
- package/types/replaceChar.d.ts +11 -7
- package/types/safeDate.d.ts +3 -23
- package/types/transformFieldNames.d.ts +2 -2
- package/types/treeToList.d.ts +1 -1
- 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/esm/transformFieldNames.doc.js +0 -35
- package/lib/transformFieldNames.doc.js +0 -42
- /package/lib/{transformFieldNames.type.js → interface.type.js} +0 -0
package/types/ajax.d.ts
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
export default ajax;
|
|
2
|
+
/**
|
|
3
|
+
* XMLHttpRequest 事件对象
|
|
4
|
+
*/
|
|
5
|
+
export type XMLHttpRequestEvent = XMLHttpRequest['onloadstart'];
|
|
6
|
+
/**
|
|
7
|
+
* ajax配置项
|
|
8
|
+
*/
|
|
9
|
+
export type AjaxOptions = {
|
|
10
|
+
/**
|
|
11
|
+
* 创建请求时使用的方法
|
|
12
|
+
*/
|
|
13
|
+
method?: string | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* 请求体被发送的数据
|
|
16
|
+
*/
|
|
17
|
+
data?: Document | XMLHttpRequestBodyInit | null | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* 自定义请求头
|
|
20
|
+
*/
|
|
21
|
+
headers?: {
|
|
22
|
+
[x: string]: string;
|
|
23
|
+
} | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* 响应类型
|
|
26
|
+
*/
|
|
27
|
+
responseType?: XMLHttpRequestResponseType | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* 请求超时的毫秒数
|
|
30
|
+
*/
|
|
31
|
+
timeout?: number | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* 跨域请求时是否需要使用凭证
|
|
34
|
+
*/
|
|
35
|
+
withCredentials?: boolean | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* 是否异步执行操作
|
|
38
|
+
*/
|
|
39
|
+
async?: boolean | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* 用户名,用于认证用途
|
|
42
|
+
*/
|
|
43
|
+
user?: string | null | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* 密码,用于认证用途
|
|
46
|
+
*/
|
|
47
|
+
password?: string | null | undefined;
|
|
48
|
+
/**
|
|
49
|
+
* 接收到响应数据时触发
|
|
50
|
+
*/
|
|
51
|
+
onLoadStart?: ((this: XMLHttpRequest, ev: ProgressEvent<EventTarget>) => any) | null | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* 请求接收到更多数据时,周期性地触发
|
|
54
|
+
*/
|
|
55
|
+
onProgress?: ((this: XMLHttpRequest, ev: ProgressEvent<EventTarget>) => any) | null | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* 当 request 被停止时触发,例如当程序调用 XMLHttpRequest.abort() 时
|
|
58
|
+
*/
|
|
59
|
+
onAbort?: ((this: XMLHttpRequest, ev: ProgressEvent<EventTarget>) => any) | null | undefined;
|
|
60
|
+
/**
|
|
61
|
+
* 在预设时间内没有接收到响应时触发
|
|
62
|
+
*/
|
|
63
|
+
onTimeout?: ((this: XMLHttpRequest, ev: ProgressEvent<EventTarget>) => any) | null | undefined;
|
|
64
|
+
/**
|
|
65
|
+
* 当 request 遭遇错误时触发
|
|
66
|
+
*/
|
|
67
|
+
onError?: ((this: XMLHttpRequest, ev: ProgressEvent<EventTarget>) => any) | null | undefined;
|
|
68
|
+
/**
|
|
69
|
+
* 请求成功完成时触发
|
|
70
|
+
*/
|
|
71
|
+
onLoad?: ((this: XMLHttpRequest, ev: ProgressEvent<EventTarget>) => any) | null | undefined;
|
|
72
|
+
/**
|
|
73
|
+
* 请求结束时触发,无论请求成功 (load) 还是失败 (abort 或 error)
|
|
74
|
+
*/
|
|
75
|
+
onLoadEnd?: ((this: XMLHttpRequest, ev: ProgressEvent<EventTarget>) => any) | null | undefined;
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* @typedef {XMLHttpRequest['onloadstart']} XMLHttpRequestEvent XMLHttpRequest 事件对象
|
|
79
|
+
*/
|
|
80
|
+
/**
|
|
81
|
+
* @see {@link https://developer.mozilla.org/zh-CN/docs/Web/API/XMLHttpRequest|XMLHttpRequest}
|
|
82
|
+
* @typedef {Object} AjaxOptions ajax配置项
|
|
83
|
+
* @property {string} [method="get"] 创建请求时使用的方法
|
|
84
|
+
* @property {Document | XMLHttpRequestBodyInit | null} [data=null] 请求体被发送的数据
|
|
85
|
+
* @property {Object.<string, string>} [headers] 自定义请求头
|
|
86
|
+
* @property {XMLHttpRequestResponseType} [responseType] 响应类型
|
|
87
|
+
* @property {number} [timeout] 请求超时的毫秒数
|
|
88
|
+
* @property {boolean} [withCredentials=false] 跨域请求时是否需要使用凭证
|
|
89
|
+
* @property {boolean} [async=true] 是否异步执行操作
|
|
90
|
+
* @property {string|null} [user=null] 用户名,用于认证用途
|
|
91
|
+
* @property {string|null} [password=null] 密码,用于认证用途
|
|
92
|
+
* @property {XMLHttpRequestEvent} [onLoadStart] 接收到响应数据时触发
|
|
93
|
+
* @property {XMLHttpRequestEvent} [onProgress] 请求接收到更多数据时,周期性地触发
|
|
94
|
+
* @property {XMLHttpRequestEvent} [onAbort] 当 request 被停止时触发,例如当程序调用 XMLHttpRequest.abort() 时
|
|
95
|
+
* @property {XMLHttpRequestEvent} [onTimeout] 在预设时间内没有接收到响应时触发
|
|
96
|
+
* @property {XMLHttpRequestEvent} [onError] 当 request 遭遇错误时触发
|
|
97
|
+
* @property {XMLHttpRequestEvent} [onLoad] 请求成功完成时触发
|
|
98
|
+
* @property {XMLHttpRequestEvent} [onLoadEnd] 请求结束时触发,无论请求成功 (load) 还是失败 (abort 或 error)
|
|
99
|
+
*/
|
|
100
|
+
/**
|
|
101
|
+
* 请求<br/><br/>
|
|
102
|
+
*
|
|
103
|
+
* <em style="font-weight: bold;">注意:该方法仅适用于浏览器端。</em>
|
|
104
|
+
*
|
|
105
|
+
* @static
|
|
106
|
+
* @alias module:Other.ajax
|
|
107
|
+
* @since 4.16.0
|
|
108
|
+
* @see {@link https://developer.mozilla.org/zh-CN/docs/Web/API/XMLHttpRequest|XMLHttpRequest}
|
|
109
|
+
* @param {string} url 地址
|
|
110
|
+
* @param {AjaxOptions} [options] 配置项
|
|
111
|
+
* @returns {Promise<ProgressEvent<EventTarget>>}
|
|
112
|
+
* @example
|
|
113
|
+
* ajax('/somefile').then(res=>{
|
|
114
|
+
* // do something
|
|
115
|
+
* });
|
|
116
|
+
*
|
|
117
|
+
* ajax('/api', { method: 'post' }).then(res=>{
|
|
118
|
+
* // do something
|
|
119
|
+
* });
|
|
120
|
+
*/
|
|
121
|
+
declare function ajax(url: string, options?: AjaxOptions | undefined): Promise<ProgressEvent<EventTarget>>;
|
package/types/blobToDataURL.d.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
export default blobToDataURL;
|
|
2
2
|
/**
|
|
3
|
-
* 将 Blob 或 File 对象转成 data:URL 格式的 Base64
|
|
3
|
+
* 将 Blob 或 File 对象转成 data:URL 格式的 Base64 字符串<br/><br/>
|
|
4
|
+
*
|
|
5
|
+
* <em style="font-weight: bold;">注意:该方法仅适用于浏览器端。</em>
|
|
4
6
|
*
|
|
5
7
|
* @static
|
|
6
8
|
* @alias module:Processor.blobToDataURL
|
|
7
9
|
* @see 参考 {@link https://developer.mozilla.org/zh-CN/docs/Web/API/FileReader/readAsDataURL|FileReader.readAsDataURL()}
|
|
8
10
|
* @since 4.1.0
|
|
11
|
+
* @ignore
|
|
12
|
+
* @deprecated 请使用 `fileReader` 方法
|
|
9
13
|
* @param {Blob} blob Blob 或 File 对象
|
|
10
14
|
* @returns {Promise<string>} data:URL 格式的 Base64 字符串。
|
|
11
15
|
* @example
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
export default download;
|
|
2
|
+
/**
|
|
3
|
+
* ajax 配置项
|
|
4
|
+
*/
|
|
5
|
+
export type AjaxOptions = import('./ajax.js').AjaxOptions;
|
|
6
|
+
export type TransformRequest = (options: AjaxOptions) => AjaxOptions;
|
|
7
|
+
export type TransformResponse = (res: Blob) => Blob;
|
|
8
|
+
/**
|
|
9
|
+
* 下载配置项
|
|
10
|
+
*/
|
|
11
|
+
export type DownloadOptions = {
|
|
12
|
+
/**
|
|
13
|
+
* 文件名称
|
|
14
|
+
*/
|
|
15
|
+
fileName?: string | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* MIME 类型
|
|
18
|
+
*/
|
|
19
|
+
type?: string | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* 手动设置数据类型,默认会根据传入的数据判断类型,主要是为了区分 url 和 text 。<br/>如果你要下载的文本是 url ,请设置 'text' ;如果你要下载的 url 是绝对/相对路径,请设置 'url' 。
|
|
22
|
+
*/
|
|
23
|
+
dataType?: "text" | "url" | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* 请求前触发,XHR 对象或配置调整
|
|
26
|
+
*/
|
|
27
|
+
transformRequest?: TransformRequest | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* 请求成功后触发,在传递给 then/catch 前,允许修改响应数据
|
|
30
|
+
*/
|
|
31
|
+
transformResponse?: TransformResponse | undefined;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* @typedef {import('./ajax.js').AjaxOptions} AjaxOptions ajax 配置项
|
|
35
|
+
*/
|
|
36
|
+
/**
|
|
37
|
+
* @callback TransformRequest
|
|
38
|
+
* @param {AjaxOptions} options ajax 配置项
|
|
39
|
+
* @returns {AjaxOptions}
|
|
40
|
+
*/
|
|
41
|
+
/**
|
|
42
|
+
* @callback TransformResponse
|
|
43
|
+
* @param {Blob} res 响应的Blob对象。如果你通过 transformRequest 修改了 responseType ,该参数将是该类型响应值。
|
|
44
|
+
* @returns {Blob}
|
|
45
|
+
*/
|
|
46
|
+
/**
|
|
47
|
+
* @typedef {Object} DownloadOptions 下载配置项
|
|
48
|
+
* @property {string} [options.fileName] 文件名称
|
|
49
|
+
* @property {string} [options.type] MIME 类型
|
|
50
|
+
* @property {'url'|'text'} [options.dataType] 手动设置数据类型,默认会根据传入的数据判断类型,主要是为了区分 url 和 text 。<br/>如果你要下载的文本是 url ,请设置 'text' ;如果你要下载的 url 是绝对/相对路径,请设置 'url' 。
|
|
51
|
+
* @property {TransformRequest} [options.transformRequest] 请求前触发,XHR 对象或配置调整
|
|
52
|
+
* @property {TransformResponse} [options.transformResponse] 请求成功后触发,在传递给 then/catch 前,允许修改响应数据
|
|
53
|
+
*/
|
|
54
|
+
/**
|
|
55
|
+
* 下载<br/><br/>
|
|
56
|
+
*
|
|
57
|
+
* <em style="font-weight: bold;">注意:该方法仅适用于浏览器端,兼容 IE10+ 和现代浏览器。</em>
|
|
58
|
+
*
|
|
59
|
+
* @static
|
|
60
|
+
* @alias module:Other.download
|
|
61
|
+
* @since 4.16.0
|
|
62
|
+
* @see {@link https://zh.wikipedia.org/wiki/多用途互聯網郵件擴展|多用途互联网邮件扩展}
|
|
63
|
+
* @param {string|Blob|ArrayBuffer|Int8Array|Uint8Array|Uint8ClampedArray|Int16Array|Uint16Array|Int32Array|Uint32Array|Float32Array|Float64Array|BigInt64Array|BigUint64Array} data 字符串、blob数据或url地址
|
|
64
|
+
* @param {string|DownloadOptions} [options] 文件名称 或 配置项
|
|
65
|
+
* @returns {Promise<void>}
|
|
66
|
+
* @example
|
|
67
|
+
* // 文本
|
|
68
|
+
* download('hello world', 'text.txt');
|
|
69
|
+
*
|
|
70
|
+
* // 远程文件
|
|
71
|
+
* download('/xxx.jpg', { dataType: 'url' });
|
|
72
|
+
*
|
|
73
|
+
* // blob文件
|
|
74
|
+
* download(new Blob(['hello world']), 'text.txt');
|
|
75
|
+
*
|
|
76
|
+
*/
|
|
77
|
+
declare function download(data: string | Blob | ArrayBuffer | Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array, options?: string | DownloadOptions | undefined): Promise<void>;
|
package/types/filterTree.d.ts
CHANGED
package/types/findTreeNode.d.ts
CHANGED
package/types/findTreeNodes.d.ts
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -27,25 +27,28 @@ export { default as numberToChinese } from "./numberToChinese";
|
|
|
27
27
|
export { default as bytesToSize } from "./bytesToSize";
|
|
28
28
|
export { default as parseIdCard } from "./parseIdCard";
|
|
29
29
|
export { default as blobToDataURL } from "./blobToDataURL";
|
|
30
|
+
export { default as fileReader } from "./fileReader";
|
|
30
31
|
export { default as dataURLToBlob } from "./dataURLToBlob";
|
|
31
32
|
export { default as setDataURLPrefix } from "./setDataURLPrefix";
|
|
32
33
|
export { default as normalizeString } from "./normalizeString";
|
|
33
34
|
export { default as safeDate } from "./safeDate";
|
|
34
35
|
export { default as formatMobile } from "./formatMobile";
|
|
35
36
|
export { default as padZero } from "./padZero";
|
|
36
|
-
export { default as transformFieldNames } from "./transformFieldNames";
|
|
37
|
-
export { default as listToTree } from "./listToTree";
|
|
38
|
-
export { default as treeToList } from "./treeToList";
|
|
39
|
-
export { default as filterTree } from "./filterTree";
|
|
40
37
|
export { default as plus } from "./plus";
|
|
41
38
|
export { default as minus } from "./minus";
|
|
42
39
|
export { default as times } from "./times";
|
|
43
40
|
export { default as divide } from "./divide";
|
|
44
41
|
export { default as round } from "./round";
|
|
45
|
-
export { default as
|
|
42
|
+
export { default as ajax } from "./ajax";
|
|
46
43
|
export { default as calculateCursorPosition } from "./calculateCursorPosition";
|
|
44
|
+
export { default as download } from "./download";
|
|
47
45
|
export { default as randomString } from "./randomString";
|
|
48
46
|
export { default as strlen } from "./strlen";
|
|
47
|
+
export { default as waitTime } from "./waitTime";
|
|
48
|
+
export { default as transformFieldNames } from "./transformFieldNames";
|
|
49
|
+
export { default as listToTree } from "./listToTree";
|
|
50
|
+
export { default as treeToList } from "./treeToList";
|
|
51
|
+
export { default as filterTree } from "./filterTree";
|
|
49
52
|
export { default as findTreeNode } from "./findTreeNode";
|
|
50
53
|
export { default as findTreeNodes } from "./findTreeNodes";
|
|
51
54
|
export { default as findTreeSelect } from "./findTreeSelect";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export type ExchangeFieldNames<D extends unknown, F extends Record<string, keyof D>> = Omit<D, F[keyof F]> & { [P in keyof F]: D[F[P]]; };
|
|
2
|
-
export type TransformFieldNames<D extends unknown, F extends Record<string,
|
|
2
|
+
export type TransformFieldNames<D extends unknown, F extends Record<string, any>, C extends string> = (C extends keyof D ? ExchangeFieldNames<Omit<D, C> & Record<C, TransformFieldNames<D, F, C>>, F> : ExchangeFieldNames<D, F>)[];
|
package/types/listToTree.d.ts
CHANGED
package/types/parseIdCard.d.ts
CHANGED
|
@@ -78,7 +78,7 @@ export type IdCardInfo = {
|
|
|
78
78
|
* @since 4.0.0
|
|
79
79
|
* @see 参考 {@link https://baike.baidu.com/item/居民身份证号码|居民身份证号码}
|
|
80
80
|
* @param {string} id 身份证号码,支持15位
|
|
81
|
-
* @returns {null
|
|
81
|
+
* @returns {IdCardInfo | null} 省份、生日、性别,省/市/区/年/月/日/性别编码。如果解析失败将返回 null 。
|
|
82
82
|
* @example
|
|
83
83
|
*
|
|
84
84
|
* parseIdCard('123456789123456'); // null
|
|
@@ -104,4 +104,4 @@ export type IdCardInfo = {
|
|
|
104
104
|
* }
|
|
105
105
|
*
|
|
106
106
|
*/
|
|
107
|
-
declare function parseIdCard(id: string):
|
|
107
|
+
declare function parseIdCard(id: string): IdCardInfo | null;
|
package/types/replaceChar.d.ts
CHANGED
|
@@ -15,20 +15,24 @@ export default replaceChar;
|
|
|
15
15
|
* @returns {string} 处理后的字符
|
|
16
16
|
* @example
|
|
17
17
|
*
|
|
18
|
-
* // 手机号
|
|
18
|
+
* // 手机号 前3后4
|
|
19
19
|
* replaceChar('13000000000'); // 130****0000
|
|
20
20
|
*
|
|
21
|
-
* // 身份证
|
|
22
|
-
* replaceChar('130701199310302288'); //
|
|
21
|
+
* // 身份证 前6后4
|
|
22
|
+
* replaceChar('130701199310302288', { start: 6, end: -4 }); // 130701********2288
|
|
23
23
|
*
|
|
24
|
-
* // 邮箱
|
|
24
|
+
* // 邮箱 @前两位
|
|
25
25
|
* const email = '12345@qq.com'
|
|
26
|
+
* const emailAtIndex = email.indexOf('@');
|
|
27
|
+
* replaceChar(email, { start: emailAtIndex - 2, end: emailAtIndex }); // 123**@qq.com
|
|
28
|
+
* // 邮箱 前2和@后面内容,固定替换字符4位
|
|
26
29
|
* replaceChar(email, {start: 2, end: email.indexOf('@'), repeat: 4}); // 12****@qq.com
|
|
27
30
|
*
|
|
28
|
-
* // 银行卡号
|
|
31
|
+
* // 银行卡号 只展示后4位,固定替换字符4位
|
|
29
32
|
* replaceChar('6228480402564890018', {start: 0, end: -4, repeat: 4}); // ****0018
|
|
30
|
-
*
|
|
31
|
-
* //
|
|
33
|
+
* // 银行卡号 前6后4
|
|
34
|
+
* replaceChar('6228480402564890018', { start: 6, end: -4 }); // 622848*********0018
|
|
35
|
+
* // 银行卡号 前4后3 忽略格式的空格
|
|
32
36
|
* replaceChar('6228 4804 0256 4890 018', {start: 4, end: -4, exclude: ' '}); // 6228 **** **** **** 018
|
|
33
37
|
*
|
|
34
38
|
* // 用户名
|
package/types/safeDate.d.ts
CHANGED
|
@@ -1,24 +1,4 @@
|
|
|
1
1
|
export default safeDate;
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
*
|
|
6
|
-
* @static
|
|
7
|
-
* @alias module:Processor.safeDate
|
|
8
|
-
* @see 参考 {@link https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Date|Date}
|
|
9
|
-
* @since 4.4.0
|
|
10
|
-
* @param {string|number|Date} [value] 日期时间字符串、毫秒数、日期对象
|
|
11
|
-
* @param {...number} args 月/日/时/分/秒/毫秒
|
|
12
|
-
* @returns {Date} Date 实例日期对象
|
|
13
|
-
* @example
|
|
14
|
-
*
|
|
15
|
-
* safeDate('2022-1-1'); // Sat Jan 01 2022 00:00:00 GMT+0800 (中国标准时间)
|
|
16
|
-
* safeDate('2022/1/1'); // Sat Jan 01 2022 00:00:00 GMT+0800 (中国标准时间)
|
|
17
|
-
* safeDate('2022.1.1'); // Sat Jan 01 2022 00:00:00 GMT+0800 (中国标准时间)
|
|
18
|
-
* safeDate('2022.1.1 11:11'); // Sat Jan 01 2022 11:11:00 GMT+0800 (中国标准时间)
|
|
19
|
-
* safeDate(99, 1); // Mon Feb 01 1999 00:00:00 GMT+0800 (中国标准时间)
|
|
20
|
-
* safeDate(1646711233171); // Tue Mar 08 2022 11:47:13 GMT+0800 (中国标准时间)
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*/
|
|
24
|
-
declare function safeDate(value?: string | number | Date | undefined, ...args: number[]): Date;
|
|
2
|
+
declare function safeDate(): Date;
|
|
3
|
+
declare function safeDate(value: number | string | Date): Date;
|
|
4
|
+
declare function safeDate(year: number, monthIndex: number, date?: number | undefined, hours?: number | undefined, minutes?: number | undefined, seconds?: number | undefined, ms?: number | undefined): Date;
|
|
@@ -12,7 +12,7 @@ export default transformFieldNames;
|
|
|
12
12
|
* @param {F} fieldNames 字段名映射
|
|
13
13
|
* @param {C} [childrenField] 子级数据字段名
|
|
14
14
|
* @param {'spread'|'self'} [nodeAssign='spread'] 节点赋值方式。spread表示使用展开运算符创建新值,self表示使用自身对象。
|
|
15
|
-
* @returns {import('./
|
|
15
|
+
* @returns {import('./interface.type.js').TransformFieldNames<D, F, C>}
|
|
16
16
|
* @example
|
|
17
17
|
*
|
|
18
18
|
* const options = [{code: '1', name: 'one'},{code:'2', name:'two'}];
|
|
@@ -32,4 +32,4 @@ export default transformFieldNames;
|
|
|
32
32
|
* const newOptions4 = transformFieldNames(options3, {label: 'name', value: 'code', children: 'childs'}, 'childs');
|
|
33
33
|
* // [{value: '1', label: 'one'},{value:'2', label:'two', children: [{value: '2-1', label:'two-one'}]}]
|
|
34
34
|
*/
|
|
35
|
-
declare function transformFieldNames<D extends unknown, F extends Record<string, keyof D>, C extends string>(data: D[], fieldNames: F, childrenField?: C | undefined, nodeAssign?: "spread" | "self" | undefined): import("./
|
|
35
|
+
declare function transformFieldNames<D extends unknown, F extends Record<string, keyof D>, C extends string>(data: D[], fieldNames: F, childrenField?: C | undefined, nodeAssign?: "spread" | "self" | undefined): import("./interface.type.js").TransformFieldNames<D, F, C>;
|
package/types/treeToList.d.ts
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
|
-
import isArguments from
|
|
2
|
-
import isArray from
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
import
|
|
17
|
-
import
|
|
18
|
-
import
|
|
19
|
-
|
|
1
|
+
import isArguments from './isArguments';
|
|
2
|
+
import isArray from './isArray';
|
|
3
|
+
import isArrayBuffer from './isArrayBuffer';
|
|
4
|
+
import isBlob from './isBlob';
|
|
5
|
+
import isBoolean from './isBoolean';
|
|
6
|
+
import isDate from './isDate';
|
|
7
|
+
import isError from './isError';
|
|
8
|
+
import isFunction from './isFunction';
|
|
9
|
+
import isObject from './isObject';
|
|
10
|
+
import isNull from './isNull';
|
|
11
|
+
import isNaN from './isNaN';
|
|
12
|
+
import isNumber from './isNumber';
|
|
13
|
+
import isRegExp from './isRegExp';
|
|
14
|
+
import isString from './isString';
|
|
15
|
+
import isSymbol from './isSymbol';
|
|
16
|
+
import isMap from './isMap';
|
|
17
|
+
import isWeakMap from './isWeakMap';
|
|
18
|
+
import isSet from './isSet';
|
|
19
|
+
import isWeakSet from './isWeakSet';
|
|
20
|
+
import isUndefined from './isUndefined';
|
|
21
|
+
export { isArguments, isArray, isArrayBuffer, isBlob, isBoolean, isDate, isError, isFunction, isObject, isNull, isNaN, isNumber, isRegExp, isString, isSymbol, isMap, isWeakMap, isSet, isWeakSet, isUndefined };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export default isArrayBuffer;
|
|
2
|
+
/**
|
|
3
|
+
* 检查值是否为ArrayBuffer对象
|
|
4
|
+
*
|
|
5
|
+
* @static
|
|
6
|
+
* @alias module:Type.isArrayBuffer
|
|
7
|
+
* @since 4.16.0
|
|
8
|
+
* @param {*} value 检查值
|
|
9
|
+
* @returns {boolean} 是否为ArrayBuffer对象
|
|
10
|
+
* @example
|
|
11
|
+
*
|
|
12
|
+
* isArrayBuffer(new ArrayBuffer(8))
|
|
13
|
+
* // => true
|
|
14
|
+
*
|
|
15
|
+
* isArrayBuffer({})
|
|
16
|
+
* // => false
|
|
17
|
+
*
|
|
18
|
+
* isArrayBuffer('2012')
|
|
19
|
+
* // => false
|
|
20
|
+
*/
|
|
21
|
+
declare function isArrayBuffer(value: any): boolean;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export default isBlob;
|
|
2
|
+
/**
|
|
3
|
+
* 检查值是否为Blob对象<br/><br/>
|
|
4
|
+
*
|
|
5
|
+
* <em style="font-weight: bold;">注意:该方法仅适用于浏览器端。</em>
|
|
6
|
+
*
|
|
7
|
+
* @static
|
|
8
|
+
* @alias module:Type.isBlob
|
|
9
|
+
* @since 4.16.0
|
|
10
|
+
* @param {*} value 检查值
|
|
11
|
+
* @returns {boolean} 是否为Blob对象
|
|
12
|
+
* @example
|
|
13
|
+
*
|
|
14
|
+
* isBlob(new Blob(['a']))
|
|
15
|
+
* // => true
|
|
16
|
+
*
|
|
17
|
+
* isBlob({})
|
|
18
|
+
* // => false
|
|
19
|
+
*
|
|
20
|
+
* isBlob('2012')
|
|
21
|
+
* // => false
|
|
22
|
+
*/
|
|
23
|
+
declare function isBlob(value: any): boolean;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-unused-vars */
|
|
2
|
-
// 该文件用于 jsdoc 生成文件。因为一些 typescript 语法, jsdoc 不支持,导致生成文档报错。
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* 转换字段名,返回一个转换字段后的值,不改变原值。
|
|
6
|
-
*
|
|
7
|
-
* @static
|
|
8
|
-
* @alias module:Processor.transformFieldNames
|
|
9
|
-
* @since 4.14.0
|
|
10
|
-
* @param {object[]} data 对象数组。如果是树结构数据,需要指定第三个参数 childrenField
|
|
11
|
-
* @param {object} fieldNames 字段名映射
|
|
12
|
-
* @param {string} [childrenField] 子级数据字段名
|
|
13
|
-
* @param {'spread'|'self'} [nodeAssign='spread'] 节点赋值方式。spread表示使用展开运算符创建新值,self表示使用自身对象。
|
|
14
|
-
* @returns {object[]}
|
|
15
|
-
* @example
|
|
16
|
-
*
|
|
17
|
-
* const options = [{code: '1', name: 'one'},{code:'2', name:'two'}];
|
|
18
|
-
* const newOptions = transformFieldNames(options, {label: 'name', value: 'code'});
|
|
19
|
-
* // [{value: '1', label: 'one'},{value:'2', label:'two'}]
|
|
20
|
-
*
|
|
21
|
-
* // 嵌套数据,指定子级字段名 children
|
|
22
|
-
* 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'}]}]}];
|
|
23
|
-
* const newOptions2 = transformFieldNames(options2, {label: 'name', value: 'code'}, 'children');
|
|
24
|
-
* // [{value: '1', label: 'one'},{value:'2', label:'two', children: [{value: '2-1', label:'two-one', children: [{value: '2-1-1', label:'two-one-one'}]}]}]
|
|
25
|
-
*
|
|
26
|
-
* const options3 = [{code: '1', name: 'one'},{code:'2', name:'two', childs: [{code:'2-1', name:'two-one'}]}];
|
|
27
|
-
* const newOptions3 = transformFieldNames(options3, {label: 'name', value: 'code'}, 'childs');
|
|
28
|
-
* // [{value: '1', label: 'one'},{value:'2', label:'two', childs: [{value: '2-1', label:'two-one'}]}]
|
|
29
|
-
*
|
|
30
|
-
* // 嵌套数据,并替换子集字段名
|
|
31
|
-
* const newOptions4 = transformFieldNames(options3, {label: 'name', value: 'code', children: 'childs'}, 'childs');
|
|
32
|
-
* // [{value: '1', label: 'one'},{value:'2', label:'two', children: [{value: '2-1', label:'two-one'}]}]
|
|
33
|
-
*/
|
|
34
|
-
function transformFieldNames(data, fieldNames, childrenField) {}
|
|
35
|
-
export default transformFieldNames;
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports["default"] = void 0;
|
|
7
|
-
/* eslint-disable no-unused-vars */
|
|
8
|
-
// 该文件用于 jsdoc 生成文件。因为一些 typescript 语法, jsdoc 不支持,导致生成文档报错。
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* 转换字段名,返回一个转换字段后的值,不改变原值。
|
|
12
|
-
*
|
|
13
|
-
* @static
|
|
14
|
-
* @alias module:Processor.transformFieldNames
|
|
15
|
-
* @since 4.14.0
|
|
16
|
-
* @param {object[]} data 对象数组。如果是树结构数据,需要指定第三个参数 childrenField
|
|
17
|
-
* @param {object} fieldNames 字段名映射
|
|
18
|
-
* @param {string} [childrenField] 子级数据字段名
|
|
19
|
-
* @param {'spread'|'self'} [nodeAssign='spread'] 节点赋值方式。spread表示使用展开运算符创建新值,self表示使用自身对象。
|
|
20
|
-
* @returns {object[]}
|
|
21
|
-
* @example
|
|
22
|
-
*
|
|
23
|
-
* const options = [{code: '1', name: 'one'},{code:'2', name:'two'}];
|
|
24
|
-
* const newOptions = transformFieldNames(options, {label: 'name', value: 'code'});
|
|
25
|
-
* // [{value: '1', label: 'one'},{value:'2', label:'two'}]
|
|
26
|
-
*
|
|
27
|
-
* // 嵌套数据,指定子级字段名 children
|
|
28
|
-
* 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'}]}]}];
|
|
29
|
-
* const newOptions2 = transformFieldNames(options2, {label: 'name', value: 'code'}, 'children');
|
|
30
|
-
* // [{value: '1', label: 'one'},{value:'2', label:'two', children: [{value: '2-1', label:'two-one', children: [{value: '2-1-1', label:'two-one-one'}]}]}]
|
|
31
|
-
*
|
|
32
|
-
* const options3 = [{code: '1', name: 'one'},{code:'2', name:'two', childs: [{code:'2-1', name:'two-one'}]}];
|
|
33
|
-
* const newOptions3 = transformFieldNames(options3, {label: 'name', value: 'code'}, 'childs');
|
|
34
|
-
* // [{value: '1', label: 'one'},{value:'2', label:'two', childs: [{value: '2-1', label:'two-one'}]}]
|
|
35
|
-
*
|
|
36
|
-
* // 嵌套数据,并替换子集字段名
|
|
37
|
-
* const newOptions4 = transformFieldNames(options3, {label: 'name', value: 'code', children: 'childs'}, 'childs');
|
|
38
|
-
* // [{value: '1', label: 'one'},{value:'2', label:'two', children: [{value: '2-1', label:'two-one'}]}]
|
|
39
|
-
*/
|
|
40
|
-
function transformFieldNames(data, fieldNames, childrenField) {}
|
|
41
|
-
var _default = transformFieldNames;
|
|
42
|
-
exports["default"] = _default;
|
|
File without changes
|