mazey 5.4.2 → 5.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.d.ts CHANGED
@@ -1,114 +1,3 @@
1
- /**
2
- * Compute the length of the longest common substring of two strings.
3
- *
4
- * Usage:
5
- *
6
- * ```javascript
7
- * import { longestComSubstring } from "mazey";
8
- *
9
- * const ret = longestComSubstring("fish", "finish");
10
- * console.log(ret);
11
- * ```
12
- *
13
- * Output:
14
- *
15
- * ```text
16
- * 3
17
- * ```
18
- *
19
- * @param {string} aStr String
20
- * @param {string} bStr String
21
- * @returns {number} Length
22
- * @category Calculate and Formula
23
- */
24
- declare function longestComSubstring(aStr: string, bStr: string): number;
25
- /**
26
- * Alias of `longestComSubstring`.
27
- *
28
- * @hidden
29
- */
30
- declare function calLongestCommonSubstring(aStr: string, bStr: string): number;
31
- /**
32
- * Compute the length of the longest common subsequence of two strings.
33
- *
34
- * Usage:
35
- *
36
- * ```javascript
37
- * import { longestComSubsequence } from "mazey";
38
- *
39
- * const ret = longestComSubsequence("fish", "finish");
40
- * console.log(ret);
41
- * ```
42
- *
43
- * Output:
44
- *
45
- * ```text
46
- * 4
47
- * ```
48
- *
49
- * @param {string} aStr The first string.
50
- * @param {string} bStr The second string.
51
- * @returns {number} The length of the longest common subsequence.
52
- * @category Calculate and Formula
53
- */
54
- declare function longestComSubsequence(aStr: string, bStr: string): number;
55
- /**
56
- * Alias of `longestComSubsequence`.
57
- *
58
- * @hidden
59
- */
60
- declare function calLongestCommonSubsequence(aStr: string, bStr: string): number;
61
- /**
62
- * Return whether a random value falls within the given probability.
63
- *
64
- * Usage:
65
- *
66
- * ```javascript
67
- * import { isHit } from "mazey";
68
- *
69
- * const ret = isHit(0.5); // A 50% chance of returning true.
70
- * console.log(ret);
71
- * ```
72
- *
73
- * Output:
74
- *
75
- * ```text
76
- * true
77
- * ```
78
- *
79
- * Example: Test the precision.
80
- *
81
- * ```javascript
82
- * let trueCount = 0;
83
- * let falseCount = 0;
84
- * new Array(1000000).fill(0).forEach(() => {
85
- * if (isHit(0.5)) {
86
- * trueCount++;
87
- * } else {
88
- * falseCount++;
89
- * }
90
- * });
91
- * console.log(trueCount, falseCount);
92
- * ```
93
- *
94
- * Output:
95
- *
96
- * ```text
97
- * 499994 500006
98
- * ```
99
- *
100
- * @param {number} rate Probability expressed as a value from 0 to 1.
101
- * @returns {boolean} Whether the random value is less than the probability.
102
- * @category Calculate and Formula
103
- */
104
- declare function isHit(rate: number): boolean;
105
- /**
106
- * Alias of `isHit`.
107
- *
108
- * @hidden
109
- */
110
- declare function inRate(rate: number): boolean;
111
-
112
1
  /**
113
2
  * @author Cheng
114
3
  */
@@ -206,1383 +95,1702 @@ interface OnURLChangeOptions {
206
95
  fireOnInit?: boolean;
207
96
  }
208
97
 
98
+ type InvestmentReturnRate = number | string;
209
99
  /**
210
- * Copy/Clone Object deeply.
100
+ * Calculate an investment's Compound Annual Growth Rate (CAGR).
211
101
  *
212
- * Custom class instances are copied as plain objects containing their own
213
- * properties. Unsupported native instances are preserved by reference.
102
+ * Numeric total returns use decimal ratios. For example, `0.202` represents
103
+ * `20.2%`. String total returns use percentage values, so `"20.2%"` and
104
+ * `"20.2"` both represent `20.2%`. A trailing percent sign is optional, and
105
+ * the complete trimmed string must be a finite JavaScript number. Scientific
106
+ * notation such as `"2.02e1%"` is accepted.
107
+ *
108
+ * The returned CAGR is a decimal ratio and is not rounded. The calculation
109
+ * uses:
110
+ *
111
+ * `CAGR = (1 + totalReturn)^(365 / durationInDays) - 1`
214
112
  *
215
113
  * Usage:
216
114
  *
217
- * ```javascript
218
- * import { deepCopy } from "mazey";
115
+ * ```typescript
116
+ * import {
117
+ * calculateCAGR,
118
+ * floatToPercent,
119
+ * } from "mazey";
219
120
  *
220
- * const ret1 = deepCopy(["a", "b", "c"]);
221
- * const ret2 = deepCopy("abc");
222
- * console.log(ret1);
223
- * console.log(ret2);
121
+ * const cagr = calculateCAGR(
122
+ * "2022-04-01",
123
+ * "2025-10-01",
124
+ * "20.2%"
125
+ * );
126
+ * const equivalentCagr = calculateCAGR(
127
+ * "2022-04-01",
128
+ * "2025-10-01",
129
+ * 0.202
130
+ * );
131
+ * const negativeCagr = calculateCAGR(
132
+ * "2022-04-01",
133
+ * "2025-10-01",
134
+ * "-15.5%"
135
+ * );
136
+ *
137
+ * console.log({
138
+ * cagr,
139
+ * equivalentCagr,
140
+ * negativeCagr,
141
+ * percentage: floatToPercent(cagr, 2),
142
+ * });
224
143
  * ```
225
144
  *
226
- * Output:
145
+ * Possible output:
227
146
  *
228
147
  * ```text
229
- * ["a", "b", "c"]
230
- * abc
148
+ * {
149
+ * cagr: 0.053908...,
150
+ * equivalentCagr: 0.053908...,
151
+ * negativeCagr: -0.046926...,
152
+ * percentage: "5.39%"
153
+ * }
231
154
  * ```
232
155
  *
233
- * @param {object} obj The value to clone.
234
- * @returns {object} Returns the deep cloned value.
235
- * @category Util
156
+ * @param startDate Start date as a supported structured string, millisecond timestamp, or `Date`.
157
+ * @param endDate End date in the same accepted forms. It must be strictly later than `startDate`.
158
+ * @param totalReturnRate Total period return. Numbers are decimal ratios; strings are percentage values.
159
+ * @returns The unrounded CAGR as a decimal ratio.
160
+ * @throws {TypeError} If either date or the total return is invalid.
161
+ * @throws {RangeError} If the dates are not increasing, the total return is at most `-1`, or the result is not finite.
162
+ * @remarks Duration uses the exact elapsed milliseconds, including time of day, converted to fractional days. A financial year is always fixed at 365 days. Input `Date` objects are copied and never mutated.
163
+ * @category Calculate and Formula
236
164
  */
237
- declare function deepCopy<T>(obj: T): T;
165
+ declare function calculateCAGR(startDate: MazeyDate, endDate: MazeyDate, totalReturnRate: InvestmentReturnRate): number;
238
166
  /**
239
- * Recursively freeze an object and its nested enumerable values.
240
- *
241
- * Primitive values and objects that are already frozen are returned unchanged.
167
+ * Compute the length of the longest common substring of two strings.
242
168
  *
243
169
  * Usage:
244
170
  *
245
171
  * ```javascript
246
- * import { deepFreeze } from "mazey";
247
- *
248
- * const config = deepFreeze({
249
- * api: {
250
- * timeout: 5000,
251
- * },
252
- * });
172
+ * import { longestComSubstring } from "mazey";
253
173
  *
254
- * console.log(Object.isFrozen(config));
255
- * console.log(Object.isFrozen(config.api));
174
+ * const ret = longestComSubstring("fish", "finish");
175
+ * console.log(ret);
256
176
  * ```
257
177
  *
258
178
  * Output:
259
179
  *
260
180
  * ```text
261
- * true
262
- * true
181
+ * 3
263
182
  * ```
264
183
  *
265
- * @param value The value to freeze.
266
- * @returns The original value with its nested enumerable values frozen.
267
- * @category Util
184
+ * @param {string} aStr String
185
+ * @param {string} bStr String
186
+ * @returns {number} Length
187
+ * @category Calculate and Formula
268
188
  */
269
- declare function deepFreeze<T>(value: T): T;
189
+ declare function longestComSubstring(aStr: string, bStr: string): number;
270
190
  /**
271
- * Alias of `deepCopy`.
191
+ * Alias of `longestComSubstring`.
272
192
  *
273
193
  * @hidden
274
194
  */
275
- declare function deepCopyObject<T>(obj: T): T;
195
+ declare function calLongestCommonSubstring(aStr: string, bStr: string): number;
276
196
  /**
277
- * Convert CamelCase to KebabCase.
197
+ * Compute the length of the longest common subsequence of two strings.
278
198
  *
279
199
  * Usage:
280
200
  *
281
201
  * ```javascript
282
- * import { convertCamelToKebab } from "mazey";
202
+ * import { longestComSubsequence } from "mazey";
283
203
  *
284
- * const ret1 = convertCamelToKebab("ABC");
285
- * const ret2 = convertCamelToKebab("aBC");
286
- * console.log(ret1);
287
- * console.log(ret2);
204
+ * const ret = longestComSubsequence("fish", "finish");
205
+ * console.log(ret);
288
206
  * ```
289
207
  *
290
208
  * Output:
291
209
  *
292
210
  * ```text
293
- * a-b-c
294
- * a-b-c
211
+ * 4
295
212
  * ```
296
213
  *
297
- * @param {string} camelCase "aBC" or "ABC"
298
- * @returns {string} "a-b-c"
299
- * @category Util
214
+ * @param {string} aStr The first string.
215
+ * @param {string} bStr The second string.
216
+ * @returns {number} The length of the longest common subsequence.
217
+ * @category Calculate and Formula
300
218
  */
301
- declare function convertCamelToKebab(camelCase: string): string;
219
+ declare function longestComSubsequence(aStr: string, bStr: string): number;
302
220
  /**
303
- * Convert KebabCase to CamelCase.
221
+ * Alias of `longestComSubsequence`.
222
+ *
223
+ * @hidden
224
+ */
225
+ declare function calLongestCommonSubsequence(aStr: string, bStr: string): number;
226
+ /**
227
+ * Return whether a random value falls within the given probability.
304
228
  *
305
229
  * Usage:
306
230
  *
307
231
  * ```javascript
308
- * import { convertKebabToCamel } from "mazey";
232
+ * import { isHit } from "mazey";
309
233
  *
310
- * const ret1 = convertKebabToCamel("a-b-c");
311
- * const ret2 = convertKebabToCamel("a-bb-cc");
312
- * console.log(ret1, ret2);
234
+ * const ret = isHit(0.5); // A 50% chance of returning true.
235
+ * console.log(ret);
313
236
  * ```
314
237
  *
315
238
  * Output:
316
239
  *
317
240
  * ```text
318
- * aBC aBbCc
241
+ * true
319
242
  * ```
320
243
  *
321
- * @param {string} kebabCase "a-bb-cc"
322
- * @returns {string} "aBbCc"
323
- * @category Util
244
+ * Example: Test the precision.
245
+ *
246
+ * ```javascript
247
+ * let trueCount = 0;
248
+ * let falseCount = 0;
249
+ * new Array(1000000).fill(0).forEach(() => {
250
+ * if (isHit(0.5)) {
251
+ * trueCount++;
252
+ * } else {
253
+ * falseCount++;
254
+ * }
255
+ * });
256
+ * console.log(trueCount, falseCount);
257
+ * ```
258
+ *
259
+ * Output:
260
+ *
261
+ * ```text
262
+ * 499994 500006
263
+ * ```
264
+ *
265
+ * @param {number} rate Probability expressed as a value from 0 to 1.
266
+ * @returns {boolean} Whether the random value is less than the probability.
267
+ * @category Calculate and Formula
324
268
  */
325
- declare function convertKebabToCamel(kebabCase: string): string;
269
+ declare function isHit(rate: number): boolean;
326
270
  /**
327
- * Alias of `convertCamelToKebab`.
271
+ * Alias of `isHit`.
328
272
  *
329
273
  * @hidden
330
274
  */
331
- declare function camelCaseToKebabCase(camelCase: string): string;
275
+ declare function inRate(rate: number): boolean;
276
+
332
277
  /**
333
- * Convert CamelCase to Underscore.
278
+ * Precision used by `formatLocalDateTime`.
279
+ *
280
+ * @category Util
281
+ */
282
+ type LocalDateTimePrecision = "minute" | "second" | "millisecond";
283
+ /**
284
+ * Parse an HTML `datetime-local` value into a local `Date`.
285
+ *
286
+ * Accepted normalized values use a year with at least four digits followed by
287
+ * `-MM-DDTHH:mm`, with optional seconds and 1-3 fractional-second digits.
288
+ * Components are validated strictly, so impossible dates and times return
289
+ * `null` instead of being normalized by `Date`.
334
290
  *
335
291
  * Usage:
336
292
  *
337
293
  * ```javascript
338
- * import { convertCamelToUnder } from "mazey";
294
+ * import { parseLocalDateTime } from "mazey";
339
295
  *
340
- * const ret1 = convertCamelToUnder("ABC");
341
- * const ret2 = convertCamelToUnder("aBC");
342
- * console.log(ret1);
343
- * console.log(ret2);
296
+ * const date = parseLocalDateTime("2026-07-21T14:30:45.123");
297
+ * console.log(date?.getFullYear());
298
+ * console.log(date?.getHours());
299
+ * console.log(date?.getMilliseconds());
344
300
  * ```
345
301
  *
346
302
  * Output:
347
303
  *
348
304
  * ```text
349
- * a_b_c
350
- * a_b_c
305
+ * 2026
306
+ * 14
307
+ * 123
351
308
  * ```
352
309
  *
353
- * @param {string} camelCase "aBC" or "ABC"
354
- * @returns {string} "a_b_c"
310
+ * @param value A normalized HTML `datetime-local` value without a timezone.
311
+ * @returns A local `Date`, or `null` when the value is malformed or represents an impossible local date and time.
312
+ * @remarks The value is interpreted using the runtime's local timezone. Timezone suffixes, surrounding whitespace, and date-only values are rejected.
355
313
  * @category Util
356
314
  */
