sculp-js 1.13.1 → 1.13.3-beta.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.
Files changed (127) hide show
  1. package/README.md +10 -11
  2. package/dist/cjs/_virtual/_commonjsHelpers.js +13 -0
  3. package/{lib → dist}/cjs/array.js +1 -1
  4. package/{lib → dist}/cjs/async.js +1 -1
  5. package/{lib/cjs/we-decode.js → dist/cjs/base64.js} +53 -44
  6. package/{lib → dist}/cjs/clipboard.js +4 -2
  7. package/{lib → dist}/cjs/cloneDeep.js +1 -1
  8. package/{lib → dist}/cjs/cookie.js +1 -1
  9. package/{lib → dist}/cjs/date.js +1 -1
  10. package/{lib → dist}/cjs/dom.js +1 -1
  11. package/{lib → dist}/cjs/download.js +4 -2
  12. package/dist/cjs/easing.js +75 -0
  13. package/{lib → dist}/cjs/file.js +7 -3
  14. package/{lib → dist}/cjs/func.js +1 -1
  15. package/{lib → dist}/cjs/index.js +11 -8
  16. package/{lib → dist}/cjs/math.js +1 -1
  17. package/dist/cjs/node_modules/bezier-easing/src/index.js +123 -0
  18. package/{lib → dist}/cjs/number.js +1 -1
  19. package/{lib → dist}/cjs/object.js +1 -1
  20. package/{lib → dist}/cjs/path.js +1 -1
  21. package/{lib → dist}/cjs/qs.js +1 -1
  22. package/{lib → dist}/cjs/random.js +1 -1
  23. package/{lib → dist}/cjs/string.js +1 -1
  24. package/{lib → dist}/cjs/tooltip.js +5 -2
  25. package/{lib → dist}/cjs/tree.js +9 -23
  26. package/{lib → dist}/cjs/type.js +8 -1
  27. package/{lib → dist}/cjs/unique.js +1 -1
  28. package/{lib → dist}/cjs/url.js +1 -1
  29. package/{lib → dist}/cjs/validator.js +1 -1
  30. package/{lib → dist}/cjs/variable.js +1 -1
  31. package/{lib → dist}/cjs/watermark.js +4 -2
  32. package/{lib/es → dist/esm}/array.js +1 -1
  33. package/{lib/es → dist/esm}/async.js +1 -1
  34. package/{lib/es/we-decode.js → dist/esm/base64.js} +52 -45
  35. package/{lib/es → dist/esm}/clipboard.js +4 -2
  36. package/{lib/es → dist/esm}/cloneDeep.js +1 -1
  37. package/{lib/es → dist/esm}/cookie.js +1 -1
  38. package/{lib/es → dist/esm}/date.js +1 -1
  39. package/{lib/es → dist/esm}/dom.js +1 -1
  40. package/{lib/es → dist/esm}/download.js +4 -2
  41. package/{lib/es → dist/esm}/easing.js +34 -2
  42. package/{lib/es → dist/esm}/file.js +7 -3
  43. package/{lib/es → dist/esm}/func.js +1 -1
  44. package/{lib/es → dist/esm}/index.js +4 -5
  45. package/{lib/es → dist/esm}/math.js +1 -1
  46. package/{lib/es → dist/esm}/number.js +1 -1
  47. package/{lib/es → dist/esm}/object.js +1 -1
  48. package/{lib/es → dist/esm}/path.js +1 -1
  49. package/{lib/es → dist/esm}/qs.js +1 -1
  50. package/{lib/es → dist/esm}/random.js +1 -1
  51. package/{lib/es → dist/esm}/string.js +1 -1
  52. package/{lib/es → dist/esm}/tooltip.js +5 -2
  53. package/{lib/es → dist/esm}/tree.js +10 -24
  54. package/{lib/es → dist/esm}/type.js +8 -2
  55. package/{lib/es → dist/esm}/unique.js +1 -1
  56. package/{lib/es → dist/esm}/url.js +1 -1
  57. package/{lib/es → dist/esm}/validator.js +1 -1
  58. package/{lib/es → dist/esm}/variable.js +1 -1
  59. package/{lib/es → dist/esm}/watermark.js +4 -2
  60. package/dist/types/array.d.ts +50 -0
  61. package/dist/types/array.d.ts.map +1 -0
  62. package/dist/types/async.d.ts +37 -0
  63. package/dist/types/async.d.ts.map +1 -0
  64. package/dist/types/base64.d.ts +25 -0
  65. package/dist/types/base64.d.ts.map +1 -0
  66. package/dist/types/clipboard.d.ts +20 -0
  67. package/dist/types/clipboard.d.ts.map +1 -0
  68. package/dist/types/cloneDeep.d.ts +12 -0
  69. package/dist/types/cloneDeep.d.ts.map +1 -0
  70. package/dist/types/cookie.d.ts +19 -0
  71. package/dist/types/cookie.d.ts.map +1 -0
  72. package/dist/types/core-index.d.ts +17 -0
  73. package/dist/types/core-index.d.ts.map +1 -0
  74. package/dist/types/date.d.ts +74 -0
  75. package/dist/types/date.d.ts.map +1 -0
  76. package/dist/types/dom.d.ts +74 -0
  77. package/dist/types/dom.d.ts.map +1 -0
  78. package/dist/types/download.d.ts +47 -0
  79. package/dist/types/download.d.ts.map +1 -0
  80. package/dist/types/easing.d.ts +32 -0
  81. package/dist/types/easing.d.ts.map +1 -0
  82. package/dist/types/file.d.ts +44 -0
  83. package/dist/types/file.d.ts.map +1 -0
  84. package/dist/types/func.d.ts +50 -0
  85. package/dist/types/func.d.ts.map +1 -0
  86. package/dist/types/index.d.ts +28 -0
  87. package/dist/types/index.d.ts.map +1 -0
  88. package/dist/types/index.js +3278 -0
  89. package/dist/types/math.d.ts +36 -0
  90. package/dist/types/math.d.ts.map +1 -0
  91. package/dist/types/number.d.ts +49 -0
  92. package/dist/types/number.d.ts.map +1 -0
  93. package/dist/types/object.d.ts +70 -0
  94. package/dist/types/object.d.ts.map +1 -0
  95. package/dist/types/path.d.ts +14 -0
  96. package/dist/types/path.d.ts.map +1 -0
  97. package/dist/types/qs.d.ts +22 -0
  98. package/dist/types/qs.d.ts.map +1 -0
  99. package/dist/types/random.d.ts +27 -0
  100. package/dist/types/random.d.ts.map +1 -0
  101. package/dist/types/string.d.ts +67 -0
  102. package/dist/types/string.d.ts.map +1 -0
  103. package/dist/types/tooltip.d.ts +36 -0
  104. package/dist/types/tooltip.d.ts.map +1 -0
  105. package/dist/types/tree.d.ts +99 -0
  106. package/dist/types/tree.d.ts.map +1 -0
  107. package/dist/types/type.d.ts +128 -0
  108. package/dist/types/type.d.ts.map +1 -0
  109. package/dist/types/unique.d.ts +21 -0
  110. package/dist/types/unique.d.ts.map +1 -0
  111. package/dist/types/url.d.ts +46 -0
  112. package/dist/types/url.d.ts.map +1 -0
  113. package/dist/types/validator.d.ts +67 -0
  114. package/dist/types/validator.d.ts.map +1 -0
  115. package/dist/types/variable.d.ts +71 -0
  116. package/dist/types/variable.d.ts.map +1 -0
  117. package/dist/types/watermark.d.ts +19 -0
  118. package/dist/types/watermark.d.ts.map +1 -0
  119. package/dist/umd/index.min.js +6 -0
  120. package/package.json +234 -17
  121. package/lib/cjs/base64.js +0 -62
  122. package/lib/cjs/easing.js +0 -40
  123. package/lib/cjs/isEqual.js +0 -133
  124. package/lib/es/base64.js +0 -59
  125. package/lib/es/isEqual.js +0 -131
  126. package/lib/index.d.ts +0 -1214
  127. package/lib/umd/index.js +0 -6
