@react-hive/honey-utils 3.0.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.
@@ -15,11 +15,29 @@ __webpack_require__.r(__webpack_exports__);
15
15
  /* harmony export */ compose: () => (/* binding */ compose),
16
16
  /* harmony export */ difference: () => (/* binding */ difference),
17
17
  /* harmony export */ intersection: () => (/* binding */ intersection),
18
+ /* harmony export */ isArray: () => (/* binding */ isArray),
19
+ /* harmony export */ isEmptyArray: () => (/* binding */ isEmptyArray),
18
20
  /* harmony export */ pipe: () => (/* binding */ pipe),
19
21
  /* harmony export */ unique: () => (/* binding */ unique)
20
22
  /* harmony export */ });
21
23
  /* harmony import */ var _guards__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./guards */ "./src/guards.ts");
22
24
 
25
+ /**
26
+ * Checks if a value is an array.
27
+ *
28
+ * @param value - The value to check.
29
+ *
30
+ * @returns `true` if the value is an array; otherwise, `false`.
31
+ */
32
+ const isArray = (value) => Array.isArray(value);
33
+ /**
34
+ * Checks if a value is an empty array.
35
+ *
36
+ * @param value - The value to check.
37
+ *
38
+ * @returns `true` if the value is an empty array; otherwise, `false`.
39
+ */
40
+ const isEmptyArray = (value) => isArray(value) && value.length === 0;
23
41
  /**
24
42
  * Removes all falsy values from an array.
25
43
  *
@@ -182,13 +200,26 @@ __webpack_require__.r(__webpack_exports__);
182
200
  /* harmony export */ filterParallel: () => (/* binding */ filterParallel),
183
201
  /* harmony export */ filterSequential: () => (/* binding */ filterSequential),
184
202
  /* harmony export */ findAsync: () => (/* binding */ findAsync),
203
+ /* harmony export */ isPromise: () => (/* binding */ isPromise),
185
204
  /* harmony export */ reduceAsync: () => (/* binding */ reduceAsync),
186
205
  /* harmony export */ runParallel: () => (/* binding */ runParallel),
187
206
  /* harmony export */ runSequential: () => (/* binding */ runSequential),
188
207
  /* harmony export */ someAsync: () => (/* binding */ someAsync)
189
208
  /* harmony export */ });
190
209
  /* harmony import */ var _array__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./array */ "./src/array.ts");
210
+ /* harmony import */ var _function__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./function */ "./src/function.ts");
191
211
 
212
+
213
+ /**
214
+ * Checks if a value is a Promise.
215
+ *
216
+ * @template T - The type of the value that the Promise resolves to.
217
+ *
218
+ * @param value - The value to check.
219
+ *
220
+ * @returns `true` if the value is a Promise; otherwise, `false`.
221
+ */
222
+ const isPromise = (value) => (0,_function__WEBPACK_IMPORTED_MODULE_1__.isFunction)(value?.then);
192
223
  /**
193
224
  * Asynchronously iterates over an array and executes an async function on each item sequentially,
194
225
  * collecting the results.
@@ -567,8 +598,20 @@ __webpack_require__.r(__webpack_exports__);
567
598
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
568
599
  /* harmony export */ blobToFile: () => (/* binding */ blobToFile),
569
600
  /* harmony export */ fileListToFiles: () => (/* binding */ fileListToFiles),
570
- /* harmony export */ parseFileName: () => (/* binding */ parseFileName)
601
+ /* harmony export */ isFile: () => (/* binding */ isFile),
602
+ /* harmony export */ parseFileName: () => (/* binding */ parseFileName),
603
+ /* harmony export */ traverseFileSystemDirectory: () => (/* binding */ traverseFileSystemDirectory)
571
604
  /* harmony export */ });