357
- declare function convertCamelToUnder(camelCase: string): string;
315
+ declare function parseLocalDateTime(value: string): Date | null;
358
316
  /**
359
- * Convert Underscore to CamelCase.
317
+ * Format a `Date` as an HTML `datetime-local` value using local fields.
318
+ *
319
+ * | Precision | Output shape |
320
+ * | ------------- | ----------------------------- |
321
+ * | `minute` | `YYYY-MM-DDTHH:mm` |
322
+ * | `second` | `YYYY-MM-DDTHH:mm:ss` |
323
+ * | `millisecond` | `YYYY-MM-DDTHH:mm:ss.SSS` |
360
324
  *
361
325
  * Usage:
362
326
  *
363
327
  * ```javascript
364
- * import { convertUnderToCamel } from "mazey";
328
+ * import { formatLocalDateTime } from "mazey";
365
329
  *
366
- * const ret1 = convertUnderToCamel("a_b_c");
367
- * const ret2 = convertUnderToCamel("a_bb_cc");
368
- * console.log(ret1, ret2);
330
+ * const date = new Date(2026, 6, 21, 14, 30, 45, 123);
331
+ * const minutes = formatLocalDateTime(date);
332
+ * const seconds = formatLocalDateTime(date, { precision: "second" });
333
+ * const milliseconds = formatLocalDateTime(date, {
334
+ * precision: "millisecond",
335
+ * });
336
+ * console.log(minutes);
337
+ * console.log(seconds);
338
+ * console.log(milliseconds);
369
339
  * ```
370
340
  *
371
341
  * Output:
372
342
  *
373
343
  * ```text
374
- * aBC aBbCc
344
+ * 2026-07-21T14:30
345
+ * 2026-07-21T14:30:45
346
+ * 2026-07-21T14:30:45.123
375
347
  * ```
376
348
  *
377
- * @param {string} underCase "a_bb_cc"
378
- * @returns {string} "aBbCc"
349
+ * @param date A valid `Date` to format.
350
+ * @param options Formatting options. Precision defaults to `minute`.
351
+ * @returns A normalized HTML `datetime-local` value containing local calendar fields. The year is padded to at least four digits.
352
+ * @throws {TypeError} If `date` is not a `Date` or `precision` is unsupported.
353
+ * @throws {RangeError} If `date` is invalid or its local year is earlier than 1.
354
+ * @remarks This function does not call `toISOString()` and does not convert the value to UTC. It does not mutate the supplied `Date`.
379
355
  * @category Util
380
356
  */
381
- declare function convertUnderToCamel(underCase: string): string;
382
- /**
383
- * Alias of `convertCamelToUnder`.
384
- *
385
- * @hidden
386
- */
387
- declare function camelCase2Underscore(camelCase: string): string;
357
+ declare function formatLocalDateTime(date: Date, options?: {
358
+ precision?: LocalDateTimePrecision;
359
+ }): string;
388
360
  /**
389
- * Convert text to a deterministic uppercase ASCII JavaScript identifier.
390
- *
391
- * Characters outside `A-Z`, `a-z`, `0-9`, `_`, and `$` become `_`. A result
392
- * beginning with a digit is prefixed with `_`; an empty input therefore returns `_`.
361
+ * Get the current timestamp in milliseconds.
393
362
  *
394
363
  * Usage:
395
364
  *
396
365
  * ```javascript
397
- * import { toJavaScriptGlobalName } from "mazey";
366
+ * import { mNow } from "mazey";
398
367
  *
399
- * const globalName = toJavaScriptGlobalName("@scope/my-library");
400
- * console.log(globalName);
368
+ * const ret = mNow();
369
+ * console.log(ret);
401
370
  * ```
402
371
  *
403
372
  * Output:
404
373
  *
405
374
  * ```text
406
- * _SCOPE_MY_LIBRARY
375
+ * 1585325367122
407
376
  * ```
408
377
  *
409
- * @param value Text such as a package name or bundle filename.
410
- * @returns An uppercase identifier suitable for an IIFE global name.
411
- * @throws TypeError when `value` is not a string.
378
+ * @returns {number} The current timestamp in milliseconds.
412
379
  * @category Util
413
380
  */
414
- declare function toJavaScriptGlobalName(value: string): string;
381
+ declare function mNow(): number;
415
382
  /**
416
- * Remove leading and trailing whitespace or specified characters from string.
383
+ * Calculate the interval between two dates or timestamps.
417
384
  *
418
- * Note: This method is used to replace the native `String.prototype.trim()`. But it is not necessary to use it in modern browsers.
385
+ * The default `d` type returns the number of whole days. The `text` type
386
+ * returns an English duration using days, hours, minutes, and seconds while
387
+ * omitting zero-valued units. A zero interval returns `"0 seconds"`. Any other
388
+ * type returns the number of whole seconds. Negative intervals and invalid
389
+ * dates return an empty string.
419
390
  *
420
391
  * Usage:
421
392
  *
422
393
  * ```javascript
423
- * import { mTrim } from "mazey";
394
+ * import { getDateDifference } from "mazey";
424
395
  *
425
- * const ret1 = mTrim(" 1 2 3 ");
426
- * const ret2 = mTrim("abc ");
427
- * console.log(ret1);
428
- * console.log(ret2);
396
+ * const days = getDateDifference(0, 90061000);
397
+ * const text = getDateDifference(0, 90061000, { type: "text" });
398
+ * const compactText = getDateDifference(0, 90060000, { type: "text" });
399
+ * const dateStringDays = getDateDifference(
400
+ * "2020-03-28 00:09:27",
401
+ * "2023-04-18 10:54:00"
402
+ * );
403
+ * console.log(days);
404
+ * console.log(text);
405
+ * console.log(compactText);
406
+ * console.log(dateStringDays);
429
407
  * ```
430
408
  *
431
409
  * Output:
432
410
  *
433
411
  * ```text
434
- * 1 2 3
435
- * abc
412
+ * 1
413
+ * 1 day 1 hour 1 minute 1 second
414
+ * 1 day 1 hour 1 minute
415
+ * 1116
436
416
  * ```
437
417
  *
438
- * @param {string} str The string to trim.
439
- * @returns {string} Trimmed string.
418
+ * @param start Start date or timestamp.
419
+ * @param end End date or timestamp.
420
+ * @param options Formatting options. Use `d` for whole days or `text` for an English duration.
421
+ * @returns Whole days, whole seconds, an English duration, or an empty string for a negative or invalid interval.
422
+ * @remarks Strings in `YYYY-MM-DD HH:mm:ss` format are normalized and parsed as local time. Other date strings use the runtime's native `Date` parser; use timestamps or ISO strings with an explicit timezone when parsing must be portable.
440
423
  * @category Util
424
+ */
425
+ declare function getDateDifference(start?: number | string | Date, end?: number | string | Date, options?: {
426
+ type?: string;
427
+ }): number | string;
428
+ /**
429
+ * Alias of `getDateDifference`.
430
+ *
441
431
  * @hidden
442
432
  */
443
- declare function mTrim(str: string): string;
433
+ declare function getFriendlyInterval(start?: number | string | Date, end?: number | string | Date, options?: {
434
+ type?: string;
435
+ }): number | string;
444
436
  /**
445
- * Check whether it is a valid JSON string.
437
+ * Format a duration in milliseconds using its largest applicable English unit.
438
+ *
439
+ * Values are rounded to at most one decimal place. Negative durations are
440
+ * clamped to zero, and non-finite values return `"0 seconds"`.
446
441
  *
447
442
  * Usage:
448
443
  *
449
444
  * ```javascript
450
- * import { isJSONString } from "mazey";
451
- *
452
- * const ret1 = isJSONString(`['a', 'b', 'c']`);
453
- * const ret2 = isJSONString(`["a", "b", "c"]`);
454
- * console.log(ret1);
455
- * console.log(ret2);
456
- * ```
457
- *
458
- * Output:
445
+ * import { formatDurationFromMs } from "mazey";
459
446
  *
460
- * ```text
461
- * false
462
- * true
447
+ * formatDurationFromMs(500); // "0.5 seconds"
448
+ * formatDurationFromMs(90000); // "1.5 minutes"
449
+ * formatDurationFromMs(3600000); // "1 hour"
450
+ * formatDurationFromMs(129600000); // "1.5 days"
463
451
  * ```
464
452
  *
465
- * @param {string} str The string to check.
466
- * @returns {boolean} Return the result of checking.
453
+ * @param {number} durationMs Duration in milliseconds.
454
+ * @returns {string} Concise duration using seconds, minutes, hours, or days.
467
455
  * @category Util
468
456
  */
469
- declare function isJSONString(str: string): boolean;
457
+ declare function formatDurationFromMs(durationMs: number): string;
470
458
  /**
471
- * Alias of `isJSONString`.
459
+ * Check whether an unknown value represents a valid date.
472
460
  *
473
- * @hidden
474
- */
475
- declare function isJsonString(str: string): boolean;
476
- /**
477
- * Parse a JSON string and return a caller-defined fallback when parsing fails.
461
+ * Valid inputs include `Date` instances, finite millisecond timestamps,
462
+ * structured local date strings, and ISO 8601 strings with `Z` or a numeric
463
+ * timezone offset. Structured strings are parsed into numeric components and
464
+ * validated strictly, so invalid calendar dates are not normalized.
465
+ *
466
+ * Supported string forms are `YYYY-MM-DD`, `YYYY-MM-DD HH:mm[:ss]`,
467
+ * `YYYY-MM-DDTHH:mm[:ss]`, and the same `T`-separated date-time with `Z` or
468
+ * a `+HH:mm`/`-HH:mm` offset. Zoned strings may include 1-3 millisecond digits.
478
469
  *
479
470
  * Usage:
480
471
  *
481
472
  * ```javascript
482
- * import { parseJsonSafe } from "mazey";
473
+ * import { isValidDate } from "mazey";
483
474
  *
484
- * const data = parseJsonSafe('{"enabled":true}');
485
- * const fallback = parseJsonSafe("invalid", {});
475
+ * const ret1 = isValidDate(1577877720000);
476
+ * const ret2 = isValidDate("2020-01-01 11:22");
477
+ * const ret3 = isValidDate("2020-02-30");
478
+ * const ret4 = isValidDate(new Date("invalid"));
479
+ *
480
+ * console.log(ret1, ret2, ret3, ret4);
486
481
  * ```
487
482
  *
488
- * @param value JSON string to parse.
489
- * @param fallback Value returned when parsing fails. Defaults to `null`.
490
- * @returns The parsed JSON value or the supplied fallback.
483
+ * Output:
484
+ *
485
+ * ```text
486
+ * true true false false
487
+ * ```
488
+ *
489
+ * @param value A `Date`, millisecond timestamp, or supported structured date string.
490
+ * @returns Whether the value represents a valid date.
491
491
  * @category Util
492
492
  */
493
- declare function parseJsonSafe<T, F = null>(value: string, fallback?: F): T | F;
493
+ declare function isValidDate(value: unknown): boolean;
494
494
  /**
495
- * Generate a random string of number, `genRndNumString(7)` => "7658495".
495
+ * Check whether a date is today in the runtime's local timezone.
496
496
  *
497
497
  * Usage:
498
498
  *
499
499
  * ```javascript
500
- * import { genRndNumString } from "mazey";
500
+ * import { isToday } from "mazey";
501
501
  *
502
- * const ret1 = genRndNumString(4);
503
- * const ret2 = genRndNumString(7);
504
- * console.log(ret1);
505
- * console.log(ret2);
502
+ * const ret = isToday(new Date());
503
+ * console.log(ret);
506
504
  * ```
507
505
  *
508
506
  * Output:
509
507
  *
510
508
  * ```text
511
- * 9730
512
- * 2262490
509
+ * true
513
510
  * ```
514
511
  *
515
- * @param {number} n Length
516
- * @returns {string} Return the random string.
512
+ * @param date A `Date`, millisecond timestamp, or string accepted by `isValidDate`.
513
+ * @returns Whether the value has the current local year, month, and day. Invalid input returns `false`.
514
+ * @remarks Hours, minutes, seconds, and milliseconds are ignored. Results depend on the runtime's local timezone.
517
515
  * @category Util
518
516
  */
519
- declare function genRndNumString(n?: number): string;
520
- /**
521
- * Alias of `genRndNumString`.
522
- *
523
- * @hidden
524
- */
525
- declare function generateRndNum(n?: number): string;
517
+ declare function isToday(date: MazeyDate): boolean;
526
518
  /**
527
- * Generate a numeric identifier by combining the current timestamp with a
528
- * random numeric suffix.
519
+ * Check whether a date is in the current local calendar year.
529
520
  *
530
521
  * Usage:
531
522
  *
532
523
  * ```javascript
533
- * import { genUniqueNumString } from "mazey";
524
+ * import { isThisYear } from "mazey";
534
525
  *
535
- * const ret1 = genUniqueNumString();
536
- * const ret2 = genUniqueNumString(3);
537
- * console.log(ret1);
538
- * console.log(ret2);
526
+ * const ret = isThisYear(new Date());
527
+ * console.log(ret);
539
528
  * ```
540
529
  *
541
530
  * Output:
542
531
  *
543
532
  * ```text
544
- * 1538324722364123
545
- * 1538324722364123
533
+ * true
546
534
  * ```
547
535
  *
548
- * @param {number} n Length of the random numeric suffix.
549
- * @returns {string} A timestamp-based numeric identifier.
536
+ * @param date A `Date`, millisecond timestamp, or string accepted by `isValidDate`.
537
+ * @returns Whether the value has the current local year. Invalid input returns `false`.
538
+ * @remarks Results depend on the runtime's local timezone.
550
539
  * @category Util
551
540
  */
