@sohanemon/utils 6.2.7 → 6.2.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/dist/index.d.mts +665 -0
  2. package/dist/index.mjs +664 -0
  3. package/package.json +42 -18
  4. package/dist/components/html-injector.d.ts +0 -50
  5. package/dist/components/html-injector.js +0 -108
  6. package/dist/components/index.d.ts +0 -5
  7. package/dist/components/index.js +0 -7
  8. package/dist/components/media-wrapper.d.ts +0 -10
  9. package/dist/components/media-wrapper.js +0 -14
  10. package/dist/components/responsive-indicator.d.ts +0 -2
  11. package/dist/components/responsive-indicator.js +0 -68
  12. package/dist/components/scrollable-marker.d.ts +0 -1
  13. package/dist/components/scrollable-marker.js +0 -56
  14. package/dist/functions/cookie.d.ts +0 -6
  15. package/dist/functions/cookie.js +0 -22
  16. package/dist/functions/deepmerge.d.ts +0 -59
  17. package/dist/functions/deepmerge.js +0 -116
  18. package/dist/functions/hydrate.d.ts +0 -15
  19. package/dist/functions/hydrate.js +0 -31
  20. package/dist/functions/index.d.ts +0 -8
  21. package/dist/functions/index.js +0 -8
  22. package/dist/functions/object.d.ts +0 -93
  23. package/dist/functions/object.js +0 -67
  24. package/dist/functions/poll.d.ts +0 -38
  25. package/dist/functions/poll.js +0 -69
  26. package/dist/functions/schedule.d.ts +0 -12
  27. package/dist/functions/schedule.js +0 -29
  28. package/dist/functions/shield.d.ts +0 -18
  29. package/dist/functions/shield.js +0 -15
  30. package/dist/functions/utils.d.ts +0 -243
  31. package/dist/functions/utils.js +0 -439
  32. package/dist/hooks/action.d.ts +0 -20
  33. package/dist/hooks/action.js +0 -84
  34. package/dist/hooks/async.d.ts +0 -30
  35. package/dist/hooks/async.js +0 -82
  36. package/dist/hooks/index.d.ts +0 -192
  37. package/dist/hooks/index.js +0 -533
  38. package/dist/hooks/schedule.d.ts +0 -36
  39. package/dist/hooks/schedule.js +0 -68
  40. package/dist/index.d.ts +0 -2
  41. package/dist/index.js +0 -2
  42. package/dist/types/gates.d.ts +0 -133
  43. package/dist/types/gates.js +0 -1
  44. package/dist/types/guards.d.ts +0 -6
  45. package/dist/types/guards.js +0 -29
  46. package/dist/types/index.d.ts +0 -3
  47. package/dist/types/index.js +0 -3
  48. package/dist/types/utilities.d.ts +0 -62
  49. package/dist/types/utilities.js +0 -1