package/lib/index.d.ts DELETED
@@ -1,1214 +0,0 @@
1
- /** 任意函数 */
2
- type AnyFunc<R = any> = (...args: any[]) => R;
3
- /** 任意数组 */
4
- type AnyArray = any[];
5
- /** 取出数组元素 */
6
- type ArrayElements<A> = A extends Array<infer R> ? R : never;
7
- /** 任意对象 */
8
- type AnyObject = Record<string | number, any>;
9
- /** 异步回调函数 */
10
- type AsyncCallback = {
11
- successCallback?: Function;
12
- failCallback?: Function;
13
- };
14
- interface Fn<T = any, R = T> {
15
- (...arg: T[]): R;
16
- }
17
- interface PromiseFn<T = any, R = T> {
18
- (...arg: T[]): Promise<R>;
19
- }
20
- /**
21
- * 将除指定属性外的所有属性变为必填
22
- *
23
- * Change all properties except the specified properties to required
24
- */
25
- type ChangeRequiredExcept<T, K extends keyof T> = Required<Omit<T, K>> & Partial<Pick<T, K>>;
26
- /**
27
- * 将指定属性变为可选
28
- *
29
- * Change the specified properties to optional
30
- */
31
- type ChangeOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
32
- /**
33
- * 将指定属性变为必填
34
- *
35
- * Change the specified properties to required
36
- */
37
- type ChangeRequired<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
38
- type PartialDeep<T> = {
39
- [P in keyof T]?: PartialDeep<T[P]>;
40
- };
41
- /**
42
- * 判断对象内是否有该静态属性
43
- * @param {object} obj
44
- * @param {string} key
45
- * @returns {boolean}
46
- */
47
- declare function objectHas<T extends AnyObject>(obj: T, key: keyof T): boolean;
48
- /**
49
- * 判断一个对象是否为类数组
50
- *
51
- * @param any
52
- * @returns {boolean}
53
- */
54
- declare function arrayLike(any: unknown): boolean;
55
- /**
56
- * 判断任意值的数据类型,检查非对象时不如typeof、instanceof的性能高
57
- *
58
- * 当检查类对象时是不可靠的,对象可以通过定义 Symbol.toStringTag 属性来更改检查结果
59
- *
60
- * 详见:https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Object/toString
61
- * @param {unknown} any
62
- * @returns
63
- */
64
- declare function typeIs(any: unknown): 'Null' | 'Undefined' | 'Symbol' | 'Boolean' | 'Number' | 'String' | 'Function' | 'Date' | 'RegExp' | 'Map' | 'Set' | 'ArrayBuffer' | 'Object' | 'Array' | 'Error' | 'BigInt' | 'Promise' | 'AsyncFunction' | string;
65
- declare const isString: (any: unknown) => any is string;
66
- declare const isBoolean: (any: unknown) => any is boolean;
67
- declare const isSymbol: (any: unknown) => any is symbol;
68
- declare const isBigInt: (any: unknown) => any is bigint;
69
- declare const isNumber: (any: unknown) => any is number;
70
- declare const isUndefined: (any: unknown) => any is undefined;
71
- declare const isNull: (any: unknown) => any is null;
72
- declare const isPrimitive: (any: unknown) => boolean;
73
- declare function isNullOrUnDef(val: unknown): val is null | undefined;
74
-
75
- declare const isObject: (any: unknown) => any is Record<string, unknown>;
76
- declare const isArray: (any: unknown) => any is unknown[];
77
- /**
78
- * 判断是否为函数
79
- * @param {unknown} any
80
- * @returns {boolean}
81
- */
82
- declare const isFunction: (any: unknown) => any is Function;
83
- declare const isNaN: (any: unknown) => any is number;
84
- declare const isDate: (any: unknown) => any is Date;
85
- declare const isError: (any: unknown) => any is Error;
86
- declare const isRegExp: (any: unknown) => any is RegExp;
87
- /**
88
- * 判断一个字符串是否为有效的 JSON, 若有效则返回有效的JSON对象,否则false
89
- * @param {string} str
90
- * @returns {Object | boolean}
91
- */
92
- declare function isJsonString(str: string): Object | boolean;
93
- /**
94
- * Checks if `value` is an empty object, collection, map, or set.
95
- *
96
- * Objects are considered empty if they have no own enumerable string keyed
97
- * properties.
98
- *
99
- * Array-like values such as `arguments` objects, arrays, buffers, strings, or
100
- * jQuery-like collections are considered empty if they have a `length` of `0`.
101
- * Similarly, maps and sets are considered empty if they have a `size` of `0`.
102
- *
103
- * @param {*} value The value to check.
104
- * @returns {boolean} Returns `true` if `value` is empty, else `false`.
105
- * @example
106
- *
107
- * isEmpty(null);
108
- * // => true
109
- *
110
- * isEmpty(true);
111
- * // => true
112
- *
113
- * isEmpty(1);
114
- * // => true
115
- *
116
- * isEmpty([1, 2, 3]);
117
- * // => false
118
- *
119
- * isEmpty({ 'a': 1 });
120
- * // => false
121
- */
122
- declare function isEmpty(value: any): boolean;
123
-
124
- /**
125
- * 遍历数组,返回 false 中断遍历(支持continue和break操作)
126
- *
127
- * @param {ArrayLike<V>} array
128
- * @param {(val: V, idx: number) => any} iterator 迭代函数, 返回值为true时continue, 返回值为false时break
129
- * @param {boolean} reverse 是否倒序
130
- * @returns {*}
131
- */
132
- declare function arrayEach<V>(array: ArrayLike<V>, iterator: (val: V, idx: number, arr: ArrayLike<V>) => boolean | void, reverse?: boolean): void;
133
- /**
134
- * 异步遍历数组,返回 false 中断遍历
135
- * @param {ArrayLike<V>} array 数组
136
- * @param {(val: V, idx: number) => Promise<any>} iterator 支持Promise类型的回调函数
137
- * @param {boolean} reverse 是否反向遍历
138
- * @example
139
- * 使用范例如下:
140
- * const start = async () => {
141
- * await arrayEachAsync(result, async (item) => {
142
- * await request(item);
143
- * count++;
144
- * })
145
- * console.log('发送次数', count);
146
- * }
147
-
148
- * for await...of 使用范例如下
149
- * const loadImages = async (images) => {
150
- * for await (const item of images) {
151
- * await request(item);
152
- * count++;
153
- * }
154
- * }
155
- */
156
- declare function arrayEachAsync<V>(array: ArrayLike<V>, iterator: (val: V, idx: number) => Promise<any> | any, reverse?: boolean): Promise<void>;
157
- /**
158
- * 插入到目标位置之前
159
- * @param {AnyArray} array
160
- * @param {number} start
161
- * @param {number} to
162
- * @returns {*}
163
- */
164
- declare function arrayInsertBefore(array: AnyArray, start: number, to: number): void;
165
- /**
166
- * 数组删除指定项目
167
- * @param {V[]} array
168
- * @param {(val: V, idx: number) => boolean} expect
169
- * @returns {V[]}
170
- */
171
- declare function arrayRemove<V>(array: V[], expect: (val: V, idx: number) => boolean): V[];
172
-
173
- type CopyTextOptions = AsyncCallback & {
174
- container?: HTMLElement;
175
- };
176
- /**
177
- * 复制文本,优先使用navigator.clipboard,仅在安全上下文(HTTPS/localhost)下生效,若不支持则回退使用execCommand方式
178
- * @param {string} text
179
- * @param {CopyTextOptions} options 可选参数:成功回调successCallback、失败回调failCallback、容器元素container
180
- * (默认document.body, 当不支持clipboard时必须传复制按钮元素,包裹模拟选择操作的临时元素,
181
- * 解决脱离文档流的元素无法复制的问题,如Modal内复制操作)
182
- */
183
- declare function copyText(text: string, options?: CopyTextOptions): void;
184
- /**
185
- * 使用execCommand方式复制文本
186
- * @param text
187
- * @param options
188
- */
189
- declare function fallbackCopyText(text: string, options?: CopyTextOptions): void;
190
-
191
- /**
192
- * 获取cookie
193
- * @param {string} name
194
- * @returns {string}
195
- */
196
- declare function cookieGet(name: string): string;
197
- /**
198
- * 设置 cookie
199
- * @param {string} name
200
- * @param {string} value
201
- * @param {number | Date} [maxAge]
202
- */
203
- declare function cookieSet(name: string, value: string, maxAge?: number | Date): void;
204
- /**
205
- * 删除单个 cookie
206
- * @param name cookie 名称
207
- */
208
- declare const cookieDel: (name: string) => void;
209
-
210
- declare const isValidDate: (any: unknown) => any is Date;
211
- interface DateObj {
212
- [propName: string]: string;
213
- }
214
- type DateValue = number | string | Date;
215
- /**
216
- * 解析为Date对象
217
- * @param {DateValue} value - 可以是数值、字符串或 Date 对象
218
- * @returns {Date} - 转换后的目标Date
219
- */
220
- declare function dateParse(value: DateValue): Date;
221
- /**
222
- * 格式化为日期对象(带自定义格式化模板)
223
- * @param {DateValue} value 可以是数值、字符串或 Date 对象
224
- * @param {string} [format] 模板,默认是 YYYY-MM-DD HH:mm:ss,模板字符:
225
- * - YYYY:年
226
- * - yyyy: 年
227
- * - MM:月
228
- * - DD:日
229
- * - dd: 日
230
- * - HH:时(24 小时制)
231
- * - hh:时(12 小时制)
232
- * - mm:分
233
- * - ss:秒
234
- * - SSS:毫秒
235
- * @returns {string}
236
- */
237
- /**
238
- * 将日期转换为一天的开始时间,即0点0分0秒0毫秒
239
- * @param {DateValue} value
240
- * @returns {Date}
241
- */
242
- declare function dateToStart(value: DateValue): Date;
243
- /**
244
- * 将日期转换为一天的结束时间,即23点59分59秒999毫秒
245
- * @param {DateValue} value
246
- * @returns {Date}
247
- */
248
- declare function dateToEnd(value: DateValue): Date;
249
- /**
250
- * 格式化为日期对象(带自定义格式化模板)
251
- * @param {Date} value - 可以是数值、字符串或 Date 对象
252
- * @param {string} [format] - 模板,默认是 YYYY-MM-DD HH:mm:ss,模板字符:
253
- * - YYYY:年
254
- * - yyyy: 年
255
- * - MM:月
256
- * - DD:日
257
- * - dd: 日
258
- * - HH:时(24 小时制)
259
- * - mm:分
260
- * - ss:秒
261
- * - SSS:毫秒
262
- * - ww: 周
263
- * @returns {string} 格式化后的日期字符串
264
- */
265
- declare function formatDate(value: DateValue, format?: string): string;
266
- /**
267
- * 计算向前或向后N天的具体日期
268
- * @param {DateValue} originDate - 参考日期
269
- * @param {number} n - 正数:向后推算;负数:向前推算
270
- * @param {string} sep - 日期格式的分隔符
271
- * @returns {string} 计算后的目标日期
272
- */
273
- declare function calculateDate(originDate: DateValue, n: number, sep?: string): string;
274
- /**
275
- * 计算向前或向后N天的具体日期时间
276
- * @param {DateValue} originDateTime - 参考日期时间
277
- * @param {number} n - 正数:向后推算;负数:向前推算
278
- * @param {string} dateSep - 日期分隔符
279
- * @param {string} timeSep - 时间分隔符
280
- * @returns {string} 转换后的目标日期时间
281
- */
282
- declare function calculateDateTime(originDateTime: DateValue, n: number, dateSep?: string, timeSep?: string): string;
283
-
284
- type EasingName = 'ease' | 'linear' | 'ease-in' | 'ease-out' | 'ease-in-out' | string;
285
-
286
- interface Style {
287
- [propName: string]: string | number;
288
- }
289
- /**
290
- * 判断元素是否包含某个样式名
291
- * @param {HTMLElement} el
292
- * @param {string} className
293
- * @returns {boolean}
294
- */
295
- declare function hasClass(el: HTMLElement, className: string): boolean;
296
- /**
297
- * 给元素增加样式名
298
- * @param {HTMLElement} el
299
- * @param {string} classNames
300
- */
301
- declare function addClass(el: HTMLElement, classNames: string): void;
302
- /**
303
- * 给元素移除样式名
304
- * @param {HTMLElement} el
305
- * @param {string} classNames
306
- */
307
- declare function removeClass(el: HTMLElement, classNames: string): void;
308
- interface SetStyle {
309
- (el: HTMLElement, key: string, val: string): void;
310
- (el: HTMLElement, style: Style): void;
311
- }
312
- /**
313
- * 设置元素样式
314
- * @param {HTMLElement} el
315
- * @param {string | Style} key
316
- * @param {string} val
317
- */
318
- declare const setStyle: SetStyle;
319
- /**
320
- * 获取元素样式
321
- * @param {HTMLElement} el 元素
322
- * @param {string} key
323
- * @returns {string}
324
- */
325
- declare function getStyle(el: HTMLElement, key: string): string;
326
- type ScrollElement = HTMLElement | Document | Window;
327
- interface SmoothScrollOptions {
328
- el: ScrollElement;
329
- to: number;
330
- duration: number;
331
- easing: EasingName;
332
- }
333
- declare function smoothScroll(options?: Partial<SmoothScrollOptions>): Promise<void>;
334
- /**
335
- * 获取元素样式属性的计算值
336
- * @param {HTMLElement} el
337
- * @param {string} property
338
- * @param {boolean} reNumber
339
- * @returns {string|number}
340
- */
341
- declare function getComputedCssVal(el: HTMLElement, property: string, reNumber?: boolean): string | number;
342
- /**
343
- * 字符串的像素宽度
344
- * @param {string} str 目标字符串
345
- * @param {number} fontSize 字符串字体大小
346
- * @param {boolean} isRemove 计算后是否移除创建的dom元素
347
- * @returns {*}
348
- */
349
- declare function getStrWidthPx(str: string, fontSize?: number, isRemove?: boolean): number;
350
- /**
351
- * Programmatically select the text of a HTML element
352
- *
353
- * @param {HTMLElement} element The element whose text you wish to select
354
- * @returns
355
- */
356
- declare function select(element: HTMLElement): any;
357
-
358
- interface Params<T = string | number> {
359
- [key: string]: T | Array<T>;
360
- }
361
- /**
362
- * 解析查询参数,内部使用的是浏览器内置的 URLSearchParams 进行处理
363
- * @param {string} queryString
364
- * @returns {Params}
365
- */
366
- declare function qsParse(queryString: string): Params;
367
- type LooseParamValue = string | number | boolean | Date | null | undefined;
368
- interface LooseParams<T = LooseParamValue> {
369
- [key: string]: T | Array<T>;
370
- }
371
- type Replacer = (value: LooseParamValue) => string | null;
372
- /**
373
- * 字符化查询对象,内部使用的是浏览器内置的 URLSearchParams 进行处理
374
- * @param {LooseParams} query
375
- * @param {Replacer} replacer
376
- * @returns {string}
377
- */
378
- declare function qsStringify(query: LooseParams, replacer?: Replacer): string;
379
-
380
- /**
381
- * 通过打开新窗口的方式下载
382
- * @param {string} url
383
- * @param {LooseParams} params
384
- */
385
- declare function downloadURL(url: string, params?: LooseParams): void;
386
- /**
387
- * 通过 A 链接的方式下载
388
- * @param {string} href
389
- * @param {string} filename
390
- * @param {Function} callback
391
- */
392
- declare function downloadHref(href: string, filename: string, callback?: Function): void;
393
- /**
394
- * 将大文件对象通过 A 链接的方式下载
395
- * @param {Blob} blob
396
- * @param {string} filename
397
- * @param {Function} callback
398
- */
399
- declare function downloadBlob(blob: Blob, filename: string, callback?: Function): void;
400
- type CrossOriginDownloadParams = AsyncCallback & {
401
- successCode?: number;
402
- };
403
- /**
404
- * 根据URL下载文件(解决跨域a.download不生效问题)
405
- *
406
- * 可定制下载成功的状态码status(浏览器原生状态码)
407
- *
408
- * 支持下载操作成功、失败后的回调
409
- * @param {string} url
410
- * @param {string} filename
411
- * @param {CrossOriginDownloadParams} options
412
- */
413
- declare function crossOriginDownload(url: string, filename: string, options?: CrossOriginDownloadParams): void;
414
- type FileType = 'json' | 'csv' | 'xls' | 'xlsx';
415
- /**
416
- * 将指定数据格式通过 A 链接的方式下载
417
- * @param {AnyObject | AnyObject[]} data
418
- * @param {FileType} fileType 支持 json/csv/xls/xlsx 四种格式
419
- * @param {string} filename
420
- * @param {string[]} [headers]
421
- */
422
- declare function downloadData(data: AnyObject | AnyObject[], fileType: FileType, filename: string, headers?: string[]): void;
423
-
424
- /**
425
- * 判断对象是否为纯对象
426
- * @param {object} obj
427
- * @returns {boolean}
428
- */
429
- declare const isPlainObject: (obj: unknown) => boolean;
430
- /**
431
- * 遍历对象,返回 false 中断遍历
432
- * @param {O} obj
433
- * @param {(val: O[keyof O], key: keyof O) => (boolean | void)} iterator
434
- */
435
- declare function objectEach<O extends AnyObject>(obj: O, iterator: (val: O[keyof O], key: Extract<keyof O, string>) => any): void;
436
- /**
437
- * 异步遍历对象,返回 false 中断遍历
438
- * @param {O} obj
439
- * @param {(val: O[keyof O], key: keyof O) => (boolean | void)} iterator
440
- */
441
- declare function objectEachAsync<O extends AnyObject>(obj: O, iterator: (val: O[keyof O], key: Extract<keyof O, string>) => Promise<any> | any): Promise<void>;
442
- /**
443
- * 对象映射
444
- * @param {O} obj
445
- * @param {(val: O[keyof O], key: Extract<keyof O, string>) => any} iterator
446
- * @returns {Record<Extract<keyof O, string>, T>}
447
- */
448
- 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>;
449
- /**
450
- * 对象提取
451
- * @param {O} obj
452
- * @param {K} keys
453
- * @returns {Pick<O, ArrayElements<K>>}
454
- */
455
- declare function objectPick<O extends AnyObject, K extends Extract<keyof O, string>[]>(obj: O, keys: K): Pick<O, ArrayElements<K>>;
456
- /**
457
- * 对象去除
458
- * @param {O} obj
459
- * @param {K} keys
460
- * @returns {Pick<O, ArrayElements<K>>}
461
- */
462
- declare function objectOmit<O extends AnyObject, K extends Extract<keyof O, string>[]>(obj: O, keys: K): Omit<O, ArrayElements<K>>;
463
- type ObjectAssignItem = AnyObject | AnyArray;
464
- /**
465
- * 对象合并,返回原始对象
466
- * @param {ObjectAssignItem} source
467
- * @param {ObjectAssignItem | undefined} targets
468
- * @returns {R}
469
- */
470
- declare function objectAssign<R = AnyObject | AnyArray>(source: ObjectAssignItem, ...targets: (ObjectAssignItem | undefined)[]): R;
471
-
472
- /**
473
- * 对象填充
474
- * @param {Partial<R>} source
475
- * @param {Partial<R>} target
476
- * @param {(s: Partial<R>, t: Partial<R>, key: keyof R) => boolean} fillable
477
- * @returns {R}
478
- */
479
- 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;
480
- /**
481
- * 获取对象/数组指定层级下的属性值(现在可用ES6+的可选链?.来替代)
482
- * @param {AnyObject} obj
483
- * @param {string} path
484
- * @param {boolean} strict
485
- * @returns
486
- */
487
- declare function objectGet(obj: AnyObject | AnyArray | undefined, path: string, strict?: boolean): {
488
- p: any | undefined;
489
- k: string | undefined;
490
- v: any | undefined;
491
- };
492
-
493
- /**
494
- * 标准化路径
495
- * @param {string} path
496
- * @returns {string}
497
- */
498
- declare const pathNormalize: (path: string) => string;
499
- /**
500
- * 路径合并
501
- * @param {string} from
502
- * @param {string} to
503
- * @returns {string}
504
- */
505
- declare const pathJoin: (from: string, ...to: string[]) => string;
506
-
507
- /**
508
- * 将字符串转换为驼峰格式
509
- * @param {string} string
510
- * @param {boolean} [bigger] 是否大写第一个字母
511
- * @returns {string}
512
- */
513
- declare function stringCamelCase(string: string, bigger?: boolean): string;
514
- /**
515
- * 将字符串转换为连字格式
516
- * @param {string} string
517
- * @param {string} [separator] 分隔符,默认是"-"(短横线)
518
- * @returns {string}
519
- */
520
- declare function stringKebabCase(string: string, separator?: string): string;
521
- declare const STRING_ARABIC_NUMERALS = "0123456789";
522
- declare const STRING_LOWERCASE_ALPHA = "abcdefghijklmnopqrstuvwxyz";
523
- declare const STRING_UPPERCASE_ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
524
- /**
525
- * 字符串格式化
526
- * @example
527
- * ```js
528
- * stringFormat("My name is %s.", "zhangsan")
529
- * // => "My name is zhangsan."
530
- * ```
531
- * @param {string} string 字符串模板,使用 %s 表示字符串,%d 表示数值,%o 表示对象,%% 表示百分号,参考 console.log
532
- * @param args
533
- * @returns {string}
534
- */
535
- declare function stringFormat(string: string, ...args: Array<unknown>): string;
536
- /**
537
- * 字符串赋值
538
- * @example
539
- * ```js
540
- * stringAssign('My name is ${user}.', { user: 'zhangsan' });
541
- * // => "My name is zhangsan."
542
- * ```
543
- * @param {string} template
544
- * @param {AnyObject} data
545
- * @returns {string}
546
- */
547
- declare const stringAssign: (template: string, data: AnyObject) => string;
548
- /**
549
- * 字符串编码 HTML
550
- * @example
551
- * ```js
552
- * stringEscapeHtml('<b>You & Me speak "xixi"</b>')
553
- * // => "&lt;b&gt;You &amp; Me speak &quot;xixi&quot;&lt;/b&gt;"
554
- * ```
555
- * @param {string} html
556
- * @returns {string}
557
- */
558
- declare const stringEscapeHtml: (html: string) => string;
559
- /**
560
- * 字符串填充
561
- * @param {number} length
562
- * @param {string} value
563
- * @returns {string}
564
- */
565
- declare const stringFill: (length: number, value?: string) => string;
566
- /**
567
- * 解析URL查询参数
568
- * @param {string} searchStr
569
- * @returns {Record<string, string | string[]>}
570
- */
571
- declare function parseQueryParams(searchStr?: string): Record<string, string | string[]>;
572
-
573
- interface Url {
574
- protocol: string;
575
- auth: string;
576
- username: string;
577
- password: string;
578
- host: string;
579
- port: string;
580
- hostname: string;
581
- hash: string;
582
- search: string;
583
- searchParams: Params;
584
- query: string;
585
- pathname: string;
586
- path: string;
587
- href: string;
588
- }
589
- /**
590
- * url 解析
591
- * @param {string} url
592
- * @param {boolean} isModernApi 使用现代API:URL, 默认true (对无效url解析会抛错), 否则使用a标签来解析(兼容性更强)
593
- * @returns {Url}
594
- */
595
- declare const urlParse: (url: string, isModernApi?: boolean) => Url;
596
- /**
597
- * url 字符化,url 对象里的 searchParams 会覆盖 url 原有的查询参数
598
- * @param {Url} url
599
- * @returns {string}
600
- */
601
- declare const urlStringify: (url: Url) => string;
602
- /**
603
- * 设置 url 查询参数
604
- * @param {string} url
605
- * @param {AnyObject} setter
606
- * @returns {string}
607
- */
608
- declare const urlSetParams: (url: string, setter: AnyObject) => string;
609
- /**
610
- * 删除 url 查询参数
611
- * @param {string} url
612
- * @param {string[]} removeKeys
613
- * @returns {string}
614
- */
615
- declare const urlDelParams: (url: string, removeKeys: string[]) => string;
616
-
617
- /**
618
- * 等待一段时间
619
- * @param {number} timeout 等待时间,单位毫秒
620
- * @returns {Promise<void>}
621
- */
622
- declare function wait(timeout?: number): Promise<void>;
623
- /**
624
- * 异步遍历
625
- * @ref https://github.com/Kevnz/async-tools/blob/master/src/mapper.js
626
- * @ref https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Array/@@iterator
627
- * @param {Array<T>} list
628
- * @param {(val: T, idx: number, list: ArrayLike<T>) => Promise<R>} mapper
629
- * @param {number} concurrency 并发数量,默认无限
630
- * @returns {Promise<R[]>}
631
- */
632
- declare function asyncMap<T, R>(list: Array<T>, mapper: (val: T, idx: number, list: Array<T>) => Promise<R>, concurrency?: number): Promise<R[]>;
633
- /**
634
- * Execute a promise safely
635
- *
636
- * @param { Promise } promise
637
- * @param { Object= } errorExt - Additional Information you can pass safeAwait the err object
638
- * @return { Promise }
639
- * @example
640
- * async function asyncTaskWithCb(cb) {
641
- let err, user, savedTask, notification;
642
-
643
- [ err, user ] = await safeAwait(UserModel.findById(1));
644
- if(!user) return cb('No user found');
645
-
646
- [ err, savedTask ] = await safeAwait(TaskModel({userId: user.id, name: 'Demo Task'}));
647
- if(err) return cb('Error occurred while saving task')
648
-
649
- cb(null, savedTask);
650
- }
651
- */
652
- declare function safeAwait<T, U = Error>(promise: Promise<T>, errorExt?: object): Promise<[U, undefined] | [null, T]>;
653
-
654
- /**
655
- * 判断是否支持canvas
656
- * @returns {boolean}
657
- */
658
- declare function supportCanvas(): boolean;
659
- /**
660
- * 选择本地文件
661
- * @param {string} accept 上传的文件类型,用于过滤
662
- * @param {Function} changeCb 选择文件回调
663
- * @returns {HTMLInputElement}
664
- */
665
- declare function chooseLocalFile(accept: string, changeCb: (FileList: any) => any): void;
666
- type ImageType = 'image/jpeg' | 'image/png' | 'image/webp';
667
- interface ICompressOptions {
668
- /** 压缩质量 0 ~ 1 之间*/
669
- quality?: number;
670
- /** 图片类型 */
671
- mime?: ImageType;
672
- maxSize?: number;
673
- minFileSizeKB?: number;
674
- }
675
- interface ICompressImgResult {
676
- file: File;
677
- bufferArray?: Uint8Array;
678
- origin?: File;
679
- beforeSrc?: string;
680
- afterSrc?: string;
681
- beforeKB?: number;
682
- afterKB?: number;
683
- }
684
- /**
685
- * Web端:等比例压缩图片批量处理 (小于minFileSizeKB:50,不压缩), 支持压缩全景图或长截图
686
- *
687
- * 1. 默认根据图片原始size及宽高适当地调整quality、width、height
688
- * 2. 可指定压缩的图片质量 quality(若不指定则根据原始图片大小来计算), 来适当调整width、height
689
- * 3. 可指定压缩的图片最大宽高 maxSize(若不指定则根据原始图片宽高来计算), 满足大屏幕图片展示的场景
690
- *
691
- * @param {File | FileList} file 图片或图片数组
692
- * @param {ICompressOptions} options 压缩图片配置项,default: {mime:'image/jpeg', minFileSizeKB: 50}
693
- * @returns {Promise<ICompressImgResult | ICompressImgResult[] | null>}
694
- */
695
- declare function compressImg(file: File | FileList, options?: ICompressOptions): Promise<ICompressImgResult | ICompressImgResult[] | null>;
696
-
697
- interface ICanvasWM {
698
- rootContainer?: HTMLElement | string;
699
- width?: string;
700
- height?: string;
701
- textAlign?: CanvasTextAlign;
702
- textBaseline?: CanvasTextBaseline;
703
- font?: string;
704
- fillStyle?: string;
705
- rotate?: number;
706
- zIndex?: number;
707
- watermarkId?: string;
708
- }
709
- /**
710
- * canvas 实现 水印, 具备防删除功能
711
- * @param {ICanvasWM} canvasWM
712
- * @example genCanvasWM({ content: 'QQMusicFE' })
713
- */
714
- declare function genCanvasWM(content?: string, canvasWM?: ICanvasWM): void;
715
-
716
- interface DebounceFunc<F extends AnyFunc> {
717
- (...args: Parameters<F>): void;
718
- cancel: () => void;
719
- }
720
- /**
721
- * 防抖函数
722
- * 当函数被连续调用时,该函数并不执行,只有当其全部停止调用超过一定时间后才执行1次。
723
- * 例如:上电梯的时候,大家陆陆续续进来,电梯的门不会关上,只有当一段时间都没有人上来,电梯才会关门。
724
- * @param {F} func
725
- * @param {number} wait
726
- * @returns {DebounceFunc<F>}
727
- */
728
- declare const debounce: <F extends AnyFunc>(func: F, wait?: number) => DebounceFunc<F>;
729
- interface ThrottleFunc<F extends AnyFunc> {
730
- (...args: Parameters<F>): void;
731
- cancel: () => void;
732
- }
733
- /**
734
- * 节流函数
735
- * 节流就是节约流量,将连续触发的事件稀释成预设评率。 比如每间隔1秒执行一次函数,无论这期间触发多少次事件。
736
- * 这有点像公交车,无论在站点等车的人多不多,公交车只会按时来一班,不会来一个人就来一辆公交车。
737
- * @param {F} func
738
- * @param {number} wait
739
- * @param {boolean} immediate
740
- * @returns {ThrottleFunc<F>}
741
- */
742
- declare const throttle: <F extends AnyFunc>(func: F, wait: number, immediate?: boolean) => ThrottleFunc<F>;
743
- interface OnceFunc<F extends AnyFunc> {
744
- (...args: Parameters<F>): ReturnType<F>;
745
- }
746
- /**
747
- * 单次函数
748
- * @param {AnyFunc} func
749
- * @returns {AnyFunc}
750
- */
751
- declare const once: <F extends AnyFunc = AnyFunc>(func: F) => OnceFunc<F>;
752
- /**
753
- * 设置全局变量
754
- * @param {string | number | symbol} key
755
- * @param val
756
- */
757
- declare function setGlobal(key: string | number | symbol, val?: any): void;
758
- /**
759
- * 获取全局变量
760
- * @param {string | number | symbol} key
761
- * @param val
762
- */
763
- declare function getGlobal<T>(key: string | number | symbol): T | void;
764
-
765
- /**
766
- * 随机整数
767
- * @param {number} min
768
- * @param {number} max
769
- * @returns {number}
770
- */
771
- declare const randomNumber: (min: number, max: number) => number;
772
- declare const STRING_POOL: string;
773
- interface RandomString {
774
- (length: number, pool: string): string;
775
- (length: number): string;
776
- (pool: string): string;
777
- (): string;
778
- }
779
- /**
780
- * 随机字符串
781
- * @param {number | string} length
782
- * @param {string} pool
783
- * @returns {string}
784
- */
785
- declare const randomString: RandomString;
786
- /**
787
- * 优先浏览器原生能力获取 UUID v4
788
- * @returns {string}
789
- */
790
- declare function randomUuid(): string;
791
-
792
- declare const HEX_POOL: string;
793
- /**
794
- * 将十进制转换成任意进制
795
- * @param {number | string} decimal 十进制数值或字符串,可以是任意长度,会使用大数进行计算
796
- * @param {string} [hexPool] 进制池,默认 62 进制
797
- * @returns {string}
798
- */
799
- declare function numberToHex(decimal: number | string, hexPool?: string): string;
800
- interface INumberAbbr {
801
- ratio?: number;
802
- decimals?: number;
803
- separator?: string;
804
- }
805
- /**
806
- * 将数字转换为携带单位的字符串
807
- * @param {number | string} num
808
- * @param {Array<string>} units
809
- * @param {INumberAbbr} options default: { ratio: 1000, decimals: 0, separator: ' ' }
810
- * @returns {string}
811
- */
812
- declare const numberAbbr: (num: number | string, units: Array<string>, options?: INumberAbbr) => string;
813
- interface IHumanFileSizeOptions {
814
- decimals?: number;
815
- si?: boolean;
816
- separator?: string;
817
- baseUnit?: string;
818
- maxUnit?: string;
819
- }
820
- /**
821
- * Converting file size in bytes to human-readable string
822
- * reference: https://zh.wikipedia.org/wiki/%E5%8D%83%E5%AD%97%E8%8A%82
823
- * @param {number | string} num bytes Number in Bytes
824
- * @param {IHumanFileSizeOptions} options default: { decimals = 0, si = false, separator = ' ' }
825
- * si: True to use metric (SI) units, aka powers of 1000, the units is
826
- * ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'].
827
- * False to use binary (IEC), aka powers of 1024, the units is
828
- * ['Byte', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB']
829
- * @returns
830
- */
831
- declare function humanFileSize(num: number | string, options?: IHumanFileSizeOptions): string;
832
- /**
833
- * 将数字格式化成千位分隔符显示的字符串
834
- * @param {number|string} num 数字
835
- * @param {number} decimals 格式化成指定小数位精度的参数
836
- * @returns {string}
837
- */
838
- declare function formatNumber(num: number | string, decimals?: number): string;
839
-
840
- declare const UNIQUE_NUMBER_SAFE_LENGTH = 18;
841
- /**
842
- * 生成唯一不重复数值
843
- * @param {number} length
844
- * @returns {string}
845
- */
846
- declare const uniqueNumber: (length?: number) => string;
847
- interface UniqueString {
848
- (length: number, pool: string): string;
849
- (length: number): string;
850
- (pool: string): string;
851
- (): string;
852
- }
853
- /**
854
- * 生成唯一不重复字符串
855
- * @param {number | string} length
856
- * @param {string} pool
857
- * @returns {string}
858
- */
859
- declare const uniqueString: UniqueString;
860
-
861
- /**
862
- * 自定义的 tooltip, 支持鼠标移动动悬浮提示
863
- * @Desc 自定义的tooltip方法, 支持拖动悬浮提示
864
- * Created by chendeqiao on 2017/5/8.
865
- * @example
866
- * <span onmouseleave="handleMouseLeave('#root')"
867
- * onmousemove="handleMouseEnter({rootContainer: '#root', title: 'title content', event: event})"
868
- * onmouseenter="handleMouseEnter({rootContainer:'#root', title: 'title content', event: event})">
869
- * title content
870
- * </span>
871
- */
872
- interface ITooltipParams {
873
- rootContainer: HTMLElement | string;
874
- title: string;
875
- event: PointerEvent | MouseEvent;
876
- bgColor?: string;
877
- color?: string;
878
- }
879
- /**
880
- * 自定义title提示功能的mouseenter事件句柄
881
- * @param {ITooltipParams} param
882
- * @returns {*}
883
- */
884
- declare function handleMouseEnter({ rootContainer, title, event, bgColor, color }: ITooltipParams): void;
885
- /**
886
- * 移除提示文案dom的事件句柄
887
- * @param {string} rootContainer
888
- * @returns {*}
889
- */
890
- declare function handleMouseLeave(rootContainer?: HTMLElement | string): void;
891
- declare const tooltipEvent: {
892
- handleMouseEnter: typeof handleMouseEnter;
893
- handleMouseLeave: typeof handleMouseLeave;
894
- };
895
-
896
- interface IFieldOptions {
897
- keyField: string;
898
- childField: string;
899
- pidField: string;
900
- }
901
- interface ISearchTreeOpts {
902
- childField: string;
903
- nameField: string;
904
- removeEmptyChild: boolean;
905
- ignoreCase: boolean;
906
- }
907
- interface IFilterCondition<V> {
908
- keyword?: string;
909
- filter?: (args: V) => boolean;
910
- }
911
- /**
912
- * 树遍历函数(支持continue和break操作), 可用于insert tree item 和 remove tree item
913
- * @param {ArrayLike<V>} tree 树形数据
914
- * @param {Function} iterator 迭代函数, 返回值为true时continue, 返回值为false时break
915
- * @param {options} options 支持定制子元素名称、反向遍历、广度优先遍历,默认{
916
- childField: 'children',
917
- reverse: false,
918
- breadthFirst: false
919
- }
920
- * @returns {*}
921
- */
922
- declare function forEachDeep<V>(tree: ArrayLike<V>, iterator: (val: V, index: number, currentArr: ArrayLike<V>, tree: ArrayLike<V>, parent: V | null, level: number) => boolean | void, options?: {
923
- childField?: string;
924
- reverse?: boolean;
925
- breadthFirst?: boolean;
926
- }): void;
927
- /**
928
- * 创建一个新数组, 深度优先遍历的Map函数(支持continue和break操作), 可用于insert tree item 和 remove tree item
929
- *
930
- * 可遍历任何带有 length 属性和数字键的类数组对象
931
- * @param {ArrayLike<V>} tree 树形数据
932
- * @param {Function} iterator 迭代函数, 返回值为true时continue, 返回值为false时break
933
- * @param {options} options 支持定制子元素名称、反向遍历,默认{
934
- childField: 'children',
935
- reverse: false,
936
- }
937
- * @returns {any[]} 新的一棵树
938
- */
939
- declare function mapDeep<T>(tree: T[], iterator: (val: T, index: number, currentArr: T[], tree: T[], parent: T | null, level: number) => {
940
- [k: string | number]: any;
941
- } | boolean, options?: {
942
- childField?: string;
943
- reverse?: boolean;
944
- breadthFirst?: boolean;
945
- }): any[];
946
- type IdLike = number | string;
947
- type ITreeConf = Omit<IFieldOptions, 'pidField'>;
948
- /**
949
- * 在树中找到 id 为某个值的节点,并返回上游的所有父级节点
950
- *
951
- * @param {ArrayLike<T>} tree - 树形数据
952
- * @param {number | string} nodeId - 目标元素ID
953
- * @param {ITreeConf} options - 迭代配置项, 默认:{ children = 'children', id = 'id' }
954
- * @returns {[(number | string)[], V[]]} - 由parentId...childId, parentObject-childObject组成的二维数组
955
- */
956
- declare function searchTreeById<V>(tree: ArrayLike<V>, nodeId: IdLike, options?: ITreeConf): [(number | string)[], ArrayLike<V>[]];
957
- /**
958
- * 扁平化数组转换成树
959
- * @param {any[]} list
960
- * @param {IFieldOptions} options 定制id字段名,子元素字段名,父元素字段名,默认
961
- * { keyField: 'key', childField: 'children', pidField: 'pid' }
962
- * @returns {any[]}
963
- */
964
- declare function formatTree(list: any[], options?: IFieldOptions): any[];
965
- /**
966
- * 树形结构转扁平化
967
- * @param {any[]} treeList
968
- * @param {IFieldOptions} options 定制id字段名,子元素字段名,父元素字段名,默认
969
- * { keyField: 'key', childField: 'children', pidField: 'pid' }
970
- * @returns {any[]}
971
- */
972
- declare function flatTree(treeList: any[], options?: IFieldOptions): any[];
973
- /**
974
- * 模糊搜索函数,返回包含搜索字符的节点及其祖先节点, 适用于树型组件的字符过滤功能
975
- * 以下搜索条件二选一,按先后优先级处理:
976
- * 1. 过滤函数filter, 返回true/false
977
- * 2. 匹配关键词,支持是否启用忽略大小写来判断
978
- *
979
- * 有以下特性:
980
- * 1. 可配置removeEmptyChild字段,来决定是否移除搜索结果中的空children字段
981
- * 2. 若无任何过滤条件或keyword模式匹配且keyword为空串,返回原对象;其他情况返回新数组
982
- * @param {V[]} nodes
983
- * @param {IFilterCondition} filterCondition
984
- * @param {ISearchTreeOpts} options 默认配置项 {
985
- childField: 'children',
986
- nameField: 'name',
987
- removeEmptyChild: false,
988
- ignoreCase: true
989
- }
990
- * @returns {V[]}
991
- */
992
- declare function fuzzySearchTree<V>(nodes: V[], filterCondition: IFilterCondition<V>, options?: ISearchTreeOpts): V[];
993
-
994
- /**
995
- * 数值安全乘法
996
- * @param arg1 数值1
997
- * @param arg2 数值2
998
- */
999
- declare const multiply: (arg1: number, arg2: number) => number;
1000
- /**
1001
- * 数值安全加法
1002
- * @param arg1 数值1
1003
- * @param arg2 数值2
1004
- */
1005
- declare const add: (arg1: number, arg2: number) => number;
1006
- /**
1007
- * 数值安全减法
1008
- * @param arg1 数值1
1009
- * @param arg2 数值2
1010
- */
1011
- declare const subtract: (arg1: number, arg2: number) => number;
1012
- /**
1013
- * 数值安全除法
1014
- * @param arg1 数值1
1015
- * @param arg2 数值2
1016
- */
1017
- declare const divide: (arg1: number, arg2: number) => number;
1018
- type NumberType = number | string;
1019
- /**
1020
- * Correct the given number to specifying significant digits.
1021
- *
1022
- * @param num The input number
1023
- * @param precision An integer specifying the number of significant digits
1024
- *
1025
- * @example strip(0.09999999999999998) === 0.1 // true
1026
- */
1027
- declare function strip(num: NumberType, precision?: number): number;
1028
-
1029
- /**
1030
- * 字符串编码成Base64, 平替浏览器的btoa, 不包含中文的处理 (适用于任何环境,包括小程序)
1031
- * @param {string} string
1032
- * @returns {string}
1033
- */
1034
- declare function weBtoa(string: string): string;
1035
- /**
1036
- * Base64解码为原始字符串,平替浏览器的atob, 不包含中文的处理(适用于任何环境,包括小程序)
1037
- * @param {string} string
1038
- * @returns {string}
1039
- */
1040
- declare function weAtob(string: string): string;
1041
-
1042
- /**
1043
- * 将base64编码的字符串转换为原始字符串,包括对中文内容的处理(高性能,且支持Web、Node、小程序等任意平台)
1044
- * @param base64 base64编码的字符串
1045
- * @returns 原始字符串,包括中文内容
1046
- */
1047
- declare function decodeFromBase64(base64: string): string;
1048
- /**
1049
- * 将原始字符串,包括中文内容,转换为base64编码的字符串(高性能,且支持Web、Node、小程序等任意平台)
1050
- * @param rawStr 原始字符串,包括中文内容
1051
- * @returns base64编码的字符串
1052
- */
1053
- declare function encodeToBase64(rawStr: string): string;
1054
-
1055
- declare const EMAIL_REGEX: RegExp;
1056
- /**
1057
- * 判断字符串是否为邮箱格式,不对邮箱真实性做验证,如域名是否正确等
1058
- * @param {string} value
1059
- * @returns {boolean}
1060
- */
1061
- declare const isEmail: (value: string) => boolean;
1062
- declare const PHONE_REGEX: RegExp;
1063
- /**
1064
- * 判断字符串是否为宽松手机格式,即首位为 1 的 11 位数字都属于手机号
1065
- * @param {string} value
1066
- * @returns {boolean}
1067
- */
1068
- declare const isPhone: (value: string) => boolean;
1069
- /**
1070
- * 判断字符串是否为身份证号码格式
1071
- * @param {string} value
1072
- * @returns {boolean}
1073
- */
1074
- declare const isIdNo: (value: string) => boolean;
1075
- declare const URL_REGEX: RegExp;
1076
- declare const HTTP_URL_REGEX: RegExp;
1077
- /**
1078
- * 判断字符串是否为 url 格式,支持 http、https、ftp 协议,支持域名或者 ipV4
1079
- * @param {string} value
1080
- * @returns {boolean}
1081
- */
1082
- declare const isUrl: (url: string, includeFtp?: boolean) => boolean;
1083
- declare const IPV4_REGEX: RegExp;
1084
- declare const IPV6_REGEX: RegExp;
1085
- /**
1086
- * 判断字符串是否为 IPV4 格式,不对 ip 真实性做验证
1087
- * @param {string} value
1088
- * @returns {boolean}
1089
- */
1090
- declare const isIpV4: (value: string) => boolean;
1091
- /**
1092
- * 判断字符串是否为 IPV6 格式,不对 ip 真实性做验证
1093
- * @param {string} value
1094
- * @returns {boolean}
1095
- */
1096
- declare const isIpV6: (value: string) => boolean;
1097
- /**
1098
- * 判断字符串是否为整数(自然数),即 ...,-3,-2,-1,0,1,2,3,...
1099
- * @param {string} value
1100
- * @returns {boolean}
1101
- */
1102
- declare const isInteger: (value: string) => boolean;
1103
- /**
1104
- * 判断字符串是否为浮点数,即必须有小数点的有理数
1105
- * @param {string} value
1106
- * @returns {boolean}
1107
- */
1108
- declare const isFloat: (value: string) => boolean;
1109
- /**
1110
- * 判断字符串是否为正确数值,包括整数和浮点数
1111
- * @param {string} value
1112
- * @returns {boolean}
1113
- */
1114
- declare const isNumerical: (value: string) => boolean;
1115
- /**
1116
- * 判断字符串是否为数字,例如六位数字短信验证码(093031)
1117
- * @param {string} value
1118
- * @returns {boolean}
1119
- */
1120
- declare const isDigit: (value: string) => boolean;
1121
-
1122
- /**
1123
- * 去除字符串中重复字符
1124
- * @param {string} str
1125
- * @returns string
1126
- * @example
1127
- *
1128
- * uniqueSymbol('1a1bac');
1129
- * // => '1abc'
1130
- */
1131
- declare function uniqueSymbol(str: string): string;
1132
- /**
1133
- * 转义所有特殊字符
1134
- * @param {string} str 原字符串
1135
- * reference: https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Guide/Regular_expressions
1136
- * @returns string
1137
- */
1138
- declare function escapeRegExp(str: string): string;
1139
- /**
1140
- * 解析字符串的插值变量
1141
- * @param {string} str 字符串
1142
- * @param {string} leftMatchSymbol 变量左侧匹配符号,默认:{
1143
- * @param {string} rightMatchSymbol 变量右侧匹配符号,默认:}
1144
- * @returns string[]
1145
- * @example
1146
- *
1147
- * default match symbol {} same as /{\s*([^{}\s]*)\s*}/g
1148
- */
1149
- declare function parseVarFromString(str: string, leftMatchSymbol?: string, rightMatchSymbol?: string): string[];
1150
- /**
1151
- * 替换字符串中的插值变量
1152
- * @param {string} sourceStr
1153
- * @param {Record<string, any>} targetObj
1154
- * @param {string} leftMatchSymbol 变量左侧匹配符号,默认:{
1155
- * @param {string} rightMatchSymbol 变量右侧匹配符号,默认:}
1156
- * @returns string
1157
- */
1158
- declare function replaceVarFromString(sourceStr: string, targetObj: Record<string, any>, leftMatchSymbol?: string, rightMatchSymbol?: string): string;
1159
- /**
1160
- * 在指定作用域中执行代码
1161
- * @param {string} code 要执行的代码(需包含 return 语句或表达式)
1162
- * @param {Object} scope 作用域对象(键值对形式的变量环境)
1163
- * @returns 代码执行结果
1164
- *
1165
- * @example
1166
- * // 测试用例 1: 基本变量访问
1167
- * executeInScope("return a + b;", { a: 1, b: 2 });
1168
- * // 3
1169
- *
1170
- * // 测试用例 2: 支持复杂表达式和运算
1171
- * executeInScope(
1172
- * "return Array.from({ length: 3 }, (_, i) => base + i);",
1173
- * { base: 100 }
1174
- * );
1175
- * // [100, 101, 102]
1176
- *
1177
- * // 支持外传函数作用域执行
1178
- * const scope = {
1179
- * $: {
1180
- * fun: {
1181
- * time: {
1182
- * now: function () {
1183
- * return new Date();
1184
- * },
1185
- * },
1186
- * },
1187
- * },
1188
- * };
1189
- * executeInScope("return $.fun.time.now()", scope)
1190
- */
1191
- declare function executeInScope(code: string, scope?: Record<string, any>): any;
1192
-
1193
- /**
1194
- * 深拷贝堪称完全体 即:任何类型的数据都会被深拷贝
1195
- *
1196
- * 包含对null、原始值、对象循环引用的处理
1197
- *
1198
- * 对Map、Set、ArrayBuffer、Date、RegExp、Array、Object及原型链属性方法执行深拷贝
1199
- * @param {T} source
1200
- * @param {WeakMap} map
1201
- * @returns {T}
1202
- */
1203
- declare function cloneDeep<T>(source: T, map?: WeakMap<any, any>): T;
1204
-
1205
- type Comparable = null | undefined | boolean | number | string | Date | RegExp | Map<any, any> | Set<any> | ArrayBuffer | object | Array<any>;
1206
- /**
1207
- * 比较两值是否相等,适用所有数据类型
1208
- * @param {Comparable} a
1209
- * @param {Comparable} b
1210
- * @returns {boolean}
1211
- */
1212
- declare function isEqual(a: Comparable, b: Comparable): boolean;
1213
-
1214
- export { type AnyArray, type AnyFunc, type AnyObject, type ArrayElements, type AsyncCallback, type ChangeOptional, type ChangeRequired, type ChangeRequiredExcept, type Comparable, type DateObj, type DateValue, type DebounceFunc, EMAIL_REGEX, type FileType, type Fn, HEX_POOL, HTTP_URL_REGEX, type ICanvasWM, type ICompressImgResult, type ICompressOptions, type IFieldOptions, type IFilterCondition, IPV4_REGEX, IPV6_REGEX, type ISearchTreeOpts, type ITreeConf, type IdLike, type LooseParamValue, type LooseParams, type ObjectAssignItem, type OnceFunc, PHONE_REGEX, type Params, type PartialDeep, type PromiseFn, type RandomString, 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, URL_REGEX, type UniqueString, type Url, add, addClass, arrayEach, arrayEachAsync, arrayInsertBefore, arrayLike, arrayRemove, asyncMap, calculateDate, calculateDateTime, chooseLocalFile, cloneDeep, compressImg, cookieDel, cookieGet, cookieSet, copyText, crossOriginDownload, dateParse, dateToEnd, dateToStart, debounce, decodeFromBase64, divide, downloadBlob, downloadData, downloadHref, downloadURL, encodeToBase64, escapeRegExp, executeInScope, fallbackCopyText, flatTree, forEachDeep, formatDate, formatNumber as formatMoney, formatNumber, formatTree, fuzzySearchTree, genCanvasWM, getComputedCssVal, getGlobal, getStrWidthPx, getStyle, hasClass, humanFileSize, isArray, isBigInt, isBoolean, isDate, isDigit, isEmail, isEmpty, isEqual, isError, isFloat, isFunction, isIdNo, isInteger, isIpV4, isIpV6, isJsonString, isNaN, isNull, isNullOrUnDef, isNullOrUnDef as isNullish, isNumber, isNumerical, isObject, isPhone, isPlainObject, isPrimitive, isRegExp, isString, isSymbol, isUndefined, isUrl, isValidDate, mapDeep, multiply, numberAbbr, numberToHex, objectAssign, objectEach, objectEachAsync, objectFill, objectGet, objectHas, objectMap, objectAssign as objectMerge, objectOmit, objectPick, once, parseQueryParams, parseVarFromString, pathJoin, pathNormalize, qsParse, qsStringify, randomNumber, randomString, randomUuid, removeClass, replaceVarFromString, safeAwait, searchTreeById, select, setGlobal, setStyle, smoothScroll, stringAssign, stringCamelCase, stringEscapeHtml, stringFill, stringFormat, stringKebabCase, strip, subtract, supportCanvas, throttle, tooltipEvent, typeIs, uniqueNumber, uniqueString, uniqueSymbol, urlDelParams, urlParse, urlSetParams, urlStringify, wait, weAtob, weBtoa };