552
- declare function genUniqueNumString(n?: number): string;
553
- /**
554
- * Alias of `genUniqueNumString`.
555
- *
556
- * @hidden
557
- */
558
- declare function generateUniqueNum(n?: number): string;
541
+ declare function isThisYear(date: MazeyDate): boolean;
559
542
  /**
560
- * Get the current timestamp in milliseconds.
543
+ * Check whether a date is in the current local calendar month and year.
561
544
  *
562
545
  * Usage:
563
546
  *
564
547
  * ```javascript
565
- * import { mNow } from "mazey";
548
+ * import { isThisMonth } from "mazey";
566
549
  *
567
- * const ret = mNow();
550
+ * const ret = isThisMonth(new Date());
568
551
  * console.log(ret);
569
552
  * ```
570
553
  *
571
554
  * Output:
572
555
  *
573
556
  * ```text
574
- * 1585325367122
557
+ * true
575
558
  * ```
576
559
  *
577
- * @returns {number} The current timestamp in milliseconds.
560
+ * @param date A `Date`, millisecond timestamp, or string accepted by `isValidDate`.
561
+ * @returns Whether the value has the current local year and month. Invalid input returns `false`.
562
+ * @remarks Results depend on the runtime's local timezone.
578
563
  * @category Util
579
564
  */
580
- declare function mNow(): number;
565
+ declare function isThisMonth(date: MazeyDate): boolean;
581
566
  /**
582
- * Convert a floating-point ratio to a percentage string.
567
+ * Check whether a date is in the current Monday-first local calendar week.
583
568
  *
584
569
  * Usage:
585
570
  *
586
571
  * ```javascript
587
- * import { floatToPercent } from "mazey";
572
+ * import { isThisWeek } from "mazey";
588
573
  *
589
- * const ret1 = floatToPercent(0.2);
590
- * const ret2 = floatToPercent(0.2, 2);
591
- * console.log(ret1);
592
- * console.log(ret2);
574
+ * const ret = isThisWeek(new Date());
575
+ * console.log(ret);
593
576
  * ```
594
577
  *
595
578
  * Output:
596
579
  *
597
580
  * ```text
598
- * 20%
599
- * 20.00%
581
+ * true
600
582
  * ```
601
583
  *
602
- * @param {number} num Floating-point ratio to convert.
603
- * @param {number} fixSize Number of decimal places in the percentage.
604
- * @returns {string} The percentage string.
584
+ * @param date A `Date`, millisecond timestamp, or string accepted by `isValidDate`.
585
+ * @returns Whether the value is in the current local week. Invalid input returns `false`.
586
+ * @remarks The week begins on Monday and ends before the following Monday. Boundaries use local time and a half-open range.
605
587
  * @category Util
606
588
  */
607
- declare function floatToPercent(num: number, fixSize?: number): string;
589
+ declare function isThisWeek(date: MazeyDate): boolean;
608
590
  /**
609
- * Format a number with a fixed number of decimal places.
591
+ * Check whether a date is within the current local clock hour.
610
592
  *
611
593
  * Usage:
612
594
  *
613
595
  * ```javascript
614
- * import { floatFixed } from "mazey";
596
+ * import { isThisHour } from "mazey";
615
597
  *
616
- * const ret1 = floatFixed(0.2);
617
- * const ret2 = floatFixed(0.2, 2);
618
- * console.log(ret1);
619
- * console.log(ret2);
598
+ * const ret = isThisHour(new Date());
599
+ * console.log(ret);
620
600
  * ```
621
601
  *
622
602
  * Output:
623
603
  *
624
604
  * ```text
625
- * 0
626
- * 0.20
605
+ * true
627
606
  * ```
628
607
  *
629
- * @param num Number or numeric string to format.
630
- * @param size Number of decimal places.
631
- * @returns The fixed-point string.
608
+ * @param date A `Date`, millisecond timestamp, or string accepted by `isValidDate`.
609
+ * @returns Whether the value has the current local year, month, day, and hour. Invalid input returns `false`.
610
+ * @remarks Minutes, seconds, and milliseconds are ignored. Results depend on the runtime's local timezone.
632
611
  * @category Util
633
612
  */
634
- declare function floatFixed(num: number | string, size?: number): string;
613
+ declare function isThisHour(date: MazeyDate): boolean;
635
614
  /**
636
- * Limit how frequently a function can be invoked over time.
615
+ * Format the absolute distance from a date to now in concise English words.
637
616
  *
638
617
  * Usage:
639
618
  *
640
619
  * ```javascript
641
- * import { throttle } from "mazey";
620
+ * import { formatDistanceToNow } from "mazey";
642
621
  *
643
- * const foo = throttle(() => {
644
- * console.log("The function will be invoked at most once per every wait 1000 milliseconds.");
645
- * }, 1000, { leading: true });
622
+ * const ret = formatDistanceToNow(new Date(Date.now() - 60 * 60 * 1000));
623
+ * console.log(ret);
646
624
  * ```
647
625
  *
648
- * Reference: [Lodash](https://lodash.com/docs/4.17.15#throttle)
626
+ * Output:
649
627
  *
650
- * @param func Function to throttle.
651
- * @param wait Minimum interval between invocations, in milliseconds.
652
- * @param options.leading Whether to invoke on the leading edge.
653
- * @param options.trailing Whether to invoke on the trailing edge.
654
- * @returns The throttled function.
628
+ * ```text
629
+ * about 1 hour
630
+ * ```
631
+ *
632
+ * @param date A `Date`, millisecond timestamp, or string accepted by `isValidDate`.
633
+ * @returns The absolute approximate distance phrase, or an empty string for invalid input.
634
+ * @remarks Past and future dates use the same wording without `ago` or `in`. Months and years use fixed approximate durations of 30 and 365 days.
655
635
  * @category Util
656
636
  */
657
- declare function throttle<T extends (...args: MazeyFnParams) => MazeyFnReturn>(func: T, wait: number, options?: {
658
- leading?: boolean;
659
- trailing?: boolean;
660
- }): ThrottleFunc<T>;
637
+ declare function formatDistanceToNow(date: MazeyDate): string;
661
638
  /**
662
- * Delay function execution until the specified time has passed since the last
663
- * invocation.
639
+ * Return the formatted date string in the given format.
640
+ *
641
+ * Supported format tokens:
642
+ *
643
+ * | Token | Meaning | Range or example |
644
+ * | ------ | -------------------------------------- | ---------------- |
645
+ * | `yyyy` | Four-digit year | `2022` |
646
+ * | `MM` | Two-digit month | `01`–`12` |
647
+ * | `dd` | Two-digit day of the month | `01`–`31` |
648
+ * | `HH` | Two-digit hour using the 24-hour clock | `00`–`23` |
649
+ * | `hh` | Two-digit hour using the 12-hour clock | `01`–`12` |
650
+ * | `mm` | Two-digit minute | `00`–`59` |
651
+ * | `ss` | Two-digit second | `00`–`59` |
652
+ * | `a` | Uppercase meridiem indicator | `AM` or `PM` |
653
+ *
654
+ * The function creates a native `Date` and reads its local date and time
655
+ * fields. Timestamp output can therefore differ between runtime time zones.
664
656
  *
665
657
  * Usage:
666
658
  *
667
659
  * ```javascript
668
- * import { debounce } from "mazey";
660
+ * import { formatDate } from "mazey";
669
661
  *
670
- * const foo = debounce(() => {
671
- * console.log("The debounced function will only be invoked in 1000 milliseconds, the other invoking will disappear during the wait time.");
672
- * }, 1000, true);
662
+ * const ret1 = formatDate();
663
+ * const ret2 = formatDate("Tue Jan 11 2022 14:12:26 GMT+0800 (China Standard Time)", "yyyy-MM-dd hh:mm:ss a");
664
+ * const ret3 = formatDate(1641881235000, "yyyy-MM-dd hh:mm:ss a");
665
+ * const ret4 = formatDate(new Date(2014, 1, 11), "MM/dd/yyyy");
666
+ * console.log("Default formatDate value:", ret1);
667
+ * console.log("String formatDate value:", ret2);
668
+ * console.log("Number formatDate value:", ret3);
669
+ * console.log("Date formatDate value:", ret4);
673
670
  * ```
674
671
  *
675
- * @param func Function to debounce.
676
- * @param wait Delay after the last invocation, in milliseconds.
677
- * @param immediate Whether to invoke on the leading edge instead.
678
- * @returns The debounced function.
672
+ * Output:
673
+ *
674
+ * ```text
675
+ * Default formatDate value: 2023-01-11
676
+ * String formatDate value: 2022-01-11 02:12:26 PM
677
+ * Number formatDate value: 2022-01-11 02:07:15 PM
678
+ * Date formatDate value: 02/11/2014
679
+ * ```
680
+ *
681
+ * @param {MazeyDate} dateIns Original date value. Defaults to the current date and time.
682
+ * @param {string} format Format string composed of supported format tokens. Defaults to `yyyy-MM-dd`.
683
+ * @returns {string} The formatted date string.
684
+ * @throws {RangeError} If `dateIns` is not a valid date.
679
685
  * @category Util
680
686
  */
681
- declare function debounce<T extends (...args: MazeyFnParams) => MazeyFnReturn>(func: T, wait: number, immediate?: boolean): DebounceFunc<T>;
687
+ declare function formatDate(dateIns?: MazeyDate, format?: string): string;
682
688
  /**
683
- * Calculate the interval between two dates or timestamps.
689
+ * Generate a local-time Calendar Versioning string from a date.
684
690
  *
685
- * The default `d` type returns the number of whole days. The `text` type
686
- * returns an English duration using days, hours, minutes, and seconds while
687
- * omitting zero-valued units. A zero interval returns `"0 seconds"`. Any other
688
- * type returns the number of whole seconds. Negative intervals and invalid
689
- * dates return an empty string.
691
+ * The conceptual format is `yyyy.MMdd.HHmmss`. Leading zeroes are removed
692
+ * from each segment to keep numeric Semantic Versioning identifiers valid.
690
693
  *
691
694
  * Usage:
692
695
  *
693
696
  * ```javascript
694
- * import { getDateDifference } from "mazey";
697
+ * import { generateCalendarVersion } from "mazey";
695
698
  *
696
- * const days = getDateDifference(0, 90061000);
697
- * const text = getDateDifference(0, 90061000, { type: "text" });
698
- * const compactText = getDateDifference(0, 90060000, { type: "text" });
699
- * const dateStringDays = getDateDifference(
700
- * "2020-03-28 00:09:27",
701
- * "2023-04-18 10:54:00"
699
+ * const ret = generateCalendarVersion(new Date(2026, 6, 11, 7, 40, 35));
700
+ * console.log(ret);
701
+ * ```
702
+ *
703
+ * Output:
704
+ *
705
+ * ```text
706
+ * 2026.711.74035
707
+ * ```
708
+ *
709
+ * @param {MazeyDate} dateIns Original date. Defaults to the current date.
710
+ * @returns {string} Return the generated calendar version.
711
+ * @throws {RangeError} If `dateIns` is not a valid date.
712
+ * @category Util
713
+ */
714
+ declare function generateCalendarVersion(dateIns?: MazeyDate): string;
715
+
716
+ /**
717
+ * Copy/Clone Object deeply.
718
+ *
719
+ * Custom class instances are copied as plain objects containing their own
720
+ * properties. Unsupported native instances are preserved by reference.
721
+ *
722
+ * Usage:
723
+ *
724
+ * ```javascript
725
+ * import { deepCopy } from "mazey";
726
+ *
727
+ * const ret1 = deepCopy(["a", "b", "c"]);
728
+ * const ret2 = deepCopy("abc");
729
+ * console.log(ret1);
730
+ * console.log(ret2);
731
+ * ```
732
+ *
733
+ * Output:
734
+ *
735
+ * ```text
736
+ * ["a", "b", "c"]
737
+ * abc
738
+ * ```
739
+ *
740
+ * @param {object} obj The value to clone.
741
+ * @returns {object} Returns the deep cloned value.
742
+ * @category Util
743
+ */
744
+ declare function deepCopy<T>(obj: T): T;
745
+ /**
746
+ * Recursively freeze an object and its nested enumerable values.
747
+ *
748
+ * Primitive values and objects that are already frozen are returned unchanged.
749
+ *
750
+ * Usage:
751
+ *
752
+ * ```javascript
753
+ * import { deepFreeze } from "mazey";
754
+ *
755
+ * const config = deepFreeze({
756
+ * api: {
757
+ * timeout: 5000,
758
+ * },
759
+ * });
760
+ *
761
+ * console.log(Object.isFrozen(config));
762
+ * console.log(Object.isFrozen(config.api));
763
+ * ```
764
+ *
765
+ * Output:
766
+ *
767
+ * ```text
768
+ * true
769
+ * true
770
+ * ```
771
+ *
772
+ * @param value The value to freeze.
773
+ * @returns The original value with its nested enumerable values frozen.
774
+ * @category Util
775
+ */
776
+ declare function deepFreeze<T>(value: T): T;
777
+ /**
778
+ * Shallowly assign defined properties from one or more sources.
779
+ *
780
+ * The target is mutated. Only own enumerable string-keyed properties are
781
+ * considered, and `undefined` values are skipped. Other falsy values such as
782
+ * `null`, an empty string, `0`, and `false` are assigned.
783
+ *
784
+ * Usage:
785
+ *
786
+ * ```javascript
787
+ * import { assignDefined } from "mazey";
788
+ *
789
+ * const options = assignDefined(
790
+ * { retries: 3, verbose: true },
791
+ * { retries: undefined, verbose: false },
702
792
  * );
703
- * console.log(days);
704
- * console.log(text);
705
- * console.log(compactText);
706
- * console.log(dateStringDays);
793
+ *
794
+ * console.log(options);
707
795
  * ```
708
796
  *
709
797
  * Output:
710
798
  *
711
799
  * ```text
712
- * 1
713
- * 1 day 1 hour 1 minute 1 second
714
- * 1 day 1 hour 1 minute
715
- * 1116
800
+ * { retries: 3, verbose: false }
716
801
  * ```
717
802
  *
718
- * @param start Start date or timestamp.
719
- * @param end End date or timestamp.
720
- * @param options Formatting options. Use `d` for whole days or `text` for an English duration.
721
- * @returns Whole days, whole seconds, an English duration, or an empty string for a negative or invalid interval.
722
- * @remarks Strings in `YYYY-MM-DD HH:mm:ss` format are normalized and parsed as local time. Other date strings use the runtime's native `Date` parser; use timestamps or ISO strings with an explicit timezone when parsing must be portable.
803
+ * @param target The object to mutate.
804
+ * @param sources Sources applied from left to right.
805
+ * @returns The mutated target.
723
806
  * @category Util
724
807
  */
