@react-hive/honey-utils 3.15.0 → 3.17.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.
@@ -2451,6 +2451,126 @@ __webpack_require__.r(__webpack_exports__);
2451
2451
  const camelToWords = (input) => input.replace(/([a-z0-9])([A-Z])/g, '$1 $2');
2452
2452
 
2453
2453
 
2454
+ /***/ }),
2455
+
2456
+ /***/ "./src/string/find-char-indices.ts":
2457
+ /*!*****************************************!*\
2458
+ !*** ./src/string/find-char-indices.ts ***!
2459
+ \*****************************************/
2460
+ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
2461
+
2462
+ __webpack_require__.r(__webpack_exports__);
2463
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
2464
+ /* harmony export */ findCharIndices: () => (/* binding */ findCharIndices)
2465
+ /* harmony export */ });
2466
+ /**
2467
+ * Finds all zero-based indices where a given single character occurs in a string.
2468
+ *
2469
+ * The string is scanned once from start to end and each matching character position is collected.
2470
+ *
2471
+ * ⚠️ Character comparison is performed at the UTF-16 code unit level
2472
+ * (`String.charCodeAt`), not by Unicode grapheme clusters.
2473
+ *
2474
+ * @param input - The string to scan.
2475
+ * @param targetChar - A single character to search for.
2476
+ *
2477
+ * @returns An array of zero-based indices for each occurrence of `targetChar`.
2478
+ * Returns an empty array if no matches are found.
2479
+ */
2480
+ const findCharIndices = (input, targetChar) => {
2481
+ if (input.length === 0) {
2482
+ return [];
2483
+ }
2484
+ const targetCode = targetChar.charCodeAt(0);
2485
+ const indices = [];
2486
+ for (let i = 0; i < input.length; i++) {
2487
+ if (input.charCodeAt(i) === targetCode) {
2488
+ indices.push(i);
2489
+ }
2490
+ }
2491
+ return indices;
2492
+ };
2493
+
2494
+
2495
+ /***/ }),
2496
+
2497
+ /***/ "./src/string/for-each-char.ts":
2498
+ /*!*************************************!*\
2499
+ !*** ./src/string/for-each-char.ts ***!
2500
+ \*************************************/
2501
+ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
2502
+
2503
+ __webpack_require__.r(__webpack_exports__);
2504
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
2505
+ /* harmony export */ forEachChar: () => (/* binding */ forEachChar)
2506
+ /* harmony export */ });
2507
+ /**
2508
+ * Iterates over each character of a string and invokes a callback for each one.
2509
+ *
2510
+ * Iteration is performed over UTF-16 code units (not Unicode grapheme clusters).
2511
+ * Characters may be conditionally skipped using an optional predicate.
2512
+ *
2513
+ * @param input - The string to iterate over.
2514
+ * @param onChar - Invoked for each character that is not skipped.
2515
+ * @param shouldSkipChar - Optional predicate; returning `true` skips the character.
2516
+ */
2517
+ const forEachChar = (input, onChar, shouldSkipChar) => {
2518
+ if (input.length === 0) {
2519
+ return;
2520
+ }
2521
+ const length = input.length;
2522
+ for (let charIndex = 0; charIndex < length; charIndex++) {
2523
+ const char = input[charIndex];
2524
+ const context = {
2525
+ charIndex,
2526
+ prevChar: charIndex > 0 ? input[charIndex - 1] : null,
2527
+ nextChar: charIndex < length - 1 ? input[charIndex + 1] : null,
2528
+ };
2529
+ if (shouldSkipChar?.(char, context)) {
2530
+ continue;
2531
+ }
2532
+ onChar(char, context);
2533
+ }
2534
+ };
2535
+
2536
+
2537
+ /***/ }),
2538
+
2539
+ /***/ "./src/string/get-words-initials.ts":
2540
+ /*!******************************************!*\
2541
+ !*** ./src/string/get-words-initials.ts ***!
2542
+ \******************************************/
2543
+ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
2544
+
2545
+ __webpack_require__.r(__webpack_exports__);
2546
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
2547
+ /* harmony export */ getWordsInitials: () => (/* binding */ getWordsInitials)
2548
+ /* harmony export */ });
2549
+ /* harmony import */ var _split_string_into_words__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./split-string-into-words */ "./src/string/split-string-into-words.ts");
2550
+
2551
+ /**
2552
+ * Returns the uppercase initials of the words in a string.
2553
+ *
2554
+ * The first character of each word is extracted, concatenated, and uppercased.
2555
+ *
2556
+ * @param input - The input string.
2557
+ * @param maxWords - Maximum number of words to include when generating initials.
2558
+ * Defaults to `Infinity`.
2559
+ *
2560
+ * @returns A string containing the uppercase initials of the selected words.
2561
+ */
2562
+ const getWordsInitials = (input, maxWords = Infinity) => {
2563
+ if (input.length === 0) {
2564
+ return '';
2565
+ }
2566
+ return (0,_split_string_into_words__WEBPACK_IMPORTED_MODULE_0__.splitStringIntoWords)(input)
2567
+ .slice(0, maxWords)
2568
+ .map(word => word[0])
2569
+ .join('')
2570
+ .toUpperCase();
2571
+ };
2572
+
2573
+
2454
2574
  /***/ }),
2455
2575
 
2456
2576
  /***/ "./src/string/index.ts":
