@react-hive/honey-utils 2.4.0 → 3.1.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
@@ -48,33 +48,64 @@ import * as HoneyUtils from '@react-hive/honey-utils';
48
48
  ### String Utilities
49
49
 
50
50
  ```ts
51
- import { toKebabCase, camelToDashCase, splitStringIntoWords, hashString } from '@react-hive/honey-utils';
51
+ import {
52
+ isString,
53
+ isNilOrEmptyString,
54
+ toKebabCase,
55
+ camelToDashCase,
56
+ splitStringIntoWords,
57
+ hashString
58
+ } from '@react-hive/honey-utils';
59
+
60
+ /**
61
+ * Check if value is a string
62
+ */
63
+ isString('hello');
64
+ // ➜ true
65
+ isString(123);
66
+ // ➜ false
67
+
68
+ /**
69
+ * Check if value is null, undefined, or empty string
70
+ */
71
+ isNilOrEmptyString('');
72
+ // ➜ true
73
+ isNilOrEmptyString(null);
74
+ // ➜ true
75
+ isNilOrEmptyString('hello');
76
+ // ➜ false
52
77
 
53
78
  /**
54
79
  * Convert string to kebab-case
55
80
  */
56
- toKebabCase('helloWorld'); // 'hello-world'
81
+ toKebabCase('helloWorld');
82
+ // ➜ 'hello-world'
57
83
 
58
84
  /**
59
85
  * Convert camelCase to dash-case
60
86
  */
61
- camelToDashCase('helloWorld'); // 'hello-world'
87
+ camelToDashCase('helloWorld');
88
+ // ➜ 'hello-world'
62
89
 
63
90
  /**
64
91
  * Split string into words
65
92
  */
66
- splitStringIntoWords('hello world'); // ['hello', 'world']
93
+ splitStringIntoWords('hello world');
94
+ // ➜ ['hello', 'world']
67
95
 
68
96
  /**
69
97
  * Generate a hash from a string
70
98
  */
71
- const hash = hashString('background-color: red;'); // 'e4k1z0x'
99
+ const hash = hashString('background-color: red;');
100
+ // ➜ 'e4k1z0x'
72
101
  ```
73
102
 
74
103
  ### Array Utilities
75
104
 
76
105
  ```ts
77
106
  import {
107
+ isArray,
108
+ isEmptyArray,
78
109
  compact,
79
110
  unique,
80
111
  chunk,
@@ -84,6 +115,22 @@ import {
84
115
  compose,
85
116
  } from '@react-hive/honey-utils';
86
117
 
118
+ /**
119
+ * Check if value is an array
120
+ */
121
+ isArray([1, 2, 3]);
122
+ // ➜ true
123
+ isArray({});
124
+ // ➜ false
125
+
126
+ /**
127
+ * Check if value is an empty array
128
+ */
129
+ isEmptyArray([]);
130
+ // ➜ true
131
+ isEmptyArray([1, 2, 3]);
132
+ // ➜ false
133
+
87
134
  /**
88
135
  * Filter out falsy values from an array
89
136
  */
@@ -134,6 +181,7 @@ compose(increment, double)(3);
134
181
 
135
182
  ```ts
