@react-hive/honey-utils 3.13.0 → 3.14.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.
@@ -1,181 +0,0 @@
1
- export declare const noop: () => void;
2
- /**
3
- * Checks if a value is a function.
4
- *
5
- * @param value - The value to check.
6
- *
7
- * @returns `true` if the value is a function; otherwise, `false`.
8
- */
9
- export declare const isFunction: (value: unknown) => value is Function;
10
- /**
11
- * Creates a function that negates the result of the given predicate function.
12
- *
13
- * @template Args - Argument types of the predicate function.
14
- *
15
- * @param fn - A function that returns any value.
16
- *
17
- * @returns A new function that returns the negated result of the original function.
18
- *
19
- * @example
20
- * ```ts
21
- * const isEven = (n: number) => n % 2 === 0;
22
- * const isOdd = not(isEven);
23
- *
24
- * console.log(isOdd(2)); // false
25
- * console.log(isOdd(3)); // true
26
- * ```
27
- */
28
- export declare const not: <Args extends unknown[]>(fn: (...args: Args) => any) => ((...args: Args) => boolean);
29
- /**
30
- * Invokes the given input if it is a function, passing the provided arguments.
31
- * Otherwise, returns the input as-is.
32
- *
33
- * @template Args - Tuple of argument types to pass to the function.
34
- * @template Result - Return type of the function or the value.
35
- *
36
- * @param input - A function to invoke with `args`, or a direct value of type `Result`.
37
- * @param args - Arguments to pass if `input` is a function.
38
- *
39
- * @returns The result of invoking the function, or the original value if it's not a function.
40
- */
41
- export declare const invokeIfFunction: <Args extends unknown[], Result>(input: ((...args: Args) => Result) | Result, ...args: Args) => Result;
42
- /**
43
- * Creates a promise that resolves after the specified delay.
44
- *
45
- * Useful for creating artificial delays, implementing timeouts, or spacing operations.
46
- *
47
- * @param delayMs - The delay in milliseconds.
48
- *
49
- * @returns A promise that resolves after the specified delay.
50
- *
51
- * @example
52
- * ```ts
53
- * // Wait for 1 second
54
- * await delay(1000);
55
- * console.log('This logs after 1 second');
56
- *
57
- * // Use with other async operations
58
- * const fetchWithTimeout = async () => {
59
- * const timeoutPromise = delay(5000).then(() => {
60
- * throw new Error('Request timed out');
61
- * });
62
- *
63
- * return Promise.race([fetchData(), timeoutPromise]);
64
- * }
65
- * ```
66
- */
67
- export declare const delay: (delayMs: number) => Promise<void>;
68
- /**
69
- * Wraps a promise with a timeout. If the promise does not settle within the specified time,
70
- * it will reject with a timeout error.
71
- *
72
- * @template T - The type of the promise result.
73
- *
74
- * @param promise - The promise to wrap.
75
- * @param timeoutMs - Timeout duration in milliseconds.
76
- * @param errorMessage - Optional custom error message.
77
- *
78
- * @returns A promise that resolves or rejects with the original promise,
79
- * or rejects with a timeout error if the duration is exceeded.
80
- *
81
- * @example
82
- * ```ts
83
- * // Rejects if fetch takes longer than 3 seconds
84
- * const response = await timeout(fetch('/api/data'), 3000);
85
- *
86
- * // With custom message
87
- * await timeout(fetchData(), 2000, 'Too long');
88
- * ```
89
- */
90
- export declare const timeout: <T>(promise: Promise<T>, timeoutMs: number, errorMessage?: string) => Promise<T>;
91
- interface RetryOptions {
92
- /**
93
- * Maximum number of retry attempts before failing.
94
- *
95
- * @default 3
96
- */
97
- maxAttempts?: number;
98
- /**
99
- * Delay in milliseconds between retry attempts.
100
- * If `backoff` is true, this is the base delay for exponential backoff.
101
- *
102
- * @default 300
103
- */
104
- delayMs?: number;
105
- /**
106
- * Whether to use exponential backoff for delays between attempts.
107
- * When enabled, the delay is multiplied by 2 ^ (`attempt` - 1).
108
- *
109
- * @default true
110
- */
111
- backoff?: boolean;
112
- /**
113
- * Optional callback triggered before each retry attempt.
114
- *
115
- * @param attempt - The current attempt number (starting from 1).
116
- * @param error - The error that caused the retry.
117
- */
118
- onRetry?: (attempt: number, error: unknown) => void;
119
- }
120
- /**
121
- * Wraps an asynchronous function with retry logic.
122
- *
123
- * The returned function will attempt to call the original function up to `maxAttempts` times,
124
- * with a delay between retries. If all attempts fail, the last encountered error is thrown.
125
- *
126
- * Useful for operations that may fail intermittently, such as network requests.
127
- *
128
- * @template Task - The type of the async function to wrap.
129
- * @template TaskResult - The result type of the async function.
130
- *
131
- * @param task - The async function to wrap with retry logic.
132
- * @param options - Configuration options for retry behavior.
133
- *
134
- * @returns A function that wraps the original function with retry support.
135
- *
136
- * @example
137
- * ```ts
138
- * async function fetchData() {
139
- * const response = await fetch('/api/data');
140
- *
141
- * if (!response.ok) {
142
- * throw new Error('Network error');
143
- * }
144
- *
145
- * return await response.json();
146
- * }
147
- *
148
- * const fetchWithRetry = retry(fetchData, {
149
- * maxAttempts: 5,
150
- * delayMs: 500,
151
- * onRetry: (attempt, error) => {
152
- * console.warn(`Attempt ${attempt} failed:`, error);
153
- * }
154
- * });
155
- *
156
- * fetchWithRetry()
157
- * .then(data => console.log('Success:', data))
158
- * .catch(error => console.error('Failed after retries:', error));
159
- * ```
160
- */
161
- export declare const retry: <Task extends (...args: unknown[]) => Promise<TaskResult>, TaskResult>(task: Task, { maxAttempts, delayMs, backoff, onRetry }?: RetryOptions) => ((...args: Parameters<Task>) => Promise<TaskResult>);
162
- /**
163
- * Wraps a function so that it can only be executed once.
164
- * The wrapped function remembers (caches) the result of the first invocation
165
- * and returns that same result for all subsequent calls, regardless of the arguments provided.
166
- *
167
- * Common use cases include:
168
- * - initializing singletons
169
- * - running setup logic only once
170
- * - avoiding repeated expensive computations
171
- *
172
- * @template T - A function type whose return value should be cached.
173
- *
174
- * @param fn - The function to execute at most once.
175
- *
176
- * @returns A new function with the same signature as `fn`, but guaranteed to
177
- * execute `fn` only on the first call and return the cached result
178
- * thereafter.
179
- */
180
- export declare const once: <T extends (...args: any[]) => any>(fn: T) => T;
181
- export {};
package/dist/string.d.ts DELETED
@@ -1,111 +0,0 @@
1
- /**
2
- * Checks if a value is a string.
3
- *
4
- * @param value - The value to check.
5
- *
6
- * @returns `true` if the value is a string; otherwise, `false`.
7
- */
8
- export declare const isString: (value: unknown) => value is string;
9
- /**
10
- * Checks whether the provided value is considered "empty".
11
- *
12
- * A value is considered empty if it is:
13
- * - `null`
14
- * - `undefined`
15
- * - `''`
16
- *
17
- * @param value - The value to check.
18
- *
19
- * @returns `true` if the value is empty; otherwise, `false`.
20
- */
21
- export declare const isNilOrEmptyString: (value: unknown) => value is null | undefined;
22
- /**
23
- * Converts a string to kebab-case format.
24
- *
25
- * This function transforms camelCase or PascalCase strings into kebab-case by inserting
26
- * hyphens between lowercase and uppercase letters, then converting everything to lowercase.
27
- *
28
- * @param input - The string to convert to kebab-case.
29
- *
30
- * @returns The kebab-case formatted string.
31
- *
32
- * @example
33
- * ```ts
34
- * toKebabCase('helloWorld'); // → 'hello-world'
35
- * toKebabCase('HelloWorld'); // → 'hello-world'
36
- * toKebabCase('hello123World'); // → 'hello123-world'
37
- * ```
38
- */
39
- export declare const toKebabCase: (input: string) => string;
40
- /**
41
- * Converts a camelCase string to dash-case format.
42
- *
43
- * This function transforms camelCase strings into dash-case by inserting
44
- * hyphens before uppercase letters and converting them to lowercase.
45
- * The function ensures that no hyphen is added at the start of the output string,
46
- * even if the input begins with an uppercase letter.
47
- *
48
- * @param input - The camelCase string to convert to dash-case.
49
- *
50
- * @returns The dash-case formatted string.
51
- *
52
- * @example
53
- * ```ts
54
- * camelToDashCase('helloWorld'); // → 'hello-world'
55
- * camelToDashCase('HelloWorld'); // → 'hello-world'
56
- * camelToDashCase('backgroundColor'); // → 'background-color'
57
- * ```
58
- */
59
- export declare const camelToDashCase: (input: string) => string;
60
- /**
61
- * Splits a camelCase or PascalCase string into separate words with spaces.
62
- *
63
- * This function inserts spaces between lowercase and uppercase letters,
64
- * making camelCase or PascalCase strings more human-readable without
65
- * altering their original capitalization.
66
- *
67
- * @param input - The camelCase or PascalCase string to split into words.
68
- *
69
- * @returns The string with spaces inserted between words.
70
- *
71
- * @example
72
- * ```ts
73
- * camelToWords('helloWorld'); // → 'hello World'
74
- * camelToWords('HelloWorld'); // → 'Hello World'
75
- * camelToWords('userIDNumber'); // → 'user ID Number'
76
- * ```
77
- */
78
- export declare const camelToWords: (input: string) => string;
79
- /**
80
- * Splits a string into an array of filtered from redundant spaces words.
81
- *
82
- * @param input - The input string to be split.
83
- *
84
- * @returns An array of words from the input string.
85
- */
86
- export declare const splitStringIntoWords: (input: string) => string[];
87
- /**
88
- * Generates a short, consistent hash string from an input string using a DJB2-inspired algorithm.
89
- *
90
- * This function uses a variation of the DJB2 algorithm, which is a simple yet effective hashing algorithm
91
- * based on bitwise XOR (`^`) and multiplication by 33. It produces a non-negative 32-bit integer,
92
- * which is then converted to a base-36 string (digits + lowercase letters) to produce a compact output.
93
- *
94
- * Useful for:
95
- * - Generating stable class names in CSS-in-JS libraries.
96
- * - Producing consistent cache keys.
97
- * - Quick and lightweight hashing needs where cryptographic security is not required.
98
- *
99
- * ⚠️ This is not cryptographically secure and should not be used for hashing passwords or sensitive data.
100
- *
101
- * @param input - The input string to hash.
102
- *
103
- * @returns A short, base-36 encoded hash string.
104
- *
105
- * @example
106
- * ```ts
107
- * const className = hashString('background-color: red;');
108
- * // → 'e4k1z0x'
109
- * ```
110
- */
111
- export declare const hashString: (input: string) => string;
File without changes