@@ -2463,6 +2583,9 @@ __webpack_require__.r(__webpack_exports__);
2463
2583
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
2464
2584
  /* harmony export */ camelToDashCase: () => (/* reexport safe */ _camel_to_dash_case__WEBPACK_IMPORTED_MODULE_2__.camelToDashCase),
2465
2585
  /* harmony export */ camelToWords: () => (/* reexport safe */ _camel_to_words__WEBPACK_IMPORTED_MODULE_3__.camelToWords),
2586
+ /* harmony export */ findCharIndices: () => (/* reexport safe */ _find_char_indices__WEBPACK_IMPORTED_MODULE_7__.findCharIndices),
2587
+ /* harmony export */ forEachChar: () => (/* reexport safe */ _for_each_char__WEBPACK_IMPORTED_MODULE_8__.forEachChar),
2588
+ /* harmony export */ getWordsInitials: () => (/* reexport safe */ _get_words_initials__WEBPACK_IMPORTED_MODULE_9__.getWordsInitials),
2466
2589
  /* harmony export */ isNilOrEmptyString: () => (/* reexport safe */ _is_nil_or_empty_string__WEBPACK_IMPORTED_MODULE_5__.isNilOrEmptyString),
2467
2590
  /* harmony export */ isString: () => (/* reexport safe */ _is_string__WEBPACK_IMPORTED_MODULE_0__.isString),
2468
2591
  /* harmony export */ parseFileName: () => (/* reexport safe */ _parse_file_name__WEBPACK_IMPORTED_MODULE_6__.parseFileName),
@@ -2476,6 +2599,12 @@ __webpack_require__.r(__webpack_exports__);
2476
2599
  /* harmony import */ var _split_string_into_words__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./split-string-into-words */ "./src/string/split-string-into-words.ts");
2477
2600
  /* harmony import */ var _is_nil_or_empty_string__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./is-nil-or-empty-string */ "./src/string/is-nil-or-empty-string.ts");
2478
2601
  /* harmony import */ var _parse_file_name__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./parse-file-name */ "./src/string/parse-file-name.ts");
2602
+ /* harmony import */ var _find_char_indices__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./find-char-indices */ "./src/string/find-char-indices.ts");
2603
+ /* harmony import */ var _for_each_char__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./for-each-char */ "./src/string/for-each-char.ts");
2604
+ /* harmony import */ var _get_words_initials__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./get-words-initials */ "./src/string/get-words-initials.ts");
2605
+
2606
+
2607
+
2479
2608
 
2480
2609
 
2481
2610
 
@@ -2592,7 +2721,12 @@ __webpack_require__.r(__webpack_exports__);
2592
2721
  *
2593
2722
  * @returns An array of words from the input string.
2594
2723
  */
2595
- const splitStringIntoWords = (input) => input.split(' ').filter(Boolean);
2724
+ const splitStringIntoWords = (input) => {
2725
+ if (input.length === 0) {
2726
+ return [];
2727
+ }
2728
+ return input.split(' ').filter(Boolean);
2729
+ };
2596
2730
 
2597
2731
 
2598
2732
  /***/ }),
@@ -2717,10 +2851,13 @@ __webpack_require__.r(__webpack_exports__);
2717
2851
  /* harmony export */ filterParallel: () => (/* reexport safe */ _async__WEBPACK_IMPORTED_MODULE_0__.filterParallel),
2718
2852
  /* harmony export */ filterSequential: () => (/* reexport safe */ _async__WEBPACK_IMPORTED_MODULE_0__.filterSequential),
2719
2853
  /* harmony export */ findAsync: () => (/* reexport safe */ _async__WEBPACK_IMPORTED_MODULE_0__.findAsync),
2854
+ /* harmony export */ findCharIndices: () => (/* reexport safe */ _string__WEBPACK_IMPORTED_MODULE_1__.findCharIndices),
2855
+ /* harmony export */ forEachChar: () => (/* reexport safe */ _string__WEBPACK_IMPORTED_MODULE_1__.forEachChar),
2720
2856
  /* harmony export */ getDOMRectIntersectionRatio: () => (/* reexport safe */ _intersection__WEBPACK_IMPORTED_MODULE_10__.getDOMRectIntersectionRatio),
2721
2857
  /* harmony export */ getElementOffsetRect: () => (/* reexport safe */ _dom__WEBPACK_IMPORTED_MODULE_6__.getElementOffsetRect),
2722
2858
  /* harmony export */ getFocusableHtmlElements: () => (/* reexport safe */ _a11y__WEBPACK_IMPORTED_MODULE_11__.getFocusableHtmlElements),
2723
2859
  /* harmony export */ getLocalStorageCapabilities: () => (/* reexport safe */ _env__WEBPACK_IMPORTED_MODULE_12__.getLocalStorageCapabilities),
2860
+ /* harmony export */ getWordsInitials: () => (/* reexport safe */ _string__WEBPACK_IMPORTED_MODULE_1__.getWordsInitials),
2724
2861
  /* harmony export */ getXOverflowWidth: () => (/* reexport safe */ _dom__WEBPACK_IMPORTED_MODULE_6__.getXOverflowWidth),
2725
2862
  /* harmony export */ getYOverflowHeight: () => (/* reexport safe */ _dom__WEBPACK_IMPORTED_MODULE_6__.getYOverflowHeight),
2726
2863
  /* harmony export */ hasXOverflow: () => (/* reexport safe */ _dom__WEBPACK_IMPORTED_MODULE_6__.hasXOverflow),