@react-hive/honey-utils 1.3.0 → 1.5.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/README.md +58 -4
- package/dist/README.md +58 -4
- package/dist/array.d.ts +71 -0
- package/dist/function.d.ts +99 -1
- package/dist/guards.d.ts +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.dev.cjs +240 -10
- package/dist/index.dev.cjs.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/string.d.ts +36 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/@react-hive/honey-utils)
|
|
4
4
|
[](https://opensource.org/licenses/MIT)
|
|
5
5
|
|
|
6
|
+
<p align="center">
|
|
7
|
+
<img src="./logo.png" alt="honey-utils logo" width="200" height="200">
|
|
8
|
+
</p>
|
|
9
|
+
|
|
6
10
|
A lightweight TypeScript utility library providing a collection of helper functions for common programming tasks.
|
|
7
11
|
|
|
8
12
|
## Features
|
|
@@ -62,17 +66,34 @@ const hash = hashString('background-color: red;'); // 'e4k1z0x'
|
|
|
62
66
|
### Array Utilities
|
|
63
67
|
|
|
64
68
|
```typescript
|
|
65
|
-
import {
|
|
69
|
+
import {
|
|
70
|
+
boolFilter,
|
|
71
|
+
unique,
|
|
72
|
+
chunk,
|
|
73
|
+
intersection,
|
|
74
|
+
difference
|
|
75
|
+
} from '@react-hive/honey-utils';
|
|
66
76
|
|
|
67
77
|
// Filter out falsy values from an array
|
|
68
|
-
|
|
69
|
-
|
|
78
|
+
boolFilter([0, 1, false, 2, '', 3, null, undefined, true]); // [1, 2, 3, true]
|
|
79
|
+
|
|
80
|
+
// Remove duplicate values from an array
|
|
81
|
+
unique([1, 2, 2, 3, 1, 4]); // [1, 2, 3, 4]
|
|
82
|
+
|
|
83
|
+
// Split an array into chunks of specified size
|
|
84
|
+
chunk([1, 2, 3, 4, 5], 2); // [[1, 2], [3, 4], [5]]
|
|
85
|
+
|
|
86
|
+
// Find common elements between arrays
|
|
87
|
+
intersection([1, 2, 3], [2, 3, 4]); // [2, 3]
|
|
88
|
+
|
|
89
|
+
// Find elements in one array not in another
|
|
90
|
+
difference([1, 2, 3, 4], [2, 4]); // [1, 3]
|
|
70
91
|
```
|
|
71
92
|
|
|
72
93
|
### Function Utilities
|
|
73
94
|
|
|
74
95
|
```typescript
|
|
75
|
-
import { noop, invokeIfFunction } from '@react-hive/honey-utils';
|
|
96
|
+
import { noop, invokeIfFunction, delay, retry } from '@react-hive/honey-utils';
|
|
76
97
|
|
|
77
98
|
// No-operation function
|
|
78
99
|
noop(); // does nothing
|
|
@@ -82,6 +103,33 @@ const fn = (x: number) => x * 2;
|
|
|
82
103
|
|
|
83
104
|
invokeIfFunction(fn, 5); // 10
|
|
84
105
|
invokeIfFunction('not a function', 5); // 'not a function'
|
|
106
|
+
|
|
107
|
+
// Create a promise that resolves after a specified delay
|
|
108
|
+
await delay(1000); // Waits for 1 second before continuing
|
|
109
|
+
|
|
110
|
+
// Retry an async function with configurable options
|
|
111
|
+
async function fetchData() {
|
|
112
|
+
const response = await fetch('/api/data');
|
|
113
|
+
|
|
114
|
+
if (!response.ok) {
|
|
115
|
+
throw new Error('Network error');
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return await response.json();
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const fetchWithRetry = retry(fetchData, {
|
|
122
|
+
maxAttempts: 5,
|
|
123
|
+
delayMs: 500,
|
|
124
|
+
backoff: true,
|
|
125
|
+
onRetry: (attempt, error) => {
|
|
126
|
+
console.warn(`Attempt ${attempt} failed:`, error);
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
fetchWithRetry()
|
|
131
|
+
.then(data => console.log('Success:', data))
|
|
132
|
+
.catch(error => console.error('Failed after retries:', error));
|
|
85
133
|
```
|
|
86
134
|
|
|
87
135
|
### Type Guards
|
|
@@ -228,11 +276,17 @@ function divide(a: number, b: number): number {
|
|
|
228
276
|
### Array Utilities
|
|
229
277
|
|
|
230
278
|
- **boolFilter<T>(array: (T | false | null | undefined)[]): T[]** - Filters out falsy values from an array
|
|
279
|
+
- **unique<T>(array: T[]): T[]** - Returns a new array with duplicate values removed
|
|
280
|
+
- **chunk<T>(array: T[], size: number): T[][]** - Splits an array into chunks of the specified size
|
|
281
|
+
- **intersection<T>(...arrays: T[][]): T[]** - Returns an array containing elements that exist in all provided arrays
|
|
282
|
+
- **difference<T>(array: T[], exclude: T[]): T[]** - Returns elements from the first array that don't exist in the second array
|
|
231
283
|
|
|
232
284
|
### Function Utilities
|
|
233
285
|
|
|
234
286
|
- **noop(): void** - A no-operation function
|
|
235
287
|
- **invokeIfFunction<Args extends any[], Result>(input: ((...args: Args) => Result) | Result, ...args: Args): Result** - Invokes the input if it's a function, otherwise returns it as-is
|
|
288
|
+
- **delay(delayMs: number): Promise<void>** - Creates a promise that resolves after the specified delay in milliseconds
|
|
289
|
+
- **retry<Task, TaskResult>(task: Task, options?: RetryOptions): Function** - Wraps an asynchronous function with retry logic, with configurable max attempts, delay between retries, exponential backoff, and retry callbacks
|
|
236
290
|
|
|
237
291
|
### Type Guards
|
|
238
292
|
|
package/dist/README.md
CHANGED
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/@react-hive/honey-utils)
|
|
4
4
|
[](https://opensource.org/licenses/MIT)
|
|
5
5
|
|
|
6
|
+
<p align="center">
|
|
7
|
+
<img src="./logo.png" alt="honey-utils logo" width="200" height="200">
|
|
8
|
+
</p>
|
|
9
|
+
|
|
6
10
|
A lightweight TypeScript utility library providing a collection of helper functions for common programming tasks.
|
|
7
11
|
|
|
8
12
|
## Features
|
|
@@ -62,17 +66,34 @@ const hash = hashString('background-color: red;'); // 'e4k1z0x'
|
|
|
62
66
|
### Array Utilities
|
|
63
67
|
|
|
64
68
|
```typescript
|
|
65
|
-
import {
|
|
69
|
+
import {
|
|
70
|
+
boolFilter,
|
|
71
|
+
unique,
|
|
72
|
+
chunk,
|
|
73
|
+
intersection,
|
|
74
|
+
difference
|
|
75
|
+
} from '@react-hive/honey-utils';
|
|
66
76
|
|
|
67
77
|
// Filter out falsy values from an array
|
|
68
|
-
|
|
69
|
-
|
|
78
|
+
boolFilter([0, 1, false, 2, '', 3, null, undefined, true]); // [1, 2, 3, true]
|
|
79
|
+
|
|
80
|
+
// Remove duplicate values from an array
|
|
81
|
+
unique([1, 2, 2, 3, 1, 4]); // [1, 2, 3, 4]
|
|
82
|
+
|
|
83
|
+
// Split an array into chunks of specified size
|
|
84
|
+
chunk([1, 2, 3, 4, 5], 2); // [[1, 2], [3, 4], [5]]
|
|
85
|
+
|
|
86
|
+
// Find common elements between arrays
|
|
87
|
+
intersection([1, 2, 3], [2, 3, 4]); // [2, 3]
|
|
88
|
+
|
|
89
|
+
// Find elements in one array not in another
|
|
90
|
+
difference([1, 2, 3, 4], [2, 4]); // [1, 3]
|
|
70
91
|
```
|
|
71
92
|
|
|
72
93
|
### Function Utilities
|
|
73
94
|
|
|
74
95
|
```typescript
|
|
75
|
-
import { noop, invokeIfFunction } from '@react-hive/honey-utils';
|
|
96
|
+
import { noop, invokeIfFunction, delay, retry } from '@react-hive/honey-utils';
|
|
76
97
|
|
|
77
98
|
// No-operation function
|
|
78
99
|
noop(); // does nothing
|
|
@@ -82,6 +103,33 @@ const fn = (x: number) => x * 2;
|
|
|
82
103
|
|
|
83
104
|
invokeIfFunction(fn, 5); // 10
|
|
84
105
|
invokeIfFunction('not a function', 5); // 'not a function'
|
|
106
|
+
|
|
107
|
+
// Create a promise that resolves after a specified delay
|
|
108
|
+
await delay(1000); // Waits for 1 second before continuing
|
|
109
|
+
|
|
110
|
+
// Retry an async function with configurable options
|
|
111
|
+
async function fetchData() {
|
|
112
|
+
const response = await fetch('/api/data');
|
|
113
|
+
|
|
114
|
+
if (!response.ok) {
|
|
115
|
+
throw new Error('Network error');
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return await response.json();
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const fetchWithRetry = retry(fetchData, {
|
|
122
|
+
maxAttempts: 5,
|
|
123
|
+
delayMs: 500,
|
|
124
|
+
backoff: true,
|
|
125
|
+
onRetry: (attempt, error) => {
|
|
126
|
+
console.warn(`Attempt ${attempt} failed:`, error);
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
fetchWithRetry()
|
|
131
|
+
.then(data => console.log('Success:', data))
|
|
132
|
+
.catch(error => console.error('Failed after retries:', error));
|
|
85
133
|
```
|
|
86
134
|
|
|
87
135
|
### Type Guards
|
|
@@ -228,11 +276,17 @@ function divide(a: number, b: number): number {
|
|
|
228
276
|
### Array Utilities
|
|
229
277
|
|
|
230
278
|
- **boolFilter<T>(array: (T | false | null | undefined)[]): T[]** - Filters out falsy values from an array
|
|
279
|
+
- **unique<T>(array: T[]): T[]** - Returns a new array with duplicate values removed
|
|
280
|
+
- **chunk<T>(array: T[], size: number): T[][]** - Splits an array into chunks of the specified size
|
|
281
|
+
- **intersection<T>(...arrays: T[][]): T[]** - Returns an array containing elements that exist in all provided arrays
|
|
282
|
+
- **difference<T>(array: T[], exclude: T[]): T[]** - Returns elements from the first array that don't exist in the second array
|
|
231
283
|
|
|
232
284
|
### Function Utilities
|
|
233
285
|
|
|
234
286
|
- **noop(): void** - A no-operation function
|
|
235
287
|
- **invokeIfFunction<Args extends any[], Result>(input: ((...args: Args) => Result) | Result, ...args: Args): Result** - Invokes the input if it's a function, otherwise returns it as-is
|
|
288
|
+
- **delay(delayMs: number): Promise<void>** - Creates a promise that resolves after the specified delay in milliseconds
|
|
289
|
+
- **retry<Task, TaskResult>(task: Task, options?: RetryOptions): Function** - Wraps an asynchronous function with retry logic, with configurable max attempts, delay between retries, exponential backoff, and retry callbacks
|
|
236
290
|
|
|
237
291
|
### Type Guards
|
|
238
292
|
|
package/dist/array.d.ts
CHANGED
|
@@ -11,3 +11,74 @@
|
|
|
11
11
|
* @returns A new array containing only truthy `Item` values.
|
|
12
12
|
*/
|
|
13
13
|
export declare const boolFilter: <T>(array: (T | false | null | undefined)[]) => T[];
|
|
14
|
+
/**
|
|
15
|
+
* Returns a new array with duplicate values removed.
|
|
16
|
+
*
|
|
17
|
+
* Uses Set for efficient duplicate removal while preserving the original order.
|
|
18
|
+
*
|
|
19
|
+
* @template T - The type of the items in the array.
|
|
20
|
+
*
|
|
21
|
+
* @param array - The input array that may contain duplicate values.
|
|
22
|
+
*
|
|
23
|
+
* @returns A new array with only unique values, maintaining the original order.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* unique([1, 2, 2, 3, 1, 4]); // [1, 2, 3, 4]
|
|
28
|
+
* unique(['a', 'b', 'a', 'c']); // ['a', 'b', 'c']
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare const unique: <T>(array: T[]) => T[];
|
|
32
|
+
/**
|
|
33
|
+
* Splits an array into chunks of the specified size.
|
|
34
|
+
*
|
|
35
|
+
* Useful for pagination, batch processing, or creating grid layouts.
|
|
36
|
+
*
|
|
37
|
+
* @template T - The type of the items in the array.
|
|
38
|
+
*
|
|
39
|
+
* @param array - The input array to be chunked.
|
|
40
|
+
* @param size - The size of each chunk. Must be greater than 0.
|
|
41
|
+
*
|
|
42
|
+
* @returns An array of chunks, where each chunk is an array of the specified size
|
|
43
|
+
* (except possibly the last chunk, which may be smaller).
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* chunk([1, 2, 3, 4, 5], 2); // [[1, 2], [3, 4], [5]]
|
|
48
|
+
* chunk(['a', 'b', 'c', 'd'], 3); // [['a', 'b', 'c'], ['d']]
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export declare const chunk: <T>(array: T[], size: number) => T[][];
|
|
52
|
+
/**
|
|
53
|
+
* Returns an array containing elements that exist in all provided arrays.
|
|
54
|
+
*
|
|
55
|
+
* @template T - The type of the items in the arrays.
|
|
56
|
+
*
|
|
57
|
+
* @param arrays - Two or more arrays to find common elements from.
|
|
58
|
+
*
|
|
59
|
+
* @returns A new array containing only the elements that exist in all input arrays.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* intersection([1, 2, 3], [2, 3, 4]); // [2, 3]
|
|
64
|
+
* intersection(['a', 'b', 'c'], ['b', 'c', 'd'], ['b', 'e']); // ['b']
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
export declare const intersection: <T>(...arrays: T[][]) => T[];
|
|
68
|
+
/**
|
|
69
|
+
* Returns elements from the first array that don't exist in the second array.
|
|
70
|
+
*
|
|
71
|
+
* @template T - The type of the items in the arrays.
|
|
72
|
+
*
|
|
73
|
+
* @param array - The source array.
|
|
74
|
+
* @param exclude - The array containing elements to exclude.
|
|
75
|
+
*
|
|
76
|
+
* @returns A new array with elements from the first array that don't exist in the second array.
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```ts
|
|
80
|
+
* difference([1, 2, 3, 4], [2, 4]); // [1, 3]
|
|
81
|
+
* difference(['a', 'b', 'c'], ['b']); // ['a', 'c']
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
export declare const difference: <T>(array: T[], exclude: T[]) => T[];
|
package/dist/function.d.ts
CHANGED
|
@@ -11,4 +11,102 @@ export declare const noop: () => void;
|
|
|
11
11
|
*
|
|
12
12
|
* @returns The result of invoking the function, or the original value if it's not a function.
|
|
13
13
|
*/
|
|
14
|
-
export declare const invokeIfFunction: <Args extends
|
|
14
|
+
export declare const invokeIfFunction: <Args extends unknown[], Result>(input: ((...args: Args) => Result) | Result, ...args: Args) => Result;
|
|
15
|
+
/**
|
|
16
|
+
* Creates a promise that resolves after the specified delay.
|
|
17
|
+
*
|
|
18
|
+
* Useful for creating artificial delays, implementing timeouts, or spacing operations.
|
|
19
|
+
*
|
|
20
|
+
* @param delayMs - The delay in milliseconds.
|
|
21
|
+
*
|
|
22
|
+
* @returns A promise that resolves after the specified delay.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* // Wait for 1 second
|
|
27
|
+
* await delay(1000);
|
|
28
|
+
* console.log('This logs after 1 second');
|
|
29
|
+
*
|
|
30
|
+
* // Use with other async operations
|
|
31
|
+
* async function fetchWithTimeout() {
|
|
32
|
+
* const timeoutPromise = delay(5000).then(() => {
|
|
33
|
+
* throw new Error('Request timed out');
|
|
34
|
+
* });
|
|
35
|
+
*
|
|
36
|
+
* return Promise.race([fetchData(), timeoutPromise]);
|
|
37
|
+
* }
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export declare const delay: (delayMs: number) => Promise<void>;
|
|
41
|
+
interface RetryOptions {
|
|
42
|
+
/**
|
|
43
|
+
* Maximum number of retry attempts before failing.
|
|
44
|
+
*
|
|
45
|
+
* @default 3
|
|
46
|
+
*/
|
|
47
|
+
maxAttempts?: number;
|
|
48
|
+
/**
|
|
49
|
+
* Delay in milliseconds between retry attempts.
|
|
50
|
+
* If `backoff` is true, this is the base delay for exponential backoff.
|
|
51
|
+
*
|
|
52
|
+
* @default 300
|
|
53
|
+
*/
|
|
54
|
+
delayMs?: number;
|
|
55
|
+
/**
|
|
56
|
+
* Whether to use exponential backoff for delays between attempts.
|
|
57
|
+
* When enabled, the delay is multiplied by 2 ^ (`attempt` - 1).
|
|
58
|
+
*
|
|
59
|
+
* @default true
|
|
60
|
+
*/
|
|
61
|
+
backoff?: boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Optional callback triggered before each retry attempt.
|
|
64
|
+
*
|
|
65
|
+
* @param attempt - The current attempt number (starting from 1).
|
|
66
|
+
* @param error - The error that caused the retry.
|
|
67
|
+
*/
|
|
68
|
+
onRetry?: (attempt: number, error: unknown) => void;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Wraps an asynchronous function with retry logic.
|
|
72
|
+
*
|
|
73
|
+
* The returned function will attempt to call the original function up to `maxAttempts` times,
|
|
74
|
+
* with a delay between retries. If all attempts fail, the last encountered error is thrown.
|
|
75
|
+
*
|
|
76
|
+
* Useful for operations that may fail intermittently, such as network requests.
|
|
77
|
+
*
|
|
78
|
+
* @template Task - The type of the async function to wrap.
|
|
79
|
+
* @template TaskResult - The result type of the async function.
|
|
80
|
+
*
|
|
81
|
+
* @param task - The async function to wrap with retry logic.
|
|
82
|
+
* @param options - Configuration options for retry behavior.
|
|
83
|
+
*
|
|
84
|
+
* @returns A function that wraps the original function with retry support.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```ts
|
|
88
|
+
* async function fetchData() {
|
|
89
|
+
* const response = await fetch('/api/data');
|
|
90
|
+
*
|
|
91
|
+
* if (!response.ok) {
|
|
92
|
+
* throw new Error('Network error');
|
|
93
|
+
* }
|
|
94
|
+
*
|
|
95
|
+
* return await response.json();
|
|
96
|
+
* }
|
|
97
|
+
*
|
|
98
|
+
* const fetchWithRetry = retry(fetchData, {
|
|
99
|
+
* maxAttempts: 5,
|
|
100
|
+
* delayMs: 500,
|
|
101
|
+
* onRetry: (attempt, error) => {
|
|
102
|
+
* console.warn(`Attempt ${attempt} failed:`, error);
|
|
103
|
+
* }
|
|
104
|
+
* });
|
|
105
|
+
*
|
|
106
|
+
* fetchWithRetry()
|
|
107
|
+
* .then(data => console.log('Success:', data))
|
|
108
|
+
* .catch(error => console.error('Failed after retries:', error));
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
export declare const retry: <Task extends (...args: unknown[]) => Promise<TaskResult>, TaskResult>(task: Task, { maxAttempts, delayMs, backoff, onRetry }?: RetryOptions) => ((...args: Parameters<Task>) => Promise<TaskResult>);
|
|
112
|
+
export {};
|
package/dist/guards.d.ts
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(()=>{"use strict";var e={d:(t,
|
|
1
|
+
(()=>{"use strict";var e={d:(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{assert:()=>a,boolFilter:()=>P,calculateEuclideanDistance:()=>B,calculateMovingSpeed:()=>L,calculatePercentage:()=>R,camelToDashCase:()=>n,chunk:()=>F,delay:()=>I,difference:()=>k,getTransformationValues:()=>V,hashString:()=>i,intersection:()=>T,invokeIfFunction:()=>D,isArray:()=>p,isBool:()=>u,isDate:()=>S,isEmptyArray:()=>g,isEmptyObject:()=>y,isFiniteNumber:()=>C,isFunction:()=>m,isInteger:()=>N,isMap:()=>M,isNil:()=>d,isNilOrEmptyString:()=>h,isNull:()=>s,isNumber:()=>c,isObject:()=>f,isPromise:()=>b,isRegExp:()=>A,isSet:()=>O,isString:()=>l,isSymbol:()=>j,isUndefined:()=>v,isValidDate:()=>w,noop:()=>x,retry:()=>$,splitStringIntoWords:()=>o,toKebabCase:()=>r,unique:()=>E});const r=e=>e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),n=e=>{const t=e.charAt(0),r=e.slice(1);return t.toLowerCase()+r.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`)},o=e=>e.split(" ").filter(Boolean),i=e=>{let t=5381;for(let r=0;r<e.length;r++)t=33*t^e.charCodeAt(r);return(t>>>0).toString(36)};function a(e,t){if(!e)throw new Error(t)}const s=e=>null===e,l=e=>"string"==typeof e,c=e=>"number"==typeof e,u=e=>"boolean"==typeof e,f=e=>"object"==typeof e,y=e=>f(e)&&!s(e)&&0===Object.keys(e).length,p=e=>Array.isArray(e),g=e=>p(e)&&0===e.length,m=e=>"function"==typeof e,b=e=>m(e?.then),d=e=>null==e,h=e=>""===e||d(e),S=e=>e instanceof Date,w=e=>S(e)&&!isNaN(e.getTime()),A=e=>e instanceof RegExp,M=e=>e instanceof Map,O=e=>e instanceof Set,j=e=>"symbol"==typeof e,v=e=>void 0===e,C=e=>c(e)&&isFinite(e),N=e=>c(e)&&Number.isInteger(e),P=e=>e.filter(Boolean),E=e=>[...new Set(e)],F=(e,t)=>(a(t>0,"Chunk size must be greater than 0"),Array.from({length:Math.ceil(e.length/t)},(r,n)=>e.slice(n*t,(n+1)*t))),T=(...e)=>{if(0===e.length)return[];if(1===e.length)return[...e[0]];const[t,...r]=e;return E(t).filter(e=>r.every(t=>t.includes(e)))},k=(e,t)=>e.filter(e=>!t.includes(e)),x=()=>{},D=(e,...t)=>"function"==typeof e?e(...t):e,I=e=>new Promise(t=>setTimeout(t,e)),$=(e,{maxAttempts:t=3,delayMs:r=300,backoff:n=!0,onRetry:o}={})=>async(...i)=>{let a;for(let s=1;s<=t;s++)try{return await e(...i)}catch(e){if(a=e,s<t){o?.(s,e);const t=n?r*2**(s-1):r;await I(t)}}throw a},B=(e,t,r,n)=>{const o=r-e,i=n-t;return Math.sqrt(o**2+i**2)},L=(e,t)=>Math.abs(e/t),R=(e,t)=>e*t/100,V=e=>{const t=window.getComputedStyle(e).getPropertyValue("transform").match(/^matrix\((.+)\)$/);if(!t)return{translateX:0,translateY:0};const r=t[1].split(", ");return{translateX:parseFloat(r[4]),translateY:parseFloat(r[5])}};module.exports=t})();
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","mappings":"mBACA,IAAIA,EAAsB,CCA1BA,EAAwB,CAACC,EAASC,KACjC,IAAI,IAAIC,KAAOD,EACXF,EAAoBI,EAAEF,EAAYC,KAASH,EAAoBI,EAAEH,EAASE,IAC5EE,OAAOC,eAAeL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AVA,GAAgBmC,EAAMnC,GASXqC,EAAUrC,GAAkCA,aAAiBsC,KAS7DC,EAAevC,GAC1BqC,EAAOrC,KAAWwC,MAAMxC,EAAMyC,WASnBC,EAAY1C,GAAoCA,aAAiB2C,OASjEC,EAAS5C,GAAmDA,aAAiB6C,IAS7EC,EAAS9C,GAA0CA,aAAiB+C,IASpEC,EAAYhD,GAAqD,iBAAVA,EASvDiD,EAAejD,QAAiDkD,IAAVlD,EAStDmD,EAAkBnD,GAC7BwB,EAASxB,IAAUoD,SAASpD,GASjBqD,EAAarD,GACxBwB,EAASxB,IAAUsD,OAAOD,UAAUrD,GC/LzBuD,EAA6B,CACxCC,EACAC,EACAC,EACAC,KAEA,MAAMC,EAASF,EAAOF,EAChBK,EAASF,EAAOF,EAEtB,OAAOK,KAAKC,KAAKH,GAAU,EAAIC,GAAU,IAW9BG,EAAuB,CAACC,EAAeC,IAClDJ,KAAKK,IAAIF,EAAQC,GAUNE,EAAsB,CAACpE,EAAeqE,IACzCrE,EAAQqE,EAAc,IC9BnBC,EAA2BC,IACtC,MAGMC,EAHiBC,OAAOC,iBAAiBH,GACTI,iBAAiB,aAEzBC,MAAM,oBACpC,IAAKJ,EACH,MAAO,CACLK,WAAY,EACZC,WAAY,GAIhB,MAAMC,EAAkBP,EAAO,GAAGhE,MAAM,MAKxC,MAAO,CACLqE,WAJiBG,WAAWD,EAAgB,IAK5CD,WAJiBE,WAAWD,EAAgB,MCpBzC,SAASE,EAAOC,EAAgBC,GACrC,IAAKD,EACH,MAAM,IAAIE,MAAMD,EAEpB,C","sources":["webpack://@react-hive/honey-utils/webpack/bootstrap","webpack://@react-hive/honey-utils/webpack/runtime/define property getters","webpack://@react-hive/honey-utils/webpack/runtime/hasOwnProperty shorthand","webpack://@react-hive/honey-utils/webpack/runtime/make namespace object","webpack://@react-hive/honey-utils/./src/string.ts","webpack://@react-hive/honey-utils/./src/array.ts","webpack://@react-hive/honey-utils/./src/function.ts","webpack://@react-hive/honey-utils/./src/guards.ts","webpack://@react-hive/honey-utils/./src/math.ts","webpack://@react-hive/honey-utils/./src/dom.ts","webpack://@react-hive/honey-utils/./src/index.ts"],"sourcesContent":["// The require scope\nvar __webpack_require__ = {};\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","export const toKebabCase = (input: string): string =>\n input.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();\n\nexport const camelToDashCase = (input: string): string =>\n input.replace(/[A-Z]/g, letter => `-${letter.toLowerCase()}`);\n\n/**\n * Splits a string into an array of filtered from redundant spaces words.\n *\n * @param input - The input string to be split.\n *\n * @returns An array of words from the input string.\n */\nexport const splitStringIntoWords = (input: string): string[] => input.split(' ').filter(Boolean);\n\n/**\n * Generates a short, consistent hash string from an input string using a DJB2-inspired algorithm.\n *\n * This function uses a variation of the DJB2 algorithm, which is a simple yet effective hashing algorithm\n * based on bitwise XOR (`^`) and multiplication by 33. It produces a non-negative 32-bit integer,\n * which is then converted to a base-36 string (digits + lowercase letters) to produce a compact output.\n *\n * Useful for:\n * - Generating stable class names in CSS-in-JS libraries.\n * - Producing consistent cache keys.\n * - Quick and lightweight hashing needs where cryptographic security is not required.\n *\n * ⚠️ This is not cryptographically secure and should not be used for hashing passwords or sensitive data.\n *\n * @param input - The input string to hash.\n *\n * @returns A short, base-36 encoded hash string.\n *\n * @example\n * ```ts\n * const className = hashString('background-color: red;');\n * // → 'e4k1z0x'\n * ```\n */\nexport const hashString = (input: string): string => {\n let hash = 5381;\n\n for (let i = 0; i < input.length; i++) {\n hash = (hash * 33) ^ input.charCodeAt(i);\n }\n\n return (hash >>> 0).toString(36);\n};\n","/**\n * Filters out `null`, `undefined`, and other falsy values from an array,\n * returning a typed array of only truthy `Item` values.\n *\n * Useful when working with optional or nullable items that need to be sanitized.\n *\n * @template T - The type of the items in the array.\n *\n * @param array - An array of items that may include `null`, `undefined`, or falsy values.\n *\n * @returns A new array containing only truthy `Item` values.\n */\nexport const boolFilter = <T>(array: (T | false | null | undefined)[]): T[] =>\n array.filter(Boolean) as T[];\n","export const noop = () => {};\n\n/**\n * Invokes the given input if it is a function, passing the provided arguments.\n * Otherwise, returns the input as-is.\n *\n * @template Args - Tuple of argument types to pass to the function.\n * @template Result - Return type of the function or the value.\n *\n * @param input - A function to invoke with `args`, or a direct value of type `Result`.\n * @param args - Arguments to pass if `input` is a function.\n *\n * @returns The result of invoking the function, or the original value if it's not a function.\n */\nexport const invokeIfFunction = <Args extends any[], Result>(\n input: ((...args: Args) => Result) | Result,\n ...args: Args\n): Result => (typeof input === 'function' ? (input as (...args: Args) => Result)(...args) : input);\n","/**\n * Checks if a value is null.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is null; otherwise, `false`.\n */\nexport const isNull = (value: unknown): value is null => value === null;\n\n/**\n * Checks if a value is a string.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a string; otherwise, `false`.\n */\nexport const isString = (value: unknown): value is string => typeof value === 'string';\n\n/**\n * Checks if a value is a number.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a number; otherwise, `false`.\n */\nexport const isNumber = (value: unknown): value is number => typeof value === 'number';\n\n/**\n * Checks if a value is a boolean.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a boolean; otherwise, `false`.\n */\nexport const isBool = (value: unknown): value is boolean => typeof value === 'boolean';\n\n/**\n * Checks if a value is an object.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is an object; otherwise, `false`.\n */\nexport const isObject = (value: unknown): value is object => typeof value === 'object';\n\n/**\n * Checks if a value is an empty object (no own enumerable properties).\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is an empty object; otherwise, `false`.\n */\nexport const isEmptyObject = (value: unknown): value is Record<string, never> =>\n isObject(value) && !isNull(value) && Object.keys(value).length === 0;\n\n/**\n * Checks if a value is an array.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is an array; otherwise, `false`.\n */\nexport const isArray = (value: unknown): value is unknown[] => Array.isArray(value);\n\n/**\n * Checks if a value is an empty array.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is an empty array; otherwise, `false`.\n */\nexport const isEmptyArray = (value: unknown): value is [] => isArray(value) && value.length === 0;\n\n/**\n * Checks if a value is a function.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a function; otherwise, `false`.\n */\nexport const isFunction = (value: unknown) => typeof value === 'function';\n\n/**\n * Checks if a value is a Promise.\n *\n * @template T - The type of the value that the Promise resolves to.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a Promise; otherwise, `false`.\n */\nexport const isPromise = <T = unknown>(value: unknown): value is Promise<T> =>\n isFunction((value as Promise<T>)?.then);\n\n/**\n * Checks if a value is null or undefined.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is `null` or `undefined`, otherwise `false`.\n */\nexport const isNil = (value: unknown): value is null | undefined =>\n value === undefined || value === null;\n\n/**\n * Checks whether the provided value is considered \"empty\".\n *\n * A value is considered empty if it is:\n * - `null`\n * - `undefined`\n * - `''`\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is empty; otherwise, `false`.\n */\nexport const isNilOrEmptyString = (value: unknown): value is null | undefined =>\n value === '' || isNil(value);\n\n/**\n * Checks if a value is a Date object.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a Date object; otherwise, `false`.\n */\nexport const isDate = (value: unknown): value is Date => value instanceof Date;\n\n/**\n * Checks if a value is a valid Date object (not Invalid Date).\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a valid Date object; otherwise, `false`.\n */\nexport const isValidDate = (value: unknown): value is Date =>\n isDate(value) && !isNaN(value.getTime());\n\n/**\n * Checks if a value is a RegExp object.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a RegExp object; otherwise, `false`.\n */\nexport const isRegExp = (value: unknown): value is RegExp => value instanceof RegExp;\n\n/**\n * Checks if a value is a Map.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a Map; otherwise, `false`.\n */\nexport const isMap = (value: unknown): value is Map<unknown, unknown> => value instanceof Map;\n\n/**\n * Checks if a value is a Set.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a Set; otherwise, `false`.\n */\nexport const isSet = (value: unknown): value is Set<unknown> => value instanceof Set;\n\n/**\n * Checks if a value is a Symbol.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a Symbol; otherwise, `false`.\n */\nexport const isSymbol = (value: unknown): value is symbol => typeof value === 'symbol';\n\n/**\n * Checks if a value is undefined.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is undefined; otherwise, `false`.\n */\nexport const isUndefined = (value: unknown): value is undefined => value === undefined;\n\n/**\n * Checks if a value is a finite number.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a finite number; otherwise, `false`.\n */\nexport const isFiniteNumber = (value: unknown): value is number =>\n isNumber(value) && isFinite(value);\n\n/**\n * Checks if a value is an integer.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is an integer; otherwise, `false`.\n */\nexport const isInteger = (value: unknown): value is number =>\n isNumber(value) && Number.isInteger(value);\n","/**\n * Calculates the Euclidean distance between two points in 2D space.\n *\n * @param startX - The X coordinate of the starting point.\n * @param startY - The Y coordinate of the starting point.\n * @param endX - The X coordinate of the ending point.\n * @param endY - The Y coordinate of the ending point.\n *\n * @returns The Euclidean distance between the two points.\n */\nexport const calculateEuclideanDistance = (\n startX: number,\n startY: number,\n endX: number,\n endY: number,\n): number => {\n const deltaX = endX - startX;\n const deltaY = endY - startY;\n\n return Math.sqrt(deltaX ** 2 + deltaY ** 2);\n};\n\n/**\n * Calculates the moving speed.\n *\n * @param delta - The change in position (distance).\n * @param elapsedTime - The time taken to move the distance.\n *\n * @returns The calculated speed, which is the absolute value of delta divided by elapsed time.\n */\nexport const calculateMovingSpeed = (delta: number, elapsedTime: number): number =>\n Math.abs(delta / elapsedTime);\n\n/**\n * Calculates the specified percentage of a given value.\n *\n * @param value - The value to calculate the percentage of.\n * @param percentage - The percentage to calculate.\n *\n * @returns The calculated percentage of the value.\n */\nexport const calculatePercentage = (value: number, percentage: number): number => {\n return (value * percentage) / 100;\n};\n","interface HTMLElementTransformationValues {\n translateX: number;\n translateY: number;\n}\n\n/**\n * Get various transformation values from the transformation matrix of an element.\n *\n * @param element - The element with a transformation applied.\n *\n * @returns An object containing transformation values.\n */\nexport const getTransformationValues = (element: HTMLElement): HTMLElementTransformationValues => {\n const computedStyles = window.getComputedStyle(element);\n const transformValue = computedStyles.getPropertyValue('transform');\n\n const matrix = transformValue.match(/^matrix\\((.+)\\)$/);\n if (!matrix) {\n return {\n translateX: 0,\n translateY: 0,\n };\n }\n\n const transformMatrix = matrix[1].split(', ');\n\n const translateX = parseFloat(transformMatrix[4]);\n const translateY = parseFloat(transformMatrix[5]);\n\n return {\n translateX,\n translateY,\n };\n};\n","export * from './string';\nexport * from './array';\nexport * from './function';\nexport * from './guards';\nexport * from './math';\nexport * from './dom';\n\nexport function assert(condition: any, message: string): asserts condition {\n if (!condition) {\n throw new Error(message);\n }\n}\n"],"names":["__webpack_require__","exports","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","toKebabCase","input","replace","toLowerCase","camelToDashCase","letter","splitStringIntoWords","split","filter","Boolean","hashString","hash","i","length","charCodeAt","toString","boolFilter","array","noop","invokeIfFunction","args","isNull","isString","isNumber","isBool","isObject","isEmptyObject","keys","isArray","Array","isEmptyArray","isFunction","isPromise","then","isNil","isNilOrEmptyString","isDate","Date","isValidDate","isNaN","getTime","isRegExp","RegExp","isMap","Map","isSet","Set","isSymbol","isUndefined","undefined","isFiniteNumber","isFinite","isInteger","Number","calculateEuclideanDistance","startX","startY","endX","endY","deltaX","deltaY","Math","sqrt","calculateMovingSpeed","delta","elapsedTime","abs","calculatePercentage","percentage","getTransformationValues","element","matrix","window","getComputedStyle","getPropertyValue","match","translateX","translateY","transformMatrix","parseFloat","assert","condition","message","Error"],"sourceRoot":""}
|
|
1
|
+
{"version":3,"file":"index.cjs","mappings":"mBACA,IAAIA,EAAsB,CCA1BA,EAAwB,CAACC,EAASC,KACjC,IAAI,IAAIC,KAAOD,EACXF,EAAoBI,EAAEF,EAAYC,KAASH,EAAoBI,EAAEH,EAASE,IAC5EE,OAAOC,eAAeL,EAASE,EAAK,CAAEI,YAAY,EAAMC,IAAKN,EAAWC,MCJ3EH,EAAwB,CAACS,EAAKC,IAAUL,OAAOM,UAAUC,eAAeC,KAAKJ,EAAKC,GCClFV,EAAyBC,IACH,oBAAXa,QAA0BA,OAAOC,aAC1CV,OAAOC,eAAeL,EAASa,OAAOC,YAAa,CAAEC,MAAO,WAE7DX,OAAOC,eAAeL,EAAS,aAAc,CAAEe,OAAO,M,gsBCYhD,MAAMC,EAAeC,GAC1BA,EAAMC,QAAQ,qBAAsB,SAASC,cAqBlCC,EAAmBH,IAE9B,MAAMI,EAAYJ,EAAMK,OAAO,GACzBC,EAAeN,EAAMO,MAAM,GAQjC,OAL2BH,EAAUF,cAGfI,EAAaL,QAAQ,SAAUO,GAAU,IAAIA,EAAON,kBAY/DO,EAAwBT,GAA4BA,EAAMU,MAAM,KAAKC,OAAOC,SA0B5EC,EAAcb,IACzB,IAAIc,EAAO,KAEX,IAAK,IAAIC,EAAI,EAAGA,EAAIf,EAAMgB,OAAQD,IAChCD,EAAe,GAAPA,EAAad,EAAMiB,WAAWF,GAGxC,OAAQD,IAAS,GAAGI,SAAS,KC7FxB,S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O,GAAGnG,MAAM,MAKxC,MAAO,CACLwG,WAJiBG,WAAWD,EAAgB,IAK5CD,WAJiBE,WAAWD,EAAgB,M","sources":["webpack://@react-hive/honey-utils/webpack/bootstrap","webpack://@react-hive/honey-utils/webpack/runtime/define property getters","webpack://@react-hive/honey-utils/webpack/runtime/hasOwnProperty shorthand","webpack://@react-hive/honey-utils/webpack/runtime/make namespace object","webpack://@react-hive/honey-utils/./src/string.ts","webpack://@react-hive/honey-utils/./src/guards.ts","webpack://@react-hive/honey-utils/./src/array.ts","webpack://@react-hive/honey-utils/./src/function.ts","webpack://@react-hive/honey-utils/./src/math.ts","webpack://@react-hive/honey-utils/./src/dom.ts"],"sourcesContent":["// The require scope\nvar __webpack_require__ = {};\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","/**\n * Converts a string to kebab-case format.\n *\n * This function transforms camelCase or PascalCase strings into kebab-case by inserting\n * hyphens between lowercase and uppercase letters, then converting everything to lowercase.\n *\n * @param input - The string to convert to kebab-case.\n *\n * @returns The kebab-case formatted string.\n *\n * @example\n * ```ts\n * toKebabCase('helloWorld'); // → 'hello-world'\n * toKebabCase('HelloWorld'); // → 'hello-world'\n * toKebabCase('hello123World'); // → 'hello123-world'\n * ```\n */\nexport const toKebabCase = (input: string): string =>\n input.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();\n\n/**\n * Converts a camelCase string to dash-case format.\n *\n * This function transforms camelCase strings into dash-case by inserting\n * hyphens before uppercase letters and converting them to lowercase.\n * The function ensures that no hyphen is added at the start of the output string,\n * even if the input begins with an uppercase letter.\n *\n * @param input - The camelCase string to convert to dash-case.\n *\n * @returns The dash-case formatted string.\n *\n * @example\n * ```ts\n * camelToDashCase('helloWorld'); // → 'hello-world'\n * camelToDashCase('HelloWorld'); // → 'hello-world'\n * camelToDashCase('backgroundColor'); // → 'background-color'\n * ```\n */\nexport const camelToDashCase = (input: string): string => {\n // First handle the first character separately to avoid adding a hyphen at the start\n const firstChar = input.charAt(0);\n const restOfString = input.slice(1);\n \n // Convert the first character to lowercase without adding a hyphen\n const firstCharProcessed = firstChar.toLowerCase();\n \n // Process the rest of the string normally, adding hyphens before uppercase letters\n const restProcessed = restOfString.replace(/[A-Z]/g, letter => `-${letter.toLowerCase()}`);\n \n return firstCharProcessed + restProcessed;\n};\n\n/**\n * Splits a string into an array of filtered from redundant spaces words.\n *\n * @param input - The input string to be split.\n *\n * @returns An array of words from the input string.\n */\nexport const splitStringIntoWords = (input: string): string[] => input.split(' ').filter(Boolean);\n\n/**\n * Generates a short, consistent hash string from an input string using a DJB2-inspired algorithm.\n *\n * This function uses a variation of the DJB2 algorithm, which is a simple yet effective hashing algorithm\n * based on bitwise XOR (`^`) and multiplication by 33. It produces a non-negative 32-bit integer,\n * which is then converted to a base-36 string (digits + lowercase letters) to produce a compact output.\n *\n * Useful for:\n * - Generating stable class names in CSS-in-JS libraries.\n * - Producing consistent cache keys.\n * - Quick and lightweight hashing needs where cryptographic security is not required.\n *\n * ⚠️ This is not cryptographically secure and should not be used for hashing passwords or sensitive data.\n *\n * @param input - The input string to hash.\n *\n * @returns A short, base-36 encoded hash string.\n *\n * @example\n * ```ts\n * const className = hashString('background-color: red;');\n * // → 'e4k1z0x'\n * ```\n */\nexport const hashString = (input: string): string => {\n let hash = 5381;\n\n for (let i = 0; i < input.length; i++) {\n hash = (hash * 33) ^ input.charCodeAt(i);\n }\n\n return (hash >>> 0).toString(36);\n};\n","export function assert(condition: any, message: string): asserts condition {\n if (!condition) {\n throw new Error(message);\n }\n}\n\n/**\n * Checks if a value is null.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is null; otherwise, `false`.\n */\nexport const isNull = (value: unknown): value is null => value === null;\n\n/**\n * Checks if a value is a string.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a string; otherwise, `false`.\n */\nexport const isString = (value: unknown): value is string => typeof value === 'string';\n\n/**\n * Checks if a value is a number.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a number; otherwise, `false`.\n */\nexport const isNumber = (value: unknown): value is number => typeof value === 'number';\n\n/**\n * Checks if a value is a boolean.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a boolean; otherwise, `false`.\n */\nexport const isBool = (value: unknown): value is boolean => typeof value === 'boolean';\n\n/**\n * Checks if a value is an object.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is an object; otherwise, `false`.\n */\nexport const isObject = (value: unknown): value is object => typeof value === 'object';\n\n/**\n * Checks if a value is an empty object (no own enumerable properties).\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is an empty object; otherwise, `false`.\n */\nexport const isEmptyObject = (value: unknown): value is Record<string, never> =>\n isObject(value) && !isNull(value) && Object.keys(value).length === 0;\n\n/**\n * Checks if a value is an array.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is an array; otherwise, `false`.\n */\nexport const isArray = (value: unknown): value is unknown[] => Array.isArray(value);\n\n/**\n * Checks if a value is an empty array.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is an empty array; otherwise, `false`.\n */\nexport const isEmptyArray = (value: unknown): value is [] => isArray(value) && value.length === 0;\n\n/**\n * Checks if a value is a function.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a function; otherwise, `false`.\n */\nexport const isFunction = (value: unknown) => typeof value === 'function';\n\n/**\n * Checks if a value is a Promise.\n *\n * @template T - The type of the value that the Promise resolves to.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a Promise; otherwise, `false`.\n */\nexport const isPromise = <T = unknown>(value: unknown): value is Promise<T> =>\n isFunction((value as Promise<T>)?.then);\n\n/**\n * Checks if a value is null or undefined.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is `null` or `undefined`, otherwise `false`.\n */\nexport const isNil = (value: unknown): value is null | undefined =>\n value === undefined || value === null;\n\n/**\n * Checks whether the provided value is considered \"empty\".\n *\n * A value is considered empty if it is:\n * - `null`\n * - `undefined`\n * - `''`\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is empty; otherwise, `false`.\n */\nexport const isNilOrEmptyString = (value: unknown): value is null | undefined =>\n value === '' || isNil(value);\n\n/**\n * Checks if a value is a Date object.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a Date object; otherwise, `false`.\n */\nexport const isDate = (value: unknown): value is Date => value instanceof Date;\n\n/**\n * Checks if a value is a valid Date object (not Invalid Date).\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a valid Date object; otherwise, `false`.\n */\nexport const isValidDate = (value: unknown): value is Date =>\n isDate(value) && !isNaN(value.getTime());\n\n/**\n * Checks if a value is a RegExp object.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a RegExp object; otherwise, `false`.\n */\nexport const isRegExp = (value: unknown): value is RegExp => value instanceof RegExp;\n\n/**\n * Checks if a value is a Map.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a Map; otherwise, `false`.\n */\nexport const isMap = (value: unknown): value is Map<unknown, unknown> => value instanceof Map;\n\n/**\n * Checks if a value is a Set.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a Set; otherwise, `false`.\n */\nexport const isSet = (value: unknown): value is Set<unknown> => value instanceof Set;\n\n/**\n * Checks if a value is a Symbol.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a Symbol; otherwise, `false`.\n */\nexport const isSymbol = (value: unknown): value is symbol => typeof value === 'symbol';\n\n/**\n * Checks if a value is undefined.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is undefined; otherwise, `false`.\n */\nexport const isUndefined = (value: unknown): value is undefined => value === undefined;\n\n/**\n * Checks if a value is a finite number.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a finite number; otherwise, `false`.\n */\nexport const isFiniteNumber = (value: unknown): value is number =>\n isNumber(value) && isFinite(value);\n\n/**\n * Checks if a value is an integer.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is an integer; otherwise, `false`.\n */\nexport const isInteger = (value: unknown): value is number =>\n isNumber(value) && Number.isInteger(value);\n","import { assert } from './guards';\n\n/**\n * Filters out `null`, `undefined`, and other falsy values from an array,\n * returning a typed array of only truthy `Item` values.\n *\n * Useful when working with optional or nullable items that need to be sanitized.\n *\n * @template T - The type of the items in the array.\n *\n * @param array - An array of items that may include `null`, `undefined`, or falsy values.\n *\n * @returns A new array containing only truthy `Item` values.\n */\nexport const boolFilter = <T>(array: (T | false | null | undefined)[]): T[] =>\n array.filter(Boolean) as T[];\n\n/**\n * Returns a new array with duplicate values removed.\n *\n * Uses Set for efficient duplicate removal while preserving the original order.\n *\n * @template T - The type of the items in the array.\n *\n * @param array - The input array that may contain duplicate values.\n *\n * @returns A new array with only unique values, maintaining the original order.\n *\n * @example\n * ```ts\n * unique([1, 2, 2, 3, 1, 4]); // [1, 2, 3, 4]\n * unique(['a', 'b', 'a', 'c']); // ['a', 'b', 'c']\n * ```\n */\nexport const unique = <T>(array: T[]): T[] => [...new Set(array)];\n\n/**\n * Splits an array into chunks of the specified size.\n *\n * Useful for pagination, batch processing, or creating grid layouts.\n *\n * @template T - The type of the items in the array.\n *\n * @param array - The input array to be chunked.\n * @param size - The size of each chunk. Must be greater than 0.\n *\n * @returns An array of chunks, where each chunk is an array of the specified size\n * (except possibly the last chunk, which may be smaller).\n *\n * @example\n * ```ts\n * chunk([1, 2, 3, 4, 5], 2); // [[1, 2], [3, 4], [5]]\n * chunk(['a', 'b', 'c', 'd'], 3); // [['a', 'b', 'c'], ['d']]\n * ```\n */\nexport const chunk = <T>(array: T[], size: number): T[][] => {\n assert(size > 0, 'Chunk size must be greater than 0');\n\n return Array.from({ length: Math.ceil(array.length / size) }, (_, index) =>\n array.slice(index * size, (index + 1) * size),\n );\n};\n\n/**\n * Returns an array containing elements that exist in all provided arrays.\n *\n * @template T - The type of the items in the arrays.\n *\n * @param arrays - Two or more arrays to find common elements from.\n *\n * @returns A new array containing only the elements that exist in all input arrays.\n *\n * @example\n * ```ts\n * intersection([1, 2, 3], [2, 3, 4]); // [2, 3]\n * intersection(['a', 'b', 'c'], ['b', 'c', 'd'], ['b', 'e']); // ['b']\n * ```\n */\nexport const intersection = <T>(...arrays: T[][]): T[] => {\n if (arrays.length === 0) {\n return [];\n }\n\n if (arrays.length === 1) {\n return [...arrays[0]];\n }\n\n const [first, ...rest] = arrays;\n const uniqueFirst = unique(first);\n\n return uniqueFirst.filter(item => rest.every(array => array.includes(item)));\n};\n\n/**\n * Returns elements from the first array that don't exist in the second array.\n *\n * @template T - The type of the items in the arrays.\n *\n * @param array - The source array.\n * @param exclude - The array containing elements to exclude.\n *\n * @returns A new array with elements from the first array that don't exist in the second array.\n *\n * @example\n * ```ts\n * difference([1, 2, 3, 4], [2, 4]); // [1, 3]\n * difference(['a', 'b', 'c'], ['b']); // ['a', 'c']\n * ```\n */\nexport const difference = <T>(array: T[], exclude: T[]): T[] =>\n array.filter(item => !exclude.includes(item));\n","export const noop = () => {};\n\n/**\n * Invokes the given input if it is a function, passing the provided arguments.\n * Otherwise, returns the input as-is.\n *\n * @template Args - Tuple of argument types to pass to the function.\n * @template Result - Return type of the function or the value.\n *\n * @param input - A function to invoke with `args`, or a direct value of type `Result`.\n * @param args - Arguments to pass if `input` is a function.\n *\n * @returns The result of invoking the function, or the original value if it's not a function.\n */\nexport const invokeIfFunction = <Args extends unknown[], Result>(\n input: ((...args: Args) => Result) | Result,\n ...args: Args\n): Result => (typeof input === 'function' ? (input as (...args: Args) => Result)(...args) : input);\n\n/**\n * Creates a promise that resolves after the specified delay.\n *\n * Useful for creating artificial delays, implementing timeouts, or spacing operations.\n *\n * @param delayMs - The delay in milliseconds.\n *\n * @returns A promise that resolves after the specified delay.\n *\n * @example\n * ```ts\n * // Wait for 1 second\n * await delay(1000);\n * console.log('This logs after 1 second');\n *\n * // Use with other async operations\n * async function fetchWithTimeout() {\n * const timeoutPromise = delay(5000).then(() => {\n * throw new Error('Request timed out');\n * });\n *\n * return Promise.race([fetchData(), timeoutPromise]);\n * }\n * ```\n */\nexport const delay = (delayMs: number): Promise<void> =>\n new Promise(resolve => setTimeout(resolve, delayMs));\n\ninterface RetryOptions {\n /**\n * Maximum number of retry attempts before failing.\n *\n * @default 3\n */\n maxAttempts?: number;\n /**\n * Delay in milliseconds between retry attempts.\n * If `backoff` is true, this is the base delay for exponential backoff.\n *\n * @default 300\n */\n delayMs?: number;\n /**\n * Whether to use exponential backoff for delays between attempts.\n * When enabled, the delay is multiplied by 2 ^ (`attempt` - 1).\n *\n * @default true\n */\n backoff?: boolean;\n /**\n * Optional callback triggered before each retry attempt.\n *\n * @param attempt - The current attempt number (starting from 1).\n * @param error - The error that caused the retry.\n */\n onRetry?: (attempt: number, error: unknown) => void;\n}\n\n/**\n * Wraps an asynchronous function with retry logic.\n *\n * The returned function will attempt to call the original function up to `maxAttempts` times,\n * with a delay between retries. If all attempts fail, the last encountered error is thrown.\n *\n * Useful for operations that may fail intermittently, such as network requests.\n *\n * @template Task - The type of the async function to wrap.\n * @template TaskResult - The result type of the async function.\n *\n * @param task - The async function to wrap with retry logic.\n * @param options - Configuration options for retry behavior.\n *\n * @returns A function that wraps the original function with retry support.\n *\n * @example\n * ```ts\n * async function fetchData() {\n * const response = await fetch('/api/data');\n *\n * if (!response.ok) {\n * throw new Error('Network error');\n * }\n *\n * return await response.json();\n * }\n *\n * const fetchWithRetry = retry(fetchData, {\n * maxAttempts: 5,\n * delayMs: 500,\n * onRetry: (attempt, error) => {\n * console.warn(`Attempt ${attempt} failed:`, error);\n * }\n * });\n *\n * fetchWithRetry()\n * .then(data => console.log('Success:', data))\n * .catch(error => console.error('Failed after retries:', error));\n * ```\n */\nexport const retry = <Task extends (...args: unknown[]) => Promise<TaskResult>, TaskResult>(\n task: Task,\n { maxAttempts = 3, delayMs = 300, backoff = true, onRetry }: RetryOptions = {},\n): ((...args: Parameters<Task>) => Promise<TaskResult>) => {\n return async (...args: Parameters<Task>): Promise<TaskResult> => {\n let lastError: unknown;\n\n for (let attempt = 1; attempt <= maxAttempts; attempt++) {\n try {\n return await task(...args);\n } catch (e) {\n lastError = e;\n\n if (attempt < maxAttempts) {\n onRetry?.(attempt, e);\n\n const delayTime = backoff ? delayMs * 2 ** (attempt - 1) : delayMs;\n await delay(delayTime);\n }\n }\n }\n\n throw lastError;\n };\n};\n","/**\n * Calculates the Euclidean distance between two points in 2D space.\n *\n * @param startX - The X coordinate of the starting point.\n * @param startY - The Y coordinate of the starting point.\n * @param endX - The X coordinate of the ending point.\n * @param endY - The Y coordinate of the ending point.\n *\n * @returns The Euclidean distance between the two points.\n */\nexport const calculateEuclideanDistance = (\n startX: number,\n startY: number,\n endX: number,\n endY: number,\n): number => {\n const deltaX = endX - startX;\n const deltaY = endY - startY;\n\n return Math.sqrt(deltaX ** 2 + deltaY ** 2);\n};\n\n/**\n * Calculates the moving speed.\n *\n * @param delta - The change in position (distance).\n * @param elapsedTime - The time taken to move the distance.\n *\n * @returns The calculated speed, which is the absolute value of delta divided by elapsed time.\n */\nexport const calculateMovingSpeed = (delta: number, elapsedTime: number): number =>\n Math.abs(delta / elapsedTime);\n\n/**\n * Calculates the specified percentage of a given value.\n *\n * @param value - The value to calculate the percentage of.\n * @param percentage - The percentage to calculate.\n *\n * @returns The calculated percentage of the value.\n */\nexport const calculatePercentage = (value: number, percentage: number): number => {\n return (value * percentage) / 100;\n};\n","interface HTMLElementTransformationValues {\n translateX: number;\n translateY: number;\n}\n\n/**\n * Get various transformation values from the transformation matrix of an element.\n *\n * @param element - The element with a transformation applied.\n *\n * @returns An object containing transformation values.\n */\nexport const getTransformationValues = (element: HTMLElement): HTMLElementTransformationValues => {\n const computedStyles = window.getComputedStyle(element);\n const transformValue = computedStyles.getPropertyValue('transform');\n\n const matrix = transformValue.match(/^matrix\\((.+)\\)$/);\n if (!matrix) {\n return {\n translateX: 0,\n translateY: 0,\n };\n }\n\n const transformMatrix = matrix[1].split(', ');\n\n const translateX = parseFloat(transformMatrix[4]);\n const translateY = parseFloat(transformMatrix[5]);\n\n return {\n translateX,\n translateY,\n };\n};\n"],"names":["__webpack_require__","exports","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","toKebabCase","input","replace","toLowerCase","camelToDashCase","firstChar","charAt","restOfString","slice","letter","splitStringIntoWords","split","filter","Boolean","hashString","hash","i","length","charCodeAt","toString","assert","condition","message","Error","isNull","isString","isNumber","isBool","isObject","isEmptyObject","keys","isArray","Array","isEmptyArray","isFunction","isPromise","then","isNil","isNilOrEmptyString","isDate","Date","isValidDate","isNaN","getTime","isRegExp","RegExp","isMap","Map","isSet","Set","isSymbol","isUndefined","undefined","isFiniteNumber","isFinite","isInteger","Number","boolFilter","array","unique","chunk","size","from","Math","ceil","_","index","intersection","arrays","first","rest","item","every","includes","difference","exclude","noop","invokeIfFunction","args","delay","delayMs","Promise","resolve","setTimeout","retry","task","maxAttempts","backoff","onRetry","async","lastError","attempt","e","delayTime","calculateEuclideanDistance","startX","startY","endX","endY","deltaX","deltaY","sqrt","calculateMovingSpeed","delta","elapsedTime","abs","calculatePercentage","percentage","getTransformationValues","element","matrix","window","getComputedStyle","getPropertyValue","match","translateX","translateY","transformMatrix","parseFloat"],"sourceRoot":""}
|
package/dist/index.d.ts
CHANGED
package/dist/index.dev.cjs
CHANGED
|
@@ -10,8 +10,14 @@
|
|
|
10
10
|
|
|
11
11
|
__webpack_require__.r(__webpack_exports__);
|
|
12
12
|
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
13
|
-
/* harmony export */ boolFilter: () => (/* binding */ boolFilter)
|
|
13
|
+
/* harmony export */ boolFilter: () => (/* binding */ boolFilter),
|
|
14
|
+
/* harmony export */ chunk: () => (/* binding */ chunk),
|
|
15
|
+
/* harmony export */ difference: () => (/* binding */ difference),
|
|
16
|
+
/* harmony export */ intersection: () => (/* binding */ intersection),
|
|
17
|
+
/* harmony export */ unique: () => (/* binding */ unique)
|
|
14
18
|
/* harmony export */ });
|
|
19
|
+
/* harmony import */ var _guards__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./guards */ "./src/guards.ts");
|
|
20
|
+
|
|
15
21
|
/**
|
|
16
22
|
* Filters out `null`, `undefined`, and other falsy values from an array,
|
|
17
23
|
* returning a typed array of only truthy `Item` values.
|
|
@@ -25,6 +31,90 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
25
31
|
* @returns A new array containing only truthy `Item` values.
|
|
26
32
|
*/
|
|
27
33
|
const boolFilter = (array) => array.filter(Boolean);
|
|
34
|
+
/**
|
|
35
|
+
* Returns a new array with duplicate values removed.
|
|
36
|
+
*
|
|
37
|
+
* Uses Set for efficient duplicate removal while preserving the original order.
|
|
38
|
+
*
|
|
39
|
+
* @template T - The type of the items in the array.
|
|
40
|
+
*
|
|
41
|
+
* @param array - The input array that may contain duplicate values.
|
|
42
|
+
*
|
|
43
|
+
* @returns A new array with only unique values, maintaining the original order.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* unique([1, 2, 2, 3, 1, 4]); // [1, 2, 3, 4]
|
|
48
|
+
* unique(['a', 'b', 'a', 'c']); // ['a', 'b', 'c']
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
const unique = (array) => [...new Set(array)];
|
|
52
|
+
/**
|
|
53
|
+
* Splits an array into chunks of the specified size.
|
|
54
|
+
*
|
|
55
|
+
* Useful for pagination, batch processing, or creating grid layouts.
|
|
56
|
+
*
|
|
57
|
+
* @template T - The type of the items in the array.
|
|
58
|
+
*
|
|
59
|
+
* @param array - The input array to be chunked.
|
|
60
|
+
* @param size - The size of each chunk. Must be greater than 0.
|
|
61
|
+
*
|
|
62
|
+
* @returns An array of chunks, where each chunk is an array of the specified size
|
|
63
|
+
* (except possibly the last chunk, which may be smaller).
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts
|
|
67
|
+
* chunk([1, 2, 3, 4, 5], 2); // [[1, 2], [3, 4], [5]]
|
|
68
|
+
* chunk(['a', 'b', 'c', 'd'], 3); // [['a', 'b', 'c'], ['d']]
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
const chunk = (array, size) => {
|
|
72
|
+
(0,_guards__WEBPACK_IMPORTED_MODULE_0__.assert)(size > 0, 'Chunk size must be greater than 0');
|
|
73
|
+
return Array.from({ length: Math.ceil(array.length / size) }, (_, index) => array.slice(index * size, (index + 1) * size));
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Returns an array containing elements that exist in all provided arrays.
|
|
77
|
+
*
|
|
78
|
+
* @template T - The type of the items in the arrays.
|
|
79
|
+
*
|
|
80
|
+
* @param arrays - Two or more arrays to find common elements from.
|
|
81
|
+
*
|
|
82
|
+
* @returns A new array containing only the elements that exist in all input arrays.
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```ts
|
|
86
|
+
* intersection([1, 2, 3], [2, 3, 4]); // [2, 3]
|
|
87
|
+
* intersection(['a', 'b', 'c'], ['b', 'c', 'd'], ['b', 'e']); // ['b']
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
const intersection = (...arrays) => {
|
|
91
|
+
if (arrays.length === 0) {
|
|
92
|
+
return [];
|
|
93
|
+
}
|
|
94
|
+
if (arrays.length === 1) {
|
|
95
|
+
return [...arrays[0]];
|
|
96
|
+
}
|
|
97
|
+
const [first, ...rest] = arrays;
|
|
98
|
+
const uniqueFirst = unique(first);
|
|
99
|
+
return uniqueFirst.filter(item => rest.every(array => array.includes(item)));
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* Returns elements from the first array that don't exist in the second array.
|
|
103
|
+
*
|
|
104
|
+
* @template T - The type of the items in the arrays.
|
|
105
|
+
*
|
|
106
|
+
* @param array - The source array.
|
|
107
|
+
* @param exclude - The array containing elements to exclude.
|
|
108
|
+
*
|
|
109
|
+
* @returns A new array with elements from the first array that don't exist in the second array.
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```ts
|
|
113
|
+
* difference([1, 2, 3, 4], [2, 4]); // [1, 3]
|
|
114
|
+
* difference(['a', 'b', 'c'], ['b']); // ['a', 'c']
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
const difference = (array, exclude) => array.filter(item => !exclude.includes(item));
|
|
28
118
|
|
|
29
119
|
|
|
30
120
|
/***/ }),
|
|
@@ -76,8 +166,10 @@ const getTransformationValues = (element) => {
|
|
|
76
166
|
|
|
77
167
|
__webpack_require__.r(__webpack_exports__);
|
|
78
168
|
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
169
|
+
/* harmony export */ delay: () => (/* binding */ delay),
|
|
79
170
|
/* harmony export */ invokeIfFunction: () => (/* binding */ invokeIfFunction),
|
|
80
|
-
/* harmony export */ noop: () => (/* binding */ noop)
|
|
171
|
+
/* harmony export */ noop: () => (/* binding */ noop),
|
|
172
|
+
/* harmony export */ retry: () => (/* binding */ retry)
|
|
81
173
|
/* harmony export */ });
|
|
82
174
|
const noop = () => { };
|
|
83
175
|
/**
|
|
@@ -93,6 +185,92 @@ const noop = () => { };
|
|
|
93
185
|
* @returns The result of invoking the function, or the original value if it's not a function.
|
|
94
186
|
*/
|
|
95
187
|
const invokeIfFunction = (input, ...args) => (typeof input === 'function' ? input(...args) : input);
|
|
188
|
+
/**
|
|
189
|
+
* Creates a promise that resolves after the specified delay.
|
|
190
|
+
*
|
|
191
|
+
* Useful for creating artificial delays, implementing timeouts, or spacing operations.
|
|
192
|
+
*
|
|
193
|
+
* @param delayMs - The delay in milliseconds.
|
|
194
|
+
*
|
|
195
|
+
* @returns A promise that resolves after the specified delay.
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* ```ts
|
|
199
|
+
* // Wait for 1 second
|
|
200
|
+
* await delay(1000);
|
|
201
|
+
* console.log('This logs after 1 second');
|
|
202
|
+
*
|
|
203
|
+
* // Use with other async operations
|
|
204
|
+
* async function fetchWithTimeout() {
|
|
205
|
+
* const timeoutPromise = delay(5000).then(() => {
|
|
206
|
+
* throw new Error('Request timed out');
|
|
207
|
+
* });
|
|
208
|
+
*
|
|
209
|
+
* return Promise.race([fetchData(), timeoutPromise]);
|
|
210
|
+
* }
|
|
211
|
+
* ```
|
|
212
|
+
*/
|
|
213
|
+
const delay = (delayMs) => new Promise(resolve => setTimeout(resolve, delayMs));
|
|
214
|
+
/**
|
|
215
|
+
* Wraps an asynchronous function with retry logic.
|
|
216
|
+
*
|
|
217
|
+
* The returned function will attempt to call the original function up to `maxAttempts` times,
|
|
218
|
+
* with a delay between retries. If all attempts fail, the last encountered error is thrown.
|
|
219
|
+
*
|
|
220
|
+
* Useful for operations that may fail intermittently, such as network requests.
|
|
221
|
+
*
|
|
222
|
+
* @template Task - The type of the async function to wrap.
|
|
223
|
+
* @template TaskResult - The result type of the async function.
|
|
224
|
+
*
|
|
225
|
+
* @param task - The async function to wrap with retry logic.
|
|
226
|
+
* @param options - Configuration options for retry behavior.
|
|
227
|
+
*
|
|
228
|
+
* @returns A function that wraps the original function with retry support.
|
|
229
|
+
*
|
|
230
|
+
* @example
|
|
231
|
+
* ```ts
|
|
232
|
+
* async function fetchData() {
|
|
233
|
+
* const response = await fetch('/api/data');
|
|
234
|
+
*
|
|
235
|
+
* if (!response.ok) {
|
|
236
|
+
* throw new Error('Network error');
|
|
237
|
+
* }
|
|
238
|
+
*
|
|
239
|
+
* return await response.json();
|
|
240
|
+
* }
|
|
241
|
+
*
|
|
242
|
+
* const fetchWithRetry = retry(fetchData, {
|
|
243
|
+
* maxAttempts: 5,
|
|
244
|
+
* delayMs: 500,
|
|
245
|
+
* onRetry: (attempt, error) => {
|
|
246
|
+
* console.warn(`Attempt ${attempt} failed:`, error);
|
|
247
|
+
* }
|
|
248
|
+
* });
|
|
249
|
+
*
|
|
250
|
+
* fetchWithRetry()
|
|
251
|
+
* .then(data => console.log('Success:', data))
|
|
252
|
+
* .catch(error => console.error('Failed after retries:', error));
|
|
253
|
+
* ```
|
|
254
|
+
*/
|
|
255
|
+
const retry = (task, { maxAttempts = 3, delayMs = 300, backoff = true, onRetry } = {}) => {
|
|
256
|
+
return async (...args) => {
|
|
257
|
+
let lastError;
|
|
258
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
259
|
+
try {
|
|
260
|
+
return await task(...args);
|
|
261
|
+
}
|
|
262
|
+
catch (e) {
|
|
263
|
+
lastError = e;
|
|
264
|
+
if (attempt < maxAttempts) {
|
|
265
|
+
onRetry?.(attempt, e);
|
|
266
|
+
const delayTime = backoff ? delayMs * 2 ** (attempt - 1) : delayMs;
|
|
267
|
+
await delay(delayTime);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
throw lastError;
|
|
272
|
+
};
|
|
273
|
+
};
|
|
96
274
|
|
|
97
275
|
|
|
98
276
|
/***/ }),
|
|
@@ -105,6 +283,7 @@ const invokeIfFunction = (input, ...args) => (typeof input === 'function' ? inpu
|
|
|
105
283
|
|
|
106
284
|
__webpack_require__.r(__webpack_exports__);
|
|
107
285
|
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
286
|
+
/* harmony export */ assert: () => (/* binding */ assert),
|
|
108
287
|
/* harmony export */ isArray: () => (/* binding */ isArray),
|
|
109
288
|
/* harmony export */ isBool: () => (/* binding */ isBool),
|
|
110
289
|
/* harmony export */ isDate: () => (/* binding */ isDate),
|
|
@@ -127,6 +306,11 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
127
306
|
/* harmony export */ isUndefined: () => (/* binding */ isUndefined),
|
|
128
307
|
/* harmony export */ isValidDate: () => (/* binding */ isValidDate)
|
|
129
308
|
/* harmony export */ });
|
|
309
|
+
function assert(condition, message) {
|
|
310
|
+
if (!condition) {
|
|
311
|
+
throw new Error(message);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
130
314
|
/**
|
|
131
315
|
* Checks if a value is null.
|
|
132
316
|
*
|
|
@@ -370,8 +554,53 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
370
554
|
/* harmony export */ splitStringIntoWords: () => (/* binding */ splitStringIntoWords),
|
|
371
555
|
/* harmony export */ toKebabCase: () => (/* binding */ toKebabCase)
|
|
372
556
|
/* harmony export */ });
|
|
557
|
+
/**
|
|
558
|
+
* Converts a string to kebab-case format.
|
|
559
|
+
*
|
|
560
|
+
* This function transforms camelCase or PascalCase strings into kebab-case by inserting
|
|
561
|
+
* hyphens between lowercase and uppercase letters, then converting everything to lowercase.
|
|
562
|
+
*
|
|
563
|
+
* @param input - The string to convert to kebab-case.
|
|
564
|
+
*
|
|
565
|
+
* @returns The kebab-case formatted string.
|
|
566
|
+
*
|
|
567
|
+
* @example
|
|
568
|
+
* ```ts
|
|
569
|
+
* toKebabCase('helloWorld'); // → 'hello-world'
|
|
570
|
+
* toKebabCase('HelloWorld'); // → 'hello-world'
|
|
571
|
+
* toKebabCase('hello123World'); // → 'hello123-world'
|
|
572
|
+
* ```
|
|
573
|
+
*/
|
|
373
574
|
const toKebabCase = (input) => input.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();
|
|
374
|
-
|
|
575
|
+
/**
|
|
576
|
+
* Converts a camelCase string to dash-case format.
|
|
577
|
+
*
|
|
578
|
+
* This function transforms camelCase strings into dash-case by inserting
|
|
579
|
+
* hyphens before uppercase letters and converting them to lowercase.
|
|
580
|
+
* The function ensures that no hyphen is added at the start of the output string,
|
|
581
|
+
* even if the input begins with an uppercase letter.
|
|
582
|
+
*
|
|
583
|
+
* @param input - The camelCase string to convert to dash-case.
|
|
584
|
+
*
|
|
585
|
+
* @returns The dash-case formatted string.
|
|
586
|
+
*
|
|
587
|
+
* @example
|
|
588
|
+
* ```ts
|
|
589
|
+
* camelToDashCase('helloWorld'); // → 'hello-world'
|
|
590
|
+
* camelToDashCase('HelloWorld'); // → 'hello-world'
|
|
591
|
+
* camelToDashCase('backgroundColor'); // → 'background-color'
|
|
592
|
+
* ```
|
|
593
|
+
*/
|
|
594
|
+
const camelToDashCase = (input) => {
|
|
595
|
+
// First handle the first character separately to avoid adding a hyphen at the start
|
|
596
|
+
const firstChar = input.charAt(0);
|
|
597
|
+
const restOfString = input.slice(1);
|
|
598
|
+
// Convert the first character to lowercase without adding a hyphen
|
|
599
|
+
const firstCharProcessed = firstChar.toLowerCase();
|
|
600
|
+
// Process the rest of the string normally, adding hyphens before uppercase letters
|
|
601
|
+
const restProcessed = restOfString.replace(/[A-Z]/g, letter => `-${letter.toLowerCase()}`);
|
|
602
|
+
return firstCharProcessed + restProcessed;
|
|
603
|
+
};
|
|
375
604
|
/**
|
|
376
605
|
* Splits a string into an array of filtered from redundant spaces words.
|
|
377
606
|
*
|
|
@@ -479,14 +708,18 @@ var __webpack_exports__ = {};
|
|
|
479
708
|
\**********************/
|
|
480
709
|
__webpack_require__.r(__webpack_exports__);
|
|
481
710
|
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
482
|
-
/* harmony export */ assert: () => (/*
|
|
711
|
+
/* harmony export */ assert: () => (/* reexport safe */ _guards__WEBPACK_IMPORTED_MODULE_3__.assert),
|
|
483
712
|
/* harmony export */ boolFilter: () => (/* reexport safe */ _array__WEBPACK_IMPORTED_MODULE_1__.boolFilter),
|
|
484
713
|
/* harmony export */ calculateEuclideanDistance: () => (/* reexport safe */ _math__WEBPACK_IMPORTED_MODULE_4__.calculateEuclideanDistance),
|
|
485
714
|
/* harmony export */ calculateMovingSpeed: () => (/* reexport safe */ _math__WEBPACK_IMPORTED_MODULE_4__.calculateMovingSpeed),
|
|
486
715
|
/* harmony export */ calculatePercentage: () => (/* reexport safe */ _math__WEBPACK_IMPORTED_MODULE_4__.calculatePercentage),
|
|
487
716
|
/* harmony export */ camelToDashCase: () => (/* reexport safe */ _string__WEBPACK_IMPORTED_MODULE_0__.camelToDashCase),
|
|
717
|
+
/* harmony export */ chunk: () => (/* reexport safe */ _array__WEBPACK_IMPORTED_MODULE_1__.chunk),
|
|
718
|
+
/* harmony export */ delay: () => (/* reexport safe */ _function__WEBPACK_IMPORTED_MODULE_2__.delay),
|
|
719
|
+
/* harmony export */ difference: () => (/* reexport safe */ _array__WEBPACK_IMPORTED_MODULE_1__.difference),
|
|
488
720
|
/* harmony export */ getTransformationValues: () => (/* reexport safe */ _dom__WEBPACK_IMPORTED_MODULE_5__.getTransformationValues),
|
|
489
721
|
/* harmony export */ hashString: () => (/* reexport safe */ _string__WEBPACK_IMPORTED_MODULE_0__.hashString),
|
|
722
|
+
/* harmony export */ intersection: () => (/* reexport safe */ _array__WEBPACK_IMPORTED_MODULE_1__.intersection),
|
|
490
723
|
/* harmony export */ invokeIfFunction: () => (/* reexport safe */ _function__WEBPACK_IMPORTED_MODULE_2__.invokeIfFunction),
|
|
491
724
|
/* harmony export */ isArray: () => (/* reexport safe */ _guards__WEBPACK_IMPORTED_MODULE_3__.isArray),
|
|
492
725
|
/* harmony export */ isBool: () => (/* reexport safe */ _guards__WEBPACK_IMPORTED_MODULE_3__.isBool),
|
|
@@ -510,8 +743,10 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
510
743
|
/* harmony export */ isUndefined: () => (/* reexport safe */ _guards__WEBPACK_IMPORTED_MODULE_3__.isUndefined),
|
|
511
744
|
/* harmony export */ isValidDate: () => (/* reexport safe */ _guards__WEBPACK_IMPORTED_MODULE_3__.isValidDate),
|
|
512
745
|
/* harmony export */ noop: () => (/* reexport safe */ _function__WEBPACK_IMPORTED_MODULE_2__.noop),
|
|
746
|
+
/* harmony export */ retry: () => (/* reexport safe */ _function__WEBPACK_IMPORTED_MODULE_2__.retry),
|
|
513
747
|
/* harmony export */ splitStringIntoWords: () => (/* reexport safe */ _string__WEBPACK_IMPORTED_MODULE_0__.splitStringIntoWords),
|
|
514
|
-
/* harmony export */ toKebabCase: () => (/* reexport safe */ _string__WEBPACK_IMPORTED_MODULE_0__.toKebabCase)
|
|
748
|
+
/* harmony export */ toKebabCase: () => (/* reexport safe */ _string__WEBPACK_IMPORTED_MODULE_0__.toKebabCase),
|
|
749
|
+
/* harmony export */ unique: () => (/* reexport safe */ _array__WEBPACK_IMPORTED_MODULE_1__.unique)
|
|
515
750
|
/* harmony export */ });
|
|
516
751
|
/* harmony import */ var _string__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./string */ "./src/string.ts");
|
|
517
752
|
/* harmony import */ var _array__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./array */ "./src/array.ts");
|
|
@@ -525,11 +760,6 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
525
760
|
|
|
526
761
|
|
|
527
762
|
|
|
528
|
-
function assert(condition, message) {
|
|
529
|
-
if (!condition) {
|
|
530
|
-
throw new Error(message);
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
763
|
|
|
534
764
|
})();
|
|
535
765
|
|
package/dist/index.dev.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.dev.cjs","mappings":";;;;;;;;;;;;;;AAAA;;;;;;;;;;;GAWG;AACI,MAAM,UAAU,GAAG,CAAI,KAAuC,EAAO,EAAE,CAC5E,KAAK,CAAC,MAAM,CAAC,OAAO,CAAQ,CAAC;;;;;;;;;;;;;;;ACR/B;;;;;;GAMG;AACI,MAAM,uBAAuB,GAAG,CAAC,OAAoB,EAAmC,EAAE;IAC/F,MAAM,cAAc,GAAG,MAAM,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;IACxD,MAAM,cAAc,GAAG,cAAc,CAAC,gBAAgB,CAAC,WAAW,C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UAEA;UACA;;UAEA;UACA;UACA;;;;;WCtBA;WACA;WACA;WACA;WACA,yCAAyC,wCAAwC;WACjF;WACA;WACA,E;;;;;WCPA,wF;;;;;WCAA;WACA;WACA;WACA,uDAAuD,iBAAiB;WACxE;WACA,gDAAgD,aAAa;WAC7D,E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACNyB;AACD;AACG;AACF;AACF;AACD;AAEf,SAAS,MAAM,CAAC,SAAc,EAAE,OAAe;IACpD,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;IAC3B,CAAC;AACH,CAAC","sources":["webpack://@react-hive/honey-utils/./src/array.ts","webpack://@react-hive/honey-utils/./src/dom.ts","webpack://@react-hive/honey-utils/./src/function.ts","webpack://@react-hive/honey-utils/./src/guards.ts","webpack://@react-hive/honey-utils/./src/math.ts","webpack://@react-hive/honey-utils/./src/string.ts","webpack://@react-hive/honey-utils/webpack/bootstrap","webpack://@react-hive/honey-utils/webpack/runtime/define property getters","webpack://@react-hive/honey-utils/webpack/runtime/hasOwnProperty shorthand","webpack://@react-hive/honey-utils/webpack/runtime/make namespace object","webpack://@react-hive/honey-utils/./src/index.ts"],"sourcesContent":["/**\n * Filters out `null`, `undefined`, and other falsy values from an array,\n * returning a typed array of only truthy `Item` values.\n *\n * Useful when working with optional or nullable items that need to be sanitized.\n *\n * @template T - The type of the items in the array.\n *\n * @param array - An array of items that may include `null`, `undefined`, or falsy values.\n *\n * @returns A new array containing only truthy `Item` values.\n */\nexport const boolFilter = <T>(array: (T | false | null | undefined)[]): T[] =>\n array.filter(Boolean) as T[];\n","interface HTMLElementTransformationValues {\n translateX: number;\n translateY: number;\n}\n\n/**\n * Get various transformation values from the transformation matrix of an element.\n *\n * @param element - The element with a transformation applied.\n *\n * @returns An object containing transformation values.\n */\nexport const getTransformationValues = (element: HTMLElement): HTMLElementTransformationValues => {\n const computedStyles = window.getComputedStyle(element);\n const transformValue = computedStyles.getPropertyValue('transform');\n\n const matrix = transformValue.match(/^matrix\\((.+)\\)$/);\n if (!matrix) {\n return {\n translateX: 0,\n translateY: 0,\n };\n }\n\n const transformMatrix = matrix[1].split(', ');\n\n const translateX = parseFloat(transformMatrix[4]);\n const translateY = parseFloat(transformMatrix[5]);\n\n return {\n translateX,\n translateY,\n };\n};\n","export const noop = () => {};\n\n/**\n * Invokes the given input if it is a function, passing the provided arguments.\n * Otherwise, returns the input as-is.\n *\n * @template Args - Tuple of argument types to pass to the function.\n * @template Result - Return type of the function or the value.\n *\n * @param input - A function to invoke with `args`, or a direct value of type `Result`.\n * @param args - Arguments to pass if `input` is a function.\n *\n * @returns The result of invoking the function, or the original value if it's not a function.\n */\nexport const invokeIfFunction = <Args extends any[], Result>(\n input: ((...args: Args) => Result) | Result,\n ...args: Args\n): Result => (typeof input === 'function' ? (input as (...args: Args) => Result)(...args) : input);\n","/**\n * Checks if a value is null.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is null; otherwise, `false`.\n */\nexport const isNull = (value: unknown): value is null => value === null;\n\n/**\n * Checks if a value is a string.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a string; otherwise, `false`.\n */\nexport const isString = (value: unknown): value is string => typeof value === 'string';\n\n/**\n * Checks if a value is a number.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a number; otherwise, `false`.\n */\nexport const isNumber = (value: unknown): value is number => typeof value === 'number';\n\n/**\n * Checks if a value is a boolean.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a boolean; otherwise, `false`.\n */\nexport const isBool = (value: unknown): value is boolean => typeof value === 'boolean';\n\n/**\n * Checks if a value is an object.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is an object; otherwise, `false`.\n */\nexport const isObject = (value: unknown): value is object => typeof value === 'object';\n\n/**\n * Checks if a value is an empty object (no own enumerable properties).\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is an empty object; otherwise, `false`.\n */\nexport const isEmptyObject = (value: unknown): value is Record<string, never> =>\n isObject(value) && !isNull(value) && Object.keys(value).length === 0;\n\n/**\n * Checks if a value is an array.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is an array; otherwise, `false`.\n */\nexport const isArray = (value: unknown): value is unknown[] => Array.isArray(value);\n\n/**\n * Checks if a value is an empty array.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is an empty array; otherwise, `false`.\n */\nexport const isEmptyArray = (value: unknown): value is [] => isArray(value) && value.length === 0;\n\n/**\n * Checks if a value is a function.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a function; otherwise, `false`.\n */\nexport const isFunction = (value: unknown) => typeof value === 'function';\n\n/**\n * Checks if a value is a Promise.\n *\n * @template T - The type of the value that the Promise resolves to.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a Promise; otherwise, `false`.\n */\nexport const isPromise = <T = unknown>(value: unknown): value is Promise<T> =>\n isFunction((value as Promise<T>)?.then);\n\n/**\n * Checks if a value is null or undefined.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is `null` or `undefined`, otherwise `false`.\n */\nexport const isNil = (value: unknown): value is null | undefined =>\n value === undefined || value === null;\n\n/**\n * Checks whether the provided value is considered \"empty\".\n *\n * A value is considered empty if it is:\n * - `null`\n * - `undefined`\n * - `''`\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is empty; otherwise, `false`.\n */\nexport const isNilOrEmptyString = (value: unknown): value is null | undefined =>\n value === '' || isNil(value);\n\n/**\n * Checks if a value is a Date object.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a Date object; otherwise, `false`.\n */\nexport const isDate = (value: unknown): value is Date => value instanceof Date;\n\n/**\n * Checks if a value is a valid Date object (not Invalid Date).\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a valid Date object; otherwise, `false`.\n */\nexport const isValidDate = (value: unknown): value is Date =>\n isDate(value) && !isNaN(value.getTime());\n\n/**\n * Checks if a value is a RegExp object.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a RegExp object; otherwise, `false`.\n */\nexport const isRegExp = (value: unknown): value is RegExp => value instanceof RegExp;\n\n/**\n * Checks if a value is a Map.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a Map; otherwise, `false`.\n */\nexport const isMap = (value: unknown): value is Map<unknown, unknown> => value instanceof Map;\n\n/**\n * Checks if a value is a Set.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a Set; otherwise, `false`.\n */\nexport const isSet = (value: unknown): value is Set<unknown> => value instanceof Set;\n\n/**\n * Checks if a value is a Symbol.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a Symbol; otherwise, `false`.\n */\nexport const isSymbol = (value: unknown): value is symbol => typeof value === 'symbol';\n\n/**\n * Checks if a value is undefined.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is undefined; otherwise, `false`.\n */\nexport const isUndefined = (value: unknown): value is undefined => value === undefined;\n\n/**\n * Checks if a value is a finite number.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a finite number; otherwise, `false`.\n */\nexport const isFiniteNumber = (value: unknown): value is number =>\n isNumber(value) && isFinite(value);\n\n/**\n * Checks if a value is an integer.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is an integer; otherwise, `false`.\n */\nexport const isInteger = (value: unknown): value is number =>\n isNumber(value) && Number.isInteger(value);\n","/**\n * Calculates the Euclidean distance between two points in 2D space.\n *\n * @param startX - The X coordinate of the starting point.\n * @param startY - The Y coordinate of the starting point.\n * @param endX - The X coordinate of the ending point.\n * @param endY - The Y coordinate of the ending point.\n *\n * @returns The Euclidean distance between the two points.\n */\nexport const calculateEuclideanDistance = (\n startX: number,\n startY: number,\n endX: number,\n endY: number,\n): number => {\n const deltaX = endX - startX;\n const deltaY = endY - startY;\n\n return Math.sqrt(deltaX ** 2 + deltaY ** 2);\n};\n\n/**\n * Calculates the moving speed.\n *\n * @param delta - The change in position (distance).\n * @param elapsedTime - The time taken to move the distance.\n *\n * @returns The calculated speed, which is the absolute value of delta divided by elapsed time.\n */\nexport const calculateMovingSpeed = (delta: number, elapsedTime: number): number =>\n Math.abs(delta / elapsedTime);\n\n/**\n * Calculates the specified percentage of a given value.\n *\n * @param value - The value to calculate the percentage of.\n * @param percentage - The percentage to calculate.\n *\n * @returns The calculated percentage of the value.\n */\nexport const calculatePercentage = (value: number, percentage: number): number => {\n return (value * percentage) / 100;\n};\n","export const toKebabCase = (input: string): string =>\n input.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();\n\nexport const camelToDashCase = (input: string): string =>\n input.replace(/[A-Z]/g, letter => `-${letter.toLowerCase()}`);\n\n/**\n * Splits a string into an array of filtered from redundant spaces words.\n *\n * @param input - The input string to be split.\n *\n * @returns An array of words from the input string.\n */\nexport const splitStringIntoWords = (input: string): string[] => input.split(' ').filter(Boolean);\n\n/**\n * Generates a short, consistent hash string from an input string using a DJB2-inspired algorithm.\n *\n * This function uses a variation of the DJB2 algorithm, which is a simple yet effective hashing algorithm\n * based on bitwise XOR (`^`) and multiplication by 33. It produces a non-negative 32-bit integer,\n * which is then converted to a base-36 string (digits + lowercase letters) to produce a compact output.\n *\n * Useful for:\n * - Generating stable class names in CSS-in-JS libraries.\n * - Producing consistent cache keys.\n * - Quick and lightweight hashing needs where cryptographic security is not required.\n *\n * ⚠️ This is not cryptographically secure and should not be used for hashing passwords or sensitive data.\n *\n * @param input - The input string to hash.\n *\n * @returns A short, base-36 encoded hash string.\n *\n * @example\n * ```ts\n * const className = hashString('background-color: red;');\n * // → 'e4k1z0x'\n * ```\n */\nexport const hashString = (input: string): string => {\n let hash = 5381;\n\n for (let i = 0; i < input.length; i++) {\n hash = (hash * 33) ^ input.charCodeAt(i);\n }\n\n return (hash >>> 0).toString(36);\n};\n","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","export * from './string';\nexport * from './array';\nexport * from './function';\nexport * from './guards';\nexport * from './math';\nexport * from './dom';\n\nexport function assert(condition: any, message: string): asserts condition {\n if (!condition) {\n throw new Error(message);\n }\n}\n"],"names":[],"sourceRoot":""}
|
|
1
|
+
{"version":3,"file":"index.dev.cjs","mappings":";;;;;;;;;;;;;;;;;;;AAAkC;AAElC;;;;;;;;;;;GAWG;AACI,MAAM,UAAU,GAAG,CAAI,KAAuC,EAAO,EAAE,CAC5E,KAAK,CAAC,MAAM,CAAC,OAAO,CAAQ,CAAC;AAE/B;;;;;;;;;;;;;;;;GAgBG;AACI,MAAM,MAAM,GAAG,CAAI,KAAU,EAAO,EAAE,CAAC,CAAC,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;AAElE;;;;;;;;;;;;;;;;;;GAkBG;AACI,MAAM,KAAK,GAAG,CAAI,KAAU,EAAE,IAAY,EAAS,EAAE;IAC1D,+CAAM,CAAC,IA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;;;;;;;;;GAuBG;AACI,MAAM,UAAU,GAAG,CAAC,KAAa,EAAU,EAAE;IAClD,IAAI,IAAI,GAAG,IAAI,CAAC;IAEhB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACtC,IAAI,GAAG,CAAC,IAAI,GAAG,EAAE,CAAC,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IAC3C,CAAC;IAED,OAAO,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;AACnC,CAAC,CAAC;;;;;;;UC9FF;UACA;;UAEA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;;UAEA;UACA;;UAEA;UACA;UACA;;;;;WCtBA;WACA;WACA;WACA;WACA,yCAAyC,wCAAwC;WACjF;WACA;WACA,E;;;;;WCPA,wF;;;;;WCAA;WACA;WACA;WACA,uDAAuD,iBAAiB;WACxE;WACA,gDAAgD,aAAa;WAC7D,E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACNyB;AACD;AACG;AACF;AACF;AACD","sources":["webpack://@react-hive/honey-utils/./src/array.ts","webpack://@react-hive/honey-utils/./src/dom.ts","webpack://@react-hive/honey-utils/./src/function.ts","webpack://@react-hive/honey-utils/./src/guards.ts","webpack://@react-hive/honey-utils/./src/math.ts","webpack://@react-hive/honey-utils/./src/string.ts","webpack://@react-hive/honey-utils/webpack/bootstrap","webpack://@react-hive/honey-utils/webpack/runtime/define property getters","webpack://@react-hive/honey-utils/webpack/runtime/hasOwnProperty shorthand","webpack://@react-hive/honey-utils/webpack/runtime/make namespace object","webpack://@react-hive/honey-utils/./src/index.ts"],"sourcesContent":["import { assert } from './guards';\n\n/**\n * Filters out `null`, `undefined`, and other falsy values from an array,\n * returning a typed array of only truthy `Item` values.\n *\n * Useful when working with optional or nullable items that need to be sanitized.\n *\n * @template T - The type of the items in the array.\n *\n * @param array - An array of items that may include `null`, `undefined`, or falsy values.\n *\n * @returns A new array containing only truthy `Item` values.\n */\nexport const boolFilter = <T>(array: (T | false | null | undefined)[]): T[] =>\n array.filter(Boolean) as T[];\n\n/**\n * Returns a new array with duplicate values removed.\n *\n * Uses Set for efficient duplicate removal while preserving the original order.\n *\n * @template T - The type of the items in the array.\n *\n * @param array - The input array that may contain duplicate values.\n *\n * @returns A new array with only unique values, maintaining the original order.\n *\n * @example\n * ```ts\n * unique([1, 2, 2, 3, 1, 4]); // [1, 2, 3, 4]\n * unique(['a', 'b', 'a', 'c']); // ['a', 'b', 'c']\n * ```\n */\nexport const unique = <T>(array: T[]): T[] => [...new Set(array)];\n\n/**\n * Splits an array into chunks of the specified size.\n *\n * Useful for pagination, batch processing, or creating grid layouts.\n *\n * @template T - The type of the items in the array.\n *\n * @param array - The input array to be chunked.\n * @param size - The size of each chunk. Must be greater than 0.\n *\n * @returns An array of chunks, where each chunk is an array of the specified size\n * (except possibly the last chunk, which may be smaller).\n *\n * @example\n * ```ts\n * chunk([1, 2, 3, 4, 5], 2); // [[1, 2], [3, 4], [5]]\n * chunk(['a', 'b', 'c', 'd'], 3); // [['a', 'b', 'c'], ['d']]\n * ```\n */\nexport const chunk = <T>(array: T[], size: number): T[][] => {\n assert(size > 0, 'Chunk size must be greater than 0');\n\n return Array.from({ length: Math.ceil(array.length / size) }, (_, index) =>\n array.slice(index * size, (index + 1) * size),\n );\n};\n\n/**\n * Returns an array containing elements that exist in all provided arrays.\n *\n * @template T - The type of the items in the arrays.\n *\n * @param arrays - Two or more arrays to find common elements from.\n *\n * @returns A new array containing only the elements that exist in all input arrays.\n *\n * @example\n * ```ts\n * intersection([1, 2, 3], [2, 3, 4]); // [2, 3]\n * intersection(['a', 'b', 'c'], ['b', 'c', 'd'], ['b', 'e']); // ['b']\n * ```\n */\nexport const intersection = <T>(...arrays: T[][]): T[] => {\n if (arrays.length === 0) {\n return [];\n }\n\n if (arrays.length === 1) {\n return [...arrays[0]];\n }\n\n const [first, ...rest] = arrays;\n const uniqueFirst = unique(first);\n\n return uniqueFirst.filter(item => rest.every(array => array.includes(item)));\n};\n\n/**\n * Returns elements from the first array that don't exist in the second array.\n *\n * @template T - The type of the items in the arrays.\n *\n * @param array - The source array.\n * @param exclude - The array containing elements to exclude.\n *\n * @returns A new array with elements from the first array that don't exist in the second array.\n *\n * @example\n * ```ts\n * difference([1, 2, 3, 4], [2, 4]); // [1, 3]\n * difference(['a', 'b', 'c'], ['b']); // ['a', 'c']\n * ```\n */\nexport const difference = <T>(array: T[], exclude: T[]): T[] =>\n array.filter(item => !exclude.includes(item));\n","interface HTMLElementTransformationValues {\n translateX: number;\n translateY: number;\n}\n\n/**\n * Get various transformation values from the transformation matrix of an element.\n *\n * @param element - The element with a transformation applied.\n *\n * @returns An object containing transformation values.\n */\nexport const getTransformationValues = (element: HTMLElement): HTMLElementTransformationValues => {\n const computedStyles = window.getComputedStyle(element);\n const transformValue = computedStyles.getPropertyValue('transform');\n\n const matrix = transformValue.match(/^matrix\\((.+)\\)$/);\n if (!matrix) {\n return {\n translateX: 0,\n translateY: 0,\n };\n }\n\n const transformMatrix = matrix[1].split(', ');\n\n const translateX = parseFloat(transformMatrix[4]);\n const translateY = parseFloat(transformMatrix[5]);\n\n return {\n translateX,\n translateY,\n };\n};\n","export const noop = () => {};\n\n/**\n * Invokes the given input if it is a function, passing the provided arguments.\n * Otherwise, returns the input as-is.\n *\n * @template Args - Tuple of argument types to pass to the function.\n * @template Result - Return type of the function or the value.\n *\n * @param input - A function to invoke with `args`, or a direct value of type `Result`.\n * @param args - Arguments to pass if `input` is a function.\n *\n * @returns The result of invoking the function, or the original value if it's not a function.\n */\nexport const invokeIfFunction = <Args extends unknown[], Result>(\n input: ((...args: Args) => Result) | Result,\n ...args: Args\n): Result => (typeof input === 'function' ? (input as (...args: Args) => Result)(...args) : input);\n\n/**\n * Creates a promise that resolves after the specified delay.\n *\n * Useful for creating artificial delays, implementing timeouts, or spacing operations.\n *\n * @param delayMs - The delay in milliseconds.\n *\n * @returns A promise that resolves after the specified delay.\n *\n * @example\n * ```ts\n * // Wait for 1 second\n * await delay(1000);\n * console.log('This logs after 1 second');\n *\n * // Use with other async operations\n * async function fetchWithTimeout() {\n * const timeoutPromise = delay(5000).then(() => {\n * throw new Error('Request timed out');\n * });\n *\n * return Promise.race([fetchData(), timeoutPromise]);\n * }\n * ```\n */\nexport const delay = (delayMs: number): Promise<void> =>\n new Promise(resolve => setTimeout(resolve, delayMs));\n\ninterface RetryOptions {\n /**\n * Maximum number of retry attempts before failing.\n *\n * @default 3\n */\n maxAttempts?: number;\n /**\n * Delay in milliseconds between retry attempts.\n * If `backoff` is true, this is the base delay for exponential backoff.\n *\n * @default 300\n */\n delayMs?: number;\n /**\n * Whether to use exponential backoff for delays between attempts.\n * When enabled, the delay is multiplied by 2 ^ (`attempt` - 1).\n *\n * @default true\n */\n backoff?: boolean;\n /**\n * Optional callback triggered before each retry attempt.\n *\n * @param attempt - The current attempt number (starting from 1).\n * @param error - The error that caused the retry.\n */\n onRetry?: (attempt: number, error: unknown) => void;\n}\n\n/**\n * Wraps an asynchronous function with retry logic.\n *\n * The returned function will attempt to call the original function up to `maxAttempts` times,\n * with a delay between retries. If all attempts fail, the last encountered error is thrown.\n *\n * Useful for operations that may fail intermittently, such as network requests.\n *\n * @template Task - The type of the async function to wrap.\n * @template TaskResult - The result type of the async function.\n *\n * @param task - The async function to wrap with retry logic.\n * @param options - Configuration options for retry behavior.\n *\n * @returns A function that wraps the original function with retry support.\n *\n * @example\n * ```ts\n * async function fetchData() {\n * const response = await fetch('/api/data');\n *\n * if (!response.ok) {\n * throw new Error('Network error');\n * }\n *\n * return await response.json();\n * }\n *\n * const fetchWithRetry = retry(fetchData, {\n * maxAttempts: 5,\n * delayMs: 500,\n * onRetry: (attempt, error) => {\n * console.warn(`Attempt ${attempt} failed:`, error);\n * }\n * });\n *\n * fetchWithRetry()\n * .then(data => console.log('Success:', data))\n * .catch(error => console.error('Failed after retries:', error));\n * ```\n */\nexport const retry = <Task extends (...args: unknown[]) => Promise<TaskResult>, TaskResult>(\n task: Task,\n { maxAttempts = 3, delayMs = 300, backoff = true, onRetry }: RetryOptions = {},\n): ((...args: Parameters<Task>) => Promise<TaskResult>) => {\n return async (...args: Parameters<Task>): Promise<TaskResult> => {\n let lastError: unknown;\n\n for (let attempt = 1; attempt <= maxAttempts; attempt++) {\n try {\n return await task(...args);\n } catch (e) {\n lastError = e;\n\n if (attempt < maxAttempts) {\n onRetry?.(attempt, e);\n\n const delayTime = backoff ? delayMs * 2 ** (attempt - 1) : delayMs;\n await delay(delayTime);\n }\n }\n }\n\n throw lastError;\n };\n};\n","export function assert(condition: any, message: string): asserts condition {\n if (!condition) {\n throw new Error(message);\n }\n}\n\n/**\n * Checks if a value is null.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is null; otherwise, `false`.\n */\nexport const isNull = (value: unknown): value is null => value === null;\n\n/**\n * Checks if a value is a string.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a string; otherwise, `false`.\n */\nexport const isString = (value: unknown): value is string => typeof value === 'string';\n\n/**\n * Checks if a value is a number.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a number; otherwise, `false`.\n */\nexport const isNumber = (value: unknown): value is number => typeof value === 'number';\n\n/**\n * Checks if a value is a boolean.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a boolean; otherwise, `false`.\n */\nexport const isBool = (value: unknown): value is boolean => typeof value === 'boolean';\n\n/**\n * Checks if a value is an object.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is an object; otherwise, `false`.\n */\nexport const isObject = (value: unknown): value is object => typeof value === 'object';\n\n/**\n * Checks if a value is an empty object (no own enumerable properties).\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is an empty object; otherwise, `false`.\n */\nexport const isEmptyObject = (value: unknown): value is Record<string, never> =>\n isObject(value) && !isNull(value) && Object.keys(value).length === 0;\n\n/**\n * Checks if a value is an array.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is an array; otherwise, `false`.\n */\nexport const isArray = (value: unknown): value is unknown[] => Array.isArray(value);\n\n/**\n * Checks if a value is an empty array.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is an empty array; otherwise, `false`.\n */\nexport const isEmptyArray = (value: unknown): value is [] => isArray(value) && value.length === 0;\n\n/**\n * Checks if a value is a function.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a function; otherwise, `false`.\n */\nexport const isFunction = (value: unknown) => typeof value === 'function';\n\n/**\n * Checks if a value is a Promise.\n *\n * @template T - The type of the value that the Promise resolves to.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a Promise; otherwise, `false`.\n */\nexport const isPromise = <T = unknown>(value: unknown): value is Promise<T> =>\n isFunction((value as Promise<T>)?.then);\n\n/**\n * Checks if a value is null or undefined.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is `null` or `undefined`, otherwise `false`.\n */\nexport const isNil = (value: unknown): value is null | undefined =>\n value === undefined || value === null;\n\n/**\n * Checks whether the provided value is considered \"empty\".\n *\n * A value is considered empty if it is:\n * - `null`\n * - `undefined`\n * - `''`\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is empty; otherwise, `false`.\n */\nexport const isNilOrEmptyString = (value: unknown): value is null | undefined =>\n value === '' || isNil(value);\n\n/**\n * Checks if a value is a Date object.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a Date object; otherwise, `false`.\n */\nexport const isDate = (value: unknown): value is Date => value instanceof Date;\n\n/**\n * Checks if a value is a valid Date object (not Invalid Date).\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a valid Date object; otherwise, `false`.\n */\nexport const isValidDate = (value: unknown): value is Date =>\n isDate(value) && !isNaN(value.getTime());\n\n/**\n * Checks if a value is a RegExp object.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a RegExp object; otherwise, `false`.\n */\nexport const isRegExp = (value: unknown): value is RegExp => value instanceof RegExp;\n\n/**\n * Checks if a value is a Map.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a Map; otherwise, `false`.\n */\nexport const isMap = (value: unknown): value is Map<unknown, unknown> => value instanceof Map;\n\n/**\n * Checks if a value is a Set.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a Set; otherwise, `false`.\n */\nexport const isSet = (value: unknown): value is Set<unknown> => value instanceof Set;\n\n/**\n * Checks if a value is a Symbol.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a Symbol; otherwise, `false`.\n */\nexport const isSymbol = (value: unknown): value is symbol => typeof value === 'symbol';\n\n/**\n * Checks if a value is undefined.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is undefined; otherwise, `false`.\n */\nexport const isUndefined = (value: unknown): value is undefined => value === undefined;\n\n/**\n * Checks if a value is a finite number.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a finite number; otherwise, `false`.\n */\nexport const isFiniteNumber = (value: unknown): value is number =>\n isNumber(value) && isFinite(value);\n\n/**\n * Checks if a value is an integer.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is an integer; otherwise, `false`.\n */\nexport const isInteger = (value: unknown): value is number =>\n isNumber(value) && Number.isInteger(value);\n","/**\n * Calculates the Euclidean distance between two points in 2D space.\n *\n * @param startX - The X coordinate of the starting point.\n * @param startY - The Y coordinate of the starting point.\n * @param endX - The X coordinate of the ending point.\n * @param endY - The Y coordinate of the ending point.\n *\n * @returns The Euclidean distance between the two points.\n */\nexport const calculateEuclideanDistance = (\n startX: number,\n startY: number,\n endX: number,\n endY: number,\n): number => {\n const deltaX = endX - startX;\n const deltaY = endY - startY;\n\n return Math.sqrt(deltaX ** 2 + deltaY ** 2);\n};\n\n/**\n * Calculates the moving speed.\n *\n * @param delta - The change in position (distance).\n * @param elapsedTime - The time taken to move the distance.\n *\n * @returns The calculated speed, which is the absolute value of delta divided by elapsed time.\n */\nexport const calculateMovingSpeed = (delta: number, elapsedTime: number): number =>\n Math.abs(delta / elapsedTime);\n\n/**\n * Calculates the specified percentage of a given value.\n *\n * @param value - The value to calculate the percentage of.\n * @param percentage - The percentage to calculate.\n *\n * @returns The calculated percentage of the value.\n */\nexport const calculatePercentage = (value: number, percentage: number): number => {\n return (value * percentage) / 100;\n};\n","/**\n * Converts a string to kebab-case format.\n *\n * This function transforms camelCase or PascalCase strings into kebab-case by inserting\n * hyphens between lowercase and uppercase letters, then converting everything to lowercase.\n *\n * @param input - The string to convert to kebab-case.\n *\n * @returns The kebab-case formatted string.\n *\n * @example\n * ```ts\n * toKebabCase('helloWorld'); // → 'hello-world'\n * toKebabCase('HelloWorld'); // → 'hello-world'\n * toKebabCase('hello123World'); // → 'hello123-world'\n * ```\n */\nexport const toKebabCase = (input: string): string =>\n input.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();\n\n/**\n * Converts a camelCase string to dash-case format.\n *\n * This function transforms camelCase strings into dash-case by inserting\n * hyphens before uppercase letters and converting them to lowercase.\n * The function ensures that no hyphen is added at the start of the output string,\n * even if the input begins with an uppercase letter.\n *\n * @param input - The camelCase string to convert to dash-case.\n *\n * @returns The dash-case formatted string.\n *\n * @example\n * ```ts\n * camelToDashCase('helloWorld'); // → 'hello-world'\n * camelToDashCase('HelloWorld'); // → 'hello-world'\n * camelToDashCase('backgroundColor'); // → 'background-color'\n * ```\n */\nexport const camelToDashCase = (input: string): string => {\n // First handle the first character separately to avoid adding a hyphen at the start\n const firstChar = input.charAt(0);\n const restOfString = input.slice(1);\n \n // Convert the first character to lowercase without adding a hyphen\n const firstCharProcessed = firstChar.toLowerCase();\n \n // Process the rest of the string normally, adding hyphens before uppercase letters\n const restProcessed = restOfString.replace(/[A-Z]/g, letter => `-${letter.toLowerCase()}`);\n \n return firstCharProcessed + restProcessed;\n};\n\n/**\n * Splits a string into an array of filtered from redundant spaces words.\n *\n * @param input - The input string to be split.\n *\n * @returns An array of words from the input string.\n */\nexport const splitStringIntoWords = (input: string): string[] => input.split(' ').filter(Boolean);\n\n/**\n * Generates a short, consistent hash string from an input string using a DJB2-inspired algorithm.\n *\n * This function uses a variation of the DJB2 algorithm, which is a simple yet effective hashing algorithm\n * based on bitwise XOR (`^`) and multiplication by 33. It produces a non-negative 32-bit integer,\n * which is then converted to a base-36 string (digits + lowercase letters) to produce a compact output.\n *\n * Useful for:\n * - Generating stable class names in CSS-in-JS libraries.\n * - Producing consistent cache keys.\n * - Quick and lightweight hashing needs where cryptographic security is not required.\n *\n * ⚠️ This is not cryptographically secure and should not be used for hashing passwords or sensitive data.\n *\n * @param input - The input string to hash.\n *\n * @returns A short, base-36 encoded hash string.\n *\n * @example\n * ```ts\n * const className = hashString('background-color: red;');\n * // → 'e4k1z0x'\n * ```\n */\nexport const hashString = (input: string): string => {\n let hash = 5381;\n\n for (let i = 0; i < input.length; i++) {\n hash = (hash * 33) ^ input.charCodeAt(i);\n }\n\n return (hash >>> 0).toString(36);\n};\n","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","export * from './string';\nexport * from './array';\nexport * from './function';\nexport * from './guards';\nexport * from './math';\nexport * from './dom';\n"],"names":[],"sourceRoot":""}
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const t=t=>t.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),e=t=>t.replace(/[A-Z]/g,t=>`-${t.toLowerCase()}`),
|
|
1
|
+
const t=t=>t.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),e=t=>{const e=t.charAt(0),r=t.slice(1);return e.toLowerCase()+r.replace(/[A-Z]/g,t=>`-${t.toLowerCase()}`)},r=t=>t.split(" ").filter(Boolean),n=t=>{let e=5381;for(let r=0;r<t.length;r++)e=33*e^t.charCodeAt(r);return(e>>>0).toString(36)};function o(t,e){if(!t)throw new Error(e)}const a=t=>null===t,s=t=>"string"==typeof t,l=t=>"number"==typeof t,i=t=>"boolean"==typeof t,c=t=>"object"==typeof t,f=t=>c(t)&&!a(t)&&0===Object.keys(t).length,u=t=>Array.isArray(t),h=t=>u(t)&&0===t.length,p=t=>"function"==typeof t,y=t=>p(t?.then),g=t=>null==t,m=t=>""===t||g(t),w=t=>t instanceof Date,b=t=>w(t)&&!isNaN(t.getTime()),A=t=>t instanceof RegExp,d=t=>t instanceof Map,C=t=>t instanceof Set,M=t=>"symbol"==typeof t,x=t=>void 0===t,S=t=>l(t)&&isFinite(t),$=t=>l(t)&&Number.isInteger(t),k=t=>t.filter(Boolean),F=t=>[...new Set(t)],L=(t,e)=>(o(e>0,"Chunk size must be greater than 0"),Array.from({length:Math.ceil(t.length/e)},(r,n)=>t.slice(n*e,(n+1)*e))),N=(...t)=>{if(0===t.length)return[];if(1===t.length)return[...t[0]];const[e,...r]=t;return F(e).filter(t=>r.every(e=>e.includes(t)))},j=(t,e)=>t.filter(t=>!e.includes(t)),v=()=>{},z=(t,...e)=>"function"==typeof t?t(...e):t,B=t=>new Promise(e=>setTimeout(e,t)),E=(t,{maxAttempts:e=3,delayMs:r=300,backoff:n=!0,onRetry:o}={})=>async(...a)=>{let s;for(let l=1;l<=e;l++)try{return await t(...a)}catch(t){if(s=t,l<e){o?.(l,t);const e=n?r*2**(l-1):r;await B(e)}}throw s},P=(t,e,r,n)=>{const o=r-t,a=n-e;return Math.sqrt(o**2+a**2)},R=(t,e)=>Math.abs(t/e),T=(t,e)=>t*e/100,X=t=>{const e=window.getComputedStyle(t).getPropertyValue("transform").match(/^matrix\((.+)\)$/);if(!e)return{translateX:0,translateY:0};const r=e[1].split(", ");return{translateX:parseFloat(r[4]),translateY:parseFloat(r[5])}};export{o as assert,k as boolFilter,P as calculateEuclideanDistance,R as calculateMovingSpeed,T as calculatePercentage,e as camelToDashCase,L as chunk,B as delay,j as difference,X as getTransformationValues,n as hashString,N as intersection,z as invokeIfFunction,u as isArray,i as isBool,w as isDate,h as isEmptyArray,f as isEmptyObject,S as isFiniteNumber,p as isFunction,$ as isInteger,d as isMap,g as isNil,m as isNilOrEmptyString,a as isNull,l as isNumber,c as isObject,y as isPromise,A as isRegExp,C as isSet,s as isString,M as isSymbol,x as isUndefined,b as isValidDate,v as noop,E as retry,r as splitStringIntoWords,t as toKebabCase,F as unique};
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","mappings":"AAAO,MAAMA,EAAeC,GAC1BA,EAAMC,QAAQ,qBAAsB,SAASC,cAElCC,EAAmBH,GAC9BA,EAAMC,QAAQ,SAAUG,GAAU,IAAIA,EAAOF,iBASlCG,EAAwBL,GAA4BA,EAAMM,MAAM,KAAKC,OAAOC,SA0B5EC,EAAcT,IACzB,IAAIU,EAAO,KAEX,IA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CAACC,EAAeC,IAClDJ,KAAKK,IAAIF,EAAQC,GAUNE,EAAsB,CAAC/C,EAAegD,IACzChD,EAAQgD,EAAc,IC9BnBC,EAA2BC,IACtC,MAGMC,EAHiBC,OAAOC,iBAAiBH,GACTI,iBAAiB,aAEzBC,MAAM,oBACpC,IAAKJ,EACH,MAAO,CACLK,WAAY,EACZC,WAAY,GAIhB,MAAMC,EAAkBP,EAAO,GAAGlE,MAAM,MAKxC,MAAO,CACLuE,WAJiBG,WAAWD,EAAgB,IAK5CD,WAJiBE,WAAWD,EAAgB,MCpBzC,SAASE,EAAOC,EAAgBC,GACrC,IAAKD,EACH,MAAM,IAAIE,MAAMD,EAEpB,Q","sources":["webpack://@react-hive/honey-utils/./src/string.ts","webpack://@react-hive/honey-utils/./src/array.ts","webpack://@react-hive/honey-utils/./src/function.ts","webpack://@react-hive/honey-utils/./src/guards.ts","webpack://@react-hive/honey-utils/./src/math.ts","webpack://@react-hive/honey-utils/./src/dom.ts","webpack://@react-hive/honey-utils/./src/index.ts"],"sourcesContent":["export const toKebabCase = (input: string): string =>\n input.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();\n\nexport const camelToDashCase = (input: string): string =>\n input.replace(/[A-Z]/g, letter => `-${letter.toLowerCase()}`);\n\n/**\n * Splits a string into an array of filtered from redundant spaces words.\n *\n * @param input - The input string to be split.\n *\n * @returns An array of words from the input string.\n */\nexport const splitStringIntoWords = (input: string): string[] => input.split(' ').filter(Boolean);\n\n/**\n * Generates a short, consistent hash string from an input string using a DJB2-inspired algorithm.\n *\n * This function uses a variation of the DJB2 algorithm, which is a simple yet effective hashing algorithm\n * based on bitwise XOR (`^`) and multiplication by 33. It produces a non-negative 32-bit integer,\n * which is then converted to a base-36 string (digits + lowercase letters) to produce a compact output.\n *\n * Useful for:\n * - Generating stable class names in CSS-in-JS libraries.\n * - Producing consistent cache keys.\n * - Quick and lightweight hashing needs where cryptographic security is not required.\n *\n * ⚠️ This is not cryptographically secure and should not be used for hashing passwords or sensitive data.\n *\n * @param input - The input string to hash.\n *\n * @returns A short, base-36 encoded hash string.\n *\n * @example\n * ```ts\n * const className = hashString('background-color: red;');\n * // → 'e4k1z0x'\n * ```\n */\nexport const hashString = (input: string): string => {\n let hash = 5381;\n\n for (let i = 0; i < input.length; i++) {\n hash = (hash * 33) ^ input.charCodeAt(i);\n }\n\n return (hash >>> 0).toString(36);\n};\n","/**\n * Filters out `null`, `undefined`, and other falsy values from an array,\n * returning a typed array of only truthy `Item` values.\n *\n * Useful when working with optional or nullable items that need to be sanitized.\n *\n * @template T - The type of the items in the array.\n *\n * @param array - An array of items that may include `null`, `undefined`, or falsy values.\n *\n * @returns A new array containing only truthy `Item` values.\n */\nexport const boolFilter = <T>(array: (T | false | null | undefined)[]): T[] =>\n array.filter(Boolean) as T[];\n","export const noop = () => {};\n\n/**\n * Invokes the given input if it is a function, passing the provided arguments.\n * Otherwise, returns the input as-is.\n *\n * @template Args - Tuple of argument types to pass to the function.\n * @template Result - Return type of the function or the value.\n *\n * @param input - A function to invoke with `args`, or a direct value of type `Result`.\n * @param args - Arguments to pass if `input` is a function.\n *\n * @returns The result of invoking the function, or the original value if it's not a function.\n */\nexport const invokeIfFunction = <Args extends any[], Result>(\n input: ((...args: Args) => Result) | Result,\n ...args: Args\n): Result => (typeof input === 'function' ? (input as (...args: Args) => Result)(...args) : input);\n","/**\n * Checks if a value is null.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is null; otherwise, `false`.\n */\nexport const isNull = (value: unknown): value is null => value === null;\n\n/**\n * Checks if a value is a string.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a string; otherwise, `false`.\n */\nexport const isString = (value: unknown): value is string => typeof value === 'string';\n\n/**\n * Checks if a value is a number.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a number; otherwise, `false`.\n */\nexport const isNumber = (value: unknown): value is number => typeof value === 'number';\n\n/**\n * Checks if a value is a boolean.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a boolean; otherwise, `false`.\n */\nexport const isBool = (value: unknown): value is boolean => typeof value === 'boolean';\n\n/**\n * Checks if a value is an object.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is an object; otherwise, `false`.\n */\nexport const isObject = (value: unknown): value is object => typeof value === 'object';\n\n/**\n * Checks if a value is an empty object (no own enumerable properties).\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is an empty object; otherwise, `false`.\n */\nexport const isEmptyObject = (value: unknown): value is Record<string, never> =>\n isObject(value) && !isNull(value) && Object.keys(value).length === 0;\n\n/**\n * Checks if a value is an array.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is an array; otherwise, `false`.\n */\nexport const isArray = (value: unknown): value is unknown[] => Array.isArray(value);\n\n/**\n * Checks if a value is an empty array.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is an empty array; otherwise, `false`.\n */\nexport const isEmptyArray = (value: unknown): value is [] => isArray(value) && value.length === 0;\n\n/**\n * Checks if a value is a function.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a function; otherwise, `false`.\n */\nexport const isFunction = (value: unknown) => typeof value === 'function';\n\n/**\n * Checks if a value is a Promise.\n *\n * @template T - The type of the value that the Promise resolves to.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a Promise; otherwise, `false`.\n */\nexport const isPromise = <T = unknown>(value: unknown): value is Promise<T> =>\n isFunction((value as Promise<T>)?.then);\n\n/**\n * Checks if a value is null or undefined.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is `null` or `undefined`, otherwise `false`.\n */\nexport const isNil = (value: unknown): value is null | undefined =>\n value === undefined || value === null;\n\n/**\n * Checks whether the provided value is considered \"empty\".\n *\n * A value is considered empty if it is:\n * - `null`\n * - `undefined`\n * - `''`\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is empty; otherwise, `false`.\n */\nexport const isNilOrEmptyString = (value: unknown): value is null | undefined =>\n value === '' || isNil(value);\n\n/**\n * Checks if a value is a Date object.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a Date object; otherwise, `false`.\n */\nexport const isDate = (value: unknown): value is Date => value instanceof Date;\n\n/**\n * Checks if a value is a valid Date object (not Invalid Date).\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a valid Date object; otherwise, `false`.\n */\nexport const isValidDate = (value: unknown): value is Date =>\n isDate(value) && !isNaN(value.getTime());\n\n/**\n * Checks if a value is a RegExp object.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a RegExp object; otherwise, `false`.\n */\nexport const isRegExp = (value: unknown): value is RegExp => value instanceof RegExp;\n\n/**\n * Checks if a value is a Map.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a Map; otherwise, `false`.\n */\nexport const isMap = (value: unknown): value is Map<unknown, unknown> => value instanceof Map;\n\n/**\n * Checks if a value is a Set.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a Set; otherwise, `false`.\n */\nexport const isSet = (value: unknown): value is Set<unknown> => value instanceof Set;\n\n/**\n * Checks if a value is a Symbol.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a Symbol; otherwise, `false`.\n */\nexport const isSymbol = (value: unknown): value is symbol => typeof value === 'symbol';\n\n/**\n * Checks if a value is undefined.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is undefined; otherwise, `false`.\n */\nexport const isUndefined = (value: unknown): value is undefined => value === undefined;\n\n/**\n * Checks if a value is a finite number.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a finite number; otherwise, `false`.\n */\nexport const isFiniteNumber = (value: unknown): value is number =>\n isNumber(value) && isFinite(value);\n\n/**\n * Checks if a value is an integer.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is an integer; otherwise, `false`.\n */\nexport const isInteger = (value: unknown): value is number =>\n isNumber(value) && Number.isInteger(value);\n","/**\n * Calculates the Euclidean distance between two points in 2D space.\n *\n * @param startX - The X coordinate of the starting point.\n * @param startY - The Y coordinate of the starting point.\n * @param endX - The X coordinate of the ending point.\n * @param endY - The Y coordinate of the ending point.\n *\n * @returns The Euclidean distance between the two points.\n */\nexport const calculateEuclideanDistance = (\n startX: number,\n startY: number,\n endX: number,\n endY: number,\n): number => {\n const deltaX = endX - startX;\n const deltaY = endY - startY;\n\n return Math.sqrt(deltaX ** 2 + deltaY ** 2);\n};\n\n/**\n * Calculates the moving speed.\n *\n * @param delta - The change in position (distance).\n * @param elapsedTime - The time taken to move the distance.\n *\n * @returns The calculated speed, which is the absolute value of delta divided by elapsed time.\n */\nexport const calculateMovingSpeed = (delta: number, elapsedTime: number): number =>\n Math.abs(delta / elapsedTime);\n\n/**\n * Calculates the specified percentage of a given value.\n *\n * @param value - The value to calculate the percentage of.\n * @param percentage - The percentage to calculate.\n *\n * @returns The calculated percentage of the value.\n */\nexport const calculatePercentage = (value: number, percentage: number): number => {\n return (value * percentage) / 100;\n};\n","interface HTMLElementTransformationValues {\n translateX: number;\n translateY: number;\n}\n\n/**\n * Get various transformation values from the transformation matrix of an element.\n *\n * @param element - The element with a transformation applied.\n *\n * @returns An object containing transformation values.\n */\nexport const getTransformationValues = (element: HTMLElement): HTMLElementTransformationValues => {\n const computedStyles = window.getComputedStyle(element);\n const transformValue = computedStyles.getPropertyValue('transform');\n\n const matrix = transformValue.match(/^matrix\\((.+)\\)$/);\n if (!matrix) {\n return {\n translateX: 0,\n translateY: 0,\n };\n }\n\n const transformMatrix = matrix[1].split(', ');\n\n const translateX = parseFloat(transformMatrix[4]);\n const translateY = parseFloat(transformMatrix[5]);\n\n return {\n translateX,\n translateY,\n };\n};\n","export * from './string';\nexport * from './array';\nexport * from './function';\nexport * from './guards';\nexport * from './math';\nexport * from './dom';\n\nexport function assert(condition: any, message: string): asserts condition {\n if (!condition) {\n throw new Error(message);\n }\n}\n"],"names":["toKebabCase","input","replace","toLowerCase","camelToDashCase","letter","splitStringIntoWords","split","filter","Boolean","hashString","hash","i","length","charCodeAt","toString","boolFilter","array","noop","invokeIfFunction","args","isNull","value","isString","isNumber","isBool","isObject","isEmptyObject","Object","keys","isArray","Array","isEmptyArray","isFunction","isPromise","then","isNil","isNilOrEmptyString","isDate","Date","isValidDate","isNaN","getTime","isRegExp","RegExp","isMap","Map","isSet","Set","isSymbol","isUndefined","undefined","isFiniteNumber","isFinite","isInteger","Number","calculateEuclideanDistance","startX","startY","endX","endY","deltaX","deltaY","Math","sqrt","calculateMovingSpeed","delta","elapsedTime","abs","calculatePercentage","percentage","getTransformationValues","element","matrix","window","getComputedStyle","getPropertyValue","match","translateX","translateY","transformMatrix","parseFloat","assert","condition","message","Error"],"sourceRoot":""}
|
|
1
|
+
{"version":3,"file":"index.mjs","mappings":"AAiBO,MAAMA,EAAeC,GAC1BA,EAAMC,QAAQ,qBAAsB,SAASC,cAqBlCC,EAAmBH,IAE9B,MAAMI,EAAYJ,EAAMK,OAAO,GACzBC,EAAeN,EAAMO,MAAM,GAQjC,OAL2BH,EAAUF,cAGfI,EAAaL,QAAQ,SAAUO,GAAU,IAAIA,EAAON,kBAY/DO,EAAwBT,GAA4BA,EAAMU,MAAM,KAAKC,OAAOC,SA0B5EC,EAAcb,IACzB,IAAIc,EAAO,KAEX,IAAK,IAAIC,EAAI,EAAGA,EAAIf,EAAMgB,OAAQD,IAChCD,EAAe,GAAPA,EAAad,EAAMiB,WAAWF,GAGxC,OAAQD,IAAS,GAAGI,SAAS,KC7FxB,SAASC,EAAOC,EAAgBC,GACrC,IAAKD,EACH,MAAM,IAAIE,MAAMD,EAEpB,CASO,MAAME,EAAUC,GAA4C,OAAVA,EAS5CC,EAAYD,GAAqD,iBAAVA,EASvDE,EAAYF,GAAqD,iBAAVA,EASvDG,EAAUH,GAAsD,kBAAVA,EAStDI,EAAYJ,GAAqD,iBAAVA,EASvDK,EAAiBL,GAC5BI,EAASJ,KAAWD,EAAOC,IAAwC,IAA9BM,OAAOC,KAAKP,GAAOR,OAS7CgB,EAAWR,GAAuCS,MAAMD,QAAQR,GAShEU,EAAgBV,GAAgCQ,EAAQR,IA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AIC,QAAQC,GAAWC,WAAWD,EAASF,IAyEhCI,EAAQ,CACnBC,GACEC,cAAc,EAAGN,UAAU,IAAKO,WAAU,EAAMC,WAA0B,CAAC,IAEtEC,SAAUX,KACf,IAAIY,EAEJ,IAAK,IAAIC,EAAU,EAAGA,GAAWL,EAAaK,IAC5C,IACE,aAAaN,KAAQP,EACvB,CAAE,MAAOc,GAGP,GAFAF,EAAYE,EAERD,EAAUL,EAAa,CACzBE,IAAUG,EAASC,GAEnB,MAAMC,EAAYN,EAAUP,EAAU,IAAMW,EAAU,GAAKX,QACrDD,EAAMc,EACd,CACF,CAGF,MAAMH,GClIGI,EAA6B,CACxCC,EACAC,EACAC,EACAC,KAEA,MAAMC,EAASF,EAAOF,EAChBK,EAASF,EAAOF,EAEtB,OAAOjC,KAAKsC,KAAKF,GAAU,EAAIC,GAAU,IAW9BE,EAAuB,CAACC,EAAeC,IAClDzC,KAAK0C,IAAIF,EAAQC,GAUNE,EAAsB,CAACnF,EAAeoF,IACzCpF,EAAQoF,EAAc,IC9BnBC,EAA2BC,IACtC,MAGMC,EAHiBC,OAAOC,iBAAiBH,GACTI,iBAAiB,aAEzBC,MAAM,oBACpC,IAAKJ,EACH,MAAO,CACLK,WAAY,EACZC,WAAY,GAIhB,MAAMC,EAAkBP,EAAO,GAAGrG,MAAM,MAKxC,MAAO,CACL0G,WAJiBG,WAAWD,EAAgB,IAK5CD,WAJiBE,WAAWD,EAAgB,a","sources":["webpack://@react-hive/honey-utils/./src/string.ts","webpack://@react-hive/honey-utils/./src/guards.ts","webpack://@react-hive/honey-utils/./src/array.ts","webpack://@react-hive/honey-utils/./src/function.ts","webpack://@react-hive/honey-utils/./src/math.ts","webpack://@react-hive/honey-utils/./src/dom.ts"],"sourcesContent":["/**\n * Converts a string to kebab-case format.\n *\n * This function transforms camelCase or PascalCase strings into kebab-case by inserting\n * hyphens between lowercase and uppercase letters, then converting everything to lowercase.\n *\n * @param input - The string to convert to kebab-case.\n *\n * @returns The kebab-case formatted string.\n *\n * @example\n * ```ts\n * toKebabCase('helloWorld'); // → 'hello-world'\n * toKebabCase('HelloWorld'); // → 'hello-world'\n * toKebabCase('hello123World'); // → 'hello123-world'\n * ```\n */\nexport const toKebabCase = (input: string): string =>\n input.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();\n\n/**\n * Converts a camelCase string to dash-case format.\n *\n * This function transforms camelCase strings into dash-case by inserting\n * hyphens before uppercase letters and converting them to lowercase.\n * The function ensures that no hyphen is added at the start of the output string,\n * even if the input begins with an uppercase letter.\n *\n * @param input - The camelCase string to convert to dash-case.\n *\n * @returns The dash-case formatted string.\n *\n * @example\n * ```ts\n * camelToDashCase('helloWorld'); // → 'hello-world'\n * camelToDashCase('HelloWorld'); // → 'hello-world'\n * camelToDashCase('backgroundColor'); // → 'background-color'\n * ```\n */\nexport const camelToDashCase = (input: string): string => {\n // First handle the first character separately to avoid adding a hyphen at the start\n const firstChar = input.charAt(0);\n const restOfString = input.slice(1);\n \n // Convert the first character to lowercase without adding a hyphen\n const firstCharProcessed = firstChar.toLowerCase();\n \n // Process the rest of the string normally, adding hyphens before uppercase letters\n const restProcessed = restOfString.replace(/[A-Z]/g, letter => `-${letter.toLowerCase()}`);\n \n return firstCharProcessed + restProcessed;\n};\n\n/**\n * Splits a string into an array of filtered from redundant spaces words.\n *\n * @param input - The input string to be split.\n *\n * @returns An array of words from the input string.\n */\nexport const splitStringIntoWords = (input: string): string[] => input.split(' ').filter(Boolean);\n\n/**\n * Generates a short, consistent hash string from an input string using a DJB2-inspired algorithm.\n *\n * This function uses a variation of the DJB2 algorithm, which is a simple yet effective hashing algorithm\n * based on bitwise XOR (`^`) and multiplication by 33. It produces a non-negative 32-bit integer,\n * which is then converted to a base-36 string (digits + lowercase letters) to produce a compact output.\n *\n * Useful for:\n * - Generating stable class names in CSS-in-JS libraries.\n * - Producing consistent cache keys.\n * - Quick and lightweight hashing needs where cryptographic security is not required.\n *\n * ⚠️ This is not cryptographically secure and should not be used for hashing passwords or sensitive data.\n *\n * @param input - The input string to hash.\n *\n * @returns A short, base-36 encoded hash string.\n *\n * @example\n * ```ts\n * const className = hashString('background-color: red;');\n * // → 'e4k1z0x'\n * ```\n */\nexport const hashString = (input: string): string => {\n let hash = 5381;\n\n for (let i = 0; i < input.length; i++) {\n hash = (hash * 33) ^ input.charCodeAt(i);\n }\n\n return (hash >>> 0).toString(36);\n};\n","export function assert(condition: any, message: string): asserts condition {\n if (!condition) {\n throw new Error(message);\n }\n}\n\n/**\n * Checks if a value is null.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is null; otherwise, `false`.\n */\nexport const isNull = (value: unknown): value is null => value === null;\n\n/**\n * Checks if a value is a string.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a string; otherwise, `false`.\n */\nexport const isString = (value: unknown): value is string => typeof value === 'string';\n\n/**\n * Checks if a value is a number.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a number; otherwise, `false`.\n */\nexport const isNumber = (value: unknown): value is number => typeof value === 'number';\n\n/**\n * Checks if a value is a boolean.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a boolean; otherwise, `false`.\n */\nexport const isBool = (value: unknown): value is boolean => typeof value === 'boolean';\n\n/**\n * Checks if a value is an object.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is an object; otherwise, `false`.\n */\nexport const isObject = (value: unknown): value is object => typeof value === 'object';\n\n/**\n * Checks if a value is an empty object (no own enumerable properties).\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is an empty object; otherwise, `false`.\n */\nexport const isEmptyObject = (value: unknown): value is Record<string, never> =>\n isObject(value) && !isNull(value) && Object.keys(value).length === 0;\n\n/**\n * Checks if a value is an array.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is an array; otherwise, `false`.\n */\nexport const isArray = (value: unknown): value is unknown[] => Array.isArray(value);\n\n/**\n * Checks if a value is an empty array.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is an empty array; otherwise, `false`.\n */\nexport const isEmptyArray = (value: unknown): value is [] => isArray(value) && value.length === 0;\n\n/**\n * Checks if a value is a function.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a function; otherwise, `false`.\n */\nexport const isFunction = (value: unknown) => typeof value === 'function';\n\n/**\n * Checks if a value is a Promise.\n *\n * @template T - The type of the value that the Promise resolves to.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a Promise; otherwise, `false`.\n */\nexport const isPromise = <T = unknown>(value: unknown): value is Promise<T> =>\n isFunction((value as Promise<T>)?.then);\n\n/**\n * Checks if a value is null or undefined.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is `null` or `undefined`, otherwise `false`.\n */\nexport const isNil = (value: unknown): value is null | undefined =>\n value === undefined || value === null;\n\n/**\n * Checks whether the provided value is considered \"empty\".\n *\n * A value is considered empty if it is:\n * - `null`\n * - `undefined`\n * - `''`\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is empty; otherwise, `false`.\n */\nexport const isNilOrEmptyString = (value: unknown): value is null | undefined =>\n value === '' || isNil(value);\n\n/**\n * Checks if a value is a Date object.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a Date object; otherwise, `false`.\n */\nexport const isDate = (value: unknown): value is Date => value instanceof Date;\n\n/**\n * Checks if a value is a valid Date object (not Invalid Date).\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a valid Date object; otherwise, `false`.\n */\nexport const isValidDate = (value: unknown): value is Date =>\n isDate(value) && !isNaN(value.getTime());\n\n/**\n * Checks if a value is a RegExp object.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a RegExp object; otherwise, `false`.\n */\nexport const isRegExp = (value: unknown): value is RegExp => value instanceof RegExp;\n\n/**\n * Checks if a value is a Map.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a Map; otherwise, `false`.\n */\nexport const isMap = (value: unknown): value is Map<unknown, unknown> => value instanceof Map;\n\n/**\n * Checks if a value is a Set.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a Set; otherwise, `false`.\n */\nexport const isSet = (value: unknown): value is Set<unknown> => value instanceof Set;\n\n/**\n * Checks if a value is a Symbol.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a Symbol; otherwise, `false`.\n */\nexport const isSymbol = (value: unknown): value is symbol => typeof value === 'symbol';\n\n/**\n * Checks if a value is undefined.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is undefined; otherwise, `false`.\n */\nexport const isUndefined = (value: unknown): value is undefined => value === undefined;\n\n/**\n * Checks if a value is a finite number.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a finite number; otherwise, `false`.\n */\nexport const isFiniteNumber = (value: unknown): value is number =>\n isNumber(value) && isFinite(value);\n\n/**\n * Checks if a value is an integer.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is an integer; otherwise, `false`.\n */\nexport const isInteger = (value: unknown): value is number =>\n isNumber(value) && Number.isInteger(value);\n","import { assert } from './guards';\n\n/**\n * Filters out `null`, `undefined`, and other falsy values from an array,\n * returning a typed array of only truthy `Item` values.\n *\n * Useful when working with optional or nullable items that need to be sanitized.\n *\n * @template T - The type of the items in the array.\n *\n * @param array - An array of items that may include `null`, `undefined`, or falsy values.\n *\n * @returns A new array containing only truthy `Item` values.\n */\nexport const boolFilter = <T>(array: (T | false | null | undefined)[]): T[] =>\n array.filter(Boolean) as T[];\n\n/**\n * Returns a new array with duplicate values removed.\n *\n * Uses Set for efficient duplicate removal while preserving the original order.\n *\n * @template T - The type of the items in the array.\n *\n * @param array - The input array that may contain duplicate values.\n *\n * @returns A new array with only unique values, maintaining the original order.\n *\n * @example\n * ```ts\n * unique([1, 2, 2, 3, 1, 4]); // [1, 2, 3, 4]\n * unique(['a', 'b', 'a', 'c']); // ['a', 'b', 'c']\n * ```\n */\nexport const unique = <T>(array: T[]): T[] => [...new Set(array)];\n\n/**\n * Splits an array into chunks of the specified size.\n *\n * Useful for pagination, batch processing, or creating grid layouts.\n *\n * @template T - The type of the items in the array.\n *\n * @param array - The input array to be chunked.\n * @param size - The size of each chunk. Must be greater than 0.\n *\n * @returns An array of chunks, where each chunk is an array of the specified size\n * (except possibly the last chunk, which may be smaller).\n *\n * @example\n * ```ts\n * chunk([1, 2, 3, 4, 5], 2); // [[1, 2], [3, 4], [5]]\n * chunk(['a', 'b', 'c', 'd'], 3); // [['a', 'b', 'c'], ['d']]\n * ```\n */\nexport const chunk = <T>(array: T[], size: number): T[][] => {\n assert(size > 0, 'Chunk size must be greater than 0');\n\n return Array.from({ length: Math.ceil(array.length / size) }, (_, index) =>\n array.slice(index * size, (index + 1) * size),\n );\n};\n\n/**\n * Returns an array containing elements that exist in all provided arrays.\n *\n * @template T - The type of the items in the arrays.\n *\n * @param arrays - Two or more arrays to find common elements from.\n *\n * @returns A new array containing only the elements that exist in all input arrays.\n *\n * @example\n * ```ts\n * intersection([1, 2, 3], [2, 3, 4]); // [2, 3]\n * intersection(['a', 'b', 'c'], ['b', 'c', 'd'], ['b', 'e']); // ['b']\n * ```\n */\nexport const intersection = <T>(...arrays: T[][]): T[] => {\n if (arrays.length === 0) {\n return [];\n }\n\n if (arrays.length === 1) {\n return [...arrays[0]];\n }\n\n const [first, ...rest] = arrays;\n const uniqueFirst = unique(first);\n\n return uniqueFirst.filter(item => rest.every(array => array.includes(item)));\n};\n\n/**\n * Returns elements from the first array that don't exist in the second array.\n *\n * @template T - The type of the items in the arrays.\n *\n * @param array - The source array.\n * @param exclude - The array containing elements to exclude.\n *\n * @returns A new array with elements from the first array that don't exist in the second array.\n *\n * @example\n * ```ts\n * difference([1, 2, 3, 4], [2, 4]); // [1, 3]\n * difference(['a', 'b', 'c'], ['b']); // ['a', 'c']\n * ```\n */\nexport const difference = <T>(array: T[], exclude: T[]): T[] =>\n array.filter(item => !exclude.includes(item));\n","export const noop = () => {};\n\n/**\n * Invokes the given input if it is a function, passing the provided arguments.\n * Otherwise, returns the input as-is.\n *\n * @template Args - Tuple of argument types to pass to the function.\n * @template Result - Return type of the function or the value.\n *\n * @param input - A function to invoke with `args`, or a direct value of type `Result`.\n * @param args - Arguments to pass if `input` is a function.\n *\n * @returns The result of invoking the function, or the original value if it's not a function.\n */\nexport const invokeIfFunction = <Args extends unknown[], Result>(\n input: ((...args: Args) => Result) | Result,\n ...args: Args\n): Result => (typeof input === 'function' ? (input as (...args: Args) => Result)(...args) : input);\n\n/**\n * Creates a promise that resolves after the specified delay.\n *\n * Useful for creating artificial delays, implementing timeouts, or spacing operations.\n *\n * @param delayMs - The delay in milliseconds.\n *\n * @returns A promise that resolves after the specified delay.\n *\n * @example\n * ```ts\n * // Wait for 1 second\n * await delay(1000);\n * console.log('This logs after 1 second');\n *\n * // Use with other async operations\n * async function fetchWithTimeout() {\n * const timeoutPromise = delay(5000).then(() => {\n * throw new Error('Request timed out');\n * });\n *\n * return Promise.race([fetchData(), timeoutPromise]);\n * }\n * ```\n */\nexport const delay = (delayMs: number): Promise<void> =>\n new Promise(resolve => setTimeout(resolve, delayMs));\n\ninterface RetryOptions {\n /**\n * Maximum number of retry attempts before failing.\n *\n * @default 3\n */\n maxAttempts?: number;\n /**\n * Delay in milliseconds between retry attempts.\n * If `backoff` is true, this is the base delay for exponential backoff.\n *\n * @default 300\n */\n delayMs?: number;\n /**\n * Whether to use exponential backoff for delays between attempts.\n * When enabled, the delay is multiplied by 2 ^ (`attempt` - 1).\n *\n * @default true\n */\n backoff?: boolean;\n /**\n * Optional callback triggered before each retry attempt.\n *\n * @param attempt - The current attempt number (starting from 1).\n * @param error - The error that caused the retry.\n */\n onRetry?: (attempt: number, error: unknown) => void;\n}\n\n/**\n * Wraps an asynchronous function with retry logic.\n *\n * The returned function will attempt to call the original function up to `maxAttempts` times,\n * with a delay between retries. If all attempts fail, the last encountered error is thrown.\n *\n * Useful for operations that may fail intermittently, such as network requests.\n *\n * @template Task - The type of the async function to wrap.\n * @template TaskResult - The result type of the async function.\n *\n * @param task - The async function to wrap with retry logic.\n * @param options - Configuration options for retry behavior.\n *\n * @returns A function that wraps the original function with retry support.\n *\n * @example\n * ```ts\n * async function fetchData() {\n * const response = await fetch('/api/data');\n *\n * if (!response.ok) {\n * throw new Error('Network error');\n * }\n *\n * return await response.json();\n * }\n *\n * const fetchWithRetry = retry(fetchData, {\n * maxAttempts: 5,\n * delayMs: 500,\n * onRetry: (attempt, error) => {\n * console.warn(`Attempt ${attempt} failed:`, error);\n * }\n * });\n *\n * fetchWithRetry()\n * .then(data => console.log('Success:', data))\n * .catch(error => console.error('Failed after retries:', error));\n * ```\n */\nexport const retry = <Task extends (...args: unknown[]) => Promise<TaskResult>, TaskResult>(\n task: Task,\n { maxAttempts = 3, delayMs = 300, backoff = true, onRetry }: RetryOptions = {},\n): ((...args: Parameters<Task>) => Promise<TaskResult>) => {\n return async (...args: Parameters<Task>): Promise<TaskResult> => {\n let lastError: unknown;\n\n for (let attempt = 1; attempt <= maxAttempts; attempt++) {\n try {\n return await task(...args);\n } catch (e) {\n lastError = e;\n\n if (attempt < maxAttempts) {\n onRetry?.(attempt, e);\n\n const delayTime = backoff ? delayMs * 2 ** (attempt - 1) : delayMs;\n await delay(delayTime);\n }\n }\n }\n\n throw lastError;\n };\n};\n","/**\n * Calculates the Euclidean distance between two points in 2D space.\n *\n * @param startX - The X coordinate of the starting point.\n * @param startY - The Y coordinate of the starting point.\n * @param endX - The X coordinate of the ending point.\n * @param endY - The Y coordinate of the ending point.\n *\n * @returns The Euclidean distance between the two points.\n */\nexport const calculateEuclideanDistance = (\n startX: number,\n startY: number,\n endX: number,\n endY: number,\n): number => {\n const deltaX = endX - startX;\n const deltaY = endY - startY;\n\n return Math.sqrt(deltaX ** 2 + deltaY ** 2);\n};\n\n/**\n * Calculates the moving speed.\n *\n * @param delta - The change in position (distance).\n * @param elapsedTime - The time taken to move the distance.\n *\n * @returns The calculated speed, which is the absolute value of delta divided by elapsed time.\n */\nexport const calculateMovingSpeed = (delta: number, elapsedTime: number): number =>\n Math.abs(delta / elapsedTime);\n\n/**\n * Calculates the specified percentage of a given value.\n *\n * @param value - The value to calculate the percentage of.\n * @param percentage - The percentage to calculate.\n *\n * @returns The calculated percentage of the value.\n */\nexport const calculatePercentage = (value: number, percentage: number): number => {\n return (value * percentage) / 100;\n};\n","interface HTMLElementTransformationValues {\n translateX: number;\n translateY: number;\n}\n\n/**\n * Get various transformation values from the transformation matrix of an element.\n *\n * @param element - The element with a transformation applied.\n *\n * @returns An object containing transformation values.\n */\nexport const getTransformationValues = (element: HTMLElement): HTMLElementTransformationValues => {\n const computedStyles = window.getComputedStyle(element);\n const transformValue = computedStyles.getPropertyValue('transform');\n\n const matrix = transformValue.match(/^matrix\\((.+)\\)$/);\n if (!matrix) {\n return {\n translateX: 0,\n translateY: 0,\n };\n }\n\n const transformMatrix = matrix[1].split(', ');\n\n const translateX = parseFloat(transformMatrix[4]);\n const translateY = parseFloat(transformMatrix[5]);\n\n return {\n translateX,\n translateY,\n };\n};\n"],"names":["toKebabCase","input","replace","toLowerCase","camelToDashCase","firstChar","charAt","restOfString","slice","letter","splitStringIntoWords","split","filter","Boolean","hashString","hash","i","length","charCodeAt","toString","assert","condition","message","Error","isNull","value","isString","isNumber","isBool","isObject","isEmptyObject","Object","keys","isArray","Array","isEmptyArray","isFunction","isPromise","then","isNil","isNilOrEmptyString","isDate","Date","isValidDate","isNaN","getTime","isRegExp","RegExp","isMap","Map","isSet","Set","isSymbol","isUndefined","undefined","isFiniteNumber","isFinite","isInteger","Number","boolFilter","array","unique","chunk","size","from","Math","ceil","_","index","intersection","arrays","first","rest","item","every","includes","difference","exclude","noop","invokeIfFunction","args","delay","delayMs","Promise","resolve","setTimeout","retry","task","maxAttempts","backoff","onRetry","async","lastError","attempt","e","delayTime","calculateEuclideanDistance","startX","startY","endX","endY","deltaX","deltaY","sqrt","calculateMovingSpeed","delta","elapsedTime","abs","calculatePercentage","percentage","getTransformationValues","element","matrix","window","getComputedStyle","getPropertyValue","match","translateX","translateY","transformMatrix","parseFloat"],"sourceRoot":""}
|
package/dist/string.d.ts
CHANGED
|
@@ -1,4 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a string to kebab-case format.
|
|
3
|
+
*
|
|
4
|
+
* This function transforms camelCase or PascalCase strings into kebab-case by inserting
|
|
5
|
+
* hyphens between lowercase and uppercase letters, then converting everything to lowercase.
|
|
6
|
+
*
|
|
7
|
+
* @param input - The string to convert to kebab-case.
|
|
8
|
+
*
|
|
9
|
+
* @returns The kebab-case formatted string.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* toKebabCase('helloWorld'); // → 'hello-world'
|
|
14
|
+
* toKebabCase('HelloWorld'); // → 'hello-world'
|
|
15
|
+
* toKebabCase('hello123World'); // → 'hello123-world'
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
1
18
|
export declare const toKebabCase: (input: string) => string;
|
|
19
|
+
/**
|
|
20
|
+
* Converts a camelCase string to dash-case format.
|
|
21
|
+
*
|
|
22
|
+
* This function transforms camelCase strings into dash-case by inserting
|
|
23
|
+
* hyphens before uppercase letters and converting them to lowercase.
|
|
24
|
+
* The function ensures that no hyphen is added at the start of the output string,
|
|
25
|
+
* even if the input begins with an uppercase letter.
|
|
26
|
+
*
|
|
27
|
+
* @param input - The camelCase string to convert to dash-case.
|
|
28
|
+
*
|
|
29
|
+
* @returns The dash-case formatted string.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* camelToDashCase('helloWorld'); // → 'hello-world'
|
|
34
|
+
* camelToDashCase('HelloWorld'); // → 'hello-world'
|
|
35
|
+
* camelToDashCase('backgroundColor'); // → 'background-color'
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
2
38
|
export declare const camelToDashCase: (input: string) => string;
|
|
3
39
|
/**
|
|
4
40
|
* Splits a string into an array of filtered from redundant spaces words.
|
package/package.json
CHANGED