136
183
  import {
184
+ isPromise,
137
185
  runParallel,
138
186
  runSequential,
139
187
  reduceAsync,
@@ -143,6 +191,14 @@ import {
143
191
  findAsync,
144
192
  } from '@react-hive/honey-utils';
145
193
 
194
+ /**
195
+ * Check if value is a Promise
196
+ */
197
+ isPromise(Promise.resolve());
198
+ // ➜ true
199
+ isPromise({});
200
+ // ➜ false
201
+
146
202
  /**
147
203
  * Run async operations in parallel and collect results
148
204
  */
@@ -210,20 +266,35 @@ await findAsync([1, 3, 4, 5], async (n) => {
210
266
  ### Function Utilities
211
267
 
212
268
  ```ts
213
- import { noop, invokeIfFunction, delay, retry } from '@react-hive/honey-utils';
269
+ import {
270
+ noop,
271
+ isFunction,
272
+ invokeIfFunction,
273
+ delay,
274
+ retry
275
+ } from '@react-hive/honey-utils';
214
276
 
215
277
  /**
216
278
  * No-operation function. Does nothing
217
279
  */
218
280
  noop();
219
281
 
282
+ /**
283
+ * Check if value is a function
284
+ */
285
+ isFunction(() => {});
286
+ // ➜ true
287
+ isFunction({});
288
+ // ➜ false
289
+
220
290
  /**
221
291
  * Invoke if function, otherwise return value
222
292
  */
223
293
  const fn = (x: number) => x * 2;
224
294
 
225
295
  invokeIfFunction(fn, 5); // 10
226
- invokeIfFunction('not a function', 5); // 'not a function'
296
+ invokeIfFunction('not a function', 5);
297
+ // ➜ 'not a function'
227
298
 
228
299
  /**
229
300
  * Waits for 1 second before continuing
@@ -260,151 +331,132 @@ fetchWithRetry()
260
331
  ### Type Guards
261
332
 
262
333
  ```ts
263
- import {
264
- isString,
265
- isNumber,
266
- isBool,
267
- isObject,
268
- isFunction,
269
- isPromise,
270
- isNil,
271
- isNilOrEmptyString,
272
- isArray,
273
- isEmptyArray,
274
- isEmptyObject,
275
- isNull,
276
- isUndefined,
277
- isDate,
278
- isValidDate,
279
- isRegExp,
280
- isMap,
281
- isSet
334
+ import {
335
+ isNumber,
336
+ isBool,
337
+ isObject,
338
+ isNil,
339
+ isEmptyObject,
340
+ isNull,
341
+ isUndefined,
342
+ isDate,
343
+ isValidDate,
344
+ isRegExp,
345
+ isMap,
346
+ isSet
282
347
  } from '@react-hive/honey-utils';
283
348
 
284
- /**
285
- * Check if value is a string
286
- */
287
- isString('hello'); // true
288
- isString(123); // false
289
-
290
349
  /**
291
350
  * Check if value is a number
292
351
  */
293
- isNumber(123); // true
294
- isNumber('123'); // false
352
+ isNumber(123);
353
+ // ➜ true
354
+ isNumber('123');
355
+ // ➜ false
295
356
 
296
357
  /**
297
358
  * Check if value is a boolean
298
359
  */
299
- isBool(true); // true
300
- isBool('true'); // false
360
+ isBool(true);
361
+ // ➜ true
362
+ isBool('true');
363
+ // ➜ false
301
364
 
302
365
  /**
303
366
  * Check if value is an object
304
367
  */
305
- isObject({}); // true
306
- isObject('object'); // false
307
-
308
- /**
309
- * Check if value is a function
310
- */
311
- isFunction(() => {}); // true
312
- isFunction({}); // false
313
-
314
- /**
315
- * Check if value is a Promise
316
- */
317
- isPromise(Promise.resolve()); // true
318
- isPromise({}); // false
368
+ isObject({});
369
+ // ➜ true
370
+ isObject('object');
371
+ // ➜ false
319
372
 
320
373
  /**
321
374
  * Check if value is null or undefined
322
375
  */
323
- isNil(null); // true
324
- isNil(undefined); // true
325
- isNil(''); // false
326
-
327
- /**
328
- * Check if value is null, undefined, or empty string
329
- */
330
- isNilOrEmptyString(''); // true
331
- isNilOrEmptyString(null); // true
332
- isNilOrEmptyString('hello'); // false
333
-
334
- /**
335
- * Check if value is an array
336
- */
337
- isArray([1, 2, 3]); // true
338
- isArray({}); // false
339
-
340
- /**
341
- * Check if value is an empty array
342
- */
343
- isEmptyArray([]); // true
344
- isEmptyArray([1, 2, 3]); // false
376
+ isNil(null);
377
+ // true
378
+ isNil(undefined);
379
+ // ➜ true
380
+ isNil('');
381
+ // false
345
382
 
346
383
  /**
347
384
  * Check if value is an empty object
348
385
  */
349
- isEmptyObject({}); // true
350
- isEmptyObject({ key: 'value' }); // false
386
+ isEmptyObject({});
387
+ // true
388
+ isEmptyObject({ key: 'value' });
389
+ // ➜ false
351
390
 
352
391
  /**
353
392
  * Check if value is a Date object
354
393
  */
355
- isDate(new Date()); // true
356
- isDate('2023-01-01'); // false
394
+ isDate(new Date());
395
+ // ➜ true
396
+ isDate('2023-01-01');
397
+ // ➜ false
357
398
 
358
399
  /**
359
400
  * Check if value is a valid Date object
360
401
  */
361
- isValidDate(new Date()); // true
362
- isValidDate(new Date('invalid')); // false
402
+ isValidDate(new Date());
403
+ // true
404
+ isValidDate(new Date('invalid'));
405
+ // ➜ false
363
406
 
364
407
  /**
365
408
  * Check if value is a RegExp
366
409
  */
367
- isRegExp(/test/); // true
368
- isRegExp('test'); // false
410
+ isRegExp(/test/);
411
+ // ➜ true
412
+ isRegExp('test');
413
+ // ➜ false
369
414
 
370
415
  /**
371
416
  * Check if value is a Map or Set
372
417
  */
373
- isMap(new Map()); // true
374
- isSet(new Set()); // true
418
+ isMap(new Map());
419
+ // true
420
+ isSet(new Set());
421
+ // ➜ true
375
422
  ```
376
423
 
377
424
  ### Math Utilities
378
425
 
379
426
  ```ts
380
- import {
381
- calculateEuclideanDistance,
382
- calculateMovingSpeed,
383
- calculatePercentage
427
+ import {
428
+ calculateEuclideanDistance,
429
+ calculateMovingSpeed,
430
+ calculatePercentage
384
431
  } from '@react-hive/honey-utils';
385
432
 
386
433
  /**
387
434
  * Calculate Euclidean distance between two points
388
435
  */
389
- calculateEuclideanDistance(0, 0, 3, 4); // 5
436
+ calculateEuclideanDistance(0, 0, 3, 4);
437
+ // ➜ 5
390
438
 
391
439
  /**
392
440
  * Calculate moving speed
393
441
  */
394
- calculateMovingSpeed(100, 5); // 20
442
+ calculateMovingSpeed(100, 5);
443
+ // ➜ 20
395
444
 
396
445
  /**
397
446
  * Calculate percentage of a value
398
447
  */
399
- calculatePercentage(200, 25); // 50
448
+ calculatePercentage(200, 25);
449
+ // ➜ 50
400
450
  ```
401
451
 
402
452
  ### DOM Utilities
403
453
 
404
454
  ```ts
405
- import { parse2DMatrix, cloneBlob, convertBlobToFile } from '@react-hive/honey-utils';
455
+ import { parse2DMatrix, cloneBlob } from '@react-hive/honey-utils';
406
456
 
407
- // Extract transformation values from an HTML element's 2D matrix
457
+ /**
458
+ * Extract transformation values from an HTML element's 2D matrix
459
+ */
408
460
  const element = document.getElementById('my-element');
409
461
  if (element) {
410
462
  const { translateX, translateY, scaleX, scaleY, skewX, skewY } = parse2DMatrix(element);
@@ -414,19 +466,68 @@ if (element) {
414
466
  console.log(`Element is skewed by ${skewX} horizontally and ${skewY} vertically`);
415
467
  }
416
468
 
417
- // Clone a Blob object
469
+ /**
470
+ * Clone a Blob object
471
+ */
418
472
  const originalBlob = new Blob(['Hello World'], { type: 'text/plain' });
419
473
  const clonedBlob = cloneBlob(originalBlob);
420
474
 
421
- console.log(clonedBlob.type); // 'text/plain'
475
+ console.log(clonedBlob.type);
476
+ // ➜ 'text/plain'
477
+ ```
478
+
479
+ ### File Utilities
480
+
481
+ ```ts
482
+ import { parseFileName, fileListToFile, blobToFile } from '@react-hive/honey-utils';
483
+
484
+ /**
485
+ * Parse a file name into base name + extension
486
+ */
487
+ const [base, ext] = parseFileName('archive.tar.gz');
488
+
489
+ console.log(base);
490
+ // ➜ 'archive.tar'
491
+ console.log(ext);
492
+ // ➜ 'gz'
493
+
494
+ /**
495
+ * Hidden file (no name)
496
+ */
497
+ parseFileName('.gitignore');
498
+ // ➜ ['.gitignore', '']
499
+
500
+ /**
501
+ * No file extension
502
+ */
503
+ parseFileName('README');
504
+ // ➜ ['README', '']
505
+
506
+ /**
507
+ * Convert a FileList to an array
508
+ */
509
+ const input = document.querySelector('input[type="file"]')!;
510
+ input.addEventListener('change', () => {
511
+ const files = fileListToFiles(input.files);
512
+
513
+ console.log(Array.isArray(files));
514
+ // ➜ true
515
+ console.log(files[0] instanceof File);
516
+ // ➜ true
517
+ });
422
518
 
423
- // Convert a Blob to a File
519
+ /**
520
+ * Convert a Blob to a File
521
+ */
424
522
  const blob = new Blob(['Hello world'], { type: 'text/plain' });
425
- const file = convertBlobToFile(blob, 'hello.txt');
523
+ const file = blobToFile(blob, 'hello.txt');
426
524
 
427
- console.log(file instanceof File); // true
428
- console.log(file.name); // 'hello.txt'
429
- console.log(file.type); // 'text/plain'
525
+ console.log(file instanceof File);
526
+ // ➜ true
527
+ console.log(file.name);
528
+ // ➜ 'hello.txt'
529
+ console.log(file.type);
530
+ // ➜ 'text/plain'
430
531
  ```
431
532
 
432
533
  ### Assert Function
@@ -445,6 +546,8 @@ function divide(a: number, b: number): number {
445
546
 
446
547
  ### String Utilities
447
548
 
549
+ - `isString(value: unknown): value is string` - Checks if a value is a `string`.
550
+ - `isNilOrEmptyString(value: unknown): value is null | undefined` - Checks if a value is `null`, `undefined`, or an empty string.
448
551
  - `toKebabCase(input: string): string` - Converts a string to kebab-case.
449
552
  - `camelToDashCase(input: string): string` - Converts camelCase to dash-case.
450
553
  - `splitStringIntoWords(input: string): string[]` - Splits a string into an array of words.
@@ -452,6 +555,8 @@ function divide(a: number, b: number): number {
452
555
 
453
556
  ### Array Utilities
454
557
 
558
+ - `isArray(value: unknown): value is unknown[]` - Checks if a value is an array.
559
+ - `isEmptyArray(value: unknown): value is []` - Checks if a value is an empty array.
455
560
  - `compact<T>(array: (T | Falsy)[]): T[]` – Returns a new array with all falsy values (false, null, undefined, 0, '', NaN) removed, preserving only truthy items of type `T`.
456
561
  - `unique<T>(array: T[]): T[]` - Returns a new array with all duplicate elements removed. Keeps only the first occurrence of each value.
457
562
  - `chunk<T>(array: T[], size: number): T[][]` - Splits an array into smaller arrays ("chunks") of the specified size.
@@ -462,6 +567,7 @@ function divide(a: number, b: number): number {
462
567
 
463
568
  ### Function Utilities
464
569
 
570
+ - `isFunction(value: unknown): value is Function` - Checks if a value is a `function`.
465
571
  - `noop(): void` - A no-operation function.
466
572
  - `not<Args extends any[]>(fn: (...args: Args) => any): (...args: Args) => boolean` - Creates a new function that negates the result of the given predicate function. Useful for logical inversions, e.g., turning `isEven` into `isOdd`.
467
573
  - `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.
@@ -472,16 +578,10 @@ function divide(a: number, b: number): number {
472
578
  ### Type Guards
473
579
 
474
580
  - `assert(condition: any, message: string): asserts condition` - Asserts that a condition is truthy, throwing an error with the provided message if it's not.
475
- - `isString(value: unknown): value is string` - Checks if a value is a `string`.
476
581
  - `isNumber(value: unknown): value is number` - Checks if a value is a `number`.
477
582
  - `isBool(value: unknown): value is boolean` - Checks if a value is a `boolean`.
478
583
  - `isObject(value: unknown): value is object` - Checks if a value is an `object`.
479
- - `isFunction(value: unknown): value is Function` - Checks if a value is a `function`.
480
- - `isPromise<T = unknown>(value: unknown): value is Promise<T>` - Checks if a value is a `Promise`.
481
584
  - `isNil(value: unknown): value is null | undefined` - Checks if a value is `null` or `undefined`.
482
- - `isNilOrEmptyString(value: unknown): value is null | undefined` - Checks if a value is `null`, `undefined`, or an empty string.
483
- - `isArray(value: unknown): value is unknown[]` - Checks if a value is an array.
484
- - `isEmptyArray(value: unknown): value is []` - Checks if a value is an empty array.
485
585
  - `isEmptyObject(value: unknown): value is Record<string, never>` - Checks if a value is an empty object.
486
586
  - `isNull(value: unknown): value is null` - Checks if a value is `null`.
487
587
  - `isUndefined(value: unknown): value is undefined` - Checks if a value is `undefined`.
@@ -505,7 +605,6 @@ function divide(a: number, b: number): number {
505
605
 
506
606
  - `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.
507
607
  - `cloneBlob(blob: Blob): Blob` - Creates a clone of a Blob object with the same content and type as the original.
508
- - `convertBlobToFile(blob: Blob, fileName: string): File` - Converts a Blob object into a File object with the specified name.
509
608
  - `getDOMRectIntersectionRatio(sourceRect: DOMRect, targetRect: DOMRect): number` - Calculates the ratio of the `targetRect` that is overlapped by the `sourceRect`. Returns a number between `0` (no overlap) and `1` (fully covered).
510
609
  - `getElementOffsetRect(element: HTMLElement): DOMRect` - Returns a `DOMRect` representing the element's layout position using `offsetLeft`, `offsetTop`, and `clientWidth`/`clientHeight`.
511
610
  - `isAnchorHtmlElement(element: HTMLElement): element is HTMLAnchorElement` - Determines whether the provided element is an `<a>` tag. Acts as a type guard that narrows the element to `HTMLAnchorElement`.
@@ -513,8 +612,17 @@ function divide(a: number, b: number): number {
513
612
  - `isHtmlElementFocusable(element: Nullable<HTMLElement>): boolean` - Checks whether an element is considered focusable according to browser rules. Factors include: visibility, `display`, `disabled`, `tabindex`, native focusable tags, `contenteditable`, and presence of a non-null `tabindex`.
514
613
  - `getFocusableHtmlElements(container: HTMLElement): HTMLElement[]` - Returns all focusable descendant elements within a container, using `isHtmlElementFocusable` to filter them.
515
614
 
615
+ ### File Utilities
616
+
617
+ - `isFile(value: unknown): value is File` - Checks if a value is a `File`.
618
+ - `parseFileName(fileName: string): [baseName: string, extension: string]` - Splits a file name into its base name and extension using the last `.` as the separator. Handles edge cases such as hidden files (`.gitignore`), multi-dot names (`archive.tar.gz`), and names ending with a dot (`"file."`). The extension is returned in lowercase.
619
+ - `fileListToFiles(fileList: FileList | null): File[]` - Converts a `FileList` object (such as the one returned from an `<input type="file">`) into a standard array of `File` objects. Returns an empty array when the input is `null`.
620
+ - `blobToFile(blob: Blob, fileName: string): File` - Converts a Blob object into a File object with the specified name.
621
+ - `traverseFileSystemDirectory(directoryEntry: FileSystemDirectoryEntry, options?: TraverseDirectoryOptions): Promise<File[]>` — Recursively scans a directory using the File System API and returns all nested files as `File` objects. Supports skipping system files and reporting progress through an optional `onProgress` callback.
622
+
516
623
  ### Asynchronous Utilities
517
624
 
625
+ - `isPromise<T = unknown>(value: unknown): value is Promise<T>` - Checks if a value is a `Promise`.
518
626
  - `runSequential<Item, Result>(array: Item[], fn: (item, index, array) => Promise<Result>): Promise<Result[]>` - Runs asynchronous operations on each array item *sequentially* and returns the results in the original order.
519
627
  - `runParallel<Item, Result>(array: Item[], fn: (item, index, array) => Promise<Result>): Promise<Result[]>` - Executes an asynchronous function for each array item *in parallel* and returns a promise of all results.
520
628
  - `reduceAsync<Item, Accumulator>(array: Item[], fn, initialValue): Promise<Accumulator>` - Asynchronously reduces an array to a single accumulated value. Each step waits for the previous promise to resolve.
package/dist/array.d.ts CHANGED
@@ -1,3 +1,19 @@
1
+ /**
2
+ * Checks if a value is an array.
3
+ *
4
+ * @param value - The value to check.
5
+ *
6
+ * @returns `true` if the value is an array; otherwise, `false`.
7
+ */
8
+ export declare const isArray: (value: unknown) => value is unknown[];
9
+ /**
10
+ * Checks if a value is an empty array.
11
+ *
12
+ * @param value - The value to check.
13
+ *
14
+ * @returns `true` if the value is an empty array; otherwise, `false`.
15
+ */
16
+ export declare const isEmptyArray: (value: unknown) => value is [];
1
17
  /**
2
18
  * Represents all falsy values.
3
19
  */
package/dist/async.d.ts CHANGED
@@ -1,3 +1,13 @@
1
+ /**
2
+ * Checks if a value is a Promise.
3
+ *
4
+ * @template T - The type of the value that the Promise resolves to.
5
+ *
6
+ * @param value - The value to check.
7
+ *
8
+ * @returns `true` if the value is a Promise; otherwise, `false`.
9
+ */
10
+ export declare const isPromise: <T = unknown>(value: unknown) => value is Promise<T>;
1
11
  /**
2
12
  * Asynchronously iterates over an array and executes an async function on each item sequentially,
3
13
  * collecting the results.
package/dist/dom.d.ts CHANGED
@@ -31,26 +31,6 @@ export declare const parse2DMatrix: (element: HTMLElement) => HTMLElementTransfo
31
31
  * @returns A new Blob with the same content and type as the original.
32
32
  */
33
33
  export declare const cloneBlob: (blob: Blob) => Blob;
34
- /**
35
- * Converts a `Blob` object into a `File` object with the specified name.
36
- *
37
- * This is useful when you receive a `Blob` (e.g., from canvas, fetch, or file manipulation)
38
- * and need to convert it into a `File` to upload via `FormData` or file inputs.
39
- *
40
- * @param blob - The `Blob` to convert.
41
- * @param fileName - The desired name for the resulting file (including extension).
42
- *
43
- * @returns A `File` instance with the same content and MIME type as the input `Blob`.
44
- *
45
- * @example
46
- * ```ts
47
- * const blob = new Blob(['Hello world'], { type: 'text/plain' });
48
- * const file = convertBlobToFile(blob, 'hello.txt');
49
- *
50
- * console.log(file instanceof File); // true
51
- * ```
52
- */
53
- export declare const convertBlobToFile: (blob: Blob, fileName: string) => File;
54
34
  /**
55
35
  * Calculates the intersection ratio between two DOM rectangles.
56
36
  *
package/dist/file.d.ts ADDED
@@ -0,0 +1,99 @@
1
+ /**
2
+ * Checks if a value is a `File` object.
3
+ *
4
+ * @param value - The value to check.
5
+ *
6
+ * @returns `true` if the value is a `File` object; otherwise, `false`.
7
+ */
8
+ export declare const isFile: (value: unknown) => value is File;
9
+ /**
10
+ * Splits a file name into its base name and extension.
11
+ *
12
+ * Special cases:
13
+ * - Files without a dot return `[fileName, ""]`
14
+ * - Hidden files like `.gitignore` return `[".gitignore", ""]`
15
+ * - Names ending with a trailing dot (e.g., `"file."`) return `["file.", ""]`
16
+ * - Multi-dot names (e.g., `"archive.tar.gz"`) split on the last dot
17
+ *
18
+ * @param fileName - The full file name to parse.
19
+ *
20
+ * @returns A tuple where:
21
+ * - index 0 is the base name
22
+ * - index 1 is the file extension (lowercased), or an empty string if none exists
23
+ */
24
+ export declare const parseFileName: (fileName: string) => string[];
25
+ /**
26
+ * Converts a `FileList` object to an array of `File` objects.
27
+ *
28
+ * @param fileList - The `FileList` object to convert.
29
+ *
30
+ * @returns An array of `File` objects.
31
+ */
32
+ export declare const fileListToFiles: (fileList: FileList | null) => File[];
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 = blobToFile(blob, 'hello.txt');
48
+ *
49
+ * console.log(file instanceof File); // true
50
+ * ```
51
+ */
52
+ export declare const blobToFile: (blob: Blob, fileName: string) => File;
53
+ /**
54
+ * A callback function invoked whenever a file is discovered during directory traversal.
55
+ *
56
+ * @param progress - An object containing details about the current traversal state.
57
+ * @param progress.processed - The total number of files processed so far.
58
+ * @param progress.currentFile - The `File` object for the file just discovered (if available).
59
+ * @param progress.path - The full path of the file relative to the traversed directory (if available).
60
+ */
61
+ type TraverseDirectoryOnProgressHandler = (progress: {
62
+ processed: number;
63
+ currentFile?: File;
64
+ path?: string;
65
+ }) => void;
66
+ interface TraverseDirectoryOptions {
67
+ /**
68
+ * A list of file names that should be ignored during traversal.
69
+ * Any file whose name matches an entry will be skipped entirely.
70
+ *
71
+ * Common values include OS-generated metadata files such as:
72
+ * `.DS_Store`, `Thumbs.db`, `desktop.ini`, `.Spotlight-V100`, etc.
73
+ */
74
+ skipFiles?: string[];
75
+ /**
76
+ * Optional callback invoked each time a file is discovered.
77
+ * Useful for progress tracking when traversing large or deeply nested directories.
78
+ */
79
+ onProgress?: TraverseDirectoryOnProgressHandler;
80
+ }
81
+ /**
82
+ * Recursively scans a directory using the File System API and collects all nested files.
83
+ *
84
+ * This function walks through all subdirectories, resolving each file into a `File` object.
85
+ * Directories themselves are not returned. To avoid unnecessary noise, certain system or
86
+ * OS-generated files can be excluded via the `skipFiles` option.
87
+ *
88
+ * A progress callback (`onProgress`) may be provided to receive updates each time a file
89
+ * is discovered. This is useful when working with large folders or deeply nested structures.
90
+ *
91
+ * @param directoryEntry - The starting directory entry to traverse.
92
+ * @param options - Optional settings that control traversal behavior.
93
+ * @param processed - Internal counter used to track the number of processed files
94
+ * during recursive traversal. Not intended to be provided manually.
95
+ *
96
+ * @returns A promise resolving to a flat array of all collected `File` objects.
97
+ */
98
+ export declare const traverseFileSystemDirectory: (directoryEntry: FileSystemDirectoryEntry, { skipFiles, onProgress, }?: TraverseDirectoryOptions, processed?: number) => Promise<File[]>;
99
+ export {};
@@ -1,4 +1,12 @@
1
1
  export declare const noop: () => void;
2
+ /**
3
+ * Checks if a value is a function.
4
+ *
5
+ * @param value - The value to check.
6
+ *
7
+ * @returns `true` if the value is a function; otherwise, `false`.
8
+ */
9
+ export declare const isFunction: (value: unknown) => value is Function;
2
10
  /**
3
11
  * Creates a function that negates the result of the given predicate function.
4
12
  *