605
+ /* harmony import */ var _async__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./async */ "./src/async.ts");
606
+
607
+ /**
608
+ * Checks if a value is a `File` object.
609
+ *
610
+ * @param value - The value to check.
611
+ *
612
+ * @returns `true` if the value is a `File` object; otherwise, `false`.
613
+ */
614
+ const isFile = (value) => value instanceof File;
572
615
  /**
573
616
  * Splits a file name into its base name and extension.
574
617
  *
@@ -631,6 +674,85 @@ const fileListToFiles = (fileList) => {
631
674
  const blobToFile = (blob, fileName) => new File([blob], fileName, {
632
675
  type: blob.type,
633
676
  });
677
+ /**
678
+ * Reads all entries from a file system directory asynchronously.
679
+ *
680
+ * @param directoryEntry - The directory entry to read.
681
+ *
682
+ * @returns A promise that resolves to all `FileSystemEntry` items in the directory.
683
+ */
684
+ const readFileSystemDirectoryEntries = async (directoryEntry) => {
685
+ const directoryReader = directoryEntry.createReader();
686
+ const readAll = async () => new Promise((resolve, reject) => {
687
+ directoryReader.readEntries(async (entries) => {
688
+ if (!entries.length) {
689
+ resolve([]);
690
+ return;
691
+ }
692
+ try {
693
+ const restEntries = await readAll();
694
+ resolve([...entries, ...restEntries]);
695
+ }
696
+ catch (e) {
697
+ reject(e);
698
+ }
699
+ }, reject);
700
+ });
701
+ return readAll();
702
+ };
703
+ /**
704
+ * Recursively scans a directory using the File System API and collects all nested files.
705
+ *
706
+ * This function walks through all subdirectories, resolving each file into a `File` object.
707
+ * Directories themselves are not returned. To avoid unnecessary noise, certain system or
708
+ * OS-generated files can be excluded via the `skipFiles` option.
709
+ *
710
+ * A progress callback (`onProgress`) may be provided to receive updates each time a file
711
+ * is discovered. This is useful when working with large folders or deeply nested structures.
712
+ *
713
+ * @param directoryEntry - The starting directory entry to traverse.
714
+ * @param options - Optional settings that control traversal behavior.
715
+ * @param processed - Internal counter used to track the number of processed files
716
+ * during recursive traversal. Not intended to be provided manually.
717
+ *
718
+ * @returns A promise resolving to a flat array of all collected `File` objects.
719
+ */
720
+ const traverseFileSystemDirectory = async (directoryEntry, { skipFiles = [
721
+ '.DS_Store',
722
+ 'Thumbs.db',
723
+ 'desktop.ini',
724
+ 'ehthumbs.db',
725
+ '.Spotlight-V100',
726
+ '.Trashes',
727
+ '.fseventsd',
728
+ '__MACOSX',
729
+ ], onProgress, } = {}, processed = 0) => {
730
+ const skipSet = new Set(skipFiles);
731
+ const entries = await readFileSystemDirectoryEntries(directoryEntry);
732
+ const filePromises = await (0,_async__WEBPACK_IMPORTED_MODULE_0__.runParallel)(entries, async (entry) => {
733
+ if (entry.isDirectory) {
734
+ return traverseFileSystemDirectory(entry, {
735
+ skipFiles,
736
+ }, processed);
737
+ }
738
+ else if (!skipSet.has(entry.name)) {
739
+ const file = await new Promise((resolve, reject) => {
740
+ entry.file(resolve, reject);
741
+ });
742
+ if (onProgress) {
743
+ processed++;
744
+ onProgress({
745
+ processed,
746
+ path: `${directoryEntry.fullPath}/${entry.name}`,
747
+ currentFile: file,
748
+ });
749
+ }
750
+ return [file];
751
+ }
752
+ return [];
753
+ });
754
+ return filePromises.flat();
755
+ };
634
756
 
635
757
 
636
758
  /***/ }),
@@ -645,12 +767,21 @@ __webpack_require__.r(__webpack_exports__);
645
767
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
646
768
  /* harmony export */ delay: () => (/* binding */ delay),
647
769
  /* harmony export */ invokeIfFunction: () => (/* binding */ invokeIfFunction),
770
+ /* harmony export */ isFunction: () => (/* binding */ isFunction),
648
771
  /* harmony export */ noop: () => (/* binding */ noop),
649
772
  /* harmony export */ not: () => (/* binding */ not),
650
773
  /* harmony export */ retry: () => (/* binding */ retry),
651
774
  /* harmony export */ timeout: () => (/* binding */ timeout)
652
775
  /* harmony export */ });
653
776
  const noop = () => { };
777
+ /**
778
+ * Checks if a value is a function.
779
+ *
780
+ * @param value - The value to check.
781
+ *
782
+ * @returns `true` if the value is a function; otherwise, `false`.
783
+ */
784
+ const isFunction = (value) => typeof value === 'function';
654
785
  /**
655
786
  * Creates a function that negates the result of the given predicate function.
656
787
  *
@@ -818,25 +949,19 @@ const retry = (task, { maxAttempts = 3, delayMs = 300, backoff = true, onRetry }
818
949
  __webpack_require__.r(__webpack_exports__);
819
950
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
820
951
  /* harmony export */ assert: () => (/* binding */ assert),