@@ -1,31 +0,0 @@
1
- import { isPlainObject } from '../types';
2
- /**
3
- * Converts all `null` values to `undefined` in the data structure recursively.
4
- *
5
- * @param data - Any input data (object, array, primitive)
6
- * @returns Same type as input, but with all nulls replaced by undefined
7
- *
8
- * @example
9
- * hydrate({ a: null, b: 'test' }) // { a: undefined, b: 'test' }
10
- * hydrate([null, 1, { c: null }]) // [undefined, 1, { c: undefined }]
11
- */
12
- export function hydrate(data) {
13
- return convertNulls(data);
14
- }
15
- function convertNulls(value) {
16
- if (value === null)
17
- return undefined;
18
- if (typeof value !== 'object' || value === null)
19
- return value;
20
- if (Array.isArray(value)) {
21
- return value.map(convertNulls);
22
- }
23
- if (isPlainObject(value)) {
24
- const result = {};
25
- for (const key in value) {
26
- result[key] = convertNulls(value[key]);
27
- }
28
- return result;
29
- }
30
- return value;
31
- }
@@ -1,8 +0,0 @@
1
- export * from './cookie';
2
- export * from './deepmerge';
3
- export * from './hydrate';
4
- export * from './object';
5
- export * from './poll';
6
- export * from './schedule';
7
- export * from './shield';
8
- export * from './utils';
@@ -1,8 +0,0 @@
1
- export * from './cookie';
2
- export * from './deepmerge';
3
- export * from './hydrate';
4
- export * from './object';
5
- export * from './poll';
6
- export * from './schedule';
7
- export * from './shield';
8
- export * from './utils';
@@ -1,93 +0,0 @@
1
- /**
2
- * Type representing a path split into segments
3
- * @template S - The original path string type
4
- */
5
- type SplitPath<S extends string> = S extends `${infer First}.${infer Rest}` ? [First, ...SplitPath<Rest>] : [S];
6
- /**
7
- * Recursive type to resolve nested object types based on path
8
- * @template T - Current object type
9
- * @template K - Array of path segments
10
- */
11
- type GetValue<T, K extends Array<string | number>> = K extends [
12
- infer First,
13
- ...infer Rest
14
- ] ? First extends keyof T ? GetValue<T[First], Rest extends Array<string | number> ? Rest : []> : First extends `${number}` ? T extends any[] ? GetValue<T[number], Rest extends Array<string | number> ? Rest : []> : undefined : undefined : T;
15
- /**
16
- * Get a nested value from an object using array path segments
17
- * @template T - Object type
18
- * @template K - Path segments array type
19
- * @template D - Default value type
20
- * @param obj - Source object
21
- * @param path - Array of path segments
22
- * @param defaultValue - Fallback value if path not found
23
- * @returns Value at path or default value
24
- *
25
- * @example
26
- * getObjectValue({a: [{b: 1}]}, ['a', 0, 'b']) // 1
27
- */
28
- export declare function getObjectValue<T, K extends Array<string | number>, D>(obj: T, path: K, defaultValue: D): Exclude<GetValue<T, K>, undefined> | D;
29
- /**
30
- * Get a nested value from an object using array path segments
31
- * @template T - Object type
32
- * @template K - Path segments array type
33
- * @param obj - Source object
34
- * @param path - Array of path segments
35
- * @returns Value at path or undefined
36
- *
37
- * @example
38
- * getObjectValue({a: [{b: 1}]}, ['a', 0, 'b']) // 1
39
- */
40
- export declare function getObjectValue<T, K extends Array<string | number>>(obj: T, path: K): GetValue<T, K> | undefined;
41
- /**
42
- * Get a nested value from an object using dot notation path
43
- * @template T - Object type
44
- * @template S - Path string literal type
45
- * @template D - Default value type
46
- * @param obj - Source object
47
- * @param path - Dot-separated path string
48
- * @param defaultValue - Fallback value if path not found
49
- * @returns Value at path or default value
50
- *
51
- * @example
52
- * getObjectValue({a: [{b: 1}]}, 'a.0.b', 2) // 1
53
- */
54
- export declare function getObjectValue<T, S extends string, D>(obj: T, path: S, defaultValue: D): Exclude<GetValue<T, SplitPath<S>>, undefined> | D;
55
- /**
56
- * Get a nested value from an object using dot notation path
57
- * @template T - Object type
58
- * @template S - Path string literal type
59
- * @param obj - Source object
60
- * @param path - Dot-separated path string
61
- * @returns Value at path or undefined
62
- *
63
- * @example
64
- * getObjectValue({a: [{b: 1}]}, 'a.0.b') // 1
65
- */
66
- export declare function getObjectValue<T, S extends string>(obj: T, path: S): GetValue<T, SplitPath<S>> | undefined;
67
- /**
68
- * Extend an object or function with additional properties while
69
- * preserving the original type information.
70
- *
71
- * Works with both plain objects and callable functions since
72
- * functions in JavaScript are objects too.
73
- *
74
- * @template T The base object or function type
75
- * @template P The additional properties type
76
- *
77
- * @param base - The object or function to extend
78
- * @param props - An object containing properties to attach
79
- *
80
- * @returns The same object/function, augmented with the given properties
81
- *
82
- * @example
83
- * // Extend an object
84
- * const obj = extendProps({ a: 1 }, { b: "hello" });
85
- * // obj has { a: number; b: string }
86
- *
87
- * // Extend a function
88
- * const fn = (x: number) => x * 2;
89
- * const enhanced = extendProps(fn, { name: "doubler" });
90
- * // enhanced is callable and also has { name: string }
91
- */
92
- export declare function extendProps<T extends object, P extends object>(base: T, props: P): T & P;
93
- export {};
@@ -1,67 +0,0 @@
1
- /**
2
- * Implementation of deep object value retrieval with type safety
3
- * @param obj - Source object
4
- * @param path - Path specification (string or array)
5
- * @param defaultValue - Optional fallback value
6
- * @returns Value at path or default/undefined
7
- */
8
- export function getObjectValue(obj, path, defaultValue) {
9
- // Validate path type and handle edge cases
10
- if (typeof path !== 'string' && !Array.isArray(path)) {
11
- return defaultValue;
12
- }
13
- // Ensure pathArray is always an array
14
- const pathArray = (() => {
15
- if (Array.isArray(path))
16
- return path;
17
- if (path === '')
18
- return [];
19
- return String(path)
20
- .split('.')
21
- .filter((segment) => segment !== '');
22
- })();
23
- // Final safety check for array type
24
- if (!Array.isArray(pathArray)) {
25
- return defaultValue;
26
- }
27
- let current = obj;
28
- for (const key of pathArray) {
29
- if (current === null || current === undefined) {
30
- return defaultValue;
31
- }
32
- // Convert numeric strings to numbers for arrays
33
- const actualKey = typeof key === 'string' && Array.isArray(current) && /^\d+$/.test(key)
34
- ? Number.parseInt(key, 10)
35
- : key;
36
- current = current[actualKey];
37
- }
38
- return current !== undefined ? current : defaultValue;
39
- }
40
- /**
41
- * Extend an object or function with additional properties while
42
- * preserving the original type information.
43
- *
44
- * Works with both plain objects and callable functions since
45
- * functions in JavaScript are objects too.
46
- *
47
- * @template T The base object or function type
48
- * @template P The additional properties type
49
- *
50
- * @param base - The object or function to extend
51
- * @param props - An object containing properties to attach
52
- *
53
- * @returns The same object/function, augmented with the given properties
54
- *
55
- * @example
56
- * // Extend an object
57
- * const obj = extendProps({ a: 1 }, { b: "hello" });
58
- * // obj has { a: number; b: string }
59
- *
60
- * // Extend a function
61
- * const fn = (x: number) => x * 2;
62
- * const enhanced = extendProps(fn, { name: "doubler" });
63
- * // enhanced is callable and also has { name: string }
64
- */
65
- export function extendProps(base, props) {
66
- return Object.assign(base, props);
67
- }
@@ -1,38 +0,0 @@
1
- /**
2
- * Repeatedly polls an async `cond` function UNTIL it returns a TRUTHY value,
3
- * or until the operation times out or is aborted.
4
- *
5
- * Designed for waiting on async jobs, external state, or delayed availability.
6
- *
7
- * @template T The type of the successful result.
8
- *
9
- * @param cond
10
- * A function returning a Promise that resolves to:
11
- * - a truthy value `T` → stop polling and return it
12
- * - falsy/null/undefined → continue polling
13
- *
14
- * @param options
15
- * Configuration options:
16
- * - `interval` (number) — Time between polls in ms (default: 5000 ms)
17
- * - `timeout` (number) — Max total duration before failing (default: 5 min)
18
- * - `jitter` (boolean) — Add small random offset (±10%) to intervals to avoid sync bursts (default: true)
19
- * - `signal` (AbortSignal) — Optional abort signal to cancel polling
20
- *
21
- * @returns
22
- * Resolves with the truthy value `T` when successful.
23
- * Throws `AbortError` if aborted
24
- *
25
- * @example
26
- * ```ts
27
- * const job = await poll(async () => {
28
- * const status = await getJobStatus();
29
- * return status === 'done' ? status : null;
30
- * }, { interval: 3000, timeout: 60000 });
31
- * ```
32
- */
33
- export declare function poll<T>(cond: () => Promise<T | null | false | undefined>, { interval, timeout, jitter, signal, }?: Partial<{
34
- interval: number;
35
- timeout: number;
36
- signal: AbortSignal;
37
- jitter: boolean;
38
- }>): Promise<T>;
@@ -1,69 +0,0 @@
1
- import { sleep } from './utils';
2
- /**
3
- * Repeatedly polls an async `cond` function UNTIL it returns a TRUTHY value,
4
- * or until the operation times out or is aborted.
5
- *
6
- * Designed for waiting on async jobs, external state, or delayed availability.
7
- *
8
- * @template T The type of the successful result.
9
- *
10
- * @param cond
11
- * A function returning a Promise that resolves to:
12
- * - a truthy value `T` → stop polling and return it
13
- * - falsy/null/undefined → continue polling
14
- *
15
- * @param options
16
- * Configuration options:
17
- * - `interval` (number) — Time between polls in ms (default: 5000 ms)
18
- * - `timeout` (number) — Max total duration before failing (default: 5 min)
19
- * - `jitter` (boolean) — Add small random offset (±10%) to intervals to avoid sync bursts (default: true)
20
- * - `signal` (AbortSignal) — Optional abort signal to cancel polling
21
- *
22
- * @returns
23
- * Resolves with the truthy value `T` when successful.
24
- * Throws `AbortError` if aborted
25
- *
26
- * @example
27
- * ```ts
28
- * const job = await poll(async () => {
29
- * const status = await getJobStatus();
30
- * return status === 'done' ? status : null;
31
- * }, { interval: 3000, timeout: 60000 });
32
- * ```
33
- */
34
- export async function poll(cond, { interval = 5000, timeout = 5 * 60 * 1000, jitter = true, signal, } = {}) {
35
- const start = Date.now();
36
- let aborted = signal?.aborted ?? false;
37
- // fast listener (avoids repeated property lookups)
38
- const abortListener = () => {
39
- aborted = true;
40
- };
41
- signal?.addEventListener('abort', abortListener, { once: true });
42
- try {
43
- for (let attempt = 0;; attempt++) {
44
- // fast exit check
45
- if (aborted)
46
- throw new Error('Polling aborted');
47
- const result = await cond();
48
- if (result)
49
- return result;
50
- const elapsed = Date.now() - start;
51
- if (elapsed >= timeout)
52
- throw new Error('Polling timed out', {
53
- cause: `Polling timed out after ${timeout}ms`,
54
- });
55
- // add jitter (±10%) for anti-sync
56
- const delay = jitter
57
- ? interval + (Math.random() - 0.5) * interval * 0.2
58
- : interval;
59
- await sleep(delay, signal);
60
- }
61
- }
62
- catch (err) {
63
- throw err; // stop polling on any error
64
- }
65
- finally {
66
- // cleanup to avoid leaks
67
- signal?.removeEventListener('abort', abortListener);
68
- }
69
- }
@@ -1,12 +0,0 @@
1
- export type Task = () => Promise<void> | void;
2
- export interface ScheduleOpts {
3
- retry?: number;
4
- delay?: number;
5
- timeout?: number;
6
- }
7
- /**
8
- * Runs a function asynchronously in the background.
9
- * Returns immediately, retries on failure if configured.
10
- * Logs total time taken.
11
- */
12
- export declare function schedule(task: Task, options?: ScheduleOpts): void;
@@ -1,29 +0,0 @@
1
- /**
2
- * Runs a function asynchronously in the background.
3
- * Returns immediately, retries on failure if configured.
4
- * Logs total time taken.
5
- */
6
- export function schedule(task, options = {}) {
7
- const { retry = 0, delay = 0 } = options;
8
- const start = Date.now();
9
- const attempt = async (triesLeft) => {
10
- try {
11
- await task();
12
- const total = Date.now() - start;
13
- console.log(`⚡[schedule.ts] Completed in ${total}ms`);
14
- }
15
- catch (err) {
16
- console.log('⚡[schedule.ts] err:', err);
17
- if (triesLeft > 0) {
18
- console.log(`⚡[schedule.ts] Retrying in ${delay}ms...`);
19
- setTimeout(() => attempt(triesLeft - 1), delay);
20
- }
21
- else {
22
- const total = Date.now() - start;
23
- console.log(`⚡[schedule.ts] Failed after ${total}ms`);
24
- }
25
- }
26
- };
27
- // Schedule immediately
28
- setTimeout(() => attempt(retry), 0);
29
- }
@@ -1,18 +0,0 @@
1
- /**
2
- * A helper to run sync or async operations safely without try/catch.
3
- *
4
- * Returns a tuple `[error, data]`:
5
- * - `error`: the thrown error (if any), otherwise `null`
6
- * - `data`: the resolved value (if successful), otherwise `null`
7
- *
8
- * @example
9
- * ```ts
10
- * const [err, value] = shield(() => riskySync());
11
- * if (err) console.error(err);
12
- *
13
- * const [asyncErr, result] = await shield(fetchData());
14
- * if (asyncErr) throw asyncErr;
15
- * ```
16
- */
17
- export declare function shield<T, E = Error>(operation: Promise<T>): Promise<[E | null, T | null]>;
18
- export declare function shield<T, E = Error>(operation: () => T): [E | null, T | null];
@@ -1,15 +0,0 @@
1
- export function shield(operation) {
2
- if (operation instanceof Promise) {
3
- return operation
4
- .then((value) => [null, value])
5
- .catch((error) => [error, null]);
6
- }
7
- try {
8
- const data = operation();
9
- return [null, data];
10
- }
11
- catch (error) {
12
- console.log(`\x1b[31m🛡 [shield]\x1b[0m ${operation.name} failed →`, error);
13
- return [error, null];
14
- }
15
- }
@@ -1,243 +0,0 @@
1
- import { type ClassValue } from 'clsx';
2
- import type * as React from 'react';
3
- /**
4
- * Utility to merge class names with Tailwind CSS and additional custom merging logic.
5
- *
6
- * @param {...ClassValue[]} inputs - Class names to merge.
7
- * @returns {string} - A string of merged class names.
8
- */
9
- export declare function cn(...inputs: ClassValue[]): string;
10
- /**
11
- * @deprecated Use isLinkActive instead.
12
- *
13
- * Determines if a navigation link is active based on the current path.
14
- *
15
- * @param href - The target URL.
16
- * @param path - The current browser path.
17
- * @returns - True if the navigation is active, false otherwise.
18
- */
19
- export declare function isNavActive(href: string, path: string): boolean;
20
- /**
21
- * Checks if a link is active, considering optional localization prefixes.
22
- *
23
- * @param {Object} params - Parameters object.
24
- * @param {string} params.path - The target path of the link.
25
- * @param {string} params.currentPath - The current browser path.
26
- * @param {string[]} [params.locales=['en', 'es', 'de', 'zh', 'bn', 'fr', 'it', 'nl']] - Supported locale prefixes.
27
- * @returns {boolean} - True if the link is active, false otherwise.
28
- */
29
- export declare function isLinkActive({ path, currentPath, locales, exact, }: {
30
- path: string;
31
- currentPath: string;
32
- locales?: string[];
33
- exact?: boolean;
34
- }): boolean;
35
- /**
36
- * Cleans a file path by removing the `/public/` prefix if present.
37
- *
38
- * @param src - The source path to clean.
39
- * @returns - The cleaned path.
40
- */
41
- export declare function cleanSrc(src: string): string;
42
- /**
43
- * Smoothly scrolls to the top or bottom of a specified container.
44
- *
45
- * @param containerSelector - The CSS selector or React ref for the container.
46
- * @param to - Specifies whether to scroll to the top or bottom.
47
- */
48
- export declare const scrollTo: (containerSelector: string | React.RefObject<HTMLDivElement>, to: "top" | "bottom") => void;
49
- /**
50
- * Copies a given string to the clipboard.
51
- *
52
- * @param value - The value to copy to the clipboard.
53
- * @param [onSuccess=() => {}] - Optional callback executed after successful copy.
54
- */
55
- export declare const copyToClipboard: (value: string, onSuccess?: () => void) => void;
56
- /**
57
- * Converts camelCase, PascalCase, kebab-case, snake_case into normal case.
58
- *
59
- * @param inputString - The string need to be converted into normal case
60
- * @returns - Normal Case
61
- */
62
- export declare function convertToNormalCase(inputString: string): string;
63
- /**
64
- * Converts a string to a URL-friendly slug by trimming, converting to lowercase,
65
- * replacing diacritics, removing invalid characters, and replacing spaces with hyphens.
66
- * @param {string} [str] - The input string to convert.
67
- * @returns {string} The generated slug.
68
- * @example
69
- * convertToSlug("Hello World!"); // "hello-world"
70
- * convertToSlug("Déjà Vu"); // "deja-vu"
71
- */
72
- export declare const convertToSlug: (str: string) => string;
73
- /**
74
- * Checks if the code is running in a server-side environment.
75
- *
76
- * @returns - True if the code is executed in SSR (Server-Side Rendering) context, false otherwise
77
- */
78
- export declare const isSSR: boolean;
79
- /**
80
- * Converts an SVG string to a Base64-encoded string.
81
- *
82
- * @param str - The SVG string to encode
83
- * @returns - Base64-encoded string representation of the SVG
84
- */
85
- export declare const svgToBase64: (str: string) => string;
86
- /**
87
- * Pauses execution for the specified time.
88
- *
89
- * `signal` allows cancelling the sleep via AbortSignal.
90
- *
91
- * @param time - Time in milliseconds to sleep (default is 1000ms)
92
- * @param signal - Optional AbortSignal to cancel the sleep early
93
- * @returns - A Promise that resolves after the specified time or when aborted
94
- */
95
- export declare const sleep: (time?: number, signal?: AbortSignal) => Promise<void>;
96
- type DebouncedFunction<F extends (...args: any[]) => any> = {
97
- (...args: Parameters<F>): ReturnType<F> | undefined;
98
- readonly isPending: boolean;
99
- };
100
- /**
101
- * Creates a debounced function that delays invoking the provided function until
102
- * after the specified `wait` time has elapsed since the last invocation.
103
- *
104
- * If the `immediate` option is set to `true`, the function will be invoked immediately
105
- * on the leading edge of the wait interval. Subsequent calls during the wait interval
106
- * will reset the timer but not invoke the function until the interval elapses again.
107
- *
108
- * The returned function includes the `isPending` property to check if the debounce
109
- * timer is currently active.
110
- *
111
- * @typeParam F - The type of the function to debounce.
112
- *
113
- * @param function_ - The function to debounce.
114
- * @param wait - The number of milliseconds to delay (default is 100ms).
115
- * @param options - An optional object with the following properties:
116
- * - `immediate` (boolean): If `true`, invokes the function on the leading edge
117
- * of the wait interval instead of the trailing edge.
118
- *
119
- * @returns A debounced version of the provided function, enhanced with the `isPending` property.
120
- *
121
- * @throws {TypeError} If the first parameter is not a function.
122
- * @throws {RangeError} If the `wait` parameter is negative.
123
- *
124
- * @example
125
- * const log = debounce((message: string) => console.log(message), 200);
126
- * log('Hello'); // Logs "Hello" after 200ms if no other call is made.
127
- * console.log(log.isPending); // true if the timer is active.
128
- */
129
- export declare function debounce<F extends (...args: any[]) => any>(function_: F, wait?: number, options?: {
130
- immediate: boolean;
131
- }): DebouncedFunction<F>;
132
- type ThrottledFunction<F extends (...args: any[]) => any> = {
133
- (...args: Parameters<F>): ReturnType<F> | undefined;
134
- readonly isPending: boolean;
135
- };
136
- /**
137
- * Creates a throttled function that invokes the provided function at most once
138
- * every `wait` milliseconds.
139
- *
140
- * If the `leading` option is set to `true`, the function will be invoked immediately
141
- * on the leading edge of the throttle interval. If the `trailing` option is set to `true`,
142
- * the function will also be invoked at the end of the throttle interval if additional
143
- * calls were made during the interval.
144
- *
145
- * The returned function includes the `isPending` property to check if the throttle
146
- * timer is currently active.
147
- *
148
- * @typeParam F - The type of the function to throttle.
149
- *
150
- * @param function_ - The function to throttle.
151
- * @param wait - The number of milliseconds to wait between invocations (default is 100ms).
152
- * @param options - An optional object with the following properties:
153
- * - `leading` (boolean): If `true`, invokes the function on the leading edge of the interval.
154
- * - `trailing` (boolean): If `true`, invokes the function on the trailing edge of the interval.
155
- *
156
- * @returns A throttled version of the provided function, enhanced with the `isPending` property.
157
- *
158
- * @throws {TypeError} If the first parameter is not a function.
159
- * @throws {RangeError} If the `wait` parameter is negative.
160
- *
161
- * @example
162
- * const log = throttle((message: string) => console.log(message), 200);
163
- * log('Hello'); // Logs "Hello" immediately if leading is true.
164
- * console.log(log.isPending); // true if the timer is active.
165
- */
166
- export declare function throttle<F extends (...args: any[]) => any>(function_: F, wait?: number, options?: {
167
- leading?: boolean;
168
- trailing?: boolean;
169
- }): ThrottledFunction<F>;
170
- /**
171
- * Formats a string by replacing each '%s' placeholder with the corresponding argument.
172
- * This function mimics the basic behavior of C's printf for %s substitution.
173
- *
174
- * It supports both calls like `printf(format, ...args)` and `printf(format, argsArray)`.
175
- *
176
- * @param format - The format string containing '%s' placeholders.
177
- * @param args - The values to substitute into the placeholders, either as separate arguments or as a single array.
178
- * @returns The formatted string with all '%s' replaced by the provided arguments.
179
- *
180
- * @example
181
- * ```ts
182
- * const message = printf("%s love %s", "I", "Bangladesh");
183
- * // message === "I love Bangladesh"
184
- *
185
- * const arr = ["I", "Bangladesh"];
186
- * const message2 = printf("%s love %s", arr);
187
- * // message2 === "I love Bangladesh"
188
- *
189
- * // If there are too few arguments:
190
- * const incomplete = printf("Bangladesh is %s %s", "beautiful");
191
- * // incomplete === "Bangladesh is beautiful"
192
- * ```
193
- */
194
- export declare function printf(format: string, ...args: unknown[]): string;
195
- /**
196
- * Merges multiple refs into a single ref callback.
197
- *
198
- * @param refs - An array of refs to merge.
199
- *
200
- * @returns - A function that updates the merged ref with the provided value.
201
- */
202
- export type MergeRefs = <T>(...refs: Array<React.Ref<T> | undefined>) => React.RefCallback<T>;
203
- export declare const mergeRefs: MergeRefs;
204
- /**
205
- * Navigates to the specified client-side hash without ssr.
206
- * use `scroll-margin-top` with css to add margins
207
- *
208
- * @param id - The ID of the element without # to navigate to.
209
- *
210
- * @example goToClientSideHash('my-element');
211
- */
212
- export declare function goToClientSideHash(id: string, opts?: ScrollIntoViewOptions): void;
213
- /**
214
- * Escapes a string for use in a regular expression.
215
- *
216
- * @param str - The string to escape
217
- * @returns - The escaped string
218
- *
219
- * @example
220
- * const escapedString = escapeRegExp('Hello, world!');
221
- * // escapedString === 'Hello\\, world!'
222
- */
223
- export declare function escapeRegExp(str: string): string;
224
- /**
225
- * Normalizes a string by:
226
- * - Applying Unicode normalization (NFC)
227
- * - Optionally removing diacritic marks (accents)
228
- * - Optionally trimming leading/trailing non-alphanumeric characters
229
- * - Optionally converting to lowercase
230
- *
231
- * @param str - The string to normalize
232
- * @param options - Normalization options
233
- * @param options.lowercase - Whether to convert the result to lowercase (default: true)
234
- * @param options.removeAccents - Whether to remove diacritic marks like accents (default: true)
235
- * @param options.removeNonAlphanumeric - Whether to trim non-alphanumeric characters from the edges (default: true)
236
- * @returns The normalized string
237
- */
238
- export declare function normalizeText(str?: string | null, options?: {
239
- lowercase?: boolean;
240
- removeAccents?: boolean;
241
- removeNonAlphanumeric?: boolean;
242
- }): string;
243
- export {};