sculp-js 0.0.2 → 1.0.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/LICENSE.md +1 -1
- package/README.md +22 -1
- package/lib/cjs/array.js +32 -55
- package/lib/cjs/async.js +3 -3
- package/lib/cjs/clipboard.js +3 -3
- package/lib/cjs/cookie.js +5 -5
- package/lib/cjs/date.js +142 -24
- package/lib/cjs/dom.js +24 -10
- package/lib/cjs/download.js +9 -9
- package/lib/cjs/easing.js +1 -1
- package/lib/cjs/file.js +5 -4
- package/lib/cjs/func.js +160 -0
- package/lib/cjs/index.js +28 -2
- package/lib/cjs/number.js +82 -0
- package/lib/cjs/object.js +13 -11
- package/lib/cjs/path.js +1 -1
- package/lib/cjs/qs.js +5 -5
- package/lib/cjs/random.js +72 -0
- package/lib/cjs/string.js +40 -7
- package/lib/cjs/type.js +12 -2
- package/lib/cjs/unique.js +83 -0
- package/lib/cjs/url.js +1 -1
- package/lib/cjs/watermark.js +8 -9
- package/lib/es/array.js +33 -55
- package/lib/es/async.js +3 -3
- package/lib/es/clipboard.js +3 -3
- package/lib/es/cookie.js +5 -5
- package/lib/es/date.js +139 -25
- package/lib/es/dom.js +24 -11
- package/lib/es/download.js +9 -9
- package/lib/es/easing.js +1 -1
- package/lib/es/file.js +5 -4
- package/lib/es/func.js +154 -0
- package/lib/es/index.js +10 -6
- package/lib/es/number.js +77 -0
- package/lib/es/object.js +12 -10
- package/lib/es/path.js +1 -1
- package/lib/es/qs.js +5 -5
- package/lib/es/random.js +67 -0
- package/lib/es/string.js +40 -8
- package/lib/es/type.js +12 -3
- package/lib/es/unique.js +79 -0
- package/lib/es/url.js +1 -1
- package/lib/es/watermark.js +8 -9
- package/lib/index.d.ts +254 -80
- package/lib/umd/index.js +637 -132
- package/package.json +36 -12
package/lib/index.d.ts
CHANGED
|
@@ -1,10 +1,20 @@
|
|
|
1
|
+
/** 任意函数 */
|
|
1
2
|
type AnyFunc<R = any> = (...args: any[]) => R;
|
|
3
|
+
/** 任意数组 */
|
|
2
4
|
type AnyArray = any[];
|
|
5
|
+
/** 取出数组元素 */
|
|
3
6
|
type ArrayElements<A> = A extends Array<infer R> ? R : never;
|
|
7
|
+
/** 任意对象 */
|
|
4
8
|
type AnyObject = Record<string | number, any>;
|
|
5
9
|
type PartialDeep<T> = {
|
|
6
10
|
[P in keyof T]?: PartialDeep<T[P]>;
|
|
7
11
|
};
|
|
12
|
+
/**
|
|
13
|
+
* 判断任意值的数据类型
|
|
14
|
+
* @param {unknown} any
|
|
15
|
+
* @returns {string}
|
|
16
|
+
*/
|
|
17
|
+
declare const typeIs: (any: unknown) => string;
|
|
8
18
|
declare const isString: (any: unknown) => any is string;
|
|
9
19
|
declare const isBoolean: (any: unknown) => any is boolean;
|
|
10
20
|
declare const isSymbol: (any: unknown) => any is symbol;
|
|
@@ -15,6 +25,11 @@ declare const isNull: (any: unknown) => any is null;
|
|
|
15
25
|
declare const isPrimitive: (any: unknown) => boolean;
|
|
16
26
|
declare const isObject: (any: unknown) => any is Record<string, unknown>;
|
|
17
27
|
declare const isArray: (any: unknown) => any is unknown[];
|
|
28
|
+
/**
|
|
29
|
+
* 判断是否为函数
|
|
30
|
+
* @param {unknown} any
|
|
31
|
+
* @returns {boolean}
|
|
32
|
+
*/
|
|
18
33
|
declare const isFunction: (any: unknown) => any is Function;
|
|
19
34
|
declare const isNaN: (any: unknown) => any is number;
|
|
20
35
|
declare const isDate: (any: unknown) => any is Date;
|
|
@@ -23,22 +38,25 @@ declare const isRegExp: (any: unknown) => any is RegExp;
|
|
|
23
38
|
|
|
24
39
|
/**
|
|
25
40
|
* 判断一个对象是否为类数组
|
|
41
|
+
*
|
|
26
42
|
* @param any
|
|
27
43
|
* @returns {boolean}
|
|
28
44
|
*/
|
|
29
|
-
declare
|
|
45
|
+
declare function arrayLike(any: unknown): boolean;
|
|
30
46
|
/**
|
|
31
47
|
* 遍历数组,返回 false 中断遍历
|
|
48
|
+
*
|
|
32
49
|
* @param {ArrayLike<V>} array
|
|
33
50
|
* @param {(val: V, idx: number) => any} iterator
|
|
34
51
|
* @param reverse {boolean} 是否倒序
|
|
52
|
+
* @returns {*}
|
|
35
53
|
*/
|
|
36
|
-
declare
|
|
54
|
+
declare function arrayEach<V>(array: ArrayLike<V>, iterator: (val: V, idx: number, arr: ArrayLike<V>) => any, reverse?: boolean): void;
|
|
37
55
|
/**
|
|
38
56
|
* 异步遍历数组,返回 false 中断遍历
|
|
39
|
-
* @param {ArrayLike<V>} array
|
|
40
|
-
* @param {(val: V, idx: number) => Promise<any>} iterator
|
|
41
|
-
* @param {boolean} reverse
|
|
57
|
+
* @param {ArrayLike<V>} array 数组
|
|
58
|
+
* @param {(val: V, idx: number) => Promise<any>} iterator 支持Promise类型的回调函数
|
|
59
|
+
* @param {boolean} reverse 是否反向遍历
|
|
42
60
|
*/
|
|
43
61
|
declare function arrayEachAsync<V>(array: ArrayLike<V>, iterator: (val: V, idx: number) => Promise<any> | any, reverse?: boolean): Promise<void>;
|
|
44
62
|
/**
|
|
@@ -46,8 +64,9 @@ declare function arrayEachAsync<V>(array: ArrayLike<V>, iterator: (val: V, idx:
|
|
|
46
64
|
* @param {AnyArray} array
|
|
47
65
|
* @param {number} start
|
|
48
66
|
* @param {number} to
|
|
67
|
+
* @returns {*}
|
|
49
68
|
*/
|
|
50
|
-
declare
|
|
69
|
+
declare function arrayInsertBefore(array: AnyArray, start: number, to: number): void;
|
|
51
70
|
/**
|
|
52
71
|
* 数组删除指定项目
|
|
53
72
|
* @param {V[]} array
|
|
@@ -57,12 +76,13 @@ declare const arrayInsertBefore: (array: AnyArray, start: number, to: number) =>
|
|
|
57
76
|
declare function arrayRemove<V>(array: V[], expect: (val: V, idx: number) => boolean): V[];
|
|
58
77
|
/**
|
|
59
78
|
* 自定义深度优先遍历函数(支持continue和break操作)
|
|
60
|
-
* @param {
|
|
61
|
-
* @param {
|
|
62
|
-
* @param {
|
|
63
|
-
* @param {boolean} isReverse
|
|
79
|
+
* @param {ArrayLike<V>} tree 树形数据
|
|
80
|
+
* @param {Function} iterator 迭代函数
|
|
81
|
+
* @param {string} children 定制子元素的key
|
|
82
|
+
* @param {boolean} isReverse 是否反向遍历
|
|
83
|
+
* @returns {*}
|
|
64
84
|
*/
|
|
65
|
-
declare
|
|
85
|
+
declare function deepTraversal<V>(tree: ArrayLike<V>, iterator: (val: V, i: number, arr: ArrayLike<V>, parent: V | null, level: number) => any, children?: string, isReverse?: boolean): void;
|
|
66
86
|
type IdLike = number | string;
|
|
67
87
|
interface ITreeConf {
|
|
68
88
|
id: string | number;
|
|
@@ -70,62 +90,50 @@ interface ITreeConf {
|
|
|
70
90
|
}
|
|
71
91
|
/**
|
|
72
92
|
* 在树中找到 id 为某个值的节点,并返回上游的所有父级节点
|
|
73
|
-
*
|
|
74
|
-
* @param {
|
|
75
|
-
* @param {
|
|
76
|
-
* @
|
|
93
|
+
*
|
|
94
|
+
* @param {ArrayLike<T>} tree - 树形数据
|
|
95
|
+
* @param {IdLike} nodeId - 元素ID
|
|
96
|
+
* @param {ITreeConf} config - 迭代配置项
|
|
97
|
+
* @returns {[IdLike[], ITreeItem<V>[]]} - 由parentId...childId, parentObject-childObject组成的二维数组
|
|
77
98
|
*/
|
|
78
99
|
declare function getTreeIds<V>(tree: ArrayLike<V>, nodeId: IdLike, config?: ITreeConf): [IdLike[], ArrayLike<V>[]];
|
|
79
|
-
/**
|
|
80
|
-
* 异步ForEach函数
|
|
81
|
-
* @param {array} array
|
|
82
|
-
* @param {asyncFuntion} callback
|
|
83
|
-
* // asyncForEach 使用范例如下
|
|
84
|
-
// const start = async () => {
|
|
85
|
-
// await asyncForEach(result, async (item) => {
|
|
86
|
-
// await request(item);
|
|
87
|
-
// count++;
|
|
88
|
-
// });
|
|
89
|
-
|
|
90
|
-
// console.log('发送次数', count);
|
|
91
|
-
// }
|
|
92
|
-
|
|
93
|
-
// for await...of 使用范例如下
|
|
94
|
-
// const loadImages = async (images) => {
|
|
95
|
-
// for await (const item of images) {
|
|
96
|
-
// await request(item);
|
|
97
|
-
// count++;
|
|
98
|
-
// }
|
|
99
|
-
// }
|
|
100
|
-
* @return {*}
|
|
101
|
-
*/
|
|
102
|
-
declare function asyncForEach(array: any[], callback: Function): Promise<void>;
|
|
103
100
|
|
|
104
101
|
/**
|
|
105
102
|
* 复制文本
|
|
106
103
|
* @param {string} text
|
|
107
104
|
*/
|
|
108
|
-
declare
|
|
105
|
+
declare function copyText(text: string): void;
|
|
109
106
|
|
|
110
107
|
/**
|
|
111
108
|
* 获取cookie
|
|
112
109
|
* @param {string} name
|
|
113
110
|
* @returns {string}
|
|
114
111
|
*/
|
|
115
|
-
declare
|
|
112
|
+
declare function cookieGet(name: string): string;
|
|
116
113
|
/**
|
|
117
114
|
* 设置 cookie
|
|
118
115
|
* @param {string} name
|
|
119
116
|
* @param {string} value
|
|
120
117
|
* @param {number | Date} [maxAge]
|
|
121
118
|
*/
|
|
122
|
-
declare
|
|
119
|
+
declare function cookieSet(name: string, value: string, maxAge?: number | Date): void;
|
|
123
120
|
/**
|
|
124
121
|
* 删除单个 cookie
|
|
125
122
|
* @param name cookie 名称
|
|
126
123
|
*/
|
|
127
124
|
declare const cookieDel: (name: string) => void;
|
|
128
125
|
|
|
126
|
+
declare const isValidDate: (any: unknown) => any is Date;
|
|
127
|
+
interface DateObj {
|
|
128
|
+
[propName: string]: string;
|
|
129
|
+
}
|
|
130
|
+
type DateValue = number | string | Date;
|
|
131
|
+
/**
|
|
132
|
+
* 解析为Date对象
|
|
133
|
+
* @param {DateValue} value - 可以是数值、字符串或 Date 对象
|
|
134
|
+
* @returns {Date} - 转换后的目标Date
|
|
135
|
+
*/
|
|
136
|
+
declare function dateParse(value: DateValue): Date;
|
|
129
137
|
/**
|
|
130
138
|
* 格式化为日期对象(带自定义格式化模板)
|
|
131
139
|
* @param {DateValue} value 可以是数值、字符串或 Date 对象
|
|
@@ -140,24 +148,52 @@ declare const cookieDel: (name: string) => void;
|
|
|
140
148
|
* - mm:分
|
|
141
149
|
* - ss:秒
|
|
142
150
|
* - SSS:毫秒
|
|
143
|
-
* - ww: 周
|
|
144
151
|
* @returns {string}
|
|
145
152
|
*/
|
|
146
|
-
|
|
153
|
+
/**
|
|
154
|
+
* 将日期转换为一天的开始时间,即0点0分0秒0毫秒
|
|
155
|
+
* @param {DateValue} value
|
|
156
|
+
* @returns {Date}
|
|
157
|
+
*/
|
|
158
|
+
declare function dateToStart(value: DateValue): Date;
|
|
159
|
+
/**
|
|
160
|
+
* 将日期转换为一天的结束时间,即23点59分59秒999毫秒
|
|
161
|
+
* @param {DateValue} value
|
|
162
|
+
* @returns {Date}
|
|
163
|
+
*/
|
|
164
|
+
declare function dateToEnd(value: DateValue): Date;
|
|
165
|
+
/**
|
|
166
|
+
* 格式化为日期对象(带自定义格式化模板)
|
|
167
|
+
* @param {Date} value - 可以是数值、字符串或 Date 对象
|
|
168
|
+
* @param {string} [format] - 模板,默认是 YYYY-MM-DD HH:mm:ss,模板字符:
|
|
169
|
+
* - YYYY:年
|
|
170
|
+
* - yyyy: 年
|
|
171
|
+
* - MM:月
|
|
172
|
+
* - DD:日
|
|
173
|
+
* - dd: 日
|
|
174
|
+
* - HH:时(24 小时制)
|
|
175
|
+
* - hh:时(12 小时制)
|
|
176
|
+
* - mm:分
|
|
177
|
+
* - ss:秒
|
|
178
|
+
* - SSS:毫秒
|
|
179
|
+
* - ww: 周
|
|
180
|
+
* @returns {string} 格式化后的日期字符串
|
|
181
|
+
*/
|
|
182
|
+
declare function formatDate(value: DateValue, format?: string): string;
|
|
147
183
|
/**
|
|
148
184
|
* 计算向前或向后N天的具体日期
|
|
149
|
-
* @param {string} strDate 参考日期
|
|
150
|
-
* @param {number} n 正数:向后推算;负数:向前推算
|
|
151
|
-
* @param {string} sep 日期格式的分隔符
|
|
152
|
-
* @
|
|
185
|
+
* @param {string} strDate - 参考日期
|
|
186
|
+
* @param {number} n - 正数:向后推算;负数:向前推算
|
|
187
|
+
* @param {string} sep - 日期格式的分隔符
|
|
188
|
+
* @returns {string} 计算后的目标日期
|
|
153
189
|
*/
|
|
154
190
|
declare function calculateDate(strDate: string, n: number, sep?: string): string;
|
|
155
191
|
/**
|
|
156
192
|
* 计算向前或向后N天的具体时间日期
|
|
157
|
-
* @param {number} n 正数:向后推算;负数:向前推算
|
|
158
|
-
* @param {string} dateSep 日期分隔符
|
|
159
|
-
* @param {string} timeSep 时间分隔符
|
|
160
|
-
* @
|
|
193
|
+
* @param {number} n - 正数:向后推算;负数:向前推算
|
|
194
|
+
* @param {string} dateSep - 日期分隔符
|
|
195
|
+
* @param {string} timeSep - 时间分隔符
|
|
196
|
+
* @returns {string} 转换后的目标日期时间
|
|
161
197
|
*/
|
|
162
198
|
declare function calculateDateTime(n: number, dateSep?: string, timeSep?: string): string;
|
|
163
199
|
|
|
@@ -172,19 +208,19 @@ interface Style {
|
|
|
172
208
|
* @param {string} className
|
|
173
209
|
* @returns {boolean}
|
|
174
210
|
*/
|
|
175
|
-
declare
|
|
211
|
+
declare function hasClass(el: HTMLElement, className: string): boolean;
|
|
176
212
|
/**
|
|
177
213
|
* 给元素增加样式名
|
|
178
214
|
* @param {HTMLElement} el
|
|
179
215
|
* @param {string} classNames
|
|
180
216
|
*/
|
|
181
|
-
declare
|
|
217
|
+
declare function addClass(el: HTMLElement, classNames: string): void;
|
|
182
218
|
/**
|
|
183
219
|
* 给元素移除样式名
|
|
184
220
|
* @param {HTMLElement} el
|
|
185
221
|
* @param {string} classNames
|
|
186
222
|
*/
|
|
187
|
-
declare
|
|
223
|
+
declare function removeClass(el: HTMLElement, classNames: string): void;
|
|
188
224
|
interface SetStyle {
|
|
189
225
|
(el: HTMLElement, key: string, val: string): void;
|
|
190
226
|
(el: HTMLElement, style: Style): void;
|
|
@@ -198,11 +234,11 @@ interface SetStyle {
|
|
|
198
234
|
declare const setStyle: SetStyle;
|
|
199
235
|
/**
|
|
200
236
|
* 获取元素样式
|
|
201
|
-
* @param {HTMLElement} el
|
|
237
|
+
* @param {HTMLElement} el 元素
|
|
202
238
|
* @param {string} key
|
|
203
239
|
* @returns {string}
|
|
204
240
|
*/
|
|
205
|
-
declare
|
|
241
|
+
declare function getStyle(el: HTMLElement, key: string): string;
|
|
206
242
|
type ScrollElement = HTMLElement | Document | Window;
|
|
207
243
|
interface SmoothScrollOptions {
|
|
208
244
|
el: ScrollElement;
|
|
@@ -214,6 +250,14 @@ declare function smoothScroll(options?: Partial<SmoothScrollOptions>): Promise<v
|
|
|
214
250
|
type ReadyCallback = () => void;
|
|
215
251
|
declare function isDomReady(): boolean;
|
|
216
252
|
declare function onDomReady(callback: ReadyCallback): void;
|
|
253
|
+
/**
|
|
254
|
+
* 获取元素样式属性的计算值
|
|
255
|
+
* @param {HTMLElement} el
|
|
256
|
+
* @param {string} property
|
|
257
|
+
* @param {boolean} reNumber
|
|
258
|
+
* @returns {string|number}
|
|
259
|
+
*/
|
|
260
|
+
declare function getComputedCssVal(el: HTMLElement, property: string, reNumber?: boolean): string | number;
|
|
217
261
|
|
|
218
262
|
interface Params<T = string | number> {
|
|
219
263
|
[key: string]: T | Array<T>;
|
|
@@ -223,7 +267,7 @@ interface Params<T = string | number> {
|
|
|
223
267
|
* @param {string} queryString
|
|
224
268
|
* @returns {Params}
|
|
225
269
|
*/
|
|
226
|
-
declare
|
|
270
|
+
declare function qsParse(queryString: string): Params;
|
|
227
271
|
type LooseParamValue = string | number | boolean | Date | null | undefined;
|
|
228
272
|
interface LooseParams<T = LooseParamValue> {
|
|
229
273
|
[key: string]: T | Array<T>;
|
|
@@ -235,26 +279,26 @@ type Replacer = (value: LooseParamValue) => string | null;
|
|
|
235
279
|
* @param {Replacer} replacer
|
|
236
280
|
* @returns {string}
|
|
237
281
|
*/
|
|
238
|
-
declare
|
|
282
|
+
declare function qsStringify(query: LooseParams, replacer?: Replacer): string;
|
|
239
283
|
|
|
240
284
|
/**
|
|
241
285
|
* 通过打开新窗口的方式下载
|
|
242
286
|
* @param {string} url
|
|
243
287
|
* @param {LooseParams} params
|
|
244
288
|
*/
|
|
245
|
-
declare
|
|
289
|
+
declare function downloadURL(url: string, params?: LooseParams): void;
|
|
246
290
|
/**
|
|
247
291
|
* 通过 A 链接的方式下载
|
|
248
292
|
* @param {string} href
|
|
249
293
|
* @param {string} filename
|
|
250
294
|
*/
|
|
251
|
-
declare
|
|
295
|
+
declare function downloadHref(href: string, filename: string): void;
|
|
252
296
|
/**
|
|
253
297
|
* 将大文件对象通过 A 链接的方式下载
|
|
254
298
|
* @param {Blob} blob
|
|
255
299
|
* @param {string} filename
|
|
256
300
|
*/
|
|
257
|
-
declare
|
|
301
|
+
declare function downloadBlob(blob: Blob, filename: string): void;
|
|
258
302
|
type FileType = 'json' | 'csv' | 'xls' | 'xlsx';
|
|
259
303
|
/**
|
|
260
304
|
* 将指定数据格式通过 A 链接的方式下载
|
|
@@ -263,7 +307,7 @@ type FileType = 'json' | 'csv' | 'xls' | 'xlsx';
|
|
|
263
307
|
* @param {string} filename
|
|
264
308
|
* @param {string[]} [headers]
|
|
265
309
|
*/
|
|
266
|
-
declare
|
|
310
|
+
declare function downloadData(data: AnyObject | AnyObject[], fileType: FileType, filename: string, headers?: string[]): void;
|
|
267
311
|
|
|
268
312
|
/**
|
|
269
313
|
* 判断对象是否为纯对象
|
|
@@ -277,13 +321,13 @@ declare const isPlainObject: (obj: unknown) => boolean;
|
|
|
277
321
|
* @param {string} key
|
|
278
322
|
* @returns {boolean}
|
|
279
323
|
*/
|
|
280
|
-
declare
|
|
324
|
+
declare function objectHas<T extends AnyObject>(obj: T, key: keyof T): boolean;
|
|
281
325
|
/**
|
|
282
326
|
* 遍历对象,返回 false 中断遍历
|
|
283
327
|
* @param {O} obj
|
|
284
328
|
* @param {(val: O[keyof O], key: keyof O) => (boolean | void)} iterator
|
|
285
329
|
*/
|
|
286
|
-
declare
|
|
330
|
+
declare function objectEach<O extends AnyObject>(obj: O, iterator: (val: O[keyof O], key: Extract<keyof O, string>) => any): void;
|
|
287
331
|
/**
|
|
288
332
|
* 异步遍历对象,返回 false 中断遍历
|
|
289
333
|
* @param {O} obj
|
|
@@ -318,7 +362,7 @@ type ObjectAssignItem = AnyObject | AnyArray;
|
|
|
318
362
|
* @param {ObjectAssignItem | undefined} targets
|
|
319
363
|
* @returns {R}
|
|
320
364
|
*/
|
|
321
|
-
declare
|
|
365
|
+
declare function objectAssign<R = AnyObject | AnyArray>(source: ObjectAssignItem, ...targets: (ObjectAssignItem | undefined)[]): R;
|
|
322
366
|
|
|
323
367
|
/**
|
|
324
368
|
* 对象填充
|
|
@@ -327,7 +371,7 @@ declare const objectAssign: <R = AnyObject | AnyArray>(source: ObjectAssignItem,
|
|
|
327
371
|
* @param {(s: Partial<R>, t: Partial<R>, key: keyof R) => boolean} fillable
|
|
328
372
|
* @returns {R}
|
|
329
373
|
*/
|
|
330
|
-
declare
|
|
374
|
+
declare function objectFill<R extends AnyObject = AnyObject>(source: Partial<R>, target: Partial<R>, fillable?: (s: typeof source, t: typeof target, key: keyof R) => boolean): R;
|
|
331
375
|
declare function objectGet(obj: AnyObject, path: string, strict?: boolean): {
|
|
332
376
|
p: any | undefined;
|
|
333
377
|
k: string | undefined;
|
|
@@ -337,9 +381,9 @@ declare function objectGet(obj: AnyObject, path: string, strict?: boolean): {
|
|
|
337
381
|
* 深拷贝堪称完全体 即:任何类型的数据都会被深拷贝
|
|
338
382
|
* @param {AnyObject | AnyArray} obj
|
|
339
383
|
* @param {WeakMap} map
|
|
340
|
-
* @
|
|
384
|
+
* @returns {AnyObject | AnyArray}
|
|
341
385
|
*/
|
|
342
|
-
declare function cloneDeep(obj: Object, map?: WeakMap<
|
|
386
|
+
declare function cloneDeep(obj: Object, map?: WeakMap<object, any>): Object;
|
|
343
387
|
|
|
344
388
|
/**
|
|
345
389
|
* 标准化路径
|
|
@@ -361,14 +405,14 @@ declare const pathJoin: (from: string, ...to: string[]) => string;
|
|
|
361
405
|
* @param {boolean} [bigger] 是否大写第一个字母
|
|
362
406
|
* @returns {string}
|
|
363
407
|
*/
|
|
364
|
-
declare
|
|
408
|
+
declare function stringCamelCase(string: string, bigger?: boolean): string;
|
|
365
409
|
/**
|
|
366
410
|
* 将字符串转换为连字格式
|
|
367
411
|
* @param {string} string
|
|
368
412
|
* @param {string} [separator] 分隔符,默认是"-"(短横线)
|
|
369
413
|
* @returns {string}
|
|
370
414
|
*/
|
|
371
|
-
declare
|
|
415
|
+
declare function stringKebabCase(string: string, separator?: string): string;
|
|
372
416
|
declare const STRING_ARABIC_NUMERALS = "0123456789";
|
|
373
417
|
declare const STRING_LOWERCASE_ALPHA = "abcdefghijklmnopqrstuvwxyz";
|
|
374
418
|
declare const STRING_UPPERCASE_ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
@@ -383,7 +427,7 @@ declare const STRING_UPPERCASE_ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
|
383
427
|
* @param args
|
|
384
428
|
* @returns {string}
|
|
385
429
|
*/
|
|
386
|
-
declare
|
|
430
|
+
declare function stringFormat(string: string, ...args: Array<unknown>): string;
|
|
387
431
|
/**
|
|
388
432
|
* 字符串赋值
|
|
389
433
|
* @example
|
|
@@ -414,6 +458,14 @@ declare const stringEscapeHtml: (html: string) => string;
|
|
|
414
458
|
* @returns {string}
|
|
415
459
|
*/
|
|
416
460
|
declare const stringFill: (length: number, value?: string) => string;
|
|
461
|
+
/**
|
|
462
|
+
* 字符串的像素宽度
|
|
463
|
+
* @param {string} str 目标字符串
|
|
464
|
+
* @param {number} fontSize 字符串字体大小
|
|
465
|
+
* @param {boolean} isRemoveDom 计算后是否移除中间dom元素
|
|
466
|
+
* @returns {*}
|
|
467
|
+
*/
|
|
468
|
+
declare function getStrWidthPx(str: string, fontSize?: number, isRemoveDom?: boolean): number;
|
|
417
469
|
|
|
418
470
|
interface Url {
|
|
419
471
|
protocol: string;
|
|
@@ -477,12 +529,11 @@ declare function asyncMap<T, R>(list: Array<T>, mapper: (val: T, idx: number, li
|
|
|
477
529
|
|
|
478
530
|
/**
|
|
479
531
|
* 选择本地文件
|
|
480
|
-
* @param {
|
|
481
|
-
* @
|
|
532
|
+
* @param {string} accept 上传的文件类型,用于过滤
|
|
533
|
+
* @param {Function} changeCb 选择文件回调
|
|
534
|
+
* @returns {HTMLInputElement}
|
|
482
535
|
*/
|
|
483
|
-
declare function chooseLocalFile(
|
|
484
|
-
accept: any;
|
|
485
|
-
}, changeCb: (FileList: any) => any): HTMLInputElement;
|
|
536
|
+
declare function chooseLocalFile(accept: string, changeCb: (FileList: any) => any): HTMLInputElement;
|
|
486
537
|
|
|
487
538
|
interface ICanvasWM {
|
|
488
539
|
container: HTMLElement;
|
|
@@ -497,9 +548,132 @@ interface ICanvasWM {
|
|
|
497
548
|
zIndex: number;
|
|
498
549
|
}
|
|
499
550
|
/**
|
|
500
|
-
* canvas 实现
|
|
551
|
+
* canvas 实现 水印, 具备防删除功能
|
|
501
552
|
* @param {ICanvasWM} canvasWM
|
|
553
|
+
* @example genCanvasWM({ content: 'QQMusicFE' })
|
|
554
|
+
*/
|
|
555
|
+
declare function genCanvasWM(canvasWM: ICanvasWM): void;
|
|
556
|
+
|
|
557
|
+
interface DebounceFunc<F extends AnyFunc> {
|
|
558
|
+
(...args: Parameters<F>): void;
|
|
559
|
+
cancel: () => void;
|
|
560
|
+
}
|
|
561
|
+
/**
|
|
562
|
+
* 防抖函数
|
|
563
|
+
* 当函数被连续调用时,该函数并不执行,只有当其全部停止调用超过一定时间后才执行1次。
|
|
564
|
+
* 例如:上电梯的时候,大家陆陆续续进来,电梯的门不会关上,只有当一段时间都没有人上来,电梯才会关门。
|
|
565
|
+
* @param {F} func
|
|
566
|
+
* @param {number} wait
|
|
567
|
+
* @returns {DebounceFunc<F>}
|
|
568
|
+
*/
|
|
569
|
+
declare const debounce: <F extends AnyFunc>(func: F, wait?: number) => DebounceFunc<F>;
|
|
570
|
+
interface ThrottleFunc<F extends AnyFunc> {
|
|
571
|
+
(...args: Parameters<F>): void;
|
|
572
|
+
cancel: () => void;
|
|
573
|
+
}
|
|
574
|
+
/**
|
|
575
|
+
* 节流函数
|
|
576
|
+
* 节流就是节约流量,将连续触发的事件稀释成预设评率。 比如每间隔1秒执行一次函数,无论这期间触发多少次事件。
|
|
577
|
+
* 这有点像公交车,无论在站点等车的人多不多,公交车只会按时来一班,不会来一个人就来一辆公交车。
|
|
578
|
+
* @param {F} func
|
|
579
|
+
* @param {number} wait
|
|
580
|
+
* @param {boolean} immediate
|
|
581
|
+
* @returns {ThrottleFunc<F>}
|
|
582
|
+
*/
|
|
583
|
+
declare const throttle: <F extends AnyFunc>(func: F, wait: number, immediate?: boolean) => ThrottleFunc<F>;
|
|
584
|
+
interface OnceFunc<F extends AnyFunc> {
|
|
585
|
+
(...args: Parameters<F>): ReturnType<F>;
|
|
586
|
+
}
|
|
587
|
+
/**
|
|
588
|
+
* 单次函数
|
|
589
|
+
* @param {AnyFunc} func
|
|
590
|
+
* @returns {AnyFunc}
|
|
591
|
+
*/
|
|
592
|
+
declare const once: <F extends AnyFunc = AnyFunc>(func: F) => OnceFunc<F>;
|
|
593
|
+
/**
|
|
594
|
+
* 设置全局变量
|
|
595
|
+
* @param {string | number | symbol} key
|
|
596
|
+
* @param val
|
|
597
|
+
*/
|
|
598
|
+
declare function setGlobal(key: string | number | symbol, val?: any): void;
|
|
599
|
+
/**
|
|
600
|
+
* 设置全局变量
|
|
601
|
+
* @param {string | number | symbol} key
|
|
602
|
+
* @param val
|
|
603
|
+
*/
|
|
604
|
+
declare function getGlobal<T>(key: string | number | symbol): T | void;
|
|
605
|
+
|
|
606
|
+
/**
|
|
607
|
+
* 随机整数
|
|
608
|
+
* @param {number} min
|
|
609
|
+
* @param {number} max
|
|
610
|
+
* @returns {number}
|
|
611
|
+
*/
|
|
612
|
+
declare const randomNumber: (min: number, max: number) => number;
|
|
613
|
+
declare const STRING_POOL: string;
|
|
614
|
+
interface RandomString {
|
|
615
|
+
(length: number, pool: string): string;
|
|
616
|
+
(length: number): string;
|
|
617
|
+
(pool: string): string;
|
|
618
|
+
(): string;
|
|
619
|
+
}
|
|
620
|
+
/**
|
|
621
|
+
* 随机字符串
|
|
622
|
+
* @param {number | string} length
|
|
623
|
+
* @param {string} pool
|
|
624
|
+
* @returns {string}
|
|
625
|
+
*/
|
|
626
|
+
declare const randomString: RandomString;
|
|
627
|
+
/**
|
|
628
|
+
* 优先浏览器原生能力获取 UUID v4
|
|
629
|
+
* @returns {string}
|
|
630
|
+
*/
|
|
631
|
+
declare function randomUuid(): string;
|
|
632
|
+
|
|
633
|
+
declare const HEX_POOL: string;
|
|
634
|
+
/**
|
|
635
|
+
* 将十进制转换成任意进制
|
|
636
|
+
* @param {number | string} decimal 十进制数值或字符串,可以是任意长度,会使用大数进行计算
|
|
637
|
+
* @param {string} [hexPool] 进制池,默认 62 进制
|
|
638
|
+
* @returns {string}
|
|
639
|
+
*/
|
|
640
|
+
declare function numberToHex(decimal: number | string, hexPool?: string): string;
|
|
641
|
+
/**
|
|
642
|
+
* 缩写
|
|
643
|
+
* @param {number | string} num
|
|
644
|
+
* @param {Array<string>} units
|
|
645
|
+
* @param {number} ratio
|
|
646
|
+
* @param {number} exponent
|
|
647
|
+
* @returns {string}
|
|
648
|
+
*/
|
|
649
|
+
declare const numberAbbr: (num: number | string, units: Array<string>, ratio?: number, exponent?: number) => string;
|
|
650
|
+
/**
|
|
651
|
+
* 将数字格式化成千位分隔符显示的字符串
|
|
652
|
+
* @param {number} val 数字
|
|
653
|
+
* @param {'int' | 'float'} type 展示分段显示的类型 int:整型 | float:浮点型
|
|
654
|
+
* @returns {string}
|
|
655
|
+
*/
|
|
656
|
+
declare function formatNumber(val: number, type?: string): string;
|
|
657
|
+
|
|
658
|
+
declare const UNIQUE_NUMBER_SAFE_LENGTH = 18;
|
|
659
|
+
/**
|
|
660
|
+
* 生成唯一不重复数值
|
|
661
|
+
* @param {number} length
|
|
662
|
+
* @returns {string}
|
|
663
|
+
*/
|
|
664
|
+
declare const uniqueNumber: (length?: number) => string;
|
|
665
|
+
interface UniqueString {
|
|
666
|
+
(length: number, pool: string): string;
|
|
667
|
+
(length: number): string;
|
|
668
|
+
(pool: string): string;
|
|
669
|
+
(): string;
|
|
670
|
+
}
|
|
671
|
+
/**
|
|
672
|
+
* 生成唯一不重复字符串
|
|
673
|
+
* @param {number | string} length
|
|
674
|
+
* @param {string} pool
|
|
675
|
+
* @returns {string}
|
|
502
676
|
*/
|
|
503
|
-
declare const
|
|
677
|
+
declare const uniqueString: UniqueString;
|
|
504
678
|
|
|
505
|
-
export { type AnyArray, type AnyFunc, type AnyObject, type ArrayElements, type LooseParamValue, type LooseParams, type Params, type PartialDeep, type Replacer, STRING_ARABIC_NUMERALS, STRING_LOWERCASE_ALPHA, STRING_UPPERCASE_ALPHA, addClass, arrayEach, arrayEachAsync, arrayInsertBefore, arrayLike, arrayRemove,
|
|
679
|
+
export { type AnyArray, type AnyFunc, type AnyObject, type ArrayElements, type DateObj, type DateValue, type DebounceFunc, type FileType, HEX_POOL, type ICanvasWM, type ITreeConf, type IdLike, type LooseParamValue, type LooseParams, type ObjectAssignItem, type OnceFunc, type Params, type PartialDeep, type RandomString, type ReadyCallback, type Replacer, STRING_ARABIC_NUMERALS, STRING_LOWERCASE_ALPHA, STRING_POOL, STRING_UPPERCASE_ALPHA, type SetStyle, type SmoothScrollOptions, type Style, type ThrottleFunc, UNIQUE_NUMBER_SAFE_LENGTH, type UniqueString, type Url, addClass, arrayEach, arrayEachAsync, arrayInsertBefore, arrayLike, arrayRemove, asyncMap, calculateDate, calculateDateTime, chooseLocalFile, cloneDeep, cookieDel, cookieGet, cookieSet, copyText, dateParse, dateToEnd, dateToStart, debounce, deepTraversal, downloadBlob, downloadData, downloadHref, downloadURL, formatDate, formatNumber, genCanvasWM, getComputedCssVal, getGlobal, getStrWidthPx, getStyle, getTreeIds, hasClass, isArray, isBigInt, isBoolean, isDate, isDomReady, isError, isFunction, isNaN, isNull, isNumber, isObject, isPlainObject, isPrimitive, isRegExp, isString, isSymbol, isUndefined, isValidDate, numberAbbr, numberToHex, objectAssign, objectEach, objectEachAsync, objectFill, objectGet, objectHas, objectMap, objectAssign as objectMerge, objectOmit, objectPick, onDomReady, once, pathJoin, pathNormalize, qsParse, qsStringify, randomNumber, randomString, randomUuid, removeClass, setGlobal, setStyle, smoothScroll, stringAssign, stringCamelCase, stringEscapeHtml, stringFill, stringFormat, stringKebabCase, throttle, typeIs, uniqueNumber, uniqueString, urlDelParams, urlParse, urlSetParams, urlStringify, wait };
|