725
- declare function getDateDifference(start?: number | string | Date, end?: number | string | Date, options?: {
726
- type?: string;
727
- }): number | string;
808
+ declare function assignDefined<T extends object>(target: T, ...sources: ReadonlyArray<Partial<T> | undefined>): T;
728
809
  /**
729
- * Alias of `getDateDifference`.
810
+ * Alias of `deepCopy`.
730
811
  *
731
812
  * @hidden
732
813
  */
733
- declare function getFriendlyInterval(start?: number | string | Date, end?: number | string | Date, options?: {
734
- type?: string;
735
- }): number | string;
814
+ declare function deepCopyObject<T>(obj: T): T;
736
815
  /**
737
- * Format a duration in milliseconds using its largest applicable English unit.
816
+ * Convert CamelCase to KebabCase.
738
817
  *
739
- * Values are rounded to at most one decimal place. Negative durations are
740
- * clamped to zero, and non-finite values return `"0 seconds"`.
818
+ * Usage:
819
+ *
820
+ * ```javascript
821
+ * import { convertCamelToKebab } from "mazey";
822
+ *
823
+ * const ret1 = convertCamelToKebab("ABC");
824
+ * const ret2 = convertCamelToKebab("aBC");
825
+ * console.log(ret1);
826
+ * console.log(ret2);
827
+ * ```
828
+ *
829
+ * Output:
830
+ *
831
+ * ```text
832
+ * a-b-c
833
+ * a-b-c
834
+ * ```
835
+ *
836
+ * @param {string} camelCase "aBC" or "ABC"
837
+ * @returns {string} "a-b-c"
838
+ * @category Util
839
+ */
840
+ declare function convertCamelToKebab(camelCase: string): string;
841
+ /**
842
+ * Convert KebabCase to CamelCase.
741
843
  *
742
844
  * Usage:
743
845
  *
744
846
  * ```javascript
745
- * import { formatDurationFromMs } from "mazey";
847
+ * import { convertKebabToCamel } from "mazey";
746
848
  *
747
- * formatDurationFromMs(500); // "0.5 seconds"
748
- * formatDurationFromMs(90000); // "1.5 minutes"
749
- * formatDurationFromMs(3600000); // "1 hour"
750
- * formatDurationFromMs(129600000); // "1.5 days"
849
+ * const ret1 = convertKebabToCamel("a-b-c");
850
+ * const ret2 = convertKebabToCamel("a-bb-cc");
851
+ * console.log(ret1, ret2);
751
852
  * ```
752
853
  *
753
- * @param {number} durationMs Duration in milliseconds.
754
- * @returns {string} Concise duration using seconds, minutes, hours, or days.
854
+ * Output:
855
+ *
856
+ * ```text
857
+ * aBC aBbCc
858
+ * ```
859
+ *
860
+ * @param {string} kebabCase "a-bb-cc"
861
+ * @returns {string} "aBbCc"
755
862
  * @category Util
756
863
  */
757
- declare function formatDurationFromMs(durationMs: number): string;
864
+ declare function convertKebabToCamel(kebabCase: string): string;
758
865
  /**
759
- * Check whether a value is a number allowed by the supplied options.
866
+ * Alias of `convertCamelToKebab`.
867
+ *
868
+ * @hidden
869
+ */
870
+ declare function camelCaseToKebabCase(camelCase: string): string;
871
+ /**
872
+ * Convert CamelCase to Underscore.
760
873
  *
761
874
  * Usage:
762
875
  *
763
876
  * ```javascript
764
- * import { isNumber } from "mazey";
877
+ * import { convertCamelToUnder } from "mazey";
765
878
  *
766
- * const ret1 = isNumber(123);
767
- * const ret2 = isNumber("123");
768
- * // Default: NaN, Infinity is not Number
769
- * const ret3 = isNumber(Infinity);
770
- * const ret4 = isNumber(Infinity, { isInfinityAsNumber: true });
771
- * const ret5 = isNumber(NaN);
772
- * const ret6 = isNumber(NaN, { isNaNAsNumber: true, isInfinityAsNumber: true });
773
- * console.log(ret1, ret2, ret3, ret4, ret5, ret6);
879
+ * const ret1 = convertCamelToUnder("ABC");
880
+ * const ret2 = convertCamelToUnder("aBC");
881
+ * console.log(ret1);
882
+ * console.log(ret2);
774
883
  * ```
775
884
  *
776
885
  * Output:
777
886
  *
778
887
  * ```text
779
- * true false false true false true
888
+ * a_b_c
889
+ * a_b_c
780
890
  * ```
781
891
  *
782
- * @param {*} num Value to check.
783
- * @param options Controls whether `NaN`, `Infinity`, or other non-finite values count as numbers.
784
- * @returns {boolean} Whether the value is an allowed number.
892
+ * @param {string} camelCase "aBC" or "ABC"
893
+ * @returns {string} "a_b_c"
785
894
  * @category Util
786
895
  */
787
- declare function isNumber(num: unknown, options?: IsNumberOptions): boolean;
896
+ declare function convertCamelToUnder(camelCase: string): string;
788
897
  /**
789
- * Invoke a value only when it is a function.
898
+ * Convert Underscore to CamelCase.
790
899
  *
791
900
  * Usage:
792
901
  *
793
902
  * ```javascript
794
- * import { invokeFn } from "mazey";
903
+ * import { convertUnderToCamel } from "mazey";
795
904
  *
796
- * const ret = invokeFn(() => {
797
- * console.log("invokeFn");
798
- * });
905
+ * const ret1 = convertUnderToCamel("a_b_c");
906
+ * const ret2 = convertUnderToCamel("a_bb_cc");
907
+ * console.log(ret1, ret2);
799
908
  * ```
800
909
  *
801
- * @param {function} fn Potential function to invoke.
802
- * @param params Arguments passed to the function.
803
- * @returns The function result, or `null` when `fn` is not callable.
910
+ * Output:
911
+ *
912
+ * ```text
913
+ * aBC aBbCc
914
+ * ```
915
+ *
916
+ * @param {string} underCase "a_bb_cc"
917
+ * @returns {string} "aBbCc"
804
918
  * @category Util
805
919
  */
806
- declare function invokeFn(fn: MazeyFunction | null | undefined, ...params: Parameters<MazeyFunction>): ReturnType<MazeyFunction> | null;
920
+ declare function convertUnderToCamel(underCase: string): string;
807
921
  /**
808
- * Alias of `invokeFn`.
922
+ * Alias of `convertCamelToUnder`.
809
923
  *
810
924
  * @hidden
811
925
  */
812
- declare function doFn(fn: MazeyFunction | null | undefined, ...params: Parameters<MazeyFunction>): ReturnType<MazeyFunction> | null;
926
+ declare function camelCase2Underscore(camelCase: string): string;
813
927
  /**
814
- * Verify the validity of a non-empty array.
928
+ * Convert text to a deterministic uppercase ASCII JavaScript identifier.
929
+ *
930
+ * Characters outside `A-Z`, `a-z`, `0-9`, `_`, and `$` become `_`. A result
931
+ * beginning with a digit is prefixed with `_`; an empty input therefore returns `_`.
815
932
  *
816
933
  * Usage:
817
934
  *
818
935
  * ```javascript
819
- * import { isNonEmptyArray } from "mazey";
936
+ * import { toJavaScriptGlobalName } from "mazey";
820
937
  *
821
- * const ret = isNonEmptyArray([1, 2, 3]);
822
- * console.log(ret);
938
+ * const globalName = toJavaScriptGlobalName("@scope/my-library");
939
+ * console.log(globalName);
823
940
  * ```
824
941
  *
825
942
  * Output:
826
943
  *
827
944
  * ```text
828
- * true
945
+ * _SCOPE_MY_LIBRARY
829
946
  * ```
830
947
  *
948
+ * @param value Text such as a package name or bundle filename.
949
+ * @returns An uppercase identifier suitable for an IIFE global name.
950
+ * @throws TypeError when `value` is not a string.
831
951
  * @category Util
832
952
  */
833
- declare function isNonEmptyArray<T>(arr: Array<T>): boolean;
953
+ declare function toJavaScriptGlobalName(value: string): string;
834
954
  /**
835
- * Verify the validity of a pure object.
955
+ * Remove leading and trailing whitespace or specified characters from string.
956
+ *
957
+ * Note: This method is used to replace the native `String.prototype.trim()`. But it is not necessary to use it in modern browsers.
836
958
  *
837
959
  * Usage:
838
960
  *
839
961
  * ```javascript
840
- * import { isPureObject } from "mazey";
962
+ * import { mTrim } from "mazey";
841
963
  *
842
- * const ret1 = isPureObject({ a: 1 });
843
- * const ret2 = isPureObject("abc");
844
- * const ret3 = isPureObject(null);
845
- * const ret4 = isPureObject([]);
964
+ * const ret1 = mTrim(" 1 2 3 ");
965
+ * const ret2 = mTrim("abc ");
966
+ * console.log(ret1);
967
+ * console.log(ret2);
968
+ * ```
846
969
  *
847
- * console.log(ret1, ret2, ret3, ret4);
970
+ * Output:
971
+ *
972
+ * ```text
973
+ * 1 2 3
974
+ * abc
975
+ * ```
976
+ *
977
+ * @param {string} str The string to trim.
978
+ * @returns {string} Trimmed string.
979
+ * @category Util
980
+ * @hidden
981
+ */
982
+ declare function mTrim(str: string): string;
983
+ /**
984
+ * Check whether it is a valid JSON string.
985
+ *
986
+ * Usage:
987
+ *
988
+ * ```javascript
989
+ * import { isJSONString } from "mazey";
990
+ *
991
+ * const ret1 = isJSONString(`['a', 'b', 'c']`);
992
+ * const ret2 = isJSONString(`["a", "b", "c"]`);
993
+ * console.log(ret1);
994
+ * console.log(ret2);
848
995
  * ```
849
996
  *
850
997
  * Output:
851
998
  *
852
999
  * ```text
853
- * true false false false
1000
+ * false
1001
+ * true
854
1002
  * ```
855
1003
  *
856
- * @param {MazeyObject} obj The object to verify.
857
- * @returns {boolean} Return TRUE if the object is a pure object.
1004
+ * @param {string} str The string to check.
1005
+ * @returns {boolean} Return the result of checking.
858
1006
  * @category Util
859
1007
  */
860
- declare function isPureObject(obj: MazeyObject): boolean;
1008
+ declare function isJSONString(str: string): boolean;
861
1009
  /**
862
- * Verify the validity of a function.
1010
+ * Alias of `isJSONString`.
1011
+ *
1012
+ * @hidden
1013
+ */
1014
+ declare function isJsonString(str: string): boolean;
1015
+ /**
1016
+ * Parse a JSON string and return a caller-defined fallback when parsing fails.
863
1017
  *
864
1018
  * Usage:
865
1019
  *
866
1020
  * ```javascript
867
- * import { isFunction } from "mazey";
868
- *
869
- * const ret1 = isFunction(() => {});
870
- * const ret2 = isFunction("abc");
871
- * const ret3 = isFunction(null);
872
- * console.log(ret1, ret2, ret3);
873
- * ```
874
- *
875
- * Output:
1021
+ * import { parseJsonSafe } from "mazey";
876
1022
  *
877
- * ```text
878
- * true false false
1023
+ * const data = parseJsonSafe('{"enabled":true}');
1024
+ * const fallback = parseJsonSafe("invalid", {});
879
1025
  * ```
880
1026
  *
881
- * @param {MazeyObject} fn The function to verify.
882
- * @returns {boolean} Return TRUE if the object is a function.
1027
+ * @param value JSON string to parse.
1028
+ * @param fallback Value returned when parsing fails. Defaults to `null`.
1029
+ * @returns The parsed JSON value or the supplied fallback.
883
1030
  * @category Util
884
1031
  */
885
- declare function isFunction(fn: MazeyObject): boolean;
1032
+ declare function parseJsonSafe<T, F = null>(value: string, fallback?: F): T | F;
886
1033
  /**
887
- * Verify the validity of a string.
1034
+ * Generate a random string of number, `genRndNumString(7)` => "7658495".
888
1035
  *
889
1036
  * Usage:
890
1037
  *
891
1038
  * ```javascript
892
- * import { isString } from "mazey";
1039
+ * import { genRndNumString } from "mazey";
893
1040
  *
894
- * const ret1 = isString("abc");
895
- * const ret2 = isString({ a: 1 });
896
- * const ret3 = isString(null);
897
- * console.log(ret1, ret2, ret3);
1041
+ * const ret1 = genRndNumString(4);
1042
+ * const ret2 = genRndNumString(7);
1043
+ * console.log(ret1);
1044
+ * console.log(ret2);
898
1045
  * ```
899
1046
  *
900
1047
  * Output:
901
1048
  *
902
1049
  * ```text
903
- * true false false
1050
+ * 9730
1051
+ * 2262490
904
1052
  * ```
905
1053
  *
906
- * @param {MazeyObject} str The string to verify.
907
- * @returns {boolean} Return TRUE if the object is a string.
1054
+ * @param {number} n Length
1055
+ * @returns {string} Return the random string.
908
1056
  * @category Util
909
1057
  */
