sculp-js 0.0.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/LICENSE.md +21 -0
- package/README.md +3 -0
- package/lib/cjs/array.js +217 -0
- package/lib/cjs/async.js +63 -0
- package/lib/cjs/clipboard.js +36 -0
- package/lib/cjs/cookie.js +63 -0
- package/lib/cjs/date.js +114 -0
- package/lib/cjs/dom.js +152 -0
- package/lib/cjs/download.js +82 -0
- package/lib/cjs/easing.js +40 -0
- package/lib/cjs/file.js +30 -0
- package/lib/cjs/index.js +41 -0
- package/lib/cjs/object.js +241 -0
- package/lib/cjs/path.js +66 -0
- package/lib/cjs/qs.js +71 -0
- package/lib/cjs/string.js +134 -0
- package/lib/cjs/type.js +47 -0
- package/lib/cjs/url.js +84 -0
- package/lib/cjs/watermark.js +91 -0
- package/lib/es/array.js +208 -0
- package/lib/es/async.js +60 -0
- package/lib/es/clipboard.js +34 -0
- package/lib/es/cookie.js +59 -0
- package/lib/es/date.js +110 -0
- package/lib/es/dom.js +143 -0
- package/lib/es/download.js +77 -0
- package/lib/es/easing.js +38 -0
- package/lib/es/file.js +28 -0
- package/lib/es/index.js +35 -0
- package/lib/es/object.js +228 -0
- package/lib/es/path.js +63 -0
- package/lib/es/qs.js +68 -0
- package/lib/es/string.js +124 -0
- package/lib/es/type.js +28 -0
- package/lib/es/url.js +79 -0
- package/lib/es/watermark.js +89 -0
- package/lib/index.d.ts +644 -0
- package/lib/umd/index.js +1458 -0
- package/package.json +80 -0
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,644 @@
|
|
|
1
|
+
type AnyFunc<R = any> = (...args: any[]) => R;
|
|
2
|
+
type AnyArray = any[];
|
|
3
|
+
type ArrayElements<A> = A extends Array<infer R> ? R : never;
|
|
4
|
+
type AnyObject = Record<string | number, any>;
|
|
5
|
+
type PartialDeep<T> = {
|
|
6
|
+
[P in keyof T]?: PartialDeep<T[P]>;
|
|
7
|
+
};
|
|
8
|
+
declare const typeIs: (any: unknown) => string;
|
|
9
|
+
declare const isString: (any: unknown) => any is string;
|
|
10
|
+
declare const isBoolean: (any: unknown) => any is boolean;
|
|
11
|
+
declare const isSymbol: (any: unknown) => any is symbol;
|
|
12
|
+
declare const isBigInt: (any: unknown) => any is bigint;
|
|
13
|
+
declare const isNumber: (any: unknown) => any is number;
|
|
14
|
+
declare const isUndefined: (any: unknown) => any is undefined;
|
|
15
|
+
declare const isNull: (any: unknown) => any is null;
|
|
16
|
+
declare const isPrimitive: (any: unknown) => boolean;
|
|
17
|
+
declare const isObject: (any: unknown) => any is Record<string, unknown>;
|
|
18
|
+
declare const isArray: (any: unknown) => any is unknown[];
|
|
19
|
+
declare const isFunction: (any: unknown) => any is Function;
|
|
20
|
+
declare const isNaN: (any: unknown) => any is number;
|
|
21
|
+
declare const isDate: (any: unknown) => any is Date;
|
|
22
|
+
declare const isError: (any: unknown) => any is Error;
|
|
23
|
+
declare const isRegExp: (any: unknown) => any is RegExp;
|
|
24
|
+
|
|
25
|
+
type type_AnyArray = AnyArray;
|
|
26
|
+
type type_AnyFunc<R = any> = AnyFunc<R>;
|
|
27
|
+
type type_AnyObject = AnyObject;
|
|
28
|
+
type type_ArrayElements<A> = ArrayElements<A>;
|
|
29
|
+
type type_PartialDeep<T> = PartialDeep<T>;
|
|
30
|
+
declare const type_isArray: typeof isArray;
|
|
31
|
+
declare const type_isBigInt: typeof isBigInt;
|
|
32
|
+
declare const type_isBoolean: typeof isBoolean;
|
|
33
|
+
declare const type_isDate: typeof isDate;
|
|
34
|
+
declare const type_isError: typeof isError;
|
|
35
|
+
declare const type_isFunction: typeof isFunction;
|
|
36
|
+
declare const type_isNaN: typeof isNaN;
|
|
37
|
+
declare const type_isNull: typeof isNull;
|
|
38
|
+
declare const type_isNumber: typeof isNumber;
|
|
39
|
+
declare const type_isObject: typeof isObject;
|
|
40
|
+
declare const type_isPrimitive: typeof isPrimitive;
|
|
41
|
+
declare const type_isRegExp: typeof isRegExp;
|
|
42
|
+
declare const type_isString: typeof isString;
|
|
43
|
+
declare const type_isSymbol: typeof isSymbol;
|
|
44
|
+
declare const type_isUndefined: typeof isUndefined;
|
|
45
|
+
declare namespace type {
|
|
46
|
+
export { type type_AnyArray as AnyArray, type type_AnyFunc as AnyFunc, type type_AnyObject as AnyObject, type type_ArrayElements as ArrayElements, type type_PartialDeep as PartialDeep, typeIs as default, type_isArray as isArray, type_isBigInt as isBigInt, type_isBoolean as isBoolean, type_isDate as isDate, type_isError as isError, type_isFunction as isFunction, type_isNaN as isNaN, type_isNull as isNull, type_isNumber as isNumber, type_isObject as isObject, type_isPrimitive as isPrimitive, type_isRegExp as isRegExp, type_isString as isString, type_isSymbol as isSymbol, type_isUndefined as isUndefined };
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* 判断一个对象是否为类数组
|
|
51
|
+
* @param any
|
|
52
|
+
* @returns {boolean}
|
|
53
|
+
*/
|
|
54
|
+
declare const arrayLike: (any: unknown) => boolean;
|
|
55
|
+
/**
|
|
56
|
+
* 遍历数组,返回 false 中断遍历
|
|
57
|
+
* @param {ArrayLike<V>} array
|
|
58
|
+
* @param {(val: V, idx: number) => any} iterator
|
|
59
|
+
* @param reverse {boolean} 是否倒序
|
|
60
|
+
*/
|
|
61
|
+
declare const arrayEach: <V>(array: ArrayLike<V>, iterator: (val: V, idx: number) => any, reverse?: boolean) => void;
|
|
62
|
+
/**
|
|
63
|
+
* 异步遍历数组,返回 false 中断遍历
|
|
64
|
+
* @param {ArrayLike<V>} array
|
|
65
|
+
* @param {(val: V, idx: number) => Promise<any>} iterator
|
|
66
|
+
* @param {boolean} reverse
|
|
67
|
+
*/
|
|
68
|
+
declare function arrayEachAsync<V>(array: ArrayLike<V>, iterator: (val: V, idx: number) => Promise<any> | any, reverse?: boolean): Promise<void>;
|
|
69
|
+
/**
|
|
70
|
+
* 插入到目标位置之前
|
|
71
|
+
* @param {AnyArray} array
|
|
72
|
+
* @param {number} start
|
|
73
|
+
* @param {number} to
|
|
74
|
+
*/
|
|
75
|
+
declare const arrayInsertBefore: (array: AnyArray, start: number, to: number) => void;
|
|
76
|
+
/**
|
|
77
|
+
* 数组删除指定项目
|
|
78
|
+
* @param {V[]} array
|
|
79
|
+
* @param {(val: V, idx: number) => boolean} expect
|
|
80
|
+
* @returns {V[]}
|
|
81
|
+
*/
|
|
82
|
+
declare function arrayRemove<V>(array: V[], expect: (val: V, idx: number) => boolean): V[];
|
|
83
|
+
/**
|
|
84
|
+
* 自定义深度优先遍历函数(支持continue和break操作)
|
|
85
|
+
* @param {array} deepList
|
|
86
|
+
* @param {function} iterator
|
|
87
|
+
* @param {array} children
|
|
88
|
+
* @param {boolean} isReverse 是否反向遍历
|
|
89
|
+
*/
|
|
90
|
+
declare const deepTraversal: <V>(deepList: ArrayLike<V>, iterator: (val: V, i: number, arr: ArrayLike<V>, parent: V | null, level: number) => any, children?: string, isReverse?: boolean) => void;
|
|
91
|
+
type IdLike = number | string;
|
|
92
|
+
interface ITreeConf {
|
|
93
|
+
id: string | number;
|
|
94
|
+
children: string;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* 在树中找到 id 为某个值的节点,并返回上游的所有父级节点
|
|
98
|
+
* @param {ArrayLike<T>} tree
|
|
99
|
+
* @param {IdLike} nodeId
|
|
100
|
+
* @param {ITreeConf} config
|
|
101
|
+
* @return {[IdLike[], ITreeItem<V>[]]}
|
|
102
|
+
*/
|
|
103
|
+
declare function getTreeIds<V>(tree: ArrayLike<V>, nodeId: IdLike, config?: ITreeConf): [IdLike[], ArrayLike<V>[]];
|
|
104
|
+
/**
|
|
105
|
+
* 异步ForEach函数
|
|
106
|
+
* @param {array} array
|
|
107
|
+
* @param {asyncFuntion} callback
|
|
108
|
+
* // asyncForEach 使用范例如下
|
|
109
|
+
// const start = async () => {
|
|
110
|
+
// await asyncForEach(result, async (item) => {
|
|
111
|
+
// await request(item);
|
|
112
|
+
// count++;
|
|
113
|
+
// });
|
|
114
|
+
|
|
115
|
+
// console.log('发送次数', count);
|
|
116
|
+
// }
|
|
117
|
+
|
|
118
|
+
// for await...of 使用范例如下
|
|
119
|
+
// const loadImages = async (images) => {
|
|
120
|
+
// for await (const item of images) {
|
|
121
|
+
// await request(item);
|
|
122
|
+
// count++;
|
|
123
|
+
// }
|
|
124
|
+
// }
|
|
125
|
+
* @return {*}
|
|
126
|
+
*/
|
|
127
|
+
declare function asyncForEach(array: any[], callback: Function): Promise<void>;
|
|
128
|
+
|
|
129
|
+
declare const array_arrayEach: typeof arrayEach;
|
|
130
|
+
declare const array_arrayEachAsync: typeof arrayEachAsync;
|
|
131
|
+
declare const array_arrayInsertBefore: typeof arrayInsertBefore;
|
|
132
|
+
declare const array_arrayLike: typeof arrayLike;
|
|
133
|
+
declare const array_arrayRemove: typeof arrayRemove;
|
|
134
|
+
declare const array_asyncForEach: typeof asyncForEach;
|
|
135
|
+
declare const array_deepTraversal: typeof deepTraversal;
|
|
136
|
+
declare const array_getTreeIds: typeof getTreeIds;
|
|
137
|
+
declare namespace array {
|
|
138
|
+
export { array_arrayEach as arrayEach, array_arrayEachAsync as arrayEachAsync, array_arrayInsertBefore as arrayInsertBefore, array_arrayLike as arrayLike, array_arrayRemove as arrayRemove, array_asyncForEach as asyncForEach, array_deepTraversal as deepTraversal, array_getTreeIds as getTreeIds };
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* 复制文本
|
|
143
|
+
* @param {string} text
|
|
144
|
+
*/
|
|
145
|
+
declare const copyText: (text: string) => void;
|
|
146
|
+
|
|
147
|
+
declare const clipboard_copyText: typeof copyText;
|
|
148
|
+
declare namespace clipboard {
|
|
149
|
+
export { clipboard_copyText as copyText };
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* 获取cookie
|
|
154
|
+
* @param {string} name
|
|
155
|
+
* @returns {string}
|
|
156
|
+
*/
|
|
157
|
+
declare const cookieGet: (name: string) => string;
|
|
158
|
+
/**
|
|
159
|
+
* 设置 cookie
|
|
160
|
+
* @param {string} name
|
|
161
|
+
* @param {string} value
|
|
162
|
+
* @param {number | Date} [maxAge]
|
|
163
|
+
*/
|
|
164
|
+
declare const cookieSet: (name: string, value: string, maxAge?: number | Date) => void;
|
|
165
|
+
/**
|
|
166
|
+
* 删除单个 cookie
|
|
167
|
+
* @param name cookie 名称
|
|
168
|
+
*/
|
|
169
|
+
declare const cookieDel: (name: string) => void;
|
|
170
|
+
|
|
171
|
+
declare const cookie_cookieDel: typeof cookieDel;
|
|
172
|
+
declare const cookie_cookieGet: typeof cookieGet;
|
|
173
|
+
declare const cookie_cookieSet: typeof cookieSet;
|
|
174
|
+
declare namespace cookie {
|
|
175
|
+
export { cookie_cookieDel as cookieDel, cookie_cookieGet as cookieGet, cookie_cookieSet as cookieSet };
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* 格式化为日期对象(带自定义格式化模板)
|
|
180
|
+
* @param {DateValue} value 可以是数值、字符串或 Date 对象
|
|
181
|
+
* @param {string} [format] 模板,默认是 YYYY-MM-DD HH:mm:ss,模板字符:
|
|
182
|
+
* - YYYY:年
|
|
183
|
+
* - yyyy: 年
|
|
184
|
+
* - MM:月
|
|
185
|
+
* - DD:日
|
|
186
|
+
* - dd: 日
|
|
187
|
+
* - HH:时(24 小时制)
|
|
188
|
+
* - hh:时(12 小时制)
|
|
189
|
+
* - mm:分
|
|
190
|
+
* - ss:秒
|
|
191
|
+
* - SSS:毫秒
|
|
192
|
+
* - ww: 周
|
|
193
|
+
* @returns {string}
|
|
194
|
+
*/
|
|
195
|
+
declare const formatDate: (date?: Date, format?: string) => string;
|
|
196
|
+
/**
|
|
197
|
+
* 计算向前或向后N天的具体日期
|
|
198
|
+
* @param {string} strDate 参考日期
|
|
199
|
+
* @param {number} n 正数:向后推算;负数:向前推算
|
|
200
|
+
* @param {string} sep 日期格式的分隔符
|
|
201
|
+
* @return {*} 目标日期
|
|
202
|
+
*/
|
|
203
|
+
declare function calculateDate(strDate: string, n: number, sep?: string): string;
|
|
204
|
+
/**
|
|
205
|
+
* 计算向前或向后N天的具体时间日期
|
|
206
|
+
* @param {number} n 正数:向后推算;负数:向前推算
|
|
207
|
+
* @param {string} dateSep 日期分隔符
|
|
208
|
+
* @param {string} timeSep 时间分隔符
|
|
209
|
+
* @return {*}
|
|
210
|
+
*/
|
|
211
|
+
declare function calculateDateTime(n: number, dateSep?: string, timeSep?: string): string;
|
|
212
|
+
|
|
213
|
+
declare const date_calculateDate: typeof calculateDate;
|
|
214
|
+
declare const date_calculateDateTime: typeof calculateDateTime;
|
|
215
|
+
declare const date_formatDate: typeof formatDate;
|
|
216
|
+
declare namespace date {
|
|
217
|
+
export { date_calculateDate as calculateDate, date_calculateDateTime as calculateDateTime, date_formatDate as formatDate };
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
type EasingName = 'ease' | 'linear' | 'ease-in' | 'ease-out' | 'ease-in-out' | string;
|
|
221
|
+
|
|
222
|
+
interface Style {
|
|
223
|
+
[propName: string]: string | number;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* 判断元素是否包含某个样式名
|
|
227
|
+
* @param {HTMLElement} el
|
|
228
|
+
* @param {string} className
|
|
229
|
+
* @returns {boolean}
|
|
230
|
+
*/
|
|
231
|
+
declare const hasClass: (el: HTMLElement, className: string) => boolean;
|
|
232
|
+
/**
|
|
233
|
+
* 给元素增加样式名
|
|
234
|
+
* @param {HTMLElement} el
|
|
235
|
+
* @param {string} classNames
|
|
236
|
+
*/
|
|
237
|
+
declare const addClass: (el: HTMLElement, classNames: string) => void;
|
|
238
|
+
/**
|
|
239
|
+
* 给元素移除样式名
|
|
240
|
+
* @param {HTMLElement} el
|
|
241
|
+
* @param {string} classNames
|
|
242
|
+
*/
|
|
243
|
+
declare const removeClass: (el: HTMLElement, classNames: string) => void;
|
|
244
|
+
interface SetStyle {
|
|
245
|
+
(el: HTMLElement, key: string, val: string): void;
|
|
246
|
+
(el: HTMLElement, style: Style): void;
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* 设置元素样式
|
|
250
|
+
* @param {HTMLElement} el
|
|
251
|
+
* @param {string | Style} key
|
|
252
|
+
* @param {string} val
|
|
253
|
+
*/
|
|
254
|
+
declare const setStyle: SetStyle;
|
|
255
|
+
/**
|
|
256
|
+
* 获取元素样式
|
|
257
|
+
* @param {HTMLElement} el
|
|
258
|
+
* @param {string} key
|
|
259
|
+
* @returns {string}
|
|
260
|
+
*/
|
|
261
|
+
declare const getStyle: (el: HTMLElement, key: string) => string;
|
|
262
|
+
type ScrollElement = HTMLElement | Document | Window;
|
|
263
|
+
interface SmoothScrollOptions {
|
|
264
|
+
el: ScrollElement;
|
|
265
|
+
to: number;
|
|
266
|
+
duration: number;
|
|
267
|
+
easing: EasingName;
|
|
268
|
+
}
|
|
269
|
+
declare function smoothScroll(options?: Partial<SmoothScrollOptions>): Promise<void>;
|
|
270
|
+
type ReadyCallback = () => void;
|
|
271
|
+
declare function isDomReady(): boolean;
|
|
272
|
+
declare function onDomReady(callback: ReadyCallback): void;
|
|
273
|
+
|
|
274
|
+
declare const dom_addClass: typeof addClass;
|
|
275
|
+
declare const dom_getStyle: typeof getStyle;
|
|
276
|
+
declare const dom_hasClass: typeof hasClass;
|
|
277
|
+
declare const dom_isDomReady: typeof isDomReady;
|
|
278
|
+
declare const dom_onDomReady: typeof onDomReady;
|
|
279
|
+
declare const dom_removeClass: typeof removeClass;
|
|
280
|
+
declare const dom_setStyle: typeof setStyle;
|
|
281
|
+
declare const dom_smoothScroll: typeof smoothScroll;
|
|
282
|
+
declare namespace dom {
|
|
283
|
+
export { dom_addClass as addClass, dom_getStyle as getStyle, dom_hasClass as hasClass, dom_isDomReady as isDomReady, dom_onDomReady as onDomReady, dom_removeClass as removeClass, dom_setStyle as setStyle, dom_smoothScroll as smoothScroll };
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
interface Params<T = string | number> {
|
|
287
|
+
[key: string]: T | Array<T>;
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* 解析查询参数,内部使用的是浏览器内置的 URLSearchParams 进行处理
|
|
291
|
+
* @param {string} queryString
|
|
292
|
+
* @returns {Params}
|
|
293
|
+
*/
|
|
294
|
+
declare const qsParse: (queryString: string) => Params;
|
|
295
|
+
type LooseParamValue = string | number | boolean | Date | null | undefined;
|
|
296
|
+
interface LooseParams<T = LooseParamValue> {
|
|
297
|
+
[key: string]: T | Array<T>;
|
|
298
|
+
}
|
|
299
|
+
type Replacer = (value: LooseParamValue) => string | null;
|
|
300
|
+
/**
|
|
301
|
+
* 字符化查询对象,内部使用的是浏览器内置的 URLSearchParams 进行处理
|
|
302
|
+
* @param {LooseParams} query
|
|
303
|
+
* @param {Replacer} replacer
|
|
304
|
+
* @returns {string}
|
|
305
|
+
*/
|
|
306
|
+
declare const qsStringify: (query: LooseParams, replacer?: Replacer) => string;
|
|
307
|
+
|
|
308
|
+
type qs_LooseParamValue = LooseParamValue;
|
|
309
|
+
type qs_LooseParams<T = LooseParamValue> = LooseParams<T>;
|
|
310
|
+
type qs_Params<T = string | number> = Params<T>;
|
|
311
|
+
type qs_Replacer = Replacer;
|
|
312
|
+
declare const qs_qsParse: typeof qsParse;
|
|
313
|
+
declare const qs_qsStringify: typeof qsStringify;
|
|
314
|
+
declare namespace qs {
|
|
315
|
+
export { type qs_LooseParamValue as LooseParamValue, type qs_LooseParams as LooseParams, type qs_Params as Params, type qs_Replacer as Replacer, qs_qsParse as qsParse, qs_qsStringify as qsStringify };
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* 通过打开新窗口的方式下载
|
|
320
|
+
* @param {string} url
|
|
321
|
+
* @param {LooseParams} params
|
|
322
|
+
*/
|
|
323
|
+
declare const downloadURL: (url: string, params?: LooseParams) => void;
|
|
324
|
+
/**
|
|
325
|
+
* 通过 A 链接的方式下载
|
|
326
|
+
* @param {string} href
|
|
327
|
+
* @param {string} filename
|
|
328
|
+
*/
|
|
329
|
+
declare const downloadHref: (href: string, filename: string) => void;
|
|
330
|
+
/**
|
|
331
|
+
* 将大文件对象通过 A 链接的方式下载
|
|
332
|
+
* @param {Blob} blob
|
|
333
|
+
* @param {string} filename
|
|
334
|
+
*/
|
|
335
|
+
declare const downloadBlob: (blob: Blob, filename: string) => void;
|
|
336
|
+
type FileType = 'json' | 'csv' | 'xls' | 'xlsx';
|
|
337
|
+
/**
|
|
338
|
+
* 将指定数据格式通过 A 链接的方式下载
|
|
339
|
+
* @param {AnyObject | AnyObject[]} data
|
|
340
|
+
* @param {FileType} fileType 支持 json/csv/xls/xlsx 四种格式
|
|
341
|
+
* @param {string} filename
|
|
342
|
+
* @param {string[]} [headers]
|
|
343
|
+
*/
|
|
344
|
+
declare const downloadData: (data: AnyObject | AnyObject[], fileType: FileType, filename: string, headers?: string[]) => void;
|
|
345
|
+
|
|
346
|
+
declare const download_downloadBlob: typeof downloadBlob;
|
|
347
|
+
declare const download_downloadData: typeof downloadData;
|
|
348
|
+
declare const download_downloadHref: typeof downloadHref;
|
|
349
|
+
declare const download_downloadURL: typeof downloadURL;
|
|
350
|
+
declare namespace download {
|
|
351
|
+
export { download_downloadBlob as downloadBlob, download_downloadData as downloadData, download_downloadHref as downloadHref, download_downloadURL as downloadURL };
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* 判断对象是否为纯对象
|
|
356
|
+
* @param {object} obj
|
|
357
|
+
* @returns {boolean}
|
|
358
|
+
*/
|
|
359
|
+
declare const isPlainObject: (obj: unknown) => boolean;
|
|
360
|
+
/**
|
|
361
|
+
* 判断对象内是否有该静态属性
|
|
362
|
+
* @param {object} obj
|
|
363
|
+
* @param {string} key
|
|
364
|
+
* @returns {boolean}
|
|
365
|
+
*/
|
|
366
|
+
declare const objectHas: <T extends AnyObject>(obj: T, key: keyof T) => boolean;
|
|
367
|
+
/**
|
|
368
|
+
* 遍历对象,返回 false 中断遍历
|
|
369
|
+
* @param {O} obj
|
|
370
|
+
* @param {(val: O[keyof O], key: keyof O) => (boolean | void)} iterator
|
|
371
|
+
*/
|
|
372
|
+
declare const objectEach: <O extends AnyObject>(obj: O, iterator: (val: O[keyof O], key: Extract<keyof O, string>) => any) => void;
|
|
373
|
+
/**
|
|
374
|
+
* 异步遍历对象,返回 false 中断遍历
|
|
375
|
+
* @param {O} obj
|
|
376
|
+
* @param {(val: O[keyof O], key: keyof O) => (boolean | void)} iterator
|
|
377
|
+
*/
|
|
378
|
+
declare function objectEachAsync<O extends AnyObject>(obj: O, iterator: (val: O[keyof O], key: Extract<keyof O, string>) => Promise<any> | any): Promise<void>;
|
|
379
|
+
/**
|
|
380
|
+
* 对象映射
|
|
381
|
+
* @param {O} obj
|
|
382
|
+
* @param {(val: O[keyof O], key: Extract<keyof O, string>) => any} iterator
|
|
383
|
+
* @returns {Record<Extract<keyof O, string>, T>}
|
|
384
|
+
*/
|
|
385
|
+
declare function objectMap<O extends AnyObject, T>(obj: O, iterator: (val: O[keyof O], key: Extract<keyof O, string>) => any): Record<Extract<keyof O, string>, T>;
|
|
386
|
+
/**
|
|
387
|
+
* 对象提取
|
|
388
|
+
* @param {O} obj
|
|
389
|
+
* @param {K} keys
|
|
390
|
+
* @returns {Pick<O, ArrayElements<K>>}
|
|
391
|
+
*/
|
|
392
|
+
declare function objectPick<O extends AnyObject, K extends Extract<keyof O, string>[]>(obj: O, keys: K): Pick<O, ArrayElements<K>>;
|
|
393
|
+
/**
|
|
394
|
+
* 对象祛除
|
|
395
|
+
* @param {O} obj
|
|
396
|
+
* @param {K} keys
|
|
397
|
+
* @returns {Pick<O, ArrayElements<K>>}
|
|
398
|
+
*/
|
|
399
|
+
declare function objectOmit<O extends AnyObject, K extends Extract<keyof O, string>[]>(obj: O, keys: K): Omit<O, ArrayElements<K>>;
|
|
400
|
+
type ObjectAssignItem = AnyObject | AnyArray;
|
|
401
|
+
/**
|
|
402
|
+
* 对象合并,返回原始对象
|
|
403
|
+
* @param {ObjectAssignItem} source
|
|
404
|
+
* @param {ObjectAssignItem | undefined} targets
|
|
405
|
+
* @returns {R}
|
|
406
|
+
*/
|
|
407
|
+
declare const objectAssign: <R = AnyObject | AnyArray>(source: ObjectAssignItem, ...targets: (ObjectAssignItem | undefined)[]) => R;
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* 对象填充
|
|
411
|
+
* @param {Partial<R>} source
|
|
412
|
+
* @param {Partial<R>} target
|
|
413
|
+
* @param {(s: Partial<R>, t: Partial<R>, key: keyof R) => boolean} fillable
|
|
414
|
+
* @returns {R}
|
|
415
|
+
*/
|
|
416
|
+
declare const objectFill: <R extends AnyObject = AnyObject>(source: Partial<R>, target: Partial<R>, fillable?: ((s: Partial<R>, t: Partial<R>, key: keyof R) => boolean) | undefined) => R;
|
|
417
|
+
declare function objectGet(obj: AnyObject, path: string, strict?: boolean): {
|
|
418
|
+
p: any | undefined;
|
|
419
|
+
k: string | undefined;
|
|
420
|
+
v: any | undefined;
|
|
421
|
+
};
|
|
422
|
+
/**
|
|
423
|
+
* 深拷贝堪称完全体 即:任何类型的数据都会被深拷贝
|
|
424
|
+
* @param {AnyObject | AnyArray} obj
|
|
425
|
+
* @param {WeakMap} map
|
|
426
|
+
* @return {AnyObject | AnyArray}
|
|
427
|
+
*/
|
|
428
|
+
declare function cloneDeep(obj: Object, map?: WeakMap<WeakKey, any>): Object;
|
|
429
|
+
|
|
430
|
+
declare const object_cloneDeep: typeof cloneDeep;
|
|
431
|
+
declare const object_isPlainObject: typeof isPlainObject;
|
|
432
|
+
declare const object_objectAssign: typeof objectAssign;
|
|
433
|
+
declare const object_objectEach: typeof objectEach;
|
|
434
|
+
declare const object_objectEachAsync: typeof objectEachAsync;
|
|
435
|
+
declare const object_objectFill: typeof objectFill;
|
|
436
|
+
declare const object_objectGet: typeof objectGet;
|
|
437
|
+
declare const object_objectHas: typeof objectHas;
|
|
438
|
+
declare const object_objectMap: typeof objectMap;
|
|
439
|
+
declare const object_objectOmit: typeof objectOmit;
|
|
440
|
+
declare const object_objectPick: typeof objectPick;
|
|
441
|
+
declare namespace object {
|
|
442
|
+
export { object_cloneDeep as cloneDeep, object_isPlainObject as isPlainObject, object_objectAssign as objectAssign, object_objectEach as objectEach, object_objectEachAsync as objectEachAsync, object_objectFill as objectFill, object_objectGet as objectGet, object_objectHas as objectHas, object_objectMap as objectMap, objectAssign as objectMerge, object_objectOmit as objectOmit, object_objectPick as objectPick };
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* 标准化路径
|
|
447
|
+
* @param {string} path
|
|
448
|
+
* @returns {string}
|
|
449
|
+
*/
|
|
450
|
+
declare const pathNormalize: (path: string) => string;
|
|
451
|
+
/**
|
|
452
|
+
* 路径合并
|
|
453
|
+
* @param {string} from
|
|
454
|
+
* @param {string} to
|
|
455
|
+
* @returns {string}
|
|
456
|
+
*/
|
|
457
|
+
declare const pathJoin: (from: string, ...to: string[]) => string;
|
|
458
|
+
|
|
459
|
+
declare const path_pathJoin: typeof pathJoin;
|
|
460
|
+
declare const path_pathNormalize: typeof pathNormalize;
|
|
461
|
+
declare namespace path {
|
|
462
|
+
export { path_pathJoin as pathJoin, path_pathNormalize as pathNormalize };
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
/**
|
|
466
|
+
* 将字符串转换为驼峰格式
|
|
467
|
+
* @param {string} string
|
|
468
|
+
* @param {boolean} [bigger] 是否大写第一个字母
|
|
469
|
+
* @returns {string}
|
|
470
|
+
*/
|
|
471
|
+
declare const stringCamelCase: (string: string, bigger?: boolean) => string;
|
|
472
|
+
/**
|
|
473
|
+
* 将字符串转换为连字格式
|
|
474
|
+
* @param {string} string
|
|
475
|
+
* @param {string} [separator] 分隔符,默认是"-"(短横线)
|
|
476
|
+
* @returns {string}
|
|
477
|
+
*/
|
|
478
|
+
declare const stringKebabCase: (string: string, separator?: string) => string;
|
|
479
|
+
declare const STRING_ARABIC_NUMERALS = "0123456789";
|
|
480
|
+
declare const STRING_LOWERCASE_ALPHA = "abcdefghijklmnopqrstuvwxyz";
|
|
481
|
+
declare const STRING_UPPERCASE_ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
482
|
+
/**
|
|
483
|
+
* 字符串格式化
|
|
484
|
+
* @example
|
|
485
|
+
* ```js
|
|
486
|
+
* stringFormat("My name is %s.", "zhangsan")
|
|
487
|
+
* // => "My name is zhangsan."
|
|
488
|
+
* ```
|
|
489
|
+
* @param {string} string 字符串模板,使用 %s 表示字符串,%d 表示数值,%o 表示对象,%% 表示百分号,参考 console.log
|
|
490
|
+
* @param args
|
|
491
|
+
* @returns {string}
|
|
492
|
+
*/
|
|
493
|
+
declare const stringFormat: (string: string, ...args: Array<unknown>) => string;
|
|
494
|
+
/**
|
|
495
|
+
* 字符串赋值
|
|
496
|
+
* @example
|
|
497
|
+
* ```js
|
|
498
|
+
* stringAssign('My name is ${user}.', { user: 'zhangsan' });
|
|
499
|
+
* // => "My name is zhangsan."
|
|
500
|
+
* ```
|
|
501
|
+
* @param {string} template
|
|
502
|
+
* @param {AnyObject} data
|
|
503
|
+
* @returns {string}
|
|
504
|
+
*/
|
|
505
|
+
declare const stringAssign: (template: string, data: AnyObject) => string;
|
|
506
|
+
/**
|
|
507
|
+
* 字符串编码 HTML
|
|
508
|
+
* @example
|
|
509
|
+
* ```js
|
|
510
|
+
* stringEscapeHtml('<b>You & Me speak "xixi"</b>')
|
|
511
|
+
* // => "<b>You & Me speak "xixi"</b>"
|
|
512
|
+
* ```
|
|
513
|
+
* @param {string} html
|
|
514
|
+
* @returns {string}
|
|
515
|
+
*/
|
|
516
|
+
declare const stringEscapeHtml: (html: string) => string;
|
|
517
|
+
/**
|
|
518
|
+
* 字符串填充
|
|
519
|
+
* @param {number} length
|
|
520
|
+
* @param {string} value
|
|
521
|
+
* @returns {string}
|
|
522
|
+
*/
|
|
523
|
+
declare const stringFill: (length: number, value?: string) => string;
|
|
524
|
+
|
|
525
|
+
declare const string_STRING_ARABIC_NUMERALS: typeof STRING_ARABIC_NUMERALS;
|
|
526
|
+
declare const string_STRING_LOWERCASE_ALPHA: typeof STRING_LOWERCASE_ALPHA;
|
|
527
|
+
declare const string_STRING_UPPERCASE_ALPHA: typeof STRING_UPPERCASE_ALPHA;
|
|
528
|
+
declare const string_stringAssign: typeof stringAssign;
|
|
529
|
+
declare const string_stringCamelCase: typeof stringCamelCase;
|
|
530
|
+
declare const string_stringEscapeHtml: typeof stringEscapeHtml;
|
|
531
|
+
declare const string_stringFill: typeof stringFill;
|
|
532
|
+
declare const string_stringFormat: typeof stringFormat;
|
|
533
|
+
declare const string_stringKebabCase: typeof stringKebabCase;
|
|
534
|
+
declare namespace string {
|
|
535
|
+
export { string_STRING_ARABIC_NUMERALS as STRING_ARABIC_NUMERALS, string_STRING_LOWERCASE_ALPHA as STRING_LOWERCASE_ALPHA, string_STRING_UPPERCASE_ALPHA as STRING_UPPERCASE_ALPHA, string_stringAssign as stringAssign, string_stringCamelCase as stringCamelCase, string_stringEscapeHtml as stringEscapeHtml, string_stringFill as stringFill, string_stringFormat as stringFormat, string_stringKebabCase as stringKebabCase };
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
interface Url {
|
|
539
|
+
protocol: string;
|
|
540
|
+
auth: string;
|
|
541
|
+
username: string;
|
|
542
|
+
password: string;
|
|
543
|
+
host: string;
|
|
544
|
+
port: string;
|
|
545
|
+
hostname: string;
|
|
546
|
+
hash: string;
|
|
547
|
+
search: string;
|
|
548
|
+
searchParams: Params;
|
|
549
|
+
query: string;
|
|
550
|
+
pathname: string;
|
|
551
|
+
path: string;
|
|
552
|
+
href: string;
|
|
553
|
+
}
|
|
554
|
+
/**
|
|
555
|
+
* url 解析
|
|
556
|
+
* @param {string} url
|
|
557
|
+
* @returns {Url}
|
|
558
|
+
*/
|
|
559
|
+
declare const urlParse: (url: string) => Url;
|
|
560
|
+
/**
|
|
561
|
+
* url 字符化,url 对象里的 searchParams 会覆盖 url 原有的查询参数
|
|
562
|
+
* @param {Url} url
|
|
563
|
+
* @returns {string}
|
|
564
|
+
*/
|
|
565
|
+
declare const urlStringify: (url: Url) => string;
|
|
566
|
+
/**
|
|
567
|
+
* 设置 url 查询参数
|
|
568
|
+
* @param {string} url
|
|
569
|
+
* @param {AnyObject} setter
|
|
570
|
+
* @returns {string}
|
|
571
|
+
*/
|
|
572
|
+
declare const urlSetParams: (url: string, setter: AnyObject) => string;
|
|
573
|
+
/**
|
|
574
|
+
* 删除 url 查询参数
|
|
575
|
+
* @param {string} url
|
|
576
|
+
* @param {string[]} removeKeys
|
|
577
|
+
* @returns {string}
|
|
578
|
+
*/
|
|
579
|
+
declare const urlDelParams: (url: string, removeKeys: string[]) => string;
|
|
580
|
+
|
|
581
|
+
declare const url_urlDelParams: typeof urlDelParams;
|
|
582
|
+
declare const url_urlParse: typeof urlParse;
|
|
583
|
+
declare const url_urlSetParams: typeof urlSetParams;
|
|
584
|
+
declare const url_urlStringify: typeof urlStringify;
|
|
585
|
+
declare namespace url {
|
|
586
|
+
export { url_urlDelParams as urlDelParams, url_urlParse as urlParse, url_urlSetParams as urlSetParams, url_urlStringify as urlStringify };
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
/**
|
|
590
|
+
* 等待一段时间
|
|
591
|
+
* @param {number} timeout 等待时间,单位毫秒
|
|
592
|
+
* @returns {Promise<void>}
|
|
593
|
+
*/
|
|
594
|
+
declare function wait(timeout?: number): Promise<void>;
|
|
595
|
+
/**
|
|
596
|
+
* 异步遍历
|
|
597
|
+
* @ref https://github.com/Kevnz/async-tools/blob/master/src/mapper.js
|
|
598
|
+
* @ref https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Array/@@iterator
|
|
599
|
+
* @param {Array<T>} list
|
|
600
|
+
* @param {(val: T, idx: number, list: ArrayLike<T>) => Promise<R>} mapper
|
|
601
|
+
* @param {number} concurrency 并发数量,默认无限
|
|
602
|
+
* @returns {Promise<R[]>}
|
|
603
|
+
*/
|
|
604
|
+
declare function asyncMap<T, R>(list: Array<T>, mapper: (val: T, idx: number, list: Array<T>) => Promise<R>, concurrency?: number): Promise<R[]>;
|
|
605
|
+
|
|
606
|
+
declare const async_asyncMap: typeof asyncMap;
|
|
607
|
+
declare const async_wait: typeof wait;
|
|
608
|
+
declare namespace async {
|
|
609
|
+
export { async_asyncMap as asyncMap, async_wait as wait };
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
/**
|
|
613
|
+
* 选择本地文件
|
|
614
|
+
* @param {function} changeCb 选择文件回调
|
|
615
|
+
* @return {*}
|
|
616
|
+
*/
|
|
617
|
+
declare function chooseLocalFile({ accept }: {
|
|
618
|
+
accept: any;
|
|
619
|
+
}, changeCb: (FileList: any) => any): HTMLInputElement;
|
|
620
|
+
|
|
621
|
+
declare const file_chooseLocalFile: typeof chooseLocalFile;
|
|
622
|
+
declare namespace file {
|
|
623
|
+
export { file_chooseLocalFile as chooseLocalFile };
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
interface ICanvasWM {
|
|
627
|
+
container: HTMLElement;
|
|
628
|
+
width: string;
|
|
629
|
+
height: string;
|
|
630
|
+
textAlign: CanvasTextAlign;
|
|
631
|
+
textBaseline: CanvasTextBaseline;
|
|
632
|
+
font: string;
|
|
633
|
+
fillStyle: string;
|
|
634
|
+
content: string;
|
|
635
|
+
rotate: number;
|
|
636
|
+
zIndex: number;
|
|
637
|
+
}
|
|
638
|
+
/**
|
|
639
|
+
* canvas 实现 watermark
|
|
640
|
+
* @param {ICanvasWM} canvasWM
|
|
641
|
+
*/
|
|
642
|
+
declare const genCanvasWM: (canvasWM: ICanvasWM) => void;
|
|
643
|
+
|
|
644
|
+
export { array, async, clipboard, cookie, date, dom, download, file, genCanvasWM, object, path, qs, string, type, url };
|