821
- /* harmony export */ isArray: () => (/* binding */ isArray),
822
952
  /* harmony export */ isBool: () => (/* binding */ isBool),
823
953
  /* harmony export */ isDate: () => (/* binding */ isDate),
824
954
  /* harmony export */ isDefined: () => (/* binding */ isDefined),
825
- /* harmony export */ isEmptyArray: () => (/* binding */ isEmptyArray),
826
955
  /* harmony export */ isEmptyObject: () => (/* binding */ isEmptyObject),
827
956
  /* harmony export */ isFiniteNumber: () => (/* binding */ isFiniteNumber),
828
- /* harmony export */ isFunction: () => (/* binding */ isFunction),
829
957
  /* harmony export */ isInteger: () => (/* binding */ isInteger),
830
958
  /* harmony export */ isMap: () => (/* binding */ isMap),
831
959
  /* harmony export */ isNil: () => (/* binding */ isNil),
832
- /* harmony export */ isNilOrEmptyString: () => (/* binding */ isNilOrEmptyString),
833
960
  /* harmony export */ isNull: () => (/* binding */ isNull),
834
961
  /* harmony export */ isNumber: () => (/* binding */ isNumber),
835
962
  /* harmony export */ isObject: () => (/* binding */ isObject),
836
- /* harmony export */ isPromise: () => (/* binding */ isPromise),
837
963
  /* harmony export */ isRegExp: () => (/* binding */ isRegExp),
838
964
  /* harmony export */ isSet: () => (/* binding */ isSet),
839
- /* harmony export */ isString: () => (/* binding */ isString),
840
965
  /* harmony export */ isSymbol: () => (/* binding */ isSymbol),
841
966
  /* harmony export */ isUndefined: () => (/* binding */ isUndefined),
842
967
  /* harmony export */ isValidDate: () => (/* binding */ isValidDate)
@@ -862,19 +987,6 @@ const isNull = (value) => value === null;
862
987
  * @returns `true` if the value is `null` or `undefined`, otherwise `false`.
863
988
  */
864
989
  const isNil = (value) => value === undefined || value === null;
865
- /**
866
- * Checks whether the provided value is considered "empty".
867
- *
868
- * A value is considered empty if it is:
869
- * - `null`
870
- * - `undefined`
871
- * - `''`
872
- *
873
- * @param value - The value to check.
874
- *
875
- * @returns `true` if the value is empty; otherwise, `false`.
876
- */
877
- const isNilOrEmptyString = (value) => value === '' || isNil(value);
878
990
  /**
879
991
  * Checks if a value is neither `null` nor `undefined`.
880
992
  *
@@ -883,14 +995,6 @@ const isNilOrEmptyString = (value) => value === '' || isNil(value);
883
995
  * @returns `true` if the value is defined (not `null` or `undefined`); otherwise, `false`.
884
996
  */
885
997
  const isDefined = (value) => value !== null && value !== undefined;
886
- /**
887
- * Checks if a value is a string.
888
- *
889
- * @param value - The value to check.
890
- *
891
- * @returns `true` if the value is a string; otherwise, `false`.
892
- */
893
- const isString = (value) => typeof value === 'string';
894
998
  /**
895
999
  * Checks if a value is a number.
896
1000
  *
@@ -923,40 +1027,6 @@ const isObject = (value) => typeof value === 'object';
923
1027
  * @returns `true` if the value is an empty object; otherwise, `false`.
924
1028
  */
925
1029
  const isEmptyObject = (value) => isObject(value) && !isNull(value) && Object.keys(value).length === 0;
926
- /**
927
- * Checks if a value is an array.
928
- *
929
- * @param value - The value to check.
930
- *
931
- * @returns `true` if the value is an array; otherwise, `false`.
932
- */
933
- const isArray = (value) => Array.isArray(value);
934
- /**
935
- * Checks if a value is an empty array.
936
- *
937
- * @param value - The value to check.
938
- *
939
- * @returns `true` if the value is an empty array; otherwise, `false`.
940
- */
941
- const isEmptyArray = (value) => isArray(value) && value.length === 0;
942
- /**
943
- * Checks if a value is a function.
944
- *
945
- * @param value - The value to check.
946
- *
947
- * @returns `true` if the value is a function; otherwise, `false`.
948
- */
949
- const isFunction = (value) => typeof value === 'function';
950
- /**
951
- * Checks if a value is a Promise.
952
- *
953
- * @template T - The type of the value that the Promise resolves to.
954
- *
955
- * @param value - The value to check.
956
- *
957
- * @returns `true` if the value is a Promise; otherwise, `false`.
958
- */
959
- const isPromise = (value) => isFunction(value?.then);
960
1030
  /**
961
1031
  * Checks if a value is a Date object.
962
1032
  *
@@ -1095,9 +1165,34 @@ __webpack_require__.r(__webpack_exports__);
1095
1165
  /* harmony export */ camelToDashCase: () => (/* binding */ camelToDashCase),