910
- declare function isString(str: MazeyObject): boolean;
1058
+ declare function genRndNumString(n?: number): string;
911
1059
  /**
912
- * Verify the validity of a boolean.
1060
+ * Alias of `genRndNumString`.
1061
+ *
1062
+ * @hidden
1063
+ */
1064
+ declare function generateRndNum(n?: number): string;
1065
+ /**
1066
+ * Generate a numeric identifier by combining the current timestamp with a
1067
+ * random numeric suffix.
913
1068
  *
914
1069
  * Usage:
915
1070
  *
916
1071
  * ```javascript
917
- * import { isBool } from "mazey";
1072
+ * import { genUniqueNumString } from "mazey";
918
1073
  *
919
- * const ret1 = isBool(true);
920
- * const ret2 = isBool({ a: 1 });
921
- * const ret3 = isBool("abc");
922
- * const ret4 = isBool(null);
923
- * console.log(ret1, ret2, ret3, ret4);
1074
+ * const ret1 = genUniqueNumString();
1075
+ * const ret2 = genUniqueNumString(3);
1076
+ * console.log(ret1);
1077
+ * console.log(ret2);
924
1078
  * ```
925
1079
  *
926
1080
  * Output:
927
1081
  *
928
1082
  * ```text
929
- * true false false false
1083
+ * 1538324722364123
1084
+ * 1538324722364123
930
1085
  * ```
931
1086
  *
932
- * @param {MazeyObject} bool The boolean to verify.
933
- * @returns {boolean} Return TRUE if the object is a boolean.
1087
+ * @param {number} n Length of the random numeric suffix.
1088
+ * @returns {string} A timestamp-based numeric identifier.
934
1089
  * @category Util
935
1090
  */
936
- declare function isBool(bool: MazeyObject): boolean;
1091
+ declare function genUniqueNumString(n?: number): string;
937
1092
  /**
938
- * Alias of `isBool`.
1093
+ * Alias of `genUniqueNumString`.
1094
+ *
1095
+ * @hidden
939
1096
  */
940
- declare function isBoolean(bool: MazeyObject): boolean;
1097
+ declare function generateUniqueNum(n?: number): string;
941
1098
  /**
942
- * Verify the validity of a value.
1099
+ * Convert a floating-point ratio to a percentage string.
943
1100
  *
944
1101
  * Usage:
945
1102
  *
946
1103
  * ```javascript
947
- * import { isUdfOrNul } from "mazey";
1104
+ * import { floatToPercent } from "mazey";
948
1105
  *
949
- * const ret1 = isUdfOrNul(undefined);
950
- * const ret2 = isUdfOrNul(null);
951
- * const ret3 = isUdfOrNul("abc");
952
- * console.log(ret1, ret2, ret3);
1106
+ * const ret1 = floatToPercent(0.2);
1107
+ * const ret2 = floatToPercent(0.2, 2);
1108
+ * console.log(ret1);
1109
+ * console.log(ret2);
953
1110
  * ```
954
1111
  *
955
1112
  * Output:
956
1113
  *
957
1114
  * ```text
958
- * true true false
1115
+ * 20%
1116
+ * 20.00%
959
1117
  * ```
960
1118
  *
961
- * @param {MazeyObject} val The value to verify.
962
- * @returns {boolean} Return TRUE if the object is undefined or null.
1119
+ * @param {number} num Floating-point ratio to convert.
1120
+ * @param {number} fixSize Number of decimal places in the percentage.
1121
+ * @returns {string} The percentage string.
963
1122
  * @category Util
964
1123
  */
965
- declare function isUdfOrNul(val: MazeyObject): boolean;
1124
+ declare function floatToPercent(num: number, fixSize?: number): string;
966
1125
  /**
967
- * Verify the validity of an array.
1126
+ * Format a number with a fixed number of decimal places.
968
1127
  *
969
1128
  * Usage:
970
1129
  *
971
1130
  * ```javascript
972
- * import { isArray } from "mazey";
1131
+ * import { floatFixed } from "mazey";
973
1132
  *
974
- * const ret1 = isArray([1, 2, 3]);
975
- * const ret2 = isArray({ a: 1 });
976
- * const ret3 = isArray("abc");
977
- * const ret4 = isArray(null);
978
- * console.log(ret1, ret2, ret3, ret4);
1133
+ * const ret1 = floatFixed(0.2);
1134
+ * const ret2 = floatFixed(0.2, 2);
1135
+ * console.log(ret1);
1136
+ * console.log(ret2);
979
1137
  * ```
980
1138
  *
981
1139
  * Output:
982
1140
  *
983
1141
  * ```text
984
- * true false false false
1142
+ * 0
1143
+ * 0.20
985
1144
  * ```
986
1145
  *
987
- * @param {MazeyObject} obj The object to verify.
988
- * @returns {boolean} Return TRUE if the object is an array.
1146
+ * @param num Number or numeric string to format.
1147
+ * @param size Number of decimal places.
1148
+ * @returns The fixed-point string.
989
1149
  * @category Util
990
1150
  */
991
- declare function isArray(obj: MazeyObject): boolean;
1151
+ declare function floatFixed(num: number | string, size?: number): string;
992
1152
  /**
993
- * Verify the validity of a non-empty object.
1153
+ * Limit how frequently a function can be invoked over time.
994
1154
  *
995
1155
  * Usage:
996
1156
  *
997
1157
  * ```javascript
998
- * import { isNonEmptyObject } from "mazey";
1158
+ * import { throttle } from "mazey";
999
1159
  *
1000
- * const ret1 = isNonEmptyObject({ a: 1 });
1001
- * const ret2 = isNonEmptyObject({});
1002
- * const ret3 = isNonEmptyObject("abc");
1003
- * const ret4 = isNonEmptyObject(null);
1004
- * console.log(ret1, ret2, ret3, ret4);
1160
+ * const foo = throttle(() => {
1161
+ * console.log("The function will be invoked at most once per every wait 1000 milliseconds.");
1162
+ * }, 1000, { leading: true });
1005
1163
  * ```
1006
1164
  *
1007
- * Output:
1008
- *
1009
- * ```text
1010
- * true false false false
1011
- * ```
1165
+ * Reference: [Lodash](https://lodash.com/docs/4.17.15#throttle)
1012
1166
  *
1013
- * @param obj
1014
- * @returns
1167
+ * @param func Function to throttle.
1168
+ * @param wait Minimum interval between invocations, in milliseconds.
1169
+ * @param options.leading Whether to invoke on the leading edge.
1170
+ * @param options.trailing Whether to invoke on the trailing edge.
1171
+ * @returns The throttled function.
1172
+ * @category Util
1015
1173
  */
1016
- declare function isNonEmptyObject(obj: MazeyObject): boolean;
1174
+ declare function throttle<T extends (...args: MazeyFnParams) => MazeyFnReturn>(func: T, wait: number, options?: {
1175
+ leading?: boolean;
1176
+ trailing?: boolean;
1177
+ }): ThrottleFunc<T>;
1017
1178
  /**
1018
- * Convert newline characters `\n` into HTML line breaks `<br />`.
1179
+ * Delay function execution until the specified time has passed since the last
1180
+ * invocation.
1019
1181
  *
1020
1182
  * Usage:
1021
1183
  *
1022
1184
  * ```javascript
1023
- * import { convertToHtmlBreaks } from "mazey";
1024
- *
1025
- * const ret1 = convertToHtmlBreaks("a\nb\nc");
1026
- * const ret2 = convertToHtmlBreaks("a\n\nbc");
1027
- * console.log(ret1);
1028
- * console.log(ret2);
1029
- * ```
1030
- *
1031
- * Output:
1185
+ * import { debounce } from "mazey";
1032
1186
  *
1033
- * ```text
1034
- * a<br />b<br />c
1035
- * a<br /><br />bc
1187
+ * const foo = debounce(() => {
1188
+ * console.log("The debounced function will only be invoked in 1000 milliseconds, the other invoking will disappear during the wait time.");
1189
+ * }, 1000, true);
1036
1190
  * ```
1037
1191
  *
1038
- * @param {string} str The string to make a new line.
1039
- * @returns {string} A newline with `br`.
1192
+ * @param func Function to debounce.
1193
+ * @param wait Delay after the last invocation, in milliseconds.
1194
+ * @param immediate Whether to invoke on the leading edge instead.
1195
+ * @returns The debounced function.
1040
1196
  * @category Util
1041
1197
  */
1042
- declare function convertToHtmlBreaks(str: string): string;
1043
- /**
1044
- * Alias of `convertToHtmlBreaks`.
1045
- *
1046
- * @hidden
1047
- */
1048
- declare function newLine(str: string): string;
1198
+ declare function debounce<T extends (...args: MazeyFnParams) => MazeyFnReturn>(func: T, wait: number, immediate?: boolean): DebounceFunc<T>;
1049
1199
  /**
1050
- * Remove HTML tags from a string, and optionally newline characters.
1200
+ * Check whether a value is a number allowed by the supplied options.
1051
1201
  *
1052
1202
  * Usage:
1053
1203
  *
1054
1204
  * ```javascript
1055
- * import { removeHTML } from "mazey";
1205
+ * import { isNumber } from "mazey";
1056
1206
  *
1057
- * const ret = removeHTML("<div>hello world</div>");
1058
- * console.log(ret);
1207
+ * const ret1 = isNumber(123);
1208
+ * const ret2 = isNumber("123");
1209
+ * // Default: NaN, Infinity is not Number
1210
+ * const ret3 = isNumber(Infinity);
1211
+ * const ret4 = isNumber(Infinity, { isInfinityAsNumber: true });
1212
+ * const ret5 = isNumber(NaN);
1213
+ * const ret6 = isNumber(NaN, { isNaNAsNumber: true, isInfinityAsNumber: true });
1214
+ * console.log(ret1, ret2, ret3, ret4, ret5, ret6);
1059
1215
  * ```
1060
1216
  *
1061
1217
  * Output:
1062
1218
  *
1063
1219
  * ```text
1064
- * hello world
1220
+ * true false false true false true
1065
1221
  * ```
1066
1222
  *
1067
- * @param {string} str A string that may contain HTML tags.
1068
- * @returns {string} The string with HTML tags removed.
1223
+ * @param {*} num Value to check.
1224
+ * @param options Controls whether `NaN`, `Infinity`, or other non-finite values count as numbers.
1225
+ * @returns {boolean} Whether the value is an allowed number.
1069
1226
  * @category Util
1070
1227
  */
1071
- declare function removeHTML(str: string, options?: {
1072
- removeNewLine?: boolean;
1073
- }): string;
1228
+ declare function isNumber(num: unknown, options?: IsNumberOptions): boolean;
1074
1229
  /**
1075
- * Alias of `removeHTML`.
1230
+ * Invoke a value only when it is a function.
1076
1231
  *
1077
- * @hidden
1078
- */
1079
- declare function removeHtml(str: string, options?: {
1080
- removeNewLine?: boolean;
1081
- }): string;
1082
- /**
1083
- * Alias of `removeHTML`.
1232
+ * Usage:
1084
1233
  *
1085
- * @hidden
1234
+ * ```javascript
1235
+ * import { invokeFn } from "mazey";
1236
+ *
1237
+ * const ret = invokeFn(() => {
1238
+ * console.log("invokeFn");
1239
+ * });
1240
+ * ```
1241
+ *
1242
+ * @param {function} fn Potential function to invoke.
1243
+ * @param params Arguments passed to the function.
1244
+ * @returns The function result, or `null` when `fn` is not callable.
1245
+ * @category Util
1086
1246
  */
1087
- declare function clearHTML(str: string, options?: {
1088
- removeNewLine?: boolean;
1089
- }): string;
1247
+ declare function invokeFn(fn: MazeyFunction | null | undefined, ...params: Parameters<MazeyFunction>): ReturnType<MazeyFunction> | null;
1090
1248
  /**
1091
- * Alias of `removeHTML`.
1249
+ * Alias of `invokeFn`.
1092
1250
  *
1093
1251
  * @hidden
1094
1252
  */
1095
- declare function clearHtml(str: string, options?: {
1096
- removeNewLine?: boolean;
1097
- }): string;
1253
+ declare function doFn(fn: MazeyFunction | null | undefined, ...params: Parameters<MazeyFunction>): ReturnType<MazeyFunction> | null;
1098
1254
  /**
1099
- * Sanitizes user input to prevent XSS attacks.
1255
+ * Verify the validity of a non-empty array.
1100
1256
  *
1101
1257
  * Usage:
1102
1258
  *
1103
1259
  * ```javascript
1104
- * import { sanitizeInput } from "mazey";
1260
+ * import { isNonEmptyArray } from "mazey";
1105
1261
  *
1106
- * const ret = sanitizeInput("<div>hello world</div>");
1262
+ * const ret = isNonEmptyArray([1, 2, 3]);
1107
1263
  * console.log(ret);
1108
1264
  * ```
1109
1265
  *
1110
1266
  * Output:
1111
1267
  *
1112
1268
  * ```text
1113
- * &lt;div&gt;hello world&lt;/div&gt;
1269
+ * true
1114
1270
  * ```
1115
1271
  *
1116
- * @param input - The input string to sanitize
1117
- * @returns The sanitized input string
1118
1272
  * @category Util
1119
1273
  */
