mazey 4.9.3 → 4.10.2
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/.dockerignore +35 -0
- package/.gitattributes +5 -0
- package/AGENTS.md +111 -0
- package/Dockerfile +30 -0
- package/README.md +139 -60
- package/lib/global.d.ts +3 -0
- package/lib/index.cjs.js +2 -2
- package/lib/index.esm.js +2 -2
- package/lib/mazey.min.js +2 -2
- package/lib/typing.d.ts +1 -0
- package/package.json +3 -2
- package/scripts/change-package-name.js +6 -4
- package/scripts/git-helper.js +13 -12
- package/scripts/release.js +1 -1
- package/scripts/rollup.config.mjs +5 -1
- package/lib/browser.d.ts +0 -124
- package/lib/browser.d.ts.map +0 -1
- package/lib/calc.d.ts +0 -117
- package/lib/calc.d.ts.map +0 -1
- package/lib/debug.d.ts +0 -74
- package/lib/debug.d.ts.map +0 -1
- package/lib/dom.d.ts +0 -232
- package/lib/dom.d.ts.map +0 -1
- package/lib/event.d.ts +0 -101
- package/lib/event.d.ts.map +0 -1
- package/lib/index.d.ts +0 -14
- package/lib/index.d.ts.map +0 -1
- package/lib/load.d.ts +0 -186
- package/lib/load.d.ts.map +0 -1
- package/lib/perf.d.ts +0 -213
- package/lib/perf.d.ts.map +0 -1
- package/lib/store.d.ts +0 -230
- package/lib/store.d.ts.map +0 -1
- package/lib/url.d.ts +0 -394
- package/lib/url.d.ts.map +0 -1
- package/lib/util.d.ts +0 -1174
- package/lib/util.d.ts.map +0 -1
package/lib/util.d.ts
DELETED
|
@@ -1,1174 +0,0 @@
|
|
|
1
|
-
import type { ThrottleFunc, DebounceFunc, IsNumberOptions, ZResResponse, ZResIsValidResOptions, SimpleType, MazeyDate, MazeyObject, MazeyFnParams, MazeyFnReturn, MazeyFunction, RepeatUntilOptions } from "./typing";
|
|
2
|
-
/**
|
|
3
|
-
* Copy/Clone Object deeply.
|
|
4
|
-
*
|
|
5
|
-
* Usage:
|
|
6
|
-
*
|
|
7
|
-
* ```javascript
|
|
8
|
-
* import { deepCopy } from "mazey";
|
|
9
|
-
*
|
|
10
|
-
* const ret1 = deepCopy(["a", "b", "c"]);
|
|
11
|
-
* const ret2 = deepCopy("abc");
|
|
12
|
-
* console.log(ret1);
|
|
13
|
-
* console.log(ret2);
|
|
14
|
-
* ```
|
|
15
|
-
*
|
|
16
|
-
* Output:
|
|
17
|
-
*
|
|
18
|
-
* ```text
|
|
19
|
-
* ["a", "b", "c"]
|
|
20
|
-
* abc
|
|
21
|
-
* ```
|
|
22
|
-
*
|
|
23
|
-
* @param {object} obj The value to clone.
|
|
24
|
-
* @returns {object} Returns the deep cloned value.
|
|
25
|
-
* @category Util
|
|
26
|
-
*/
|
|
27
|
-
export declare function deepCopy<T>(obj: T): T;
|
|
28
|
-
/**
|
|
29
|
-
* Alias of `deepCopy`.
|
|
30
|
-
*
|
|
31
|
-
* @hidden
|
|
32
|
-
*/
|
|
33
|
-
export declare function deepCopyObject<T>(obj: T): T;
|
|
34
|
-
/**
|
|
35
|
-
* Convert CamelCase to KebabCase.
|
|
36
|
-
*
|
|
37
|
-
* Usage:
|
|
38
|
-
*
|
|
39
|
-
* ```javascript
|
|
40
|
-
* import { convertCamelToKebab } from "mazey";
|
|
41
|
-
*
|
|
42
|
-
* const ret1 = convertCamelToKebab("ABC");
|
|
43
|
-
* const ret2 = convertCamelToKebab("aBC");
|
|
44
|
-
* console.log(ret1);
|
|
45
|
-
* console.log(ret2);
|
|
46
|
-
* ```
|
|
47
|
-
*
|
|
48
|
-
* Output:
|
|
49
|
-
*
|
|
50
|
-
* ```text
|
|
51
|
-
* a-b-c
|
|
52
|
-
* a-b-c
|
|
53
|
-
* ```
|
|
54
|
-
*
|
|
55
|
-
* @param {string} camelCase "aBC" or "ABC"
|
|
56
|
-
* @returns {string} "a-b-c"
|
|
57
|
-
* @category Util
|
|
58
|
-
*/
|
|
59
|
-
export declare function convertCamelToKebab(camelCase: string): string;
|
|
60
|
-
/**
|
|
61
|
-
* Convert KebabCase to CamelCase.
|
|
62
|
-
*
|
|
63
|
-
* Usage:
|
|
64
|
-
*
|
|
65
|
-
* ```javascript
|
|
66
|
-
* import { convertKebabToCamel } from "mazey";
|
|
67
|
-
*
|
|
68
|
-
* const ret1 = convertKebabToCamel("a-b-c");
|
|
69
|
-
* const ret2 = convertKebabToCamel("a-bb-cc");
|
|
70
|
-
* console.log(ret1, ret2);
|
|
71
|
-
* ```
|
|
72
|
-
*
|
|
73
|
-
* Output:
|
|
74
|
-
*
|
|
75
|
-
* ```text
|
|
76
|
-
* aBC aBbCc
|
|
77
|
-
* ```
|
|
78
|
-
*
|
|
79
|
-
* @param {string} kebabCase "a-bb-cc"
|
|
80
|
-
* @returns {string} "aBbCc"
|
|
81
|
-
* @category Util
|
|
82
|
-
*/
|
|
83
|
-
export declare function convertKebabToCamel(kebabCase: string): string;
|
|
84
|
-
/**
|
|
85
|
-
* Alias of `convertCamelToKebab`.
|
|
86
|
-
*
|
|
87
|
-
* @hidden
|
|
88
|
-
*/
|
|
89
|
-
export declare function camelCaseToKebabCase(camelCase: string): string;
|
|
90
|
-
/**
|
|
91
|
-
* Convert CamelCase to Underscore.
|
|
92
|
-
*
|
|
93
|
-
* Usage:
|
|
94
|
-
*
|
|
95
|
-
* ```javascript
|
|
96
|
-
* import { convertCamelToUnder } from "mazey";
|
|
97
|
-
*
|
|
98
|
-
* const ret1 = convertCamelToUnder("ABC");
|
|
99
|
-
* const ret2 = convertCamelToUnder("aBC");
|
|
100
|
-
* console.log(ret1);
|
|
101
|
-
* console.log(ret2);
|
|
102
|
-
* ```
|
|
103
|
-
*
|
|
104
|
-
* Output:
|
|
105
|
-
*
|
|
106
|
-
* ```text
|
|
107
|
-
* a_b_c
|
|
108
|
-
* a_b_c
|
|
109
|
-
* ```
|
|
110
|
-
*
|
|
111
|
-
* @param {string} camelCase "aBC" or "ABC"
|
|
112
|
-
* @returns {string} "a_b_c"
|
|
113
|
-
* @category Util
|
|
114
|
-
*/
|
|
115
|
-
export declare function convertCamelToUnder(camelCase: string): string;
|
|
116
|
-
/**
|
|
117
|
-
* Convert Underscore to CamelCase.
|
|
118
|
-
*
|
|
119
|
-
* Usage:
|
|
120
|
-
*
|
|
121
|
-
* ```javascript
|
|
122
|
-
* import { convertUnderToCamel } from "mazey";
|
|
123
|
-
*
|
|
124
|
-
* const ret1 = convertUnderToCamel("a_b_c");
|
|
125
|
-
* const ret2 = convertUnderToCamel("a_bb_cc");
|
|
126
|
-
* console.log(ret1, ret2);
|
|
127
|
-
* ```
|
|
128
|
-
*
|
|
129
|
-
* Output:
|
|
130
|
-
*
|
|
131
|
-
* ```text
|
|
132
|
-
* aBC aBbCc
|
|
133
|
-
* ```
|
|
134
|
-
*
|
|
135
|
-
* @param {string} underCase "a_bb_cc"
|
|
136
|
-
* @returns {string} "aBbCc"
|
|
137
|
-
* @category Util
|
|
138
|
-
*/
|
|
139
|
-
export declare function convertUnderToCamel(underCase: string): string;
|
|
140
|
-
/**
|
|
141
|
-
* Alias of `convertCamelToUnder`.
|
|
142
|
-
*
|
|
143
|
-
* @hidden
|
|
144
|
-
*/
|
|
145
|
-
export declare function camelCase2Underscore(camelCase: string): string;
|
|
146
|
-
/**
|
|
147
|
-
* Remove leading and trailing whitespace or specified characters from string.
|
|
148
|
-
*
|
|
149
|
-
* Note: This method is used to replace the native `String.prototype.trim()`. But it is not necessary to use it in modern browsers.
|
|
150
|
-
*
|
|
151
|
-
* Usage:
|
|
152
|
-
*
|
|
153
|
-
* ```javascript
|
|
154
|
-
* import { mTrim } from "mazey";
|
|
155
|
-
*
|
|
156
|
-
* const ret1 = mTrim(" 1 2 3 ");
|
|
157
|
-
* const ret2 = mTrim("abc ");
|
|
158
|
-
* console.log(ret1);
|
|
159
|
-
* console.log(ret2);
|
|
160
|
-
* ```
|
|
161
|
-
*
|
|
162
|
-
* Output:
|
|
163
|
-
*
|
|
164
|
-
* ```text
|
|
165
|
-
* 1 2 3
|
|
166
|
-
* abc
|
|
167
|
-
* ```
|
|
168
|
-
*
|
|
169
|
-
* @param {string} str The string to trim.
|
|
170
|
-
* @returns {string} Trimmed string.
|
|
171
|
-
* @category Util
|
|
172
|
-
* @hidden
|
|
173
|
-
*/
|
|
174
|
-
export declare function mTrim(str: string): string;
|
|
175
|
-
/**
|
|
176
|
-
* Check whether it is a valid JSON string.
|
|
177
|
-
*
|
|
178
|
-
* Usage:
|
|
179
|
-
*
|
|
180
|
-
* ```javascript
|
|
181
|
-
* import { isJSONString } from "mazey";
|
|
182
|
-
*
|
|
183
|
-
* const ret1 = isJSONString(`['a', 'b', 'c']`);
|
|
184
|
-
* const ret2 = isJSONString(`["a", "b", "c"]`);
|
|
185
|
-
* console.log(ret1);
|
|
186
|
-
* console.log(ret2);
|
|
187
|
-
* ```
|
|
188
|
-
*
|
|
189
|
-
* Output:
|
|
190
|
-
*
|
|
191
|
-
* ```text
|
|
192
|
-
* false
|
|
193
|
-
* true
|
|
194
|
-
* ```
|
|
195
|
-
*
|
|
196
|
-
* @param {string} str The string to check.
|
|
197
|
-
* @returns {boolean} Return the result of checking.
|
|
198
|
-
* @category Util
|
|
199
|
-
*/
|
|
200
|
-
export declare function isJSONString(str: string): boolean;
|
|
201
|
-
/**
|
|
202
|
-
* Alias of `isJSONString`.
|
|
203
|
-
*
|
|
204
|
-
* @hidden
|
|
205
|
-
*/
|
|
206
|
-
export declare function isJsonString(str: string): boolean;
|
|
207
|
-
/**
|
|
208
|
-
* Generate a random string of number, `genRndNumString(7)` => "7658495".
|
|
209
|
-
*
|
|
210
|
-
* Usage:
|
|
211
|
-
*
|
|
212
|
-
* ```javascript
|
|
213
|
-
* import { genRndNumString } from "mazey";
|
|
214
|
-
*
|
|
215
|
-
* const ret1 = genRndNumString(4);
|
|
216
|
-
* const ret2 = genRndNumString(7);
|
|
217
|
-
* console.log(ret1);
|
|
218
|
-
* console.log(ret2);
|
|
219
|
-
* ```
|
|
220
|
-
*
|
|
221
|
-
* Output:
|
|
222
|
-
*
|
|
223
|
-
* ```text
|
|
224
|
-
* 9730
|
|
225
|
-
* 2262490
|
|
226
|
-
* ```
|
|
227
|
-
*
|
|
228
|
-
* @param {number} n Length
|
|
229
|
-
* @returns {string} Return the random string.
|
|
230
|
-
* @category Util
|
|
231
|
-
*/
|
|
232
|
-
export declare function genRndNumString(n?: number): string;
|
|
233
|
-
/**
|
|
234
|
-
* Alias of `genRndNumString`.
|
|
235
|
-
*
|
|
236
|
-
* @hidden
|
|
237
|
-
*/
|
|
238
|
-
export declare function generateRndNum(n?: number): string;
|
|
239
|
-
/**
|
|
240
|
-
* EN: Generate a unique identifier number based on time: `genUniqueNumString()` => `1538324722364123`
|
|
241
|
-
*
|
|
242
|
-
* ZH: 根据时间生成唯一标志的数字:`genUniqueNumString()` => `1538324722364123`。
|
|
243
|
-
*
|
|
244
|
-
* Usage:
|
|
245
|
-
*
|
|
246
|
-
* ```javascript
|
|
247
|
-
* import { genUniqueNumString } from "mazey";
|
|
248
|
-
*
|
|
249
|
-
* const ret1 = genUniqueNumString();
|
|
250
|
-
* const ret2 = genUniqueNumString(3);
|
|
251
|
-
* console.log(ret1);
|
|
252
|
-
* console.log(ret2);
|
|
253
|
-
* ```
|
|
254
|
-
*
|
|
255
|
-
* Output:
|
|
256
|
-
*
|
|
257
|
-
* ```text
|
|
258
|
-
* 1538324722364123
|
|
259
|
-
* 1538324722364123
|
|
260
|
-
* ```
|
|
261
|
-
*
|
|
262
|
-
* @param {number} n 随机数的长度
|
|
263
|
-
* @category Util
|
|
264
|
-
*/
|
|
265
|
-
export declare function genUniqueNumString(n?: number): string;
|
|
266
|
-
/**
|
|
267
|
-
* Alias of `genUniqueNumString`.
|
|
268
|
-
*
|
|
269
|
-
* @hidden
|
|
270
|
-
*/
|
|
271
|
-
export declare function generateUniqueNum(n?: number): string;
|
|
272
|
-
/**
|
|
273
|
-
* EN: Get timestamp.
|
|
274
|
-
*
|
|
275
|
-
* ZH: 获取时间戳。
|
|
276
|
-
*
|
|
277
|
-
* Usage:
|
|
278
|
-
*
|
|
279
|
-
* ```javascript
|
|
280
|
-
* import { mNow } from "mazey";
|
|
281
|
-
*
|
|
282
|
-
* const ret = mNow();
|
|
283
|
-
* console.log(ret);
|
|
284
|
-
* ```
|
|
285
|
-
*
|
|
286
|
-
* Output:
|
|
287
|
-
*
|
|
288
|
-
* ```text
|
|
289
|
-
* 1585325367122
|
|
290
|
-
* ```
|
|
291
|
-
*
|
|
292
|
-
* @category Util
|
|
293
|
-
*/
|
|
294
|
-
export declare function mNow(): number;
|
|
295
|
-
/**
|
|
296
|
-
* EN: Floating point number to percentage 0.2 => 20%
|
|
297
|
-
*
|
|
298
|
-
* ZH: 浮点数转为百分比 0.2 => 20%。
|
|
299
|
-
*
|
|
300
|
-
* Usage:
|
|
301
|
-
*
|
|
302
|
-
* ```javascript
|
|
303
|
-
* import { floatToPercent } from "mazey";
|
|
304
|
-
*
|
|
305
|
-
* const ret1 = floatToPercent(0.2);
|
|
306
|
-
* const ret2 = floatToPercent(0.2, 2);
|
|
307
|
-
* console.log(ret1);
|
|
308
|
-
* console.log(ret2);
|
|
309
|
-
* ```
|
|
310
|
-
*
|
|
311
|
-
* Output:
|
|
312
|
-
*
|
|
313
|
-
* ```text
|
|
314
|
-
* 20%
|
|
315
|
-
* 20.00%
|
|
316
|
-
* ```
|
|
317
|
-
*
|
|
318
|
-
* @param {number} num 浮点数
|
|
319
|
-
* @param {number} fixSize 保留几位浮点数
|
|
320
|
-
* @category Util
|
|
321
|
-
*/
|
|
322
|
-
export declare function floatToPercent(num: number, fixSize?: number): string;
|
|
323
|
-
/**
|
|
324
|
-
* EN: Keep the specified number of decimal places for floating-point numbers.
|
|
325
|
-
*
|
|
326
|
-
* ZH: 浮点数保留指定位。
|
|
327
|
-
*
|
|
328
|
-
* Usage:
|
|
329
|
-
*
|
|
330
|
-
* ```javascript
|
|
331
|
-
* import { floatFixed } from "mazey";
|
|
332
|
-
*
|
|
333
|
-
* const ret1 = floatFixed(0.2);
|
|
334
|
-
* const ret2 = floatFixed(0.2, 2);
|
|
335
|
-
* console.log(ret1);
|
|
336
|
-
* console.log(ret2);
|
|
337
|
-
* ```
|
|
338
|
-
*
|
|
339
|
-
* Output:
|
|
340
|
-
*
|
|
341
|
-
* ```text
|
|
342
|
-
* 0
|
|
343
|
-
* 0.20
|
|
344
|
-
* ```
|
|
345
|
-
*
|
|
346
|
-
* @category Util
|
|
347
|
-
*/
|
|
348
|
-
export declare function floatFixed(num: string, size?: number): string;
|
|
349
|
-
/**
|
|
350
|
-
* EN: Throttle, used to limit the frequency of function execution over time.
|
|
351
|
-
*
|
|
352
|
-
* ZH: 节流,用于限制函数在一段时间内的执行频率。
|
|
353
|
-
*
|
|
354
|
-
* Usage:
|
|
355
|
-
*
|
|
356
|
-
* ```javascript
|
|
357
|
-
* import { throttle } from "mazey";
|
|
358
|
-
*
|
|
359
|
-
* const foo = throttle(() => {
|
|
360
|
-
* console.log("The function will be invoked at most once per every wait 1000 milliseconds.");
|
|
361
|
-
* }, 1000, { leading: true });
|
|
362
|
-
* ```
|
|
363
|
-
*
|
|
364
|
-
* Reference: [Lodash](https://lodash.com/docs/4.17.15#throttle)
|
|
365
|
-
*
|
|
366
|
-
* @category Util
|
|
367
|
-
*/
|
|
368
|
-
export declare function throttle<T extends (...args: MazeyFnParams) => MazeyFnReturn>(func: T, wait: number, options?: {
|
|
369
|
-
leading?: boolean;
|
|
370
|
-
trailing?: boolean;
|
|
371
|
-
}): ThrottleFunc<T>;
|
|
372
|
-
/**
|
|
373
|
-
* EN: Debounce, used to delay the execution of a function until a specified time has passed since the last invocation.
|
|
374
|
-
*
|
|
375
|
-
* ZH: 防抖,用于在最后一次调用后的指定时间内延迟函数的执行。
|
|
376
|
-
*
|
|
377
|
-
* Usage:
|
|
378
|
-
*
|
|
379
|
-
* ```javascript
|
|
380
|
-
* import { debounce } from "mazey";
|
|
381
|
-
*
|
|
382
|
-
* const foo = debounce(() => {
|
|
383
|
-
* console.log("The debounced function will only be invoked in 1000 milliseconds, the other invoking will disappear during the wait time.");
|
|
384
|
-
* }, 1000, true);
|
|
385
|
-
* ```
|
|
386
|
-
*
|
|
387
|
-
* @category Util
|
|
388
|
-
*/
|
|
389
|
-
export declare function debounce<T extends (...args: MazeyFnParams) => MazeyFnReturn>(func: T, wait: number, immediate?: boolean): DebounceFunc<T>;
|
|
390
|
-
/**
|
|
391
|
-
* EN: Get interval time.
|
|
392
|
-
*
|
|
393
|
-
* ZH: 获取间隔时间。
|
|
394
|
-
*
|
|
395
|
-
* Usage:
|
|
396
|
-
*
|
|
397
|
-
* ```javascript
|
|
398
|
-
* import { getFriendlyInterval } from "mazey";
|
|
399
|
-
*
|
|
400
|
-
* const ret1 = getFriendlyInterval(new Date("2020-03-28 00:09:27"), new Date("2023-04-18 10:54:00"), { type: "d" });
|
|
401
|
-
* const ret2 = getFriendlyInterval(1585325367000, 1681786440000, { type: "text" });
|
|
402
|
-
* const ret3 = getFriendlyInterval("2020-03-28 00:09:27", "2023-04-18 10:54:00", { type: "text" });
|
|
403
|
-
* console.log(ret1);
|
|
404
|
-
* console.log(ret2);
|
|
405
|
-
* console.log(ret3);
|
|
406
|
-
* ```
|
|
407
|
-
*
|
|
408
|
-
* Output:
|
|
409
|
-
*
|
|
410
|
-
* ```text
|
|
411
|
-
* 1116
|
|
412
|
-
* 1116 天 10 时 44 分 33 秒
|
|
413
|
-
* 1116 天 10 时 44 分 33 秒
|
|
414
|
-
* ```
|
|
415
|
-
*
|
|
416
|
-
* @param {number/Date} start 开始时间戳 1585325367122
|
|
417
|
-
* @param {number/Date} end 结束时间戳 1585325367122
|
|
418
|
-
* @param {string} options.type 返回类型 d: 2(天) text: 2 天 4 时...
|
|
419
|
-
* @returns {string/number} 取决于 type
|
|
420
|
-
* @category Util
|
|
421
|
-
*/
|
|
422
|
-
export declare function getFriendlyInterval(start?: number | string | Date, end?: number | string | Date, options?: {
|
|
423
|
-
type?: string;
|
|
424
|
-
}): number | string;
|
|
425
|
-
/**
|
|
426
|
-
* EN: Check whether it is a right number.
|
|
427
|
-
*
|
|
428
|
-
* ZH: 判断是否有效数字。
|
|
429
|
-
*
|
|
430
|
-
* Usage:
|
|
431
|
-
*
|
|
432
|
-
* ```javascript
|
|
433
|
-
* import { isNumber } from "mazey";
|
|
434
|
-
*
|
|
435
|
-
* const ret1 = isNumber(123);
|
|
436
|
-
* const ret2 = isNumber("123");
|
|
437
|
-
* // Default: NaN, Infinity is not Number
|
|
438
|
-
* const ret3 = isNumber(Infinity);
|
|
439
|
-
* const ret4 = isNumber(Infinity, { isInfinityAsNumber: true });
|
|
440
|
-
* const ret5 = isNumber(NaN);
|
|
441
|
-
* const ret6 = isNumber(NaN, { isNaNAsNumber: true, isInfinityAsNumber: true });
|
|
442
|
-
* console.log(ret1, ret2, ret3, ret4, ret5, ret6);
|
|
443
|
-
* ```
|
|
444
|
-
*
|
|
445
|
-
* Output:
|
|
446
|
-
*
|
|
447
|
-
* ```text
|
|
448
|
-
* true false false true false true
|
|
449
|
-
* ```
|
|
450
|
-
*
|
|
451
|
-
* @param {*} num 被判断的值
|
|
452
|
-
* @param {boolean} options.isNaNAsNumber 是否 NaN 算数字(默认不算)
|
|
453
|
-
* @param {boolean} options.isInfinityAsNumber 是否 无限 算数字(默认不算)
|
|
454
|
-
* @returns {boolean} true 是数字
|
|
455
|
-
* @category Util
|
|
456
|
-
*/
|
|
457
|
-
export declare function isNumber(num: unknown, options?: IsNumberOptions): boolean;
|
|
458
|
-
/**
|
|
459
|
-
* EN: Invoke effective function.
|
|
460
|
-
*
|
|
461
|
-
* ZH: 执行有效函数。
|
|
462
|
-
*
|
|
463
|
-
* Usage:
|
|
464
|
-
*
|
|
465
|
-
* ```javascript
|
|
466
|
-
* import { invokeFn } from "mazey";
|
|
467
|
-
*
|
|
468
|
-
* const ret = invokeFn(() => {
|
|
469
|
-
* console.log("invokeFn");
|
|
470
|
-
* });
|
|
471
|
-
* ```
|
|
472
|
-
*
|
|
473
|
-
* @param {function} fn 等待被执行的未知是否有效的函数
|
|
474
|
-
* @category Util
|
|
475
|
-
*/
|
|
476
|
-
export declare function invokeFn(fn: MazeyFunction, ...params: Parameters<MazeyFunction>): ReturnType<MazeyFunction> | null;
|
|
477
|
-
/**
|
|
478
|
-
* Alias of `invokeFn`.
|
|
479
|
-
*
|
|
480
|
-
* @hidden
|
|
481
|
-
*/
|
|
482
|
-
export declare function doFn(fn: MazeyFunction, ...params: Parameters<MazeyFunction>): ReturnType<MazeyFunction> | null;
|
|
483
|
-
/**
|
|
484
|
-
* Verify the validity of a non-empty array.
|
|
485
|
-
*
|
|
486
|
-
* Usage:
|
|
487
|
-
*
|
|
488
|
-
* ```javascript
|
|
489
|
-
* import { isNonEmptyArray } from "mazey";
|
|
490
|
-
*
|
|
491
|
-
* const ret = isNonEmptyArray([1, 2, 3]);
|
|
492
|
-
* console.log(ret);
|
|
493
|
-
* ```
|
|
494
|
-
*
|
|
495
|
-
* Output:
|
|
496
|
-
*
|
|
497
|
-
* ```text
|
|
498
|
-
* true
|
|
499
|
-
* ```
|
|
500
|
-
*
|
|
501
|
-
* @category Util
|
|
502
|
-
*/
|
|
503
|
-
export declare function isNonEmptyArray<T>(arr: Array<T>): boolean;
|
|
504
|
-
/**
|
|
505
|
-
* Verify the validity of a pure object.
|
|
506
|
-
*
|
|
507
|
-
* Usage:
|
|
508
|
-
*
|
|
509
|
-
* ```javascript
|
|
510
|
-
* import { isPureObject } from "mazey";
|
|
511
|
-
*
|
|
512
|
-
* const ret1 = isPureObject({ a: 1 });
|
|
513
|
-
* const ret2 = isPureObject("abc");
|
|
514
|
-
* const ret3 = isPureObject(null);
|
|
515
|
-
* const ret4 = isPureObject([]);
|
|
516
|
-
*
|
|
517
|
-
* console.log(ret1, ret2, ret3, ret4);
|
|
518
|
-
* ```
|
|
519
|
-
*
|
|
520
|
-
* Output:
|
|
521
|
-
*
|
|
522
|
-
* ```text
|
|
523
|
-
* true false false false
|
|
524
|
-
* ```
|
|
525
|
-
*
|
|
526
|
-
* @param {MazeyObject} obj The object to verify.
|
|
527
|
-
* @returns {boolean} Return TRUE if the object is a pure object.
|
|
528
|
-
* @category Util
|
|
529
|
-
*/
|
|
530
|
-
export declare function isPureObject(obj: MazeyObject): boolean;
|
|
531
|
-
/**
|
|
532
|
-
* Verify the validity of a function.
|
|
533
|
-
*
|
|
534
|
-
* Usage:
|
|
535
|
-
*
|
|
536
|
-
* ```javascript
|
|
537
|
-
* import { isFunction } from "mazey";
|
|
538
|
-
*
|
|
539
|
-
* const ret1 = isFunction(() => {});
|
|
540
|
-
* const ret2 = isFunction("abc");
|
|
541
|
-
* const ret3 = isFunction(null);
|
|
542
|
-
* console.log(ret1, ret2, ret3);
|
|
543
|
-
* ```
|
|
544
|
-
*
|
|
545
|
-
* Output:
|
|
546
|
-
*
|
|
547
|
-
* ```text
|
|
548
|
-
* true false false
|
|
549
|
-
* ```
|
|
550
|
-
*
|
|
551
|
-
* @param {MazeyObject} fn The function to verify.
|
|
552
|
-
* @returns {boolean} Return TRUE if the object is a function.
|
|
553
|
-
* @category Util
|
|
554
|
-
*/
|
|
555
|
-
export declare function isFunction(fn: MazeyObject): boolean;
|
|
556
|
-
/**
|
|
557
|
-
* Verify the validity of a string.
|
|
558
|
-
*
|
|
559
|
-
* Usage:
|
|
560
|
-
*
|
|
561
|
-
* ```javascript
|
|
562
|
-
* import { isString } from "mazey";
|
|
563
|
-
*
|
|
564
|
-
* const ret1 = isString("abc");
|
|
565
|
-
* const ret2 = isString({ a: 1 });
|
|
566
|
-
* const ret3 = isString(null);
|
|
567
|
-
* console.log(ret1, ret2, ret3);
|
|
568
|
-
* ```
|
|
569
|
-
*
|
|
570
|
-
* Output:
|
|
571
|
-
*
|
|
572
|
-
* ```text
|
|
573
|
-
* true false false
|
|
574
|
-
* ```
|
|
575
|
-
*
|
|
576
|
-
* @param {MazeyObject} str The string to verify.
|
|
577
|
-
* @returns {boolean} Return TRUE if the object is a string.
|
|
578
|
-
* @category Util
|
|
579
|
-
*/
|
|
580
|
-
export declare function isString(str: MazeyObject): boolean;
|
|
581
|
-
/**
|
|
582
|
-
* Verify the validity of a boolean.
|
|
583
|
-
*
|
|
584
|
-
* Usage:
|
|
585
|
-
*
|
|
586
|
-
* ```javascript
|
|
587
|
-
* import { isBool } from "mazey";
|
|
588
|
-
*
|
|
589
|
-
* const ret1 = isBool(true);
|
|
590
|
-
* const ret2 = isBool({ a: 1 });
|
|
591
|
-
* const ret3 = isBool("abc");
|
|
592
|
-
* const ret4 = isBool(null);
|
|
593
|
-
* console.log(ret1, ret2, ret3, ret4);
|
|
594
|
-
* ```
|
|
595
|
-
*
|
|
596
|
-
* Output:
|
|
597
|
-
*
|
|
598
|
-
* ```text
|
|
599
|
-
* true false false false
|
|
600
|
-
* ```
|
|
601
|
-
*
|
|
602
|
-
* @param {MazeyObject} bool The boolean to verify.
|
|
603
|
-
* @returns {boolean} Return TRUE if the object is a boolean.
|
|
604
|
-
* @category Util
|
|
605
|
-
*/
|
|
606
|
-
export declare function isBool(bool: MazeyObject): boolean;
|
|
607
|
-
/**
|
|
608
|
-
* Alias of `isBool`.
|
|
609
|
-
*/
|
|
610
|
-
export declare function isBoolean(bool: MazeyObject): boolean;
|
|
611
|
-
/**
|
|
612
|
-
* Verify the validity of a value.
|
|
613
|
-
*
|
|
614
|
-
* Usage:
|
|
615
|
-
*
|
|
616
|
-
* ```javascript
|
|
617
|
-
* import { isUdfOrNul } from "mazey";
|
|
618
|
-
*
|
|
619
|
-
* const ret1 = isUdfOrNul(undefined);
|
|
620
|
-
* const ret2 = isUdfOrNul(null);
|
|
621
|
-
* const ret3 = isUdfOrNul("abc");
|
|
622
|
-
* console.log(ret1, ret2, ret3);
|
|
623
|
-
* ```
|
|
624
|
-
*
|
|
625
|
-
* Output:
|
|
626
|
-
*
|
|
627
|
-
* ```text
|
|
628
|
-
* true true false
|
|
629
|
-
* ```
|
|
630
|
-
*
|
|
631
|
-
* @param {MazeyObject} val The value to verify.
|
|
632
|
-
* @returns {boolean} Return TRUE if the object is undefined or null.
|
|
633
|
-
* @category Util
|
|
634
|
-
*/
|
|
635
|
-
export declare function isUdfOrNul(val: MazeyObject): boolean;
|
|
636
|
-
/**
|
|
637
|
-
* Verify the validity of an array.
|
|
638
|
-
*
|
|
639
|
-
* Usage:
|
|
640
|
-
*
|
|
641
|
-
* ```javascript
|
|
642
|
-
* import { isArray } from "mazey";
|
|
643
|
-
*
|
|
644
|
-
* const ret1 = isArray([1, 2, 3]);
|
|
645
|
-
* const ret2 = isArray({ a: 1 });
|
|
646
|
-
* const ret3 = isArray("abc");
|
|
647
|
-
* const ret4 = isArray(null);
|
|
648
|
-
* console.log(ret1, ret2, ret3, ret4);
|
|
649
|
-
* ```
|
|
650
|
-
*
|
|
651
|
-
* Output:
|
|
652
|
-
*
|
|
653
|
-
* ```text
|
|
654
|
-
* true false false false
|
|
655
|
-
* ```
|
|
656
|
-
*
|
|
657
|
-
* @param {MazeyObject} obj The object to verify.
|
|
658
|
-
* @returns {boolean} Return TRUE if the object is an array.
|
|
659
|
-
* @category Util
|
|
660
|
-
*/
|
|
661
|
-
export declare function isArray(obj: MazeyObject): boolean;
|
|
662
|
-
/**
|
|
663
|
-
* Verify the validity of a non-empty object.
|
|
664
|
-
*
|
|
665
|
-
* Usage:
|
|
666
|
-
*
|
|
667
|
-
* ```javascript
|
|
668
|
-
* import { isNonEmptyObject } from "mazey";
|
|
669
|
-
*
|
|
670
|
-
* const ret1 = isNonEmptyObject({ a: 1 });
|
|
671
|
-
* const ret2 = isNonEmptyObject({});
|
|
672
|
-
* const ret3 = isNonEmptyObject("abc");
|
|
673
|
-
* const ret4 = isNonEmptyObject(null);
|
|
674
|
-
* console.log(ret1, ret2, ret3, ret4);
|
|
675
|
-
* ```
|
|
676
|
-
*
|
|
677
|
-
* Output:
|
|
678
|
-
*
|
|
679
|
-
* ```text
|
|
680
|
-
* true false false false
|
|
681
|
-
* ```
|
|
682
|
-
*
|
|
683
|
-
* @param obj
|
|
684
|
-
* @returns
|
|
685
|
-
*/
|
|
686
|
-
export declare function isNonEmptyObject(obj: MazeyObject): boolean;
|
|
687
|
-
/**
|
|
688
|
-
* Convert newline characters `\n` into HTML line breaks `<br />`.
|
|
689
|
-
*
|
|
690
|
-
* Usage:
|
|
691
|
-
*
|
|
692
|
-
* ```javascript
|
|
693
|
-
* import { convertToHtmlBreaks } from "mazey";
|
|
694
|
-
*
|
|
695
|
-
* const ret1 = convertToHtmlBreaks("a\nb\nc");
|
|
696
|
-
* const ret2 = convertToHtmlBreaks("a\n\nbc");
|
|
697
|
-
* console.log(ret1);
|
|
698
|
-
* console.log(ret2);
|
|
699
|
-
* ```
|
|
700
|
-
*
|
|
701
|
-
* Output:
|
|
702
|
-
*
|
|
703
|
-
* ```text
|
|
704
|
-
* a<br />b<br />c
|
|
705
|
-
* a<br /><br />bc
|
|
706
|
-
* ```
|
|
707
|
-
*
|
|
708
|
-
* @param {string} str The string to make a new line.
|
|
709
|
-
* @returns {string} A newline with `br`.
|
|
710
|
-
* @category Util
|
|
711
|
-
*/
|
|
712
|
-
export declare function convertToHtmlBreaks(str: string): string;
|
|
713
|
-
/**
|
|
714
|
-
* Alias of `convertToHtmlBreaks`.
|
|
715
|
-
*
|
|
716
|
-
* @hidden
|
|
717
|
-
*/
|
|
718
|
-
export declare function newLine(str: string): string;
|
|
719
|
-
/**
|
|
720
|
-
* Remove HTML tags from a string, and optionally newline characters.
|
|
721
|
-
*
|
|
722
|
-
* Usage:
|
|
723
|
-
*
|
|
724
|
-
* ```javascript
|
|
725
|
-
* import { removeHTML } from "mazey";
|
|
726
|
-
*
|
|
727
|
-
* const ret = removeHTML("<div>hello world</div>");
|
|
728
|
-
* console.log(ret);
|
|
729
|
-
* ```
|
|
730
|
-
*
|
|
731
|
-
* Output:
|
|
732
|
-
*
|
|
733
|
-
* ```text
|
|
734
|
-
* hello world
|
|
735
|
-
* ```
|
|
736
|
-
*
|
|
737
|
-
* @param {string} str 带 HTML 标签的字符串
|
|
738
|
-
* @returns {string} 字符串
|
|
739
|
-
* @category Util
|
|
740
|
-
*/
|
|
741
|
-
export declare function removeHTML(str: string, options?: {
|
|
742
|
-
removeNewLine?: boolean;
|
|
743
|
-
}): string;
|
|
744
|
-
/**
|
|
745
|
-
* Alias of `removeHTML`.
|
|
746
|
-
*
|
|
747
|
-
* @hidden
|
|
748
|
-
*/
|
|
749
|
-
export declare function removeHtml(str: string, options?: {
|
|
750
|
-
removeNewLine?: boolean;
|
|
751
|
-
}): string;
|
|
752
|
-
/**
|
|
753
|
-
* Alias of `removeHTML`.
|
|
754
|
-
*
|
|
755
|
-
* @hidden
|
|
756
|
-
*/
|
|
757
|
-
export declare function clearHTML(str: string, options?: {
|
|
758
|
-
removeNewLine?: boolean;
|
|
759
|
-
}): string;
|
|
760
|
-
/**
|
|
761
|
-
* Alias of `removeHTML`.
|
|
762
|
-
*
|
|
763
|
-
* @hidden
|
|
764
|
-
*/
|
|
765
|
-
export declare function clearHtml(str: string, options?: {
|
|
766
|
-
removeNewLine?: boolean;
|
|
767
|
-
}): string;
|
|
768
|
-
/**
|
|
769
|
-
* Sanitizes user input to prevent XSS attacks.
|
|
770
|
-
*
|
|
771
|
-
* Usage:
|
|
772
|
-
*
|
|
773
|
-
* ```javascript
|
|
774
|
-
* import { sanitizeInput } from "mazey";
|
|
775
|
-
*
|
|
776
|
-
* const ret = sanitizeInput("<div>hello world</div>");
|
|
777
|
-
* console.log(ret);
|
|
778
|
-
* ```
|
|
779
|
-
*
|
|
780
|
-
* Output:
|
|
781
|
-
*
|
|
782
|
-
* ```text
|
|
783
|
-
* <div>hello world</div>
|
|
784
|
-
* ```
|
|
785
|
-
*
|
|
786
|
-
* @param input - The input string to sanitize
|
|
787
|
-
* @returns The sanitized input string
|
|
788
|
-
* @category Util
|
|
789
|
-
*/
|
|
790
|
-
export declare function sanitizeInput(input: string): string;
|
|
791
|
-
/**
|
|
792
|
-
* Reverses the sanitization done by the `sanitizeInput` function.
|
|
793
|
-
*
|
|
794
|
-
* Usage:
|
|
795
|
-
*
|
|
796
|
-
* ```javascript
|
|
797
|
-
* import { unsanitizeInput } from "mazey";
|
|
798
|
-
*
|
|
799
|
-
* const ret = unsanitizeInput("<div>hello world</div>");
|
|
800
|
-
* console.log(ret);
|
|
801
|
-
* ```
|
|
802
|
-
*
|
|
803
|
-
* Output:
|
|
804
|
-
*
|
|
805
|
-
* ```text
|
|
806
|
-
* <div>hello world</div>
|
|
807
|
-
* ```
|
|
808
|
-
*
|
|
809
|
-
* @param input - The input string to unsanitize
|
|
810
|
-
* @returns The unsanitized input string
|
|
811
|
-
* @category Util
|
|
812
|
-
*/
|
|
813
|
-
export declare function unsanitizeInput(input: string): string;
|
|
814
|
-
/**
|
|
815
|
-
* Alias of `unsanitizeInput`.
|
|
816
|
-
*
|
|
817
|
-
* @hidden
|
|
818
|
-
*/
|
|
819
|
-
export declare function unsanitize(str: string): string;
|
|
820
|
-
/**
|
|
821
|
-
* EN: Truncate string, Chinese characters count as 2 bytes.
|
|
822
|
-
*
|
|
823
|
-
* ZH: 截取字符串,中文算 2 个字节。
|
|
824
|
-
*
|
|
825
|
-
* Usage:
|
|
826
|
-
*
|
|
827
|
-
* ```javascript
|
|
828
|
-
* import { cutZHString } from "mazey";
|
|
829
|
-
*
|
|
830
|
-
* const ret = cutZHString("hello world", 5);
|
|
831
|
-
* console.log(ret);
|
|
832
|
-
* ```
|
|
833
|
-
*
|
|
834
|
-
* Output:
|
|
835
|
-
*
|
|
836
|
-
* ```text
|
|
837
|
-
* hello
|
|
838
|
-
* ```
|
|
839
|
-
*
|
|
840
|
-
* @param {string} str 要截取的字符串
|
|
841
|
-
* @param {number} len
|
|
842
|
-
* @param {boolean} options.hasDot
|
|
843
|
-
* @param {string} options.dotText
|
|
844
|
-
* @returns {string} 返回截取后的字符串
|
|
845
|
-
* @category Util
|
|
846
|
-
*/
|
|
847
|
-
export declare function cutZHString(str: string, len: number, options?: {
|
|
848
|
-
hasDot?: boolean;
|
|
849
|
-
dotText?: string;
|
|
850
|
-
}): string;
|
|
851
|
-
/**
|
|
852
|
-
* Alias of `cutZHString`.
|
|
853
|
-
*
|
|
854
|
-
* Usage:
|
|
855
|
-
*
|
|
856
|
-
* ```javascript
|
|
857
|
-
* import { truncateZHString } from "mazey";
|
|
858
|
-
*
|
|
859
|
-
* const ret = truncateZHString("hello world", 5);
|
|
860
|
-
* console.log(ret);
|
|
861
|
-
* ```
|
|
862
|
-
*
|
|
863
|
-
* Output:
|
|
864
|
-
*
|
|
865
|
-
* ```text
|
|
866
|
-
* hello
|
|
867
|
-
*
|
|
868
|
-
* @param {string} str 要截取的字符串
|
|
869
|
-
* @param {number} len
|
|
870
|
-
* @param {boolean} hasDot
|
|
871
|
-
* @returns {string} 返回截取后的字符串
|
|
872
|
-
* @hidden
|
|
873
|
-
*/
|
|
874
|
-
export declare function truncateZHString(str: string, len: number, hasDot?: boolean): string;
|
|
875
|
-
/**
|
|
876
|
-
* Alias of `truncateZHString`.
|
|
877
|
-
*
|
|
878
|
-
* @hidden
|
|
879
|
-
*/
|
|
880
|
-
export declare function cutCHSString(str: string, len: number, hasDot?: boolean): string;
|
|
881
|
-
/**
|
|
882
|
-
* Verify the validity of axios response.
|
|
883
|
-
*
|
|
884
|
-
* Reference: [Handling Errors](https://axios-http.com/docs/handling_errors)
|
|
885
|
-
*
|
|
886
|
-
* @category Util
|
|
887
|
-
* @hidden
|
|
888
|
-
*/
|
|
889
|
-
export declare function zAxiosIsValidRes(res: ZResResponse | undefined, options?: ZResIsValidResOptions): boolean;
|
|
890
|
-
/**
|
|
891
|
-
* Determine the validity of the data.
|
|
892
|
-
*
|
|
893
|
-
* Usage:
|
|
894
|
-
*
|
|
895
|
-
* ```javascript
|
|
896
|
-
* import { isValidData } from "mazey";
|
|
897
|
-
*
|
|
898
|
-
* const validData = {
|
|
899
|
-
* a: {
|
|
900
|
-
* b: {
|
|
901
|
-
* c: 413
|
|
902
|
-
* }
|
|
903
|
-
* }
|
|
904
|
-
* };
|
|
905
|
-
* const isValidDataResA = isValidData(validData, ["a", "b", "c"], 2333);
|
|
906
|
-
* const isValidDataResB = isValidData(validData, ["a", "b", "c"], 413);
|
|
907
|
-
* const isValidDataResC = isValidData(validData, ["d", "d"], 413);
|
|
908
|
-
* console.log("isValidDataResA:", isValidDataResA);
|
|
909
|
-
* console.log("isValidDataResB:", isValidDataResB);
|
|
910
|
-
* console.log("isValidDataResC:", isValidDataResC);
|
|
911
|
-
* ```
|
|
912
|
-
*
|
|
913
|
-
* Output:
|
|
914
|
-
*
|
|
915
|
-
* ```text
|
|
916
|
-
* isValidDataResA: false
|
|
917
|
-
* isValidDataResB: true
|
|
918
|
-
* isValidDataResC: false
|
|
919
|
-
* ```
|
|
920
|
-
*
|
|
921
|
-
* @param {any} data Original Data
|
|
922
|
-
* @param {string[]} attributes Data Attributes
|
|
923
|
-
* @param {any} validValue Given Value for verifying.
|
|
924
|
-
* @returns {boolean} Return TRUE if the data is valid.
|
|
925
|
-
* @category Util
|
|
926
|
-
*/
|
|
927
|
-
export declare function isValidData(data: MazeyObject, attributes: string[], validValue: SimpleType): boolean;
|
|
928
|
-
/**
|
|
929
|
-
* EN: Semantic file size, convert bytes into a readable file size.
|
|
930
|
-
*
|
|
931
|
-
* ZH: 语义化文件大小,把字节转换成正常文件大小。
|
|
932
|
-
*
|
|
933
|
-
* Usage:
|
|
934
|
-
*
|
|
935
|
-
* ```javascript
|
|
936
|
-
* import { getFileSize } from "mazey";
|
|
937
|
-
*
|
|
938
|
-
* const ret = getFileSize(1024);
|
|
939
|
-
* console.log(ret);
|
|
940
|
-
* ```
|
|
941
|
-
*
|
|
942
|
-
* Output:
|
|
943
|
-
*
|
|
944
|
-
* ```text
|
|
945
|
-
* 1 KB
|
|
946
|
-
* ```
|
|
947
|
-
*
|
|
948
|
-
* @category Util
|
|
949
|
-
*/
|
|
950
|
-
export declare function getFileSize(size: number): string;
|
|
951
|
-
/**
|
|
952
|
-
* Generate a Hash Code from a string.
|
|
953
|
-
*
|
|
954
|
-
* Usage:
|
|
955
|
-
*
|
|
956
|
-
* ```javascript
|
|
957
|
-
* import { genHashCode } from "mazey";
|
|
958
|
-
*
|
|
959
|
-
* const ret = genHashCode("hello world");
|
|
960
|
-
* console.log(ret);
|
|
961
|
-
* ```
|
|
962
|
-
*
|
|
963
|
-
* Output:
|
|
964
|
-
*
|
|
965
|
-
* ```text
|
|
966
|
-
* 1794106052
|
|
967
|
-
* ```
|
|
968
|
-
*
|
|
969
|
-
* Reference: [Generate a Hash from string in Javascript](https://stackoverflow.com/questions/7616461/generate-a-hash-from-string-in-javascript-jquery)
|
|
970
|
-
*
|
|
971
|
-
* @category Util
|
|
972
|
-
*/
|
|
973
|
-
export declare function genHashCode(str: string): number;
|
|
974
|
-
/**
|
|
975
|
-
* Return the formatted date string in the given format.
|
|
976
|
-
*
|
|
977
|
-
* Usage:
|
|
978
|
-
*
|
|
979
|
-
* ```javascript
|
|
980
|
-
* import { formatDate } from "mazey";
|
|
981
|
-
*
|
|
982
|
-
* const ret1 = formatDate();
|
|
983
|
-
* const ret2 = formatDate("Tue Jan 11 2022 14:12:26 GMT+0800 (China Standard Time)", "yyyy-MM-dd hh:mm:ss a");
|
|
984
|
-
* const ret3 = formatDate(1641881235000, "yyyy-MM-dd hh:mm:ss a");
|
|
985
|
-
* const ret4 = formatDate(new Date(2014, 1, 11), "MM/dd/yyyy");
|
|
986
|
-
* console.log("Default formatDate value:", ret1);
|
|
987
|
-
* console.log("String formatDate value:", ret2);
|
|
988
|
-
* console.log("Number formatDate value:", ret3);
|
|
989
|
-
* console.log("Date formatDate value:", ret4);
|
|
990
|
-
* ```
|
|
991
|
-
*
|
|
992
|
-
* Output:
|
|
993
|
-
*
|
|
994
|
-
* ```text
|
|
995
|
-
* Default formatDate value: 2023-01-11
|
|
996
|
-
* String formatDate value: 2022-01-11 02:12:26 PM
|
|
997
|
-
* Number formatDate value: 2022-01-11 02:07:15 PM
|
|
998
|
-
* Date formatDate value: 02/11/2014
|
|
999
|
-
* ```
|
|
1000
|
-
*
|
|
1001
|
-
* @param {MazeyDate} dateIns Original Date
|
|
1002
|
-
* @param {string} format Format String
|
|
1003
|
-
* @returns {string} Return the formatted date string.
|
|
1004
|
-
* @category Util
|
|
1005
|
-
*/
|
|
1006
|
-
export declare function formatDate(dateIns?: MazeyDate, format?: string): string;
|
|
1007
|
-
/**
|
|
1008
|
-
* Check if the given string is a mobile phone number.
|
|
1009
|
-
*
|
|
1010
|
-
* Usage:
|
|
1011
|
-
*
|
|
1012
|
-
* ```javascript
|
|
1013
|
-
* import { isMobile } from "mazey";
|
|
1014
|
-
*
|
|
1015
|
-
* const ret1 = isMobile("13800138000");
|
|
1016
|
-
* const ret2 = isMobile("1380013800");
|
|
1017
|
-
* const ret3 = isMobile("138001380000");
|
|
1018
|
-
* const ret4 = isMobile("1380013800a");
|
|
1019
|
-
* console.log(ret1, ret2, ret3, ret4);
|
|
1020
|
-
* ```
|
|
1021
|
-
*
|
|
1022
|
-
* Output:
|
|
1023
|
-
*
|
|
1024
|
-
* ```text
|
|
1025
|
-
* true false false false
|
|
1026
|
-
* ```
|
|
1027
|
-
*
|
|
1028
|
-
* @param mobile
|
|
1029
|
-
* @returns {boolean} Return true if the given string is a mobile phone number.
|
|
1030
|
-
* @category Util
|
|
1031
|
-
*/
|
|
1032
|
-
export declare function isValidPhoneNumber(mobile: string): boolean;
|
|
1033
|
-
/**
|
|
1034
|
-
* Check if the given string is a valid email.
|
|
1035
|
-
*
|
|
1036
|
-
* Usage:
|
|
1037
|
-
*
|
|
1038
|
-
* ```javascript
|
|
1039
|
-
* import { isValidEmail } from "mazey";
|
|
1040
|
-
*
|
|
1041
|
-
* const ret = isValidEmail("mazeyqian@gmail.com");
|
|
1042
|
-
* console.log(ret);
|
|
1043
|
-
* ```
|
|
1044
|
-
*
|
|
1045
|
-
* Output:
|
|
1046
|
-
*
|
|
1047
|
-
* ```text
|
|
1048
|
-
* true
|
|
1049
|
-
* ```
|
|
1050
|
-
*
|
|
1051
|
-
* @param email
|
|
1052
|
-
* @returns {boolean} Return true if the given string is a valid email.
|
|
1053
|
-
* @category Util
|
|
1054
|
-
*/
|
|
1055
|
-
export declare function isValidEmail(email: string): boolean;
|
|
1056
|
-
/**
|
|
1057
|
-
* Convert a given 10-hex number to a lowercase 26-hex string.
|
|
1058
|
-
*
|
|
1059
|
-
* Usage:
|
|
1060
|
-
*
|
|
1061
|
-
* ```javascript
|
|
1062
|
-
* import { convert10To26 } from "mazey";
|
|
1063
|
-
*
|
|
1064
|
-
* const ret1 = convert10To26(1);
|
|
1065
|
-
* const ret2 = convert10To26(26);
|
|
1066
|
-
* const ret3 = convert10To26(27);
|
|
1067
|
-
* const ret4 = convert10To26(52);
|
|
1068
|
-
* const ret5 = convert10To26(53);
|
|
1069
|
-
* console.log(ret1, ret2, ret3, ret4, ret5);
|
|
1070
|
-
* ```
|
|
1071
|
-
*
|
|
1072
|
-
* Output:
|
|
1073
|
-
*
|
|
1074
|
-
* ```text
|
|
1075
|
-
* a z aa az ba
|
|
1076
|
-
* ```
|
|
1077
|
-
*
|
|
1078
|
-
* @param {number} num
|
|
1079
|
-
* @returns {string} Return a lowercase 26-hex string.
|
|
1080
|
-
* @category Util
|
|
1081
|
-
*/
|
|
1082
|
-
export declare function convert10To26(num: number): string;
|
|
1083
|
-
/**
|
|
1084
|
-
* Get the current version.
|
|
1085
|
-
*
|
|
1086
|
-
* @hidden
|
|
1087
|
-
*/
|
|
1088
|
-
export declare function getCurrentVersion(): string;
|
|
1089
|
-
/**
|
|
1090
|
-
* Repeatedly fires a callback function with a certain interval until a specified condition is met.
|
|
1091
|
-
*
|
|
1092
|
-
* Usage:
|
|
1093
|
-
*
|
|
1094
|
-
* ```javascript
|
|
1095
|
-
* import { repeatUntilConditionMet } from "mazey";
|
|
1096
|
-
*
|
|
1097
|
-
* repeatUntilConditionMet(
|
|
1098
|
-
* () => {
|
|
1099
|
-
* console.log("repeatUntilConditionMet");
|
|
1100
|
-
* return true;
|
|
1101
|
-
* }, {
|
|
1102
|
-
* interval: 1000,
|
|
1103
|
-
* times: 10,
|
|
1104
|
-
* context: null,
|
|
1105
|
-
* args: [],
|
|
1106
|
-
* }, (result) => {
|
|
1107
|
-
* return result === true;
|
|
1108
|
-
* }
|
|
1109
|
-
* );
|
|
1110
|
-
* ```
|
|
1111
|
-
*
|
|
1112
|
-
* @param callback The callback function to fire.
|
|
1113
|
-
* @param options An object containing the options for the function.
|
|
1114
|
-
* @param options.interval The interval between each firing of the callback function, in milliseconds. Defaults to 1000.
|
|
1115
|
-
* @param options.times The maximum number of times to fire the callback function. Defaults to 10.
|
|
1116
|
-
* @param options.context The context to use when calling the callback function. Defaults to null.
|
|
1117
|
-
* @param options.args An array of arguments to pass to the callback function.
|
|
1118
|
-
* @param condition A function that takes the result of the callback function as its argument and returns a boolean value indicating whether the condition has been met. Defaults to a function that always returns true.
|
|
1119
|
-
* @category Util
|
|
1120
|
-
*/
|
|
1121
|
-
export declare function repeatUntilConditionMet<T extends (...args: MazeyFnParams) => MazeyFnReturn>(callback: T, options?: RepeatUntilOptions, condition?: (result: ReturnType<T>) => boolean): void;
|
|
1122
|
-
/**
|
|
1123
|
-
* Wait for a specified amount of time.
|
|
1124
|
-
*
|
|
1125
|
-
* Usage:
|
|
1126
|
-
*
|
|
1127
|
-
* ```javascript
|
|
1128
|
-
* import { waitTime } from "mazey";
|
|
1129
|
-
*
|
|
1130
|
-
* waitTime(1000).then((time) => {
|
|
1131
|
-
* console.log("waitTime:", time);
|
|
1132
|
-
* });
|
|
1133
|
-
* ```
|
|
1134
|
-
*
|
|
1135
|
-
* Output:
|
|
1136
|
-
*
|
|
1137
|
-
* ```text
|
|
1138
|
-
* waitTime: 1000
|
|
1139
|
-
* ```
|
|
1140
|
-
*
|
|
1141
|
-
* @param time The amount of time to wait, in milliseconds.
|
|
1142
|
-
* @returns A Promise that resolves after the specified time has elapsed.
|
|
1143
|
-
* @category Util
|
|
1144
|
-
*/
|
|
1145
|
-
export declare function waitTime(time: number): Promise<number>;
|
|
1146
|
-
/**
|
|
1147
|
-
* Alias of `waitTime`.
|
|
1148
|
-
*
|
|
1149
|
-
* @hidden
|
|
1150
|
-
*/
|
|
1151
|
-
export declare function sleep(time: number): Promise<number>;
|
|
1152
|
-
/**
|
|
1153
|
-
* Determine if it is a browser environment.
|
|
1154
|
-
*
|
|
1155
|
-
* Usage:
|
|
1156
|
-
*
|
|
1157
|
-
* ```javascript
|
|
1158
|
-
* import { isBrowser } from "mazey";
|
|
1159
|
-
*
|
|
1160
|
-
* const ret = isBrowser();
|
|
1161
|
-
* console.log(ret);
|
|
1162
|
-
* ```
|
|
1163
|
-
*
|
|
1164
|
-
* Output:
|
|
1165
|
-
*
|
|
1166
|
-
* ```text
|
|
1167
|
-
* true
|
|
1168
|
-
* ```
|
|
1169
|
-
*
|
|
1170
|
-
* @returns {boolean} true Yes
|
|
1171
|
-
* @category Browser Information
|
|
1172
|
-
*/
|
|
1173
|
-
export declare function isBrowser(): boolean;
|
|
1174
|
-
//# sourceMappingURL=util.d.ts.map
|