1096
1166
  /* harmony export */ camelToWords: () => (/* binding */ camelToWords),
1097
1167
  /* harmony export */ hashString: () => (/* binding */ hashString),
1168
+ /* harmony export */ isNilOrEmptyString: () => (/* binding */ isNilOrEmptyString),
1169
+ /* harmony export */ isString: () => (/* binding */ isString),
1098
1170
  /* harmony export */ splitStringIntoWords: () => (/* binding */ splitStringIntoWords),
1099
1171
  /* harmony export */ toKebabCase: () => (/* binding */ toKebabCase)
1100
1172
  /* harmony export */ });
1173
+ /* harmony import */ var _guards__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./guards */ "./src/guards.ts");
1174
+
1175
+ /**
1176
+ * Checks if a value is a string.
1177
+ *
1178
+ * @param value - The value to check.
1179
+ *
1180
+ * @returns `true` if the value is a string; otherwise, `false`.
1181
+ */
1182
+ const isString = (value) => typeof value === 'string';
1183
+ /**
1184
+ * Checks whether the provided value is considered "empty".
1185
+ *
1186
+ * A value is considered empty if it is:
1187
+ * - `null`
1188
+ * - `undefined`
1189
+ * - `''`
1190
+ *
1191
+ * @param value - The value to check.
1192
+ *
1193
+ * @returns `true` if the value is empty; otherwise, `false`.
1194
+ */
1195
+ const isNilOrEmptyString = (value) => value === '' || (0,_guards__WEBPACK_IMPORTED_MODULE_0__.isNil)(value);
1101
1196
  /**
1102
1197
  * Converts a string to kebab-case format.
1103
1198
  *
@@ -1297,27 +1392,28 @@ __webpack_require__.r(__webpack_exports__);
1297
1392
  /* harmony export */ intersection: () => (/* reexport safe */ _array__WEBPACK_IMPORTED_MODULE_2__.intersection),
1298
1393
  /* harmony export */ invokeIfFunction: () => (/* reexport safe */ _function__WEBPACK_IMPORTED_MODULE_3__.invokeIfFunction),
1299
1394
  /* harmony export */ isAnchorHtmlElement: () => (/* reexport safe */ _dom__WEBPACK_IMPORTED_MODULE_6__.isAnchorHtmlElement),
1300
- /* harmony export */ isArray: () => (/* reexport safe */ _guards__WEBPACK_IMPORTED_MODULE_4__.isArray),
1395
+ /* harmony export */ isArray: () => (/* reexport safe */ _array__WEBPACK_IMPORTED_MODULE_2__.isArray),
1301
1396
  /* harmony export */ isBool: () => (/* reexport safe */ _guards__WEBPACK_IMPORTED_MODULE_4__.isBool),
1302
1397
  /* harmony export */ isContentEditableHtmlElement: () => (/* reexport safe */ _dom__WEBPACK_IMPORTED_MODULE_6__.isContentEditableHtmlElement),
1303
1398
  /* harmony export */ isDate: () => (/* reexport safe */ _guards__WEBPACK_IMPORTED_MODULE_4__.isDate),
1304
1399
  /* harmony export */ isDefined: () => (/* reexport safe */ _guards__WEBPACK_IMPORTED_MODULE_4__.isDefined),
1305
- /* harmony export */ isEmptyArray: () => (/* reexport safe */ _guards__WEBPACK_IMPORTED_MODULE_4__.isEmptyArray),
1400
+ /* harmony export */ isEmptyArray: () => (/* reexport safe */ _array__WEBPACK_IMPORTED_MODULE_2__.isEmptyArray),
1306
1401
  /* harmony export */ isEmptyObject: () => (/* reexport safe */ _guards__WEBPACK_IMPORTED_MODULE_4__.isEmptyObject),