1120
- declare function sanitizeInput(input: string): string;
1274
+ declare function isNonEmptyArray<T>(arr: Array<T>): boolean;
1121
1275
  /**
1122
- * Reverses the sanitization done by the `sanitizeInput` function.
1276
+ * Verify the validity of a pure object.
1123
1277
  *
1124
1278
  * Usage:
1125
1279
  *
1126
1280
  * ```javascript
1127
- * import { unsanitizeInput } from "mazey";
1281
+ * import { isPureObject } from "mazey";
1128
1282
  *
1129
- * const ret = unsanitizeInput("&lt;div&gt;hello world&lt;/div&gt;");
1130
- * console.log(ret);
1283
+ * const ret1 = isPureObject({ a: 1 });
1284
+ * const ret2 = isPureObject("abc");
1285
+ * const ret3 = isPureObject(null);
1286
+ * const ret4 = isPureObject([]);
1287
+ *
1288
+ * console.log(ret1, ret2, ret3, ret4);
1131
1289
  * ```
1132
1290
  *
1133
1291
  * Output:
1134
1292
  *
1135
1293
  * ```text
1136
- * <div>hello world</div>
1294
+ * true false false false
1137
1295
  * ```
1138
1296
  *
1139
- * @param input - The input string to unsanitize
1140
- * @returns The unsanitized input string
1297
+ * @param {MazeyObject} obj The object to verify.
1298
+ * @returns {boolean} Return TRUE if the object is a pure object.
1141
1299
  * @category Util
1142
1300
  */
1143
- declare function unsanitizeInput(input: string): string;
1144
- /**
1145
- * Alias of `unsanitizeInput`.
1146
- *
1147
- * @hidden
1148
- */
1149
- declare function unsanitize(str: string): string;
1301
+ declare function isPureObject(obj: MazeyObject): boolean;
1150
1302
  /**
1151
- * Truncate a string by weighted length, counting non-ASCII characters as two
1152
- * units.
1303
+ * Verify the validity of a function.
1153
1304
  *
1154
1305
  * Usage:
1155
1306
  *
1156
1307
  * ```javascript
1157
- * import { cutZHString } from "mazey";
1308
+ * import { isFunction } from "mazey";
1158
1309
  *
1159
- * const ret = cutZHString("hello world", 5);
1160
- * console.log(ret);
1310
+ * const ret1 = isFunction(() => {});
1311
+ * const ret2 = isFunction("abc");
1312
+ * const ret3 = isFunction(null);
1313
+ * console.log(ret1, ret2, ret3);
1161
1314
  * ```
1162
1315
  *
1163
1316
  * Output:
1164
1317
  *
1165
1318
  * ```text
1166
- * hello
1319
+ * true false false
1167
1320
  * ```
1168
1321
  *
1169
- * @param {string} str String to truncate.
1170
- * @param {number} len Maximum weighted length.
1171
- * @param {boolean} options.hasDot Whether to append truncation text.
1172
- * @param {string} options.dotText Text appended when truncation occurs.
1173
- * @returns {string} The truncated string.
1322
+ * @param {MazeyObject} fn The function to verify.
1323
+ * @returns {boolean} Return TRUE if the object is a function.
1174
1324
  * @category Util
1175
1325
  */
1176
- declare function cutZHString(str: string | null | undefined, len: number, options?: {
1177
- hasDot?: boolean;
1178
- dotText?: string;
1179
- }): string;
1326
+ declare function isFunction(fn: MazeyObject): boolean;
1180
1327
  /**
1181
- * Alias of `cutZHString`.
1328
+ * Verify the validity of a string.
1182
1329
  *
1183
1330
  * Usage:
1184
1331
  *
1185
1332
  * ```javascript
1186
- * import { truncateZHString } from "mazey";
1333
+ * import { isString } from "mazey";
1187
1334
  *
1188
- * const ret = truncateZHString("hello world", 5);
1189
- * console.log(ret);
1335
+ * const ret1 = isString("abc");
1336
+ * const ret2 = isString({ a: 1 });
1337
+ * const ret3 = isString(null);
1338
+ * console.log(ret1, ret2, ret3);
1190
1339
  * ```
1191
1340
  *
1192
1341
  * Output:
1193
1342
  *
1194
1343
  * ```text
1195
- * hello
1344
+ * true false false
1196
1345
  * ```
1197
1346
  *
1198
- * @param {string} str String to truncate.
1199
- * @param {number} len Maximum weighted length.
1200
- * @param {boolean} hasDot Whether to append the default truncation text.
1201
- * @returns {string} The truncated string.
1202
- * @hidden
1347
+ * @param {MazeyObject} str The string to verify.
1348
+ * @returns {boolean} Return TRUE if the object is a string.
1349
+ * @category Util
1203
1350
  */
1204
- declare function truncateZHString(str: string | null | undefined, len: number, hasDot?: boolean): string;
1351
+ declare function isString(str: MazeyObject): boolean;
1205
1352
  /**
1206
- * Alias of `truncateZHString`.
1353
+ * Verify the validity of a boolean.
1207
1354
  *
1208
- * @hidden
1209
- */
1210
- declare function cutCHSString(str: string | null | undefined, len: number, hasDot?: boolean): string;
1211
- /**
1212
- * Verify the validity of axios response.
1355
+ * Usage:
1213
1356
  *
1214
- * Reference: [Handling Errors](https://axios-http.com/docs/handling_errors)
1357
+ * ```javascript
1358
+ * import { isBool } from "mazey";
1359
+ *
1360
+ * const ret1 = isBool(true);
1361
+ * const ret2 = isBool({ a: 1 });
1362
+ * const ret3 = isBool("abc");
1363
+ * const ret4 = isBool(null);
1364
+ * console.log(ret1, ret2, ret3, ret4);
1365
+ * ```
1366
+ *
1367
+ * Output:
1368
+ *
1369
+ * ```text
1370
+ * true false false false
1371
+ * ```
1215
1372
  *
1373
+ * @param {MazeyObject} bool The boolean to verify.
1374
+ * @returns {boolean} Return TRUE if the object is a boolean.
1216
1375
  * @category Util
1217
- * @hidden
1218
1376
  */
1219
- declare function zAxiosIsValidRes(res: ZResResponse | undefined, options?: ZResIsValidResOptions | null): boolean;
1377
+ declare function isBool(bool: MazeyObject): boolean;
1220
1378
  /**
1221
- * Determine the validity of the data.
1379
+ * Alias of `isBool`.
1380
+ */
1381
+ declare function isBoolean(bool: MazeyObject): boolean;
1382
+ /**
1383
+ * Verify the validity of a value.
1222
1384
  *
1223
1385
  * Usage:
1224
1386
  *
1225
1387
  * ```javascript
1226
- * import { isValidData } from "mazey";
1388
+ * import { isUdfOrNul } from "mazey";
1227
1389
  *
1228
- * const validData = {
1229
- * a: {
1230
- * b: {
1231
- * c: 413
1232
- * }
1233
- * }
1234
- * };
1235
- * const isValidDataResA = isValidData(validData, ["a", "b", "c"], 2333);
1236
- * const isValidDataResB = isValidData(validData, ["a", "b", "c"], 413);
1237
- * const isValidDataResC = isValidData(validData, ["d", "d"], 413);
1238
- * console.log("isValidDataResA:", isValidDataResA);
1239
- * console.log("isValidDataResB:", isValidDataResB);
1240
- * console.log("isValidDataResC:", isValidDataResC);
1390
+ * const ret1 = isUdfOrNul(undefined);
1391
+ * const ret2 = isUdfOrNul(null);
1392
+ * const ret3 = isUdfOrNul("abc");
1393
+ * console.log(ret1, ret2, ret3);
1241
1394
  * ```
1242
1395
  *
1243
1396
  * Output:
1244
1397
  *
1245
1398
  * ```text
1246
- * isValidDataResA: false
1247
- * isValidDataResB: true
1248
- * isValidDataResC: false
1399
+ * true true false
1249
1400
  * ```
1250
1401
  *
1251
- * @param {any} data Original Data
1252
- * @param {string[]} attributes Data Attributes
1253
- * @param {any} validValue Given Value for verifying.
1254
- * @returns {boolean} Return TRUE if the data is valid.
1402
+ * @param {MazeyObject} val The value to verify.
1403
+ * @returns {boolean} Return TRUE if the object is undefined or null.
1255
1404
  * @category Util
1256
1405
  */
1257
- declare function isValidData(data: MazeyObject, attributes: string[], validValue: SimpleType): boolean;
1406
+ declare function isUdfOrNul(val: MazeyObject): boolean;
1258
1407
  /**
1259
- * Convert a byte count to a human-readable file size.
1408
+ * Verify the validity of an array.
1260
1409
  *
1261
1410
  * Usage:
1262
1411
  *
1263
1412
  * ```javascript
1264
- * import { getFileSize } from "mazey";
1413
+ * import { isArray } from "mazey";
1265
1414
  *
1266
- * const ret = getFileSize(1024);
1267
- * console.log(ret);
1415
+ * const ret1 = isArray([1, 2, 3]);
1416
+ * const ret2 = isArray({ a: 1 });
1417
+ * const ret3 = isArray("abc");
1418
+ * const ret4 = isArray(null);
1419
+ * console.log(ret1, ret2, ret3, ret4);
1268
1420
  * ```
1269
1421
  *
1270
1422
  * Output:
1271
1423
  *
1272
1424
  * ```text
1273
- * 1 KB
1425
+ * true false false false
1274
1426
  * ```
1275
1427
  *
1276
- * @param size File size in bytes.
1277
- * @returns A rounded file-size string, or an empty string for a non-positive or non-finite value.
1428
+ * @param {MazeyObject} obj The object to verify.
1429
+ * @returns {boolean} Return TRUE if the object is an array.
1278
1430
  * @category Util
1279
1431
  */
1280
- declare function getFileSize(size: number): string;
1432
+ declare function isArray(obj: MazeyObject): boolean;
1281
1433
  /**
1282
- * Generate a Hash Code from a string.
1434
+ * Verify the validity of a non-empty object.
1283
1435
  *
1284
1436
  * Usage:
1285
1437
  *
1286
1438
  * ```javascript
1287
- * import { genHashCode } from "mazey";
1439
+ * import { isNonEmptyObject } from "mazey";
1288
1440
  *
1289
- * const ret = genHashCode("hello world");
1290
- * console.log(ret);
1441
+ * const ret1 = isNonEmptyObject({ a: 1 });
1442
+ * const ret2 = isNonEmptyObject({});
1443
+ * const ret3 = isNonEmptyObject("abc");
1444
+ * const ret4 = isNonEmptyObject(null);
1445
+ * console.log(ret1, ret2, ret3, ret4);
1291
1446
  * ```
1292
1447
  *
1293
1448
  * Output:
1294
1449
  *
1295
1450
  * ```text
1296
- * 1794106052
1451
+ * true false false false
1297
1452
  * ```
1298
1453
  *
1299
- * Reference: [Generate a Hash from string in Javascript](https://stackoverflow.com/questions/7616461/generate-a-hash-from-string-in-javascript-jquery)
1300
- *
1301
- * @category Util
1454
+ * @param obj
1455
+ * @returns
1302
1456
  */
1303
- declare function genHashCode(str: string): number;
1457
+ declare function isNonEmptyObject(obj: MazeyObject): boolean;
1304
1458
  /**
1305
- * Generate a lowercase SHA-256 hexadecimal digest with the Web Crypto API.
1459
+ * Convert newline characters `\n` into HTML line breaks `<br />`.
1306
1460
  *
1307
1461
  * Usage:
1308
1462
  *
1309
1463
  * ```javascript
1310
- * import { sha256Hex } from "mazey";
1464
+ * import { convertToHtmlBreaks } from "mazey";
1311
1465
  *
1312
- * const digest = await sha256Hex("hello world");
1313
- * console.log(digest);
1466
+ * const ret1 = convertToHtmlBreaks("a\nb\nc");
1467
+ * const ret2 = convertToHtmlBreaks("a\n\nbc");
1468
+ * console.log(ret1);
1469
+ * console.log(ret2);
1314
1470
  * ```
1315
1471
  *
1316
1472
  * Output:
1317
1473
  *
1318
1474
  * ```text
1319
- * b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9
1475
+ * a<br />b<br />c
1476
+ * a<br /><br />bc
1320
1477
  * ```
1321
1478
  *
1322
- * @remarks Requires Web Crypto. String input also requires `TextEncoder`.
1323
- * @param input Text or binary data to hash.
1324
- * @returns A promise that resolves to the lowercase hexadecimal digest.
1325
- * @throws When the required platform API is unavailable. Digest failures are propagated.
1479
+ * @param {string} str The string to make a new line.
1480
+ * @returns {string} A newline with `br`.
1326
1481
  * @category Util
1327
1482
  */
1328
- declare function sha256Hex(input: string | BufferSource): Promise<string>;
1483
+ declare function convertToHtmlBreaks(str: string): string;
1329
1484
  /**
1330
- * Check whether an unknown value represents a valid date.
1331
- *
1332
- * Valid inputs include `Date` instances, finite millisecond timestamps,
1333
- * structured local date strings, and ISO 8601 strings with `Z` or a numeric
1334
- * timezone offset. Structured strings are parsed into numeric components and
1335
- * validated strictly, so invalid calendar dates are not normalized.
1485
+ * Alias of `convertToHtmlBreaks`.
1336
1486
  *
1337
- * Supported string forms are `YYYY-MM-DD`, `YYYY-MM-DD HH:mm[:ss]`,
1338
- * `YYYY-MM-DDTHH:mm[:ss]`, and the same `T`-separated date-time with `Z` or
1339
- * a `+HH:mm`/`-HH:mm` offset. Zoned strings may include 1-3 millisecond digits.
1487
+ * @hidden
1488
+ */
1489
+ declare function newLine(str: string): string;
1490
+ /**
1491
+ * Remove HTML tags from a string, and optionally newline characters.
1340
1492
  *
1341
1493
  * Usage:
1342
1494
  *
1343
1495
  * ```javascript
1344
- * import { isValidDate } from "mazey";
1345
- *
1346
- * const ret1 = isValidDate(1577877720000);
1347
- * const ret2 = isValidDate("2020-01-01 11:22");
1348
- * const ret3 = isValidDate("2020-02-30");
1349
- * const ret4 = isValidDate(new Date("invalid"));
1496
+ * import { removeHTML } from "mazey";
1350
1497
  *
1351
- * console.log(ret1, ret2, ret3, ret4);
1498
+ * const ret = removeHTML("<div>hello world</div>");
1499
+ * console.log(ret);
1352
1500
  * ```
1353
1501
  *
1354
1502
  * Output:
1355
1503
  *
1356
1504
  * ```text
1357
- * true true false false
1505
+ * hello world
1358
1506
  * ```
1359
1507
  *
1360
- * @param value A `Date`, millisecond timestamp, or supported structured date string.
1361
- * @returns Whether the value represents a valid date.
1362
- * @category Util
1508
+ * @param {string} str A string that may contain HTML tags.
1509
+ * @returns {string} The string with HTML tags removed.
1510
+ * @category Util
1511
+ */
1512
+ declare function removeHTML(str: string, options?: {
1513
+ removeNewLine?: boolean;
1514
+ }): string;
1515
+ /**
1516
+ * Alias of `removeHTML`.
1517
+ *
1518
+ * @hidden
1519
+ */
1520
+ declare function removeHtml(str: string, options?: {
1521
+ removeNewLine?: boolean;
1522
+ }): string;
1523
+ /**
1524
+ * Alias of `removeHTML`.
1525
+ *
1526
+ * @hidden
1527
+ */
1528
+ declare function clearHTML(str: string, options?: {
1529
+ removeNewLine?: boolean;
1530
+ }): string;
1531
+ /**
1532
+ * Alias of `removeHTML`.
1533
+ *
1534
+ * @hidden
1363
1535
  */
