@react-hive/honey-utils 1.5.0 โ†’ 1.6.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/dist/README.md CHANGED
@@ -11,6 +11,8 @@ A lightweight TypeScript utility library providing a collection of helper functi
11
11
 
12
12
  ## Features
13
13
 
14
+ ---
15
+
14
16
  - ๐Ÿ” **Type Guards** - Functions for runtime type checking
15
17
  - ๐Ÿงต **String Utilities** - String manipulation and transformation
16
18
  - ๐Ÿ”ข **Array Utilities** - Array filtering and manipulation
@@ -22,6 +24,8 @@ A lightweight TypeScript utility library providing a collection of helper functi
22
24
 
23
25
  ## Installation
24
26
 
27
+ ---
28
+
25
29
  ```bash
26
30
  # Using npm
27
31
  npm install @react-hive/honey-utils
@@ -35,9 +39,11 @@ pnpm add @react-hive/honey-utils
35
39
 
36
40
  ## Usage
37
41
 
42
+ ---
43
+
38
44
  ### Importing
39
45
 
40
- ```typescript
46
+ ```ts
41
47
  // Import specific utilities
42
48
  import { toKebabCase, isString, boolFilter } from '@react-hive/honey-utils';
43
49
 
@@ -47,7 +53,7 @@ import * as HoneyUtils from '@react-hive/honey-utils';
47
53
 
48
54
  ### String Utilities
49
55
 
50
- ```typescript
56
+ ```ts
51
57
  import { toKebabCase, camelToDashCase, splitStringIntoWords, hashString } from '@react-hive/honey-utils';
52
58
 
53
59
  // Convert string to kebab-case
@@ -65,34 +71,102 @@ const hash = hashString('background-color: red;'); // 'e4k1z0x'
65
71
 
66
72
  ### Array Utilities
67
73
 
68
- ```typescript
69
- import {
70
- boolFilter,
71
- unique,
72
- chunk,
73
- intersection,
74
- difference
74
+ ```ts
75
+ import {
76
+ boolFilter,
77
+ unique,
78
+ chunk,
79
+ intersection,
80
+ difference,
81
+ mapAsync,
82
+ forAsync,
83
+ reduceAsync,
84
+ filterAsync,
85
+ someAsync,
86
+ everyAsync,
87
+ findAsync,
75
88
  } from '@react-hive/honey-utils';
76
89
 
77
90
  // Filter out falsy values from an array
78
- boolFilter([0, 1, false, 2, '', 3, null, undefined, true]); // [1, 2, 3, true]
91
+ boolFilter([0, 1, false, 2, '', 3, null, undefined, true]);
92
+ // โžœ [1, 2, 3, true]
79
93
 
80
94
  // Remove duplicate values from an array
81
- unique([1, 2, 2, 3, 1, 4]); // [1, 2, 3, 4]
95
+ unique([1, 2, 2, 3, 1, 4]);
96
+ // โžœ [1, 2, 3, 4]
82
97
 
83
98
  // Split an array into chunks of specified size
84
- chunk([1, 2, 3, 4, 5], 2); // [[1, 2], [3, 4], [5]]
99
+ chunk([1, 2, 3, 4, 5], 2);
100
+ // โžœ [[1, 2], [3, 4], [5]]
85
101
 
86
102
  // Find common elements between arrays
87
- intersection([1, 2, 3], [2, 3, 4]); // [2, 3]
103
+ intersection([1, 2, 3], [2, 3, 4]);
104
+ // โžœ [2, 3]
88
105
 
89
106
  // Find elements in one array not in another
90
- difference([1, 2, 3, 4], [2, 4]); // [1, 3]
107
+ difference([1, 2, 3, 4], [2, 4]);
108
+ // โžœ [1, 3]
109
+
110
+ // Run async operations in parallel and collect results
111
+ await mapAsync([1, 2, 3], async (n) => {
112
+ await delay(100);
113
+
114
+ return n * 2;
115
+ });
116
+ // โžœ [2, 4, 6]
117
+
118
+ // Run async operations sequentially and collect results
119
+ await forAsync([1, 2, 3], async (n, i) => {
120
+ await delay(100);
121
+
122
+ return n * i;
123
+ });
124
+ // โžœ [0, 2, 6]
125
+
126
+ // Reduce array asynchronously
127
+ await reduceAsync([1, 2, 3], async (acc, n) => {
128
+ await delay(50);
129
+
130
+ return acc + n;
131
+ }, 0);
132
+ // โžœ 6
133
+
134
+ // Filter array asynchronously
135
+ await filterAsync([1, 2, 3, 4], async (n) => {
136
+ await delay(30);
137
+
138
+ return n % 2 === 0;
139
+ });
140
+ // โžœ [2, 4]
141
+
142
+ // Check if some items match condition asynchronously
143
+ await someAsync([1, 3, 5], async (n) => {
144
+ await delay(10);
145
+
146
+ return n % 2 === 0;
147
+ });
148
+ // โžœ false
149
+
150
+ // Check if all items match condition asynchronously
151
+ await everyAsync([2, 4, 6], async (n) => {
152
+ await delay(10);
153
+
154
+ return n % 2 === 0;
155
+ });
156
+ // โžœ true
157
+
158
+ // Find first matching item asynchronously
159
+ await findAsync([1, 3, 4, 5], async (n) => {
160
+ await delay(20);
161
+
162
+ return n % 2 === 0;
163
+ });
164
+ // โžœ 4
91
165
  ```
92
166
 
93
167
  ### Function Utilities
94
168
 
95
- ```typescript
169
+ ```ts
96
170
  import { noop, invokeIfFunction, delay, retry } from '@react-hive/honey-utils';
97
171
 
98
172
  // No-operation function
@@ -134,7 +208,7 @@ fetchWithRetry()
134
208
 
135
209
  ### Type Guards
136
210
 
137
- ```typescript
211
+ ```ts
138
212
  import {
139
213
  isString,
140
214
  isNumber,
@@ -221,7 +295,7 @@ isSet(new Set()); // true
221
295
 
222
296
  ### Math Utilities
223
297
 
224
- ```typescript
298
+ ```ts
225
299
  import {
226
300
  calculateEuclideanDistance,
227
301
  calculateMovingSpeed,
@@ -240,21 +314,37 @@ calculatePercentage(200, 25); // 50
240
314
 
241
315
  ### DOM Utilities
242
316
 
243
- ```typescript
244
- import { getTransformationValues } from '@react-hive/honey-utils';
317
+ ```ts
318
+ import { parse2DMatrix, cloneBlob, convertBlobToFile } from '@react-hive/honey-utils';
245
319
 
246
- // Get transformation values from an HTML element
320
+ // Extract transformation values from an HTML element's 2D matrix
247
321
  const element = document.getElementById('my-element');
248
322
  if (element) {
249
- const { translateX, translateY } = getTransformationValues(element);
323
+ const { translateX, translateY, scaleX, scaleY, skewX, skewY } = parse2DMatrix(element);
250
324
 
251
325
  console.log(`Element is translated by ${translateX}px horizontally and ${translateY}px vertically`);
326
+ console.log(`Element is scaled by ${scaleX} horizontally and ${scaleY} vertically`);
327
+ console.log(`Element is skewed by ${skewX} horizontally and ${skewY} vertically`);
252
328
  }
329
+
330
+ // Clone a Blob object
331
+ const originalBlob = new Blob(['Hello World'], { type: 'text/plain' });
332
+ const clonedBlob = cloneBlob(originalBlob);
333
+
334
+ console.log(clonedBlob.type); // 'text/plain'
335
+
336
+ // Convert a Blob to a File
337
+ const blob = new Blob(['Hello world'], { type: 'text/plain' });
338
+ const file = convertBlobToFile(blob, 'hello.txt');
339
+
340
+ console.log(file instanceof File); // true
341
+ console.log(file.name); // 'hello.txt'
342
+ console.log(file.type); // 'text/plain'
253
343
  ```
254
344
 
255
345
  ### Assert Function
256
346
 
257
- ```typescript
347
+ ```ts
258
348
  import { assert } from '@react-hive/honey-utils';
259
349
 
260
350
  // Assert a condition
@@ -266,66 +356,78 @@ function divide(a: number, b: number): number {
266
356
 
267
357
  ## API Documentation
268
358
 
359
+ ---
360
+
269
361
  ### String Utilities
270
362
 
271
- - **toKebabCase(input: string): string** - Converts a string to kebab-case
272
- - **camelToDashCase(input: string): string** - Converts camelCase to dash-case
273
- - **splitStringIntoWords(input: string): string[]** - Splits a string into an array of words
274
- - **hashString(input: string): string** - Generates a short hash from a string
363
+ - `toKebabCase(input: string): string` - Converts a string to kebab-case.
364
+ - `camelToDashCase(input: string): string` - Converts camelCase to dash-case.
365
+ - `splitStringIntoWords(input: string): string[]` - Splits a string into an array of words.
366
+ - `hashString(input: string): string` - Generates a short hash from a string.
275
367
 
276
368
  ### Array Utilities
277
369
 
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
370
+ #### Synchronous Utilities
371
+
372
+ - `boolFilter<T>(array: (T | false | null | undefined)[]): T[]` - Filters out falsy values (`false`, `null`, `undefined`) from an array while keeping valid items.
373
+ - `unique<T>(array: T[]): T[]` - Returns a new array with all duplicate elements removed. Keeps only the first occurrence of each value.
374
+ - `chunk<T>(array: T[], size: number): T[][]` - Splits an array into smaller arrays ("chunks") of the specified size.
375
+ - `intersection<T>(...arrays: T[][]): T[]` - Returns an array of elements that exist in all provided arrays.
376
+ - `difference<T>(array: T[], exclude: T[]): T[]` - Returns a new array that contains items from `array` that are not present in `exclude`.
377
+
378
+ #### Asynchronous Utilities
379
+
380
+ - `forAsync<Item, Result>(array: Item[], callbackFn: (item, index, array) => Promise<Result>): Promise<Result[]>` - Runs asynchronous operations on each array item *sequentially* and returns the results in the original order.
381
+ - `mapAsync<Item, Return>(array: Item[], callbackFn: (item, index, array) => Promise<Return>): Promise<Return[]>` - Executes an asynchronous function for each array item *in parallel* and returns a promise of all results.
382
+ - `reduceAsync<Item, Accumulator>(array: Item[], callbackFn, initialValue): Promise<Accumulator>` - Asynchronously reduces an array to a single accumulated value. Each step waits for the previous promise to resolve.
383
+ - `filterAsync<Item>(array: Item[], callbackFn): Promise<Item[]>` - Runs an asynchronous filter operation. Only includes items where `callbackFn(item)` resolves to `true`.
384
+ - `someAsync<Item>(array: Item[], callbackFn): Promise<boolean>` - Returns `true` if **any** item in the array passes the async predicate.
385
+ - `everyAsync<Item>(array: Item[], callbackFn): Promise<boolean>` - Returns `true` if **all** items in the array pass the async predicate.
386
+ - `findAsync<Item>(array: Item[], callbackFn): Promise<Item | null>` - Returns the first array item that passes the async predicate, or `null` if no match is found.
283
387
 
284
388
  ### Function Utilities
285
389
 
286
- - **noop(): void** - A no-operation function
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
390
+ - `noop(): void` - A no-operation function.
391
+ - `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.
392
+ - `delay(delayMs: number): Promise<void>` - Creates a promise that resolves after the specified delay in milliseconds.
393
+ - `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.
290
394
 
291
395
  ### Type Guards
292
396
 
293
- - **isString(value: unknown): value is string** - Checks if a value is a string
294
- - **isNumber(value: unknown): value is number** - Checks if a value is a number
295
- - **isBool(value: unknown): value is boolean** - Checks if a value is a boolean
296
- - **isObject(value: unknown): value is object** - Checks if a value is an object
297
- - **isFunction(value: unknown): value is Function** - Checks if a value is a function
298
- - **isPromise<T = unknown>(value: unknown): value is Promise<T>** - Checks if a value is a Promise
299
- - **isNil(value: unknown): value is null | undefined** - Checks if a value is null or undefined
300
- - **isNilOrEmptyString(value: unknown): value is null | undefined** - Checks if a value is null, undefined, or an empty string
301
- - **isArray(value: unknown): value is unknown[]** - Checks if a value is an array
302
- - **isEmptyArray(value: unknown): value is []** - Checks if a value is an empty array
303
- - **isEmptyObject(value: unknown): value is Record<string, never>** - Checks if a value is an empty object
304
- - **isNull(value: unknown): value is null** - Checks if a value is null
305
- - **isUndefined(value: unknown): value is undefined** - Checks if a value is undefined
306
- - **isFiniteNumber(value: unknown): value is number** - Checks if a value is a finite number
307
- - **isInteger(value: unknown): value is number** - Checks if a value is an integer
308
- - **isNaN(value: unknown): boolean** - Checks if a value is NaN
309
- - **isDate(value: unknown): value is Date** - Checks if a value is a Date object
310
- - **isValidDate(value: unknown): value is Date** - Checks if a value is a valid Date object (not Invalid Date)
311
- - **isRegExp(value: unknown): value is RegExp** - Checks if a value is a RegExp object
312
- - **isMap(value: unknown): value is Map<unknown, unknown>** - Checks if a value is a Map
313
- - **isSet(value: unknown): value is Set<unknown>** - Checks if a value is a Set
314
- - **isSymbol(value: unknown): value is symbol** - Checks if a value is a Symbol
397
+ - `assert(condition: any, message: string): asserts condition` - Asserts that a condition is truthy, throwing an error with the provided message if it's not.
398
+ - `isString(value: unknown): value is string` - Checks if a value is a string.
399
+ - `isNumber(value: unknown): value is number` - Checks if a value is a number.
400
+ - `isBool(value: unknown): value is boolean` - Checks if a value is a boolean.
401
+ - `isObject(value: unknown): value is object` - Checks if a value is an object.
402
+ - `isFunction(value: unknown): value is Function` - Checks if a value is a function.
403
+ - `isPromise<T = unknown>(value: unknown): value is Promise<T>` - Checks if a value is a Promise.
404
+ - `isNil(value: unknown): value is null | undefined` - Checks if a value is null or undefined.
405
+ - `isNilOrEmptyString(value: unknown): value is null | undefined` - Checks if a value is null, undefined, or an empty string.
406
+ - `isArray(value: unknown): value is unknown[]` - Checks if a value is an array.
407
+ - `isEmptyArray(value: unknown): value is []` - Checks if a value is an empty array.
408
+ - `isEmptyObject(value: unknown): value is Record<string, never>` - Checks if a value is an empty object.
409
+ - `isNull(value: unknown): value is null` - Checks if a value is null.
410
+ - `isUndefined(value: unknown): value is undefined` - Checks if a value is undefined.
411
+ - `isFiniteNumber(value: unknown): value is number` - Checks if a value is a finite number.
412
+ - `isInteger(value: unknown): value is number` - Checks if a value is an integer.
413
+ - `isDate(value: unknown): value is Date` - Checks if a value is a Date object.
414
+ - `isValidDate(value: unknown): value is Date` - Checks if a value is a valid Date object (not Invalid Date).
415
+ - `isRegExp(value: unknown): value is RegExp` - Checks if a value is a RegExp object.
416
+ - `isMap(value: unknown): value is Map<unknown, unknown>` - Checks if a value is a Map.
417
+ - `isSet(value: unknown): value is Set<unknown>` - Checks if a value is a Set.
418
+ - `isSymbol(value: unknown): value is symbol` - Checks if a value is a Symbol.
315
419
 
316
420
  ### Math Utilities
317
421
 
318
- - **calculateEuclideanDistance(startX: number, startY: number, endX: number, endY: number): number** - Calculates the Euclidean distance between two points
319
- - **calculateMovingSpeed(delta: number, elapsedTime: number): number** - Calculates moving speed
320
- - **calculatePercentage(value: number, percentage: number): number** - Calculates the specified percentage of a value
422
+ - `calculateEuclideanDistance(startX: number, startY: number, endX: number, endY: number): number` - Calculates the Euclidean distance between two points.
423
+ - `calculateMovingSpeed(delta: number, elapsedTime: number): number` - Calculates moving speed.
424
+ - `calculatePercentage(value: number, percentage: number): number` - Calculates the specified percentage of a value.
321
425
 
322
426
  ### DOM Utilities
323
427
 
324
- - **getTransformationValues(element: HTMLElement): { translateX: number, translateY: number }** - Gets transformation values from an HTML element
325
-
326
- ### Other Utilities
327
-
328
- - **assert(condition: any, message: string): asserts condition** - Asserts that a condition is truthy, throwing an error with the provided message if it's not
428
+ - `parse2DMatrix(element: HTMLElement): { translateX: number, translateY: number, scaleX: number, scaleY: number, skewX: number, skewY: number }` - Extracts transformation values (translate, scale, skew) from the 2D transformation matrix of a given HTML element.
429
+ - `cloneBlob(blob: Blob): Blob` - Creates a clone of a Blob object with the same content and type as the original.
430
+ - `convertBlobToFile(blob: Blob, fileName: string): File` - Converts a Blob object into a File object with the specified name.
329
431
 
330
432
  ## Contributing
331
433
 
package/dist/array.d.ts CHANGED
@@ -82,3 +82,89 @@ export declare const intersection: <T>(...arrays: T[][]) => T[];
82
82
  * ```
83
83
  */
84
84
  export declare const difference: <T>(array: T[], exclude: T[]) => T[];
85
+ /**
86
+ * Asynchronously iterates over an array and executes an async function on each item sequentially,
87
+ * collecting the results.
88
+ *
89
+ * Unlike `Promise.all`, this runs each promise one after another (not in parallel).
90
+ * Useful when order or timing matters (e.g., rate limits, UI updates, animations).
91
+ *
92
+ * @param array - The array of items to iterate over.
93
+ * @param callbackFn - An async function to execute for each item. Must return a value.
94
+ *
95
+ * @returns A promise that resolves with an array of results from each callback call.
96
+ *
97
+ * @example
98
+ * ```ts
99
+ * const results = await forAsync([1, 2, 3], async (item) => {
100
+ * await delay(100);
101
+ *
102
+ * return item * 2;
103
+ * });
104
+ *
105
+ * console.log(results); // [2, 4, 6]
106
+ * ```
107
+ */
108
+ export declare const forAsync: <Item, Result>(array: Item[], callbackFn: (item: Item, index: number, array: Item[]) => Promise<Result>) => Promise<Result[]>;
109
+ /**
110
+ * Executes an asynchronous operation on each element of an array and waits for all promises to resolve.
111
+ *
112
+ * @param array - The array of items to operate on.
113
+ * @param callbackFn - The asynchronous operation to perform on each item.
114
+ *
115
+ * @returns A promise that resolves with an array of results after all operations are completed.
116
+ */
117
+ export declare const mapAsync: <Item, Return>(array: Item[], callbackFn: (item: Item, index: number, array: Item[]) => Promise<Return>) => Promise<Return[]>;
118
+ /**
119
+ * A generic function that processes an array asynchronously and filters the results
120
+ * based on the provided async condition.
121
+ *
122
+ * @template Item - The type of the items in the array.
123
+ * @template Return - The type of the items returned by the condition.
124
+ *
125
+ * @param array - An array of items to be processed.
126
+ * @param callbackFn - An async function that returns a condition for each item.
127
+ *
128
+ * @returns A Promise that resolves to an array of items that match the condition.
129
+ */
130
+ export declare const filterAsync: <Item>(array: Item[], callbackFn: (item: Item, index: number, array: Item[]) => Promise<boolean>) => Promise<Item[]>;
131
+ /**
132
+ * Asynchronously checks if at least one element in the array satisfies the async condition.
133
+ *
134
+ * @param array - The array of items to check.
135
+ * @param callbackFn - An async function that returns a boolean.
136
+ *
137
+ * @returns A promise that resolves to true if any item passes the condition.
138
+ */
139
+ export declare const someAsync: <Item>(array: Item[], callbackFn: (item: Item, index: number, array: Item[]) => Promise<boolean>) => Promise<boolean>;
140
+ /**
141
+ * Asynchronously checks if all elements in the array satisfy the async condition.
142
+ *
143
+ * @param array - The array of items to check.
144
+ * @param callbackFn - An async function that returns a boolean.
145
+ *
146
+ * @returns A promise that resolves to true if all items pass the condition.
147
+ */
148
+ export declare const everyAsync: <Item>(array: Item[], callbackFn: (item: Item, index: number, array: Item[]) => Promise<boolean>) => Promise<boolean>;
149
+ /**
150
+ * Asynchronously reduces an array to a single accumulated value.
151
+ *
152
+ * @template Item - The type of items in the array.
153
+ * @template Accumulator - The type of the accumulated result.
154
+ *
155
+ * @param array - The array to reduce.
156
+ * @param callbackFn - The async reducer function that processes each item and returns the updated accumulator.
157
+ * @param initialValue - The initial accumulator value.
158
+ *
159
+ * @returns A promise that resolves to the final accumulated result.
160
+ */
161
+ export declare const reduceAsync: <Item, Accumulator>(array: Item[], callbackFn: (accumulator: Accumulator, item: Item, index: number, array: Item[]) => Promise<Accumulator>, initialValue: Accumulator) => Promise<Accumulator>;
162
+ /**
163
+ * Asynchronously finds the first element that satisfies the async condition.
164
+ *
165
+ * @param array - The array of items to search.
166
+ * @param callbackFn - An async function that returns a boolean.
167
+ *
168
+ * @returns A promise that resolves to the found item or null if none match.
169
+ */
170
+ export declare const findAsync: <Item>(array: Item[], callbackFn: (item: Item, index: number, array: Item[]) => Promise<boolean>) => Promise<Item | null>;
package/dist/dom.d.ts CHANGED
@@ -1,13 +1,53 @@
1
1
  interface HTMLElementTransformationValues {
2
2
  translateX: number;
3
3
  translateY: number;
4
+ scaleX: number;
5
+ scaleY: number;
6
+ skewX: number;
7
+ skewY: number;
4
8
  }
5
9
  /**
6
- * Get various transformation values from the transformation matrix of an element.
10
+ * Extracts transformation values (translate, scale, skew) from the 2D transformation matrix of a given HTML element.
7
11
  *
8
- * @param element - The element with a transformation applied.
12
+ * Only works with 2D transforms (i.e., `matrix(a, b, c, d, e, f)`).
9
13
  *
10
- * @returns An object containing transformation values.
14
+ * @param element - The element with a CSS transform applied.
15
+ * @returns An object with parsed transformation values.
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * const values = parse2DMatrix(myElement);
20
+ * console.log(values.translateX);
21
+ * console.log(values.scaleX);
22
+ * ```
23
+ */
24
+ export declare const parse2DMatrix: (element: HTMLElement) => HTMLElementTransformationValues;
25
+ /**
26
+ * Creates a clone of a Blob object.
27
+ *
28
+ * @param blob - The Blob object to clone.
29
+ *
30
+ * @returns A new Blob with the same content and type as the original.
31
+ */
32
+ export declare const cloneBlob: (blob: Blob) => Blob;
33
+ /**
34
+ * Converts a `Blob` object into a `File` object with the specified name.
35
+ *
36
+ * This is useful when you receive a `Blob` (e.g., from canvas, fetch, or file manipulation)
37
+ * and need to convert it into a `File` to upload via `FormData` or file inputs.
38
+ *
39
+ * @param blob - The `Blob` to convert.
40
+ * @param fileName - The desired name for the resulting file (including extension).
41
+ *
42
+ * @returns A `File` instance with the same content and MIME type as the input `Blob`.
43
+ *
44
+ * @example
45
+ * ```ts
46
+ * const blob = new Blob(['Hello world'], { type: 'text/plain' });
47
+ * const file = convertBlobToFile(blob, 'hello.txt');
48
+ *
49
+ * console.log(file instanceof File); // true
50
+ * ```
11
51
  */
12
- export declare const getTransformationValues: (element: HTMLElement) => HTMLElementTransformationValues;
52
+ export declare const convertBlobToFile: (blob: Blob, fileName: string) => File;
13
53
  export {};
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
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})();
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:()=>i,boolFilter:()=>C,calculateEuclideanDistance:()=>V,calculateMovingSpeed:()=>Z,calculatePercentage:()=>_,camelToDashCase:()=>n,chunk:()=>N,cloneBlob:()=>U,convertBlobToFile:()=>W,delay:()=>q,difference:()=>x,everyAsync:()=>Y,filterAsync:()=>T,findAsync:()=>$,forAsync:()=>B,hashString:()=>s,intersection:()=>E,invokeIfFunction:()=>R,isArray:()=>p,isBool:()=>y,isDate:()=>w,isEmptyArray:()=>g,isEmptyObject:()=>f,isFiniteNumber:()=>P,isFunction:()=>m,isInteger:()=>j,isMap:()=>v,isNil:()=>b,isNilOrEmptyString:()=>d,isNull:()=>o,isNumber:()=>c,isObject:()=>u,isPromise:()=>h,isRegExp:()=>S,isSet:()=>M,isString:()=>l,isSymbol:()=>k,isUndefined:()=>O,isValidDate:()=>A,mapAsync:()=>D,noop:()=>L,parse2DMatrix:()=>K,reduceAsync:()=>I,retry:()=>z,someAsync:()=>X,splitStringIntoWords:()=>a,toKebabCase:()=>r,unique:()=>F});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()}`)},a=e=>e.split(" ").filter(Boolean),s=e=>{let t=5381;for(let r=0;r<e.length;r++)t=33*t^e.charCodeAt(r);return(t>>>0).toString(36)};function i(e,t){if(!e)throw new Error(t)}const o=e=>null===e,l=e=>"string"==typeof e,c=e=>"number"==typeof e,y=e=>"boolean"==typeof e,u=e=>"object"==typeof e,f=e=>u(e)&&!o(e)&&0===Object.keys(e).length,p=e=>Array.isArray(e),g=e=>p(e)&&0===e.length,m=e=>"function"==typeof e,h=e=>m(e?.then),b=e=>null==e,d=e=>""===e||b(e),w=e=>e instanceof Date,A=e=>w(e)&&!isNaN(e.getTime()),S=e=>e instanceof RegExp,v=e=>e instanceof Map,M=e=>e instanceof Set,k=e=>"symbol"==typeof e,O=e=>void 0===e,P=e=>c(e)&&isFinite(e),j=e=>c(e)&&Number.isInteger(e),C=e=>e.filter(Boolean),F=e=>[...new Set(e)],N=(e,t)=>(i(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))),E=(...e)=>{if(0===e.length)return[];if(1===e.length)return[...e[0]];const[t,...r]=e;return F(t).filter(e=>r.every(t=>t.includes(e)))},x=(e,t)=>e.filter(e=>!t.includes(e)),B=async(e,t)=>{const r=[];for(let n=0;n<e.length;n++)r.push(await t(e[n],n,e));return r},D=async(e,t)=>Promise.all(e.map(t)),T=async(e,t)=>{const r=await D(e,async(e,r,n)=>!!await t(e,r,n)&&e);return C(r)},X=async(e,t)=>{for(let r=0;r<e.length;r++)if(await t(e[r],r,e))return!0;return!1},Y=async(e,t)=>{for(let r=0;r<e.length;r++)if(!await t(e[r],r,e))return!1;return!0},I=async(e,t,r)=>{let n=r;for(let r=0;r<e.length;r++)n=await t(n,e[r],r,e);return n},$=async(e,t)=>{for(let r=0;r<e.length;r++)if(await t(e[r],r,e))return e[r];return null},L=()=>{},R=(e,...t)=>"function"==typeof e?e(...t):e,q=e=>new Promise(t=>setTimeout(t,e)),z=(e,{maxAttempts:t=3,delayMs:r=300,backoff:n=!0,onRetry:a}={})=>async(...s)=>{let i;for(let o=1;o<=t;o++)try{return await e(...s)}catch(e){if(i=e,o<t){a?.(o,e);const t=n?r*2**(o-1):r;await q(t)}}throw i},V=(e,t,r,n)=>{const a=r-e,s=n-t;return Math.sqrt(a**2+s**2)},Z=(e,t)=>Math.abs(e/t),_=(e,t)=>e*t/100,K=e=>{const t=window.getComputedStyle(e).getPropertyValue("transform").match(/^matrix\((.+)\)$/);if(!t)return{translateX:0,translateY:0,scaleX:1,scaleY:1,skewX:0,skewY:0};const[r,n,a,s,i,o]=t[1].split(", ").map(parseFloat);return{translateX:i,translateY:o,scaleX:r,scaleY:s,skewX:a,skewY:n}},U=e=>new Blob([e],{type:e.type}),W=(e,t)=>new File([e],t,{type:e.type});module.exports=t})();
2
2
  //# sourceMappingURL=index.cjs.map