1402
+ /* harmony export */ isFile: () => (/* reexport safe */ _file__WEBPACK_IMPORTED_MODULE_7__.isFile),
1307
1403
  /* harmony export */ isFiniteNumber: () => (/* reexport safe */ _guards__WEBPACK_IMPORTED_MODULE_4__.isFiniteNumber),
1308
- /* harmony export */ isFunction: () => (/* reexport safe */ _guards__WEBPACK_IMPORTED_MODULE_4__.isFunction),
1404
+ /* harmony export */ isFunction: () => (/* reexport safe */ _function__WEBPACK_IMPORTED_MODULE_3__.isFunction),
1309
1405
  /* harmony export */ isHtmlElementFocusable: () => (/* reexport safe */ _dom__WEBPACK_IMPORTED_MODULE_6__.isHtmlElementFocusable),
1310
1406
  /* harmony export */ isInteger: () => (/* reexport safe */ _guards__WEBPACK_IMPORTED_MODULE_4__.isInteger),
1311
1407
  /* harmony export */ isMap: () => (/* reexport safe */ _guards__WEBPACK_IMPORTED_MODULE_4__.isMap),
1312
1408
  /* harmony export */ isNil: () => (/* reexport safe */ _guards__WEBPACK_IMPORTED_MODULE_4__.isNil),
1313
- /* harmony export */ isNilOrEmptyString: () => (/* reexport safe */ _guards__WEBPACK_IMPORTED_MODULE_4__.isNilOrEmptyString),
1409
+ /* harmony export */ isNilOrEmptyString: () => (/* reexport safe */ _string__WEBPACK_IMPORTED_MODULE_1__.isNilOrEmptyString),
1314
1410
  /* harmony export */ isNull: () => (/* reexport safe */ _guards__WEBPACK_IMPORTED_MODULE_4__.isNull),
1315
1411
  /* harmony export */ isNumber: () => (/* reexport safe */ _guards__WEBPACK_IMPORTED_MODULE_4__.isNumber),
1316
1412
  /* harmony export */ isObject: () => (/* reexport safe */ _guards__WEBPACK_IMPORTED_MODULE_4__.isObject),
1317
- /* harmony export */ isPromise: () => (/* reexport safe */ _guards__WEBPACK_IMPORTED_MODULE_4__.isPromise),
1413
+ /* harmony export */ isPromise: () => (/* reexport safe */ _async__WEBPACK_IMPORTED_MODULE_0__.isPromise),
1318
1414
  /* harmony export */ isRegExp: () => (/* reexport safe */ _guards__WEBPACK_IMPORTED_MODULE_4__.isRegExp),
1319
1415
  /* harmony export */ isSet: () => (/* reexport safe */ _guards__WEBPACK_IMPORTED_MODULE_4__.isSet),
1320
- /* harmony export */ isString: () => (/* reexport safe */ _guards__WEBPACK_IMPORTED_MODULE_4__.isString),
1416
+ /* harmony export */ isString: () => (/* reexport safe */ _string__WEBPACK_IMPORTED_MODULE_1__.isString),
1321
1417
  /* harmony export */ isSymbol: () => (/* reexport safe */ _guards__WEBPACK_IMPORTED_MODULE_4__.isSymbol),
1322
1418
  /* harmony export */ isUndefined: () => (/* reexport safe */ _guards__WEBPACK_IMPORTED_MODULE_4__.isUndefined),
1323
1419
  /* harmony export */ isValidDate: () => (/* reexport safe */ _guards__WEBPACK_IMPORTED_MODULE_4__.isValidDate),
@@ -1334,6 +1430,7 @@ __webpack_require__.r(__webpack_exports__);
1334
1430
  /* harmony export */ splitStringIntoWords: () => (/* reexport safe */ _string__WEBPACK_IMPORTED_MODULE_1__.splitStringIntoWords),
1335
1431
  /* harmony export */ timeout: () => (/* reexport safe */ _function__WEBPACK_IMPORTED_MODULE_3__.timeout),
1336
1432
  /* harmony export */ toKebabCase: () => (/* reexport safe */ _string__WEBPACK_IMPORTED_MODULE_1__.toKebabCase),
1433
+ /* harmony export */ traverseFileSystemDirectory: () => (/* reexport safe */ _file__WEBPACK_IMPORTED_MODULE_7__.traverseFileSystemDirectory),
1337
1434
  /* harmony export */ unique: () => (/* reexport safe */ _array__WEBPACK_IMPORTED_MODULE_2__.unique)
1338
1435
  /* harmony export */ });
1339
1436
  /* harmony import */ var _async__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./async */ "./src/async.ts");