1364
- declare function isValidDate(value: unknown): boolean;
1536
+ declare function clearHtml(str: string, options?: {
1537
+ removeNewLine?: boolean;
1538
+ }): string;
1365
1539
  /**
1366
- * Check whether a date is today in the runtime's local timezone.
1540
+ * Sanitizes user input to prevent XSS attacks.
1367
1541
  *
1368
1542
  * Usage:
1369
1543
  *
1370
1544
  * ```javascript
1371
- * import { isToday } from "mazey";
1545
+ * import { sanitizeInput } from "mazey";
1372
1546
  *
1373
- * const ret = isToday(new Date());
1547
+ * const ret = sanitizeInput("<div>hello world</div>");
1374
1548
  * console.log(ret);
1375
1549
  * ```
1376
1550
  *
1377
1551
  * Output:
1378
1552
  *
1379
1553
  * ```text
1380
- * true
1554
+ * &lt;div&gt;hello world&lt;/div&gt;
1381
1555
  * ```
1382
1556
  *
1383
- * @param date A `Date`, millisecond timestamp, or string accepted by `isValidDate`.
1384
- * @returns Whether the value has the current local year, month, and day. Invalid input returns `false`.
1385
- * @remarks Hours, minutes, seconds, and milliseconds are ignored. Results depend on the runtime's local timezone.
1557
+ * @param input - The input string to sanitize
1558
+ * @returns The sanitized input string
1386
1559
  * @category Util
1387
1560
  */
1388
- declare function isToday(date: MazeyDate): boolean;
1561
+ declare function sanitizeInput(input: string): string;
1389
1562
  /**
1390
- * Check whether a date is in the current local calendar year.
1563
+ * Reverses the sanitization done by the `sanitizeInput` function.
1391
1564
  *
1392
1565
  * Usage:
1393
1566
  *
1394
1567
  * ```javascript
1395
- * import { isThisYear } from "mazey";
1568
+ * import { unsanitizeInput } from "mazey";
1396
1569
  *
1397
- * const ret = isThisYear(new Date());
1570
+ * const ret = unsanitizeInput("&lt;div&gt;hello world&lt;/div&gt;");
1398
1571
  * console.log(ret);
1399
1572
  * ```
1400
1573
  *
1401
1574
  * Output:
1402
1575
  *
1403
1576
  * ```text
1404
- * true
1577
+ * <div>hello world</div>
1405
1578
  * ```
1406
1579
  *
1407
- * @param date A `Date`, millisecond timestamp, or string accepted by `isValidDate`.
1408
- * @returns Whether the value has the current local year. Invalid input returns `false`.
1409
- * @remarks Results depend on the runtime's local timezone.
1580
+ * @param input - The input string to unsanitize
1581
+ * @returns The unsanitized input string
1410
1582
  * @category Util
1411
1583
  */
1412
- declare function isThisYear(date: MazeyDate): boolean;
1584
+ declare function unsanitizeInput(input: string): string;
1413
1585
  /**
1414
- * Check whether a date is in the current local calendar month and year.
1586
+ * Alias of `unsanitizeInput`.
1587
+ *
1588
+ * @hidden
1589
+ */
1590
+ declare function unsanitize(str: string): string;
1591
+ /**
1592
+ * Truncate a string by weighted length, counting non-ASCII characters as two
1593
+ * units.
1415
1594
  *
1416
1595
  * Usage:
1417
1596
  *
1418
1597
  * ```javascript
1419
- * import { isThisMonth } from "mazey";
1598
+ * import { cutZHString } from "mazey";
1420
1599
  *
1421
- * const ret = isThisMonth(new Date());
1600
+ * const ret = cutZHString("hello world", 5);
1422
1601
  * console.log(ret);
1423
1602
  * ```
1424
1603
  *
1425
1604
  * Output:
1426
1605
  *
1427
1606
  * ```text
1428
- * true
1607
+ * hello
1429
1608
  * ```
1430
1609
  *
1431
- * @param date A `Date`, millisecond timestamp, or string accepted by `isValidDate`.
1432
- * @returns Whether the value has the current local year and month. Invalid input returns `false`.
1433
- * @remarks Results depend on the runtime's local timezone.
1610
+ * @param {string} str String to truncate.
1611
+ * @param {number} len Maximum weighted length.
1612
+ * @param {boolean} options.hasDot Whether to append truncation text.
1613
+ * @param {string} options.dotText Text appended when truncation occurs.
1614
+ * @returns {string} The truncated string.
1434
1615
  * @category Util
1435
1616
  */
1436
- declare function isThisMonth(date: MazeyDate): boolean;
1617
+ declare function cutZHString(str: string | null | undefined, len: number, options?: {
1618
+ hasDot?: boolean;
1619
+ dotText?: string;
1620
+ }): string;
1437
1621
  /**
1438
- * Check whether a date is in the current Monday-first local calendar week.
1622
+ * Alias of `cutZHString`.
1439
1623
  *
1440
1624
  * Usage:
1441
1625
  *
1442
1626
  * ```javascript
1443
- * import { isThisWeek } from "mazey";
1627
+ * import { truncateZHString } from "mazey";
1444
1628
  *
1445
- * const ret = isThisWeek(new Date());
1629
+ * const ret = truncateZHString("hello world", 5);
1446
1630
  * console.log(ret);
1447
1631
  * ```
1448
1632
  *
1449
1633
  * Output:
1450
1634
  *
1451
1635
  * ```text
1452
- * true
1636
+ * hello
1453
1637
  * ```
1454
1638
  *
1455
- * @param date A `Date`, millisecond timestamp, or string accepted by `isValidDate`.
1456
- * @returns Whether the value is in the current local week. Invalid input returns `false`.
1457
- * @remarks The week begins on Monday and ends before the following Monday. Boundaries use local time and a half-open range.
1639
+ * @param {string} str String to truncate.
1640
+ * @param {number} len Maximum weighted length.
1641
+ * @param {boolean} hasDot Whether to append the default truncation text.
1642
+ * @returns {string} The truncated string.
1643
+ * @hidden
1644
+ */
1645
+ declare function truncateZHString(str: string | null | undefined, len: number, hasDot?: boolean): string;
1646
+ /**
1647
+ * Alias of `truncateZHString`.
1648
+ *
1649
+ * @hidden
1650
+ */
1651
+ declare function cutCHSString(str: string | null | undefined, len: number, hasDot?: boolean): string;
1652
+ /**
1653
+ * Verify the validity of axios response.
1654
+ *
1655
+ * Reference: [Handling Errors](https://axios-http.com/docs/handling_errors)
1656
+ *
1458
1657
  * @category Util
1658
+ * @hidden
1459
1659
  */
1460
- declare function isThisWeek(date: MazeyDate): boolean;
1660
+ declare function zAxiosIsValidRes(res: ZResResponse | undefined, options?: ZResIsValidResOptions | null): boolean;
1461
1661
  /**
1462
- * Check whether a date is within the current local clock hour.
1662
+ * Determine the validity of the data.
1463
1663
  *
1464
1664
  * Usage:
1465
1665
  *
1466
1666
  * ```javascript
1467
- * import { isThisHour } from "mazey";
1667
+ * import { isValidData } from "mazey";
1468
1668
  *
1469
- * const ret = isThisHour(new Date());
1470
- * console.log(ret);
1669
+ * const validData = {
1670
+ * a: {
1671
+ * b: {
1672
+ * c: 413
1673
+ * }
1674
+ * }
1675
+ * };
1676
+ * const isValidDataResA = isValidData(validData, ["a", "b", "c"], 2333);
1677
+ * const isValidDataResB = isValidData(validData, ["a", "b", "c"], 413);
1678
+ * const isValidDataResC = isValidData(validData, ["d", "d"], 413);
1679
+ * console.log("isValidDataResA:", isValidDataResA);
1680
+ * console.log("isValidDataResB:", isValidDataResB);
1681
+ * console.log("isValidDataResC:", isValidDataResC);
1471
1682
  * ```
1472
1683
  *
1473
1684
  * Output:
1474
1685
  *
1475
1686
  * ```text
1476
- * true
1687
+ * isValidDataResA: false
1688
+ * isValidDataResB: true
1689
+ * isValidDataResC: false
1477
1690
  * ```
1478
1691
  *
1479
- * @param date A `Date`, millisecond timestamp, or string accepted by `isValidDate`.
1480
- * @returns Whether the value has the current local year, month, day, and hour. Invalid input returns `false`.
1481
- * @remarks Minutes, seconds, and milliseconds are ignored. Results depend on the runtime's local timezone.
1692
+ * @param {any} data Original Data
1693
+ * @param {string[]} attributes Data Attributes
1694
+ * @param {any} validValue Given Value for verifying.
1695
+ * @returns {boolean} Return TRUE if the data is valid.
1482
1696
  * @category Util
1483
1697
  */
1484
- declare function isThisHour(date: MazeyDate): boolean;
1698
+ declare function isValidData(data: MazeyObject, attributes: string[], validValue: SimpleType): boolean;
1485
1699
  /**
1486
- * Format the absolute distance from a date to now in concise English words.
1700
+ * Options for formatting a byte count.
1487
1701
  *
1488
- * Usage:
1702
+ * @category Util
1703
+ */
1704
+ interface FormatByteSizeOptions {
1705
+ /** Unit scale. Defaults to `1024`. */
1706
+ base?: 1000 | 1024;
1707
+ /** Decimal places for rounded values. Must be an integer from 0 to 20. Defaults to `1`. */
1708
+ fractionDigits?: number;
1709
+ /** Returned for negative, non-finite, or otherwise invalid input. Defaults to an empty string. */
1710
+ invalidValue?: string;
1711
+ }
1712
+ /**
1713
+ * Format a non-negative byte count using `B`, `KB`, `MB`, `GB`, or `TB`.
1489
1714
  *
1490
- * ```javascript
1491
- * import { formatDistanceToNow } from "mazey";
1715
+ * Scaling defaults to 1024 with one fractional digit. Byte values omit
1716
+ * insignificant trailing zeroes, while scaled values retain the requested
1717
+ * number of fractional digits. Values beyond terabytes remain expressed in
1718
+ * `TB`.
1492
1719
  *
1493
- * const ret = formatDistanceToNow(new Date(Date.now() - 60 * 60 * 1000));
1494
- * console.log(ret);
1495
- * ```
1720
+ * Usage:
1496
1721
  *
1497
- * Output:
1722
+ * ```javascript
1723
+ * import { formatByteSize } from "mazey";
1498
1724
  *
1499
- * ```text
1500
- * about 1 hour
1725
+ * formatByteSize(0); // "0 B"
1726
+ * formatByteSize(1536); // "1.5 KB"
1727
+ * formatByteSize(1500000, { base: 1000, fractionDigits: 2 }); // "1.50 MB"
1501
1728
  * ```
1502
1729
  *
1503
- * @param date A `Date`, millisecond timestamp, or string accepted by `isValidDate`.
1504
- * @returns The absolute approximate distance phrase, or an empty string for invalid input.
1505
- * @remarks Past and future dates use the same wording without `ago` or `in`. Months and years use fixed approximate durations of 30 and 365 days.
1730
+ * @param bytes Byte count to format.
1731
+ * @param options Formatting options.
1732
+ * @returns A formatted byte-size string, or `invalidValue` for invalid input.
1506
1733
  * @category Util
1507
1734
  */
