mazey 5.9.1 → 5.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.d.ts CHANGED
@@ -277,9 +277,9 @@ declare function calLongestCommonSubsequence(aStr: string, bStr: string): number
277
277
  * Usage:
278
278
  *
279
279
  * ```javascript
280
- * import { isHit } from "mazey";
280
+ * import { randomBoolean } from "mazey";
281
281
  *
282
- * const ret = isHit(0.5); // A 50% chance of returning true.
282
+ * const ret = randomBoolean(0.5); // A 50% chance of returning true.
283
283
  * console.log(ret);
284
284
  * ```
285
285
  *
@@ -295,7 +295,7 @@ declare function calLongestCommonSubsequence(aStr: string, bStr: string): number
295
295
  * let trueCount = 0;
296
296
  * let falseCount = 0;
297
297
  * new Array(1000000).fill(0).forEach(() => {
298
- * if (isHit(0.5)) {
298
+ * if (randomBoolean(0.5)) {
299
299
  * trueCount++;
300
300
  * } else {
301
301
  * falseCount++;
@@ -314,9 +314,18 @@ declare function calLongestCommonSubsequence(aStr: string, bStr: string): number
314
314
  * @returns {boolean} Whether the random value is less than the probability.
315
315
  * @category Calculate and Formula
316
316
  */
317
+ declare function randomBoolean(rate: number): boolean;
318
+ /**
319
+ * Deprecated alias of {@link randomBoolean}.
320
+ *
321
+ * @deprecated Use `randomBoolean` instead.
322
+ * @param rate Probability expressed as a value from 0 to 1.
323
+ * @returns Whether the random value is less than the probability.
324
+ * @category Calculate and Formula
325
+ */
317
326
  declare function isHit(rate: number): boolean;
318
327
  /**
319
- * Alias of `isHit`.
328
+ * Compatibility alias of {@link randomBoolean}.
320
329
  *
321
330
  * @hidden
322
331
  */
@@ -535,14 +544,14 @@ declare function formatLocalDateTime(date: Date, options?: {
535
544
  */
536
545
  declare function subYears(date: Date | number, amount: number): Date;
537
546
  /**
538
- * Get the current timestamp in milliseconds.
547
+ * Return the current timestamp in milliseconds.
548
+ *
549
+ * This compatibility helper delegates to native `Date.now()`.
539
550
  *
540
551
  * Usage:
541
552
  *
542
553
  * ```javascript
543
- * import { mNow } from "mazey";
544
- *
545
- * const ret = mNow();
554
+ * const ret = Date.now();
546
555
  * console.log(ret);
547
556
  * ```
548
557
  *
@@ -553,6 +562,7 @@ declare function subYears(date: Date | number, amount: number): Date;
553
562
  * ```
554
563
  *
555
564
  * @returns {number} The current timestamp in milliseconds.
565
+ * @deprecated Use `Date.now()` instead.
556
566
  * @category Util
557
567
  */
558
568
  declare function mNow(): number;
@@ -1560,16 +1570,16 @@ declare function isBool(bool: MazeyObject): boolean;
1560
1570
  */
1561
1571
  declare function isBoolean(bool: MazeyObject): boolean;
1562
1572
  /**
1563
- * Verify the validity of a value.
1573
+ * Return whether a value is exactly `undefined` or `null`.
1564
1574
  *
1565
1575
  * Usage:
1566
1576
  *
1567
1577
  * ```javascript
1568
- * import { isUdfOrNul } from "mazey";
1578
+ * import { isNullish } from "mazey";
1569
1579
  *
1570
- * const ret1 = isUdfOrNul(undefined);
1571
- * const ret2 = isUdfOrNul(null);
1572
- * const ret3 = isUdfOrNul("abc");
1580
+ * const ret1 = isNullish(undefined);
1581
+ * const ret2 = isNullish(null);
1582
+ * const ret3 = isNullish("abc");
1573
1583
  * console.log(ret1, ret2, ret3);
1574
1584
  * ```
1575
1585
  *
@@ -1579,8 +1589,20 @@ declare function isBoolean(bool: MazeyObject): boolean;
1579
1589
  * true true false
1580
1590
  * ```
1581
1591
  *
1592
+ * Other falsy values, including `false`, `0`, `NaN`, and an empty string,
1593
+ * return `false`.
1594
+ *
1582
1595
  * @param {MazeyObject} val The value to verify.
1583
- * @returns {boolean} Return TRUE if the object is undefined or null.
1596
+ * @returns {boolean} Whether the value is `undefined` or `null`.
1597
+ * @category Util
1598
+ */
1599
+ declare function isNullish(val: MazeyObject): boolean;
1600
+ /**
1601
+ * Deprecated alias of {@link isNullish}.
1602
+ *
1603
+ * @deprecated Use `isNullish` instead.
1604
+ * @param val The value to verify.
1605
+ * @returns Whether the value is `undefined` or `null`.
1584
1606
  * @category Util
1585
1607
  */
1586
1608
  declare function isUdfOrNul(val: MazeyObject): boolean;
@@ -2041,11 +2063,12 @@ declare function sha256Hex(input: string | BufferSource): Promise<string>;
2041
2063
  */
2042
2064
  declare function isValidPhoneNumber(mobile: string): boolean;
2043
2065
  /**
2044
- * Alias of {@link isValidPhoneNumber}.
2066
+ * Deprecated alias of {@link isValidPhoneNumber}.
2045
2067
  *
2046
2068
  * This helper validates an 11-digit Chinese mobile-shaped number. It does not
2047
2069
  * detect a browser's device form factor; use `isPhone` for that purpose.
2048
2070
  *
2071
+ * @deprecated Use `isValidPhoneNumber` instead.
2049
2072
  * @category Util
2050
2073
  */
2051
2074
  declare const isMobile: typeof isValidPhoneNumber;
@@ -2723,9 +2746,9 @@ declare function removeClass(obj: MazeyElement, cls: string): void;
2723
2746
  * Example 1: Add the `<style>` with `id`, and repeated invoking will update the content instead of adding a new one.
2724
2747
  *
2725
2748
  * ```javascript
2726
- * import { addStyle } from "mazey";
2749
+ * import { injectStyle } from "mazey";
2727
2750
  *
2728
- * addStyle(
2751
+ * injectStyle(
2729
2752
  * "body { background-color: #333; }",
2730
2753
  * { id: "test" }
2731
2754
  * );
@@ -2740,9 +2763,9 @@ declare function removeClass(obj: MazeyElement, cls: string): void;
2740
2763
  * Example 2: Add the `<style>` without `id`, and repeated invoking will add a new one.
2741
2764
  *
2742
2765
  * ```javascript
2743
- * import { addStyle } from "mazey";
2766
+ * import { injectStyle } from "mazey";
2744
2767
  *
2745
- * addStyle("body { background-color: #444; }");
2768
+ * injectStyle("body { background-color: #444; }");
2746
2769
  * ```
2747
2770
  *
2748
2771
  * Output:
@@ -2751,10 +2774,10 @@ declare function removeClass(obj: MazeyElement, cls: string): void;
2751
2774
  * <style>body { background-color: #444; }</style>
2752
2775
  * ```
2753
2776
  *
2754
- * Example 3: Combine `genStyleString` and `addStyle` to add multiple styles at once.
2777
+ * Example 3: Combine `genStyleString` and `injectStyle` to add multiple styles at once.
2755
2778
  *
2756
2779
  * ```javascript
2757
- * import { genStyleString, addStyle } from "mazey";
2780
+ * import { genStyleString, injectStyle } from "mazey";
2758
2781
  *
2759
2782
  * const xStyle = genStyleString(
2760
2783
  * ".footer>.x-wish>a:first-child" +
@@ -2773,7 +2796,7 @@ declare function removeClass(obj: MazeyElement, cls: string): void;
2773
2796
  * "padding-bottom: var(--y-wish-1)",
2774
2797
  * ]
2775
2798
  * );
2776
- * addStyle(xStyle + yStyle, { id: "z-style" });
2799
+ * injectStyle(xStyle + yStyle, { id: "z-style" });
2777
2800
  * ```
2778
2801
  *
2779
2802
  * Output:
@@ -2788,9 +2811,16 @@ declare function removeClass(obj: MazeyElement, cls: string): void;
2788
2811
  * @returns Whether non-empty CSS text was added or updated.
2789
2812
  * @category DOM
2790
2813
  */
2791
- declare function addStyle(style: string, options?: {
2814
+ declare function injectStyle(style: string, options?: {
2792
2815
  id?: string;
2793
2816
  }): boolean;
2817
+ /**
2818
+ * Deprecated alias of `injectStyle`.
2819
+ *
2820
+ * @deprecated Use `injectStyle` instead.
2821
+ * @category DOM
2822
+ */
2823
+ declare const addStyle: typeof injectStyle;
2794
2824
  /**
2795
2825
  * Sets the width and height of all images on the page based on their `src` attribute.
2796
2826
  * The `src` attribute should contain `width` and/or `height` values in the format "width=100" or "height=100".
@@ -2843,10 +2873,10 @@ declare function setImgWidHeiBySrc(): boolean;
2843
2873
  * #b{color:red;font-size:12px;}
2844
2874
  * ```
2845
2875
  *
2846
- * Example: Combine `genStyleString` and `addStyle` to add multiple styles at once.
2876
+ * Example: Combine `genStyleString` and `injectStyle` to add multiple styles at once.
2847
2877
  *
2848
2878
  * ```javascript
2849
- * import { genStyleString, addStyle } from "mazey";
2879
+ * import { genStyleString, injectStyle } from "mazey";
2850
2880
  *
2851
2881
  * const xStyle = genStyleString(
2852
2882
  * ".footer>.x-wish>a:first-child" +
@@ -2865,7 +2895,7 @@ declare function setImgWidHeiBySrc(): boolean;
2865
2895
  * "padding-bottom: var(--y-wish-1)",
2866
2896
  * ]
2867
2897
  * );
2868
- * addStyle(xStyle + yStyle, { id: "z-style" });
2898
+ * injectStyle(xStyle + yStyle, { id: "z-style" });
2869
2899
  * ```
2870
2900
  *
2871
2901
  * Output:
@@ -2953,12 +2983,12 @@ interface ResolveElementTargetOptions {
2953
2983
  type DomVisibilityTarget = string | Element | Iterable<Element> | ArrayLike<Element> | null | undefined;
2954
2984
  /**
2955
2985
  * Hide every resolved element while preserving its visible inline `display`
2956
- * value for a later call to {@link show}.
2986
+ * value for a later call to {@link showElements}.
2957
2987
  *
2958
2988
  * ```javascript
2959
- * import { hide } from "mazey";
2989
+ * import { hideElements } from "mazey";
2960
2990
  *
2961
- * hide(".notice");
2991
+ * hideElements(".notice");
2962
2992
  * ```
2963
2993
  *
2964
2994
  * @remarks Selectors use the global document. Direct elements and collections
@@ -2968,17 +2998,17 @@ type DomVisibilityTarget = string | Element | Iterable<Element> | ArrayLike<Elem
2968
2998
  * @returns The original target unchanged, to support chaining by the caller.
2969
2999
  * @category DOM
2970
3000
  */
2971
- declare function hide<T extends DomVisibilityTarget>(target: T): T;
3001
+ declare function hideElements<T extends DomVisibilityTarget>(target: T): T;
2972
3002
  /**
2973
3003
  * Show every resolved element by restoring a display value preserved by
2974
- * {@link hide}, or by applying the document-aware default for CSS-hidden
3004
+ * {@link hideElements}, or by applying the document-aware default for CSS-hidden
2975
3005
  * elements.
2976
3006
  *
2977
3007
  * ```javascript
2978
- * import { show } from "mazey";
3008
+ * import { showElements } from "mazey";
2979
3009
  *
2980
3010
  * const notices = document.querySelectorAll(".notice");
2981
- * show(notices);
3011
+ * showElements(notices);
2982
3012
  * ```
2983
3013
  *
2984
3014
  * @remarks Selectors use the global document. Direct elements and collections
@@ -2988,6 +3018,24 @@ declare function hide<T extends DomVisibilityTarget>(target: T): T;
2988
3018
  * @returns The original target unchanged, to support chaining by the caller.
2989
3019
  * @category DOM
2990
3020
  */
3021
+ declare function showElements<T extends DomVisibilityTarget>(target: T): T;
3022
+ /**
3023
+ * Deprecated alias of {@link hideElements}.
3024
+ *
3025
+ * @deprecated Use `hideElements` instead.
3026
+ * @param target Selector, element, iterable, array-like collection, or an empty target.
3027
+ * @returns The original target unchanged.
3028
+ * @category DOM
3029
+ */
3030
+ declare function hide<T extends DomVisibilityTarget>(target: T): T;
3031
+ /**
3032
+ * Deprecated alias of {@link showElements}.
3033
+ *
3034
+ * @deprecated Use `showElements` instead.
3035
+ * @param target Selector, element, iterable, array-like collection, or an empty target.
3036
+ * @returns The original target unchanged.
3037
+ * @category DOM
3038
+ */
2991
3039
  declare function show<T extends DomVisibilityTarget>(target: T): T;
2992
3040
  /**
2993
3041
  * Resolve an element from a direct element, a selector, an optionally
@@ -3102,17 +3150,17 @@ declare function cancelBubble(e: Event): void;
3102
3150
  */
3103
3151
  declare function getDefineListeners(): DefineListeners;
3104
3152
  /**
3105
- * Add event.
3153
+ * Register a named Mazey event callback.
3106
3154
  *
3107
3155
  * Usage:
3108
3156
  *
3109
3157
  * ```javascript
3110
- * import { addEvent } from "mazey";
3158
+ * import { fireEvent, onEvent } from "mazey";
3111
3159
  *
3112
- * addEvent("test", (e) => {
3160
+ * onEvent("test", (e) => {
3113
3161
  * console.log("test event:", e);
3114
3162
  * });
3115
- * fireEvent("test");
3163
+ * fireEvent("test", { type: "test" });
3116
3164
  * ```
3117
3165
  *
3118
3166
  * Output:
@@ -3125,7 +3173,14 @@ declare function getDefineListeners(): DefineListeners;
3125
3173
  * @param fn
3126
3174
  * @category Event
3127
3175
  */
3128
- declare function addEvent(type: string, fn: MazeyFn): void;
3176
+ declare function onEvent(type: string, fn: MazeyFn): void;
3177
+ /**
3178
+ * Deprecated alias of `onEvent`.
3179
+ *
3180
+ * @deprecated Use `onEvent` instead.
3181
+ * @category Event
3182
+ */
3183
+ declare const addEvent: typeof onEvent;
3129
3184
  /**
3130
3185
  * Fire/Invoke event.
3131
3186
  *
@@ -4600,5 +4655,5 @@ declare const mazeyCon: Console;
4600
4655
  */
4601
4656
  declare const timeCon: Console;
4602
4657
 
4603
- export { addClass, addEvent, addStyle, assignDefined, calLongestCommonSubsequence, calLongestCommonSubstring, calculateAspectRatio, calculateCAGR, camelCase2Underscore, camelCaseToKebabCase, cancelBubble, clearHTML, clearHtml, convert10To26, convertCamelToKebab, convertCamelToUnder, convertHttpToHttps, convertKebabToCamel, convertObjectToQuery, convertToHtmlBreaks, convertUnderToCamel, cutCHSString, cutZHString, debounce, deepCopy, deepCopyObject, deepFreeze, delCookie, derivePackageMetadata, detectVisitorType, doFn, escapeHtmlAttribute, 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, getLocalJSON, getLocalStorage, getPageMeta, getPerformance, getQueryParam, getScriptQueryParam, getSessionJSON, getSessionStorage, getSystemTheme, getTTFB, getUrlFileType, getUrlHost, getUrlParam, getUrlPath, hasClass, hide, inRate, invokeEvent, invokeFn, isAndroid, isArray, isBool, isBoolean, isBrowser, isDesktop, isFunction, isHit, isIOS, isJSONString, isJsonString, isLinux, isMacOS, isMobile, isNonEmptyArray, isNonEmptyObject, isNumber, isPhone, isPureObject, isSafePWAEnv, isStandalonePWA, isString, isSupportWebp, isSupportedEntryType, isTablet, isThisHour, isThisMonth, isThisWeek, isThisYear, isToday, isUdfOrNul, isValidCssSelector, isValidData, isValidDate, isValidEmail, isValidHttpUrl, isValidPhoneNumber, isValidUrl, isWindows, listenMediaQueryChanges, loadCSS, loadImage, loadScript, loadScriptIfUndefined, longestComSubsequence, longestComSubstring, mNow, mTrim, mazeyCon, newLine, onURLChange, parseGitHubRepository, parseJsonSafe, parseLocalDateTime, removeClass, removeCookie, removeEvent, removeHTML, removeHtml, repeatUntilConditionMet, replaceHttp, resolveElementTarget, resolveLanguagePreference, resolveThemePreference, sanitizeInput, setClass, setCookie, setImgSizeBySrc, setImgWidHeiBySrc, setLanguagePreference, setLocalJSON, setLocalStorage, setSessionJSON, setSessionStorage, setThemePreference, sha256Hex, show, sleep, subYears, throttle, timeCon, toJavaScriptGlobalName, truncateZHString, unsanitize, unsanitizeInput, updateQueryParam, waitTime, watchServiceWorkerUpdates, windowLoaded, zAxiosIsValidRes };
4658
+ export { addClass, addEvent, addStyle, assignDefined, calLongestCommonSubsequence, calLongestCommonSubstring, calculateAspectRatio, calculateCAGR, camelCase2Underscore, camelCaseToKebabCase, cancelBubble, clearHTML, clearHtml, convert10To26, convertCamelToKebab, convertCamelToUnder, convertHttpToHttps, convertKebabToCamel, convertObjectToQuery, convertToHtmlBreaks, convertUnderToCamel, cutCHSString, cutZHString, debounce, deepCopy, deepCopyObject, deepFreeze, delCookie, derivePackageMetadata, detectVisitorType, doFn, escapeHtmlAttribute, 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, getLocalJSON, getLocalStorage, getPageMeta, getPerformance, getQueryParam, getScriptQueryParam, getSessionJSON, getSessionStorage, getSystemTheme, getTTFB, getUrlFileType, getUrlHost, getUrlParam, getUrlPath, hasClass, hide, hideElements, inRate, injectStyle, invokeEvent, invokeFn, isAndroid, isArray, isBool, isBoolean, isBrowser, isDesktop, isFunction, isHit, isIOS, isJSONString, isJsonString, isLinux, isMacOS, isMobile, isNonEmptyArray, isNonEmptyObject, isNullish, isNumber, isPhone, isPureObject, isSafePWAEnv, isStandalonePWA, isString, isSupportWebp, isSupportedEntryType, isTablet, isThisHour, isThisMonth, isThisWeek, isThisYear, isToday, isUdfOrNul, isValidCssSelector, isValidData, isValidDate, isValidEmail, isValidHttpUrl, isValidPhoneNumber, isValidUrl, isWindows, listenMediaQueryChanges, loadCSS, loadImage, loadScript, loadScriptIfUndefined, longestComSubsequence, longestComSubstring, mNow, mTrim, mazeyCon, newLine, onEvent, onURLChange, parseGitHubRepository, parseJsonSafe, parseLocalDateTime, randomBoolean, removeClass, removeCookie, removeEvent, removeHTML, removeHtml, repeatUntilConditionMet, replaceHttp, resolveElementTarget, resolveLanguagePreference, resolveThemePreference, sanitizeInput, setClass, setCookie, setImgSizeBySrc, setImgWidHeiBySrc, setLanguagePreference, setLocalJSON, setLocalStorage, setSessionJSON, setSessionStorage, setThemePreference, sha256Hex, show, showElements, sleep, subYears, throttle, timeCon, toJavaScriptGlobalName, truncateZHString, unsanitize, unsanitizeInput, updateQueryParam, waitTime, watchServiceWorkerUpdates, windowLoaded, zAxiosIsValidRes };
4604
4659
  export type { DerivePackageMetadataOptions, DerivedPackageMetadata, DomVisibilityTarget, FormatByteSizeOptions, GitHubRepositoryDetails, InvestmentReturnRate, IsNumberOptions, IsSafePWAEnvOptions, IsStandalonePWAOptions, LocalDateTimePrecision, PWAEnvironment, PackageManager, PackageManifest, PackageManifestAuthor, PreferenceResult, ResolveElementTargetOptions, ResolvedTheme, ServiceWorkerUpdateCallbacks, ServiceWorkerUpdateWatcher, ThemePreference, VisitorType };