1508
- declare function formatDistanceToNow(date: MazeyDate): string;
1735
+ declare function formatByteSize(bytes: number, options?: FormatByteSizeOptions): string;
1509
1736
  /**
1510
- * Return the formatted date string in the given format.
1511
- *
1512
- * Supported format tokens:
1737
+ * Deprecated alias of `formatByteSize`.
1513
1738
  *
1514
- * | Token | Meaning | Range or example |
1515
- * | ------ | -------------------------------------- | ---------------- |
1516
- * | `yyyy` | Four-digit year | `2022` |
1517
- * | `MM` | Two-digit month | `01`–`12` |
1518
- * | `dd` | Two-digit day of the month | `01`–`31` |
1519
- * | `HH` | Two-digit hour using the 24-hour clock | `00`–`23` |
1520
- * | `hh` | Two-digit hour using the 12-hour clock | `01`–`12` |
1521
- * | `mm` | Two-digit minute | `00`–`59` |
1522
- * | `ss` | Two-digit second | `00`–`59` |
1523
- * | `a` | Uppercase meridiem indicator | `AM` or `PM` |
1524
- *
1525
- * The function creates a native `Date` and reads its local date and time
1526
- * fields. Timestamp output can therefore differ between runtime time zones.
1739
+ * @deprecated Use `formatByteSize` instead.
1740
+ * @param size Byte count to format.
1741
+ * @param options Formatting options.
1742
+ * @returns The result of `formatByteSize`.
1743
+ * @category Util
1744
+ */
1745
+ declare function getFileSize(size: number, options?: FormatByteSizeOptions): string;
1746
+ /**
1747
+ * Generate a Hash Code from a string.
1527
1748
  *
1528
1749
  * Usage:
1529
1750
  *
1530
1751
  * ```javascript
1531
- * import { formatDate } from "mazey";
1752
+ * import { genHashCode } from "mazey";
1532
1753
  *
1533
- * const ret1 = formatDate();
1534
- * const ret2 = formatDate("Tue Jan 11 2022 14:12:26 GMT+0800 (China Standard Time)", "yyyy-MM-dd hh:mm:ss a");
1535
- * const ret3 = formatDate(1641881235000, "yyyy-MM-dd hh:mm:ss a");
1536
- * const ret4 = formatDate(new Date(2014, 1, 11), "MM/dd/yyyy");
1537
- * console.log("Default formatDate value:", ret1);
1538
- * console.log("String formatDate value:", ret2);
1539
- * console.log("Number formatDate value:", ret3);
1540
- * console.log("Date formatDate value:", ret4);
1754
+ * const ret = genHashCode("hello world");
1755
+ * console.log(ret);
1541
1756
  * ```
1542
1757
  *
1543
1758
  * Output:
1544
1759
  *
1545
1760
  * ```text
1546
- * Default formatDate value: 2023-01-11
1547
- * String formatDate value: 2022-01-11 02:12:26 PM
1548
- * Number formatDate value: 2022-01-11 02:07:15 PM
1549
- * Date formatDate value: 02/11/2014
1761
+ * 1794106052
1550
1762
  * ```
1551
1763
  *
1552
- * @param {MazeyDate} dateIns Original date value. Defaults to the current date and time.
1553
- * @param {string} format Format string composed of supported format tokens. Defaults to `yyyy-MM-dd`.
1554
- * @returns {string} The formatted date string.
1555
- * @throws {RangeError} If `dateIns` is not a valid date.
1764
+ * Reference: [Generate a Hash from string in Javascript](https://stackoverflow.com/questions/7616461/generate-a-hash-from-string-in-javascript-jquery)
1765
+ *
1556
1766
  * @category Util
1557
1767
  */
1558
- declare function formatDate(dateIns?: MazeyDate, format?: string): string;
1768
+ declare function genHashCode(str: string): number;
1559
1769
  /**
1560
- * Generate a local-time Calendar Versioning string from a date.
1561
- *
1562
- * The conceptual format is `yyyy.MMdd.HHmmss`. Leading zeroes are removed
1563
- * from each segment to keep numeric Semantic Versioning identifiers valid.
1770
+ * Generate a lowercase SHA-256 hexadecimal digest with the Web Crypto API.
1564
1771
  *
1565
1772
  * Usage:
1566
1773
  *
1567
1774
  * ```javascript
1568
- * import { generateCalendarVersion } from "mazey";
1775
+ * import { sha256Hex } from "mazey";
1569
1776
  *
1570
- * const ret = generateCalendarVersion(new Date(2026, 6, 11, 7, 40, 35));
1571
- * console.log(ret);
1777
+ * const digest = await sha256Hex("hello world");
1778
+ * console.log(digest);
1572
1779
  * ```
1573
1780
  *
1574
1781
  * Output:
1575
1782
  *
1576
1783
  * ```text
1577
- * 2026.711.74035
1784
+ * b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9
1578
1785
  * ```
1579
1786
  *
1580
- * @param {MazeyDate} dateIns Original date. Defaults to the current date.
1581
- * @returns {string} Return the generated calendar version.
1582
- * @throws {RangeError} If `dateIns` is not a valid date.
1787
+ * @remarks Requires Web Crypto. String input also requires `TextEncoder`.
1788
+ * @param input Text or binary data to hash.
1789
+ * @returns A promise that resolves to the lowercase hexadecimal digest.
1790
+ * @throws When the required platform API is unavailable. Digest failures are propagated.
1583
1791
  * @category Util
1584
1792
  */
1585
- declare function generateCalendarVersion(dateIns?: MazeyDate): string;
1793
+ declare function sha256Hex(input: string | BufferSource): Promise<string>;
1586
1794
  /**
1587
1795
  * Check if the given string is a mobile phone number.
1588
1796
  *
@@ -3240,6 +3448,79 @@ declare function getTTFB(): Promise<number>;
3240
3448
  */
3241
3449
  declare function getPerformance(camelCase?: boolean): Promise<WebPerformance>;
3242
3450
 
3451
+ /**
3452
+ * Conservative visitor classifications detected from supported browser-side
3453
+ * signals.
3454
+ *
3455
+ * - `"crawler"`: a known crawler or automated-fetcher user-agent token matched.
3456
+ * - `"automation"`: an explicit automation user-agent token matched or
3457
+ * `navigator.webdriver` is `true`.
3458
+ * - `"unknown"`: no supported crawler or automation signal was detected.
3459
+ *
3460
+ * `"unknown"` does not mean that the visitor is verified as human.
3461
+ *
3462
+ * @remarks This heuristic result is not suitable for authentication,
3463
+ * authorization, fraud prevention, access control, or other security decisions.
3464
+ * @category Browser Information
3465
+ */
3466
+ type VisitorType = "crawler" | "automation" | "unknown";
3467
+ /**
3468
+ * Classify a visitor using conservative browser-side heuristics.
3469
+ *
3470
+ * Classification checks known crawler and automated-fetcher user-agent tokens
3471
+ * first. It then checks explicit browser-automation user-agent tokens and
3472
+ * `navigator.webdriver === true`. All other visitors return `"unknown"`.
3473
+ *
3474
+ * `"unknown"` means that no supported signal was detected. It does not verify
3475
+ * that the visitor is human. User-agent values can be modified or spoofed, and
3476
+ * automation signals can be hidden, modified, or unavailable. Both false
3477
+ * positives and false negatives are possible.
3478
+ *
3479
+ * Usage:
3480
+ *
3481
+ * ```typescript
3482
+ * import { detectVisitorType } from "mazey";
3483
+ *
3484
+ * const visitorType = detectVisitorType();
3485
+ * console.log(visitorType);
3486
+ * ```
3487
+ *
3488
+ * Possible output:
3489
+ *
3490
+ * ```text
3491
+ * unknown
3492
+ * ```
3493
+ *
3494
+ * Explicit user-agent:
3495
+ *
3496
+ * ```typescript
3497
+ * const visitorType = detectVisitorType(
3498
+ * "Mozilla/5.0 (compatible; Googlebot/2.1)"
3499
+ * );
3500
+ *
3501
+ * console.log(visitorType);
3502
+ * ```
3503
+ *
3504
+ * Output:
3505
+ *
3506
+ * ```text
3507
+ * crawler
3508
+ * ```
3509
+ *
3510
+ * @param userAgent Optional user-agent string. Defaults to
3511
+ * `navigator.userAgent` when available. An explicit value replaces only the
3512
+ * user-agent source; the current browser's WebDriver signal is still checked.
3513
+ * @returns `"crawler"`, `"automation"`, or `"unknown"`, in that priority.
3514
+ * @throws {TypeError} If an explicitly supplied user agent is not a string.
3515
+ * @remarks Safe during SSR and in Node.js. This is a heuristic classification
3516
+ * utility, not human verification, crawler authentication, or a security
3517
+ * boundary. Do not use it by itself for authentication, authorization,
3518
+ * payments, rate limiting, fraud prevention, access control, or
3519
+ * security-sensitive content. Genuine crawler verification generally requires
3520
+ * server-side request information and provider-specific validation.
3521
+ * @category Browser Information
3522
+ */
3523
+ declare function detectVisitorType(userAgent?: string): VisitorType;
3243
3524
  /**
3244
3525
  * Options for {@link isSafePWAEnv}.
3245
3526
  *
@@ -3658,5 +3939,5 @@ declare const mazeyCon: Console;
3658
3939
  */
3659
3940
  declare const timeCon: Console;
3660
3941
 
3661
- export { addClass, addEvent, addStyle, calLongestCommonSubsequence, calLongestCommonSubstring, camelCase2Underscore, camelCaseToKebabCase, cancelBubble, clearHTML, clearHtml, convert10To26, convertCamelToKebab, convertCamelToUnder, convertHttpToHttps, convertKebabToCamel, convertObjectToQuery, convertToHtmlBreaks, convertUnderToCamel, cutCHSString, cutZHString, debounce, deepCopy, deepCopyObject, deepFreeze, delCookie, doFn, extractElementText, fireEvent, floatFixed, floatToPercent, formatDate, formatDistanceToNow, formatDurationFromMs, genBrowserAttrs, genCustomConsole, genHashCode, genRndNumString, genStyleString, genUniqueNumString, generateCalendarVersion, generateRndNum, generateUniqueNum, getAllQueryParams, getBrowserInfo, getCLS, getCookie, getCurrentVersion, getDateDifference, getDefineListeners, getDomain, getFCP, getFID, getFP, getFileSize, getFriendlyInterval, getHashQueryParam, getLCP, getLocalStorage, getPageMeta, getPerformance, getQueryParam, getScriptQueryParam, getSessionStorage, getTTFB, getUrlFileType, getUrlHost, getUrlParam, getUrlPath, hasClass, inRate, invokeEvent, invokeFn, isArray, isBool, isBoolean, isBrowser, isFunction, isHit, isJSONString, isJsonString, isNonEmptyArray, isNonEmptyObject, isNumber, isPureObject, isSafePWAEnv, isStandalonePWA, isString, isSupportWebp, isSupportedEntryType, isThisHour, isThisMonth, isThisWeek, isThisYear, isToday, isUdfOrNul, isValidCssSelector, isValidData, isValidDate, isValidEmail, isValidHttpUrl, isValidPhoneNumber, isValidUrl, loadCSS, loadImage, loadScript, loadScriptIfUndefined, longestComSubsequence, longestComSubstring, mNow, mTrim, mazeyCon, newLine, onURLChange, parseGitHubRepository, parseJsonSafe, removeClass, removeCookie, removeEvent, removeHTML, removeHtml, repeatUntilConditionMet, replaceHttp, resolveLanguagePreference, resolveThemePreference, sanitizeInput, setClass, setCookie, setImgSizeBySrc, setImgWidHeiBySrc, setLanguagePreference, setLocalStorage, setSessionStorage, setThemePreference, sha256Hex, sleep, throttle, timeCon, toJavaScriptGlobalName, truncateZHString, unsanitize, unsanitizeInput, updateQueryParam, waitTime, windowLoaded, zAxiosIsValidRes };
3662
- export type { GitHubRepositoryDetails, IsSafePWAEnvOptions, PreferenceResult, ResolvedTheme, ThemePreference };
3942
+ export { addClass, addEvent, addStyle, assignDefined, calLongestCommonSubsequence, calLongestCommonSubstring, calculateCAGR, camelCase2Underscore, camelCaseToKebabCase, cancelBubble, clearHTML, clearHtml, convert10To26, convertCamelToKebab, convertCamelToUnder, convertHttpToHttps, convertKebabToCamel, convertObjectToQuery, convertToHtmlBreaks, convertUnderToCamel, cutCHSString, cutZHString, debounce, deepCopy, deepCopyObject, deepFreeze, delCookie, detectVisitorType, doFn, extractElementText, fireEvent, floatFixed, floatToPercent, formatByteSize, formatDate, formatDistanceToNow, formatDurationFromMs, formatLocalDateTime, genBrowserAttrs, genCustomConsole, genHashCode, genRndNumString, genStyleString, genUniqueNumString, generateCalendarVersion, generateRndNum, generateUniqueNum, getAllQueryParams, getBrowserInfo, getCLS, getCookie, getCurrentVersion, getDateDifference, getDefineListeners, getDomain, getFCP, getFID, getFP, getFileSize, getFriendlyInterval, getHashQueryParam, getLCP, getLocalStorage, getPageMeta, getPerformance, getQueryParam, getScriptQueryParam, getSessionStorage, getTTFB, getUrlFileType, getUrlHost, getUrlParam, getUrlPath, hasClass, inRate, invokeEvent, invokeFn, isArray, isBool, isBoolean, isBrowser, isFunction, isHit, isJSONString, isJsonString, isNonEmptyArray, isNonEmptyObject, isNumber, isPureObject, isSafePWAEnv, isStandalonePWA, isString, isSupportWebp, isSupportedEntryType, isThisHour, isThisMonth, isThisWeek, isThisYear, isToday, isUdfOrNul, isValidCssSelector, isValidData, isValidDate, isValidEmail, isValidHttpUrl, isValidPhoneNumber, isValidUrl, loadCSS, loadImage, loadScript, loadScriptIfUndefined, longestComSubsequence, longestComSubstring, mNow, mTrim, mazeyCon, newLine, onURLChange, parseGitHubRepository, parseJsonSafe, parseLocalDateTime, removeClass, removeCookie, removeEvent, removeHTML, removeHtml, repeatUntilConditionMet, replaceHttp, resolveLanguagePreference, resolveThemePreference, sanitizeInput, setClass, setCookie, setImgSizeBySrc, setImgWidHeiBySrc, setLanguagePreference, setLocalStorage, setSessionStorage, setThemePreference, sha256Hex, sleep, throttle, timeCon, toJavaScriptGlobalName, truncateZHString, unsanitize, unsanitizeInput, updateQueryParam, waitTime, windowLoaded, zAxiosIsValidRes };
3943
+ export type { FormatByteSizeOptions, GitHubRepositoryDetails, InvestmentReturnRate, IsSafePWAEnvOptions, LocalDateTimePrecision, PreferenceResult, ResolvedTheme, ThemePreference, VisitorType };