@react-hive/honey-utils 3.23.0 → 3.25.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 +7 -0
- package/dist/README.md +7 -0
- package/dist/color/hex-with-alpha.d.ts +37 -0
- package/dist/color/index.d.ts +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.dev.cjs +131 -0
- package/dist/index.dev.cjs.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/string/index.d.ts +1 -0
- package/dist/string/split-map-join.d.ts +34 -0
- package/package.json +7 -6
package/dist/index.dev.cjs
CHANGED
|
@@ -815,6 +815,79 @@ const timeout = async (promise, timeoutMs, errorMessage = 'Operation timed out')
|
|
|
815
815
|
};
|
|
816
816
|
|
|
817
817
|
|
|
818
|
+
/***/ }),
|
|
819
|
+
|
|
820
|
+
/***/ "./src/color/hex-with-alpha.ts":
|
|
821
|
+
/*!*************************************!*\
|
|
822
|
+
!*** ./src/color/hex-with-alpha.ts ***!
|
|
823
|
+
\*************************************/
|
|
824
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
825
|
+
|
|
826
|
+
__webpack_require__.r(__webpack_exports__);
|
|
827
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
828
|
+
/* harmony export */ hexWithAlpha: () => (/* binding */ hexWithAlpha)
|
|
829
|
+
/* harmony export */ });
|
|
830
|
+
/* harmony import */ var _guards__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ~/guards */ "./src/guards.ts");
|
|
831
|
+
|
|
832
|
+
/**
|
|
833
|
+
* Adds an alpha channel to a 3- or 6-digit HEX color.
|
|
834
|
+
*
|
|
835
|
+
* Accepts `#RGB`, `#RRGGBB`, `RGB`, or `RRGGBB` formats
|
|
836
|
+
* and returns a normalized 8-digit HEX color in `#RRGGBBAA` format.
|
|
837
|
+
*
|
|
838
|
+
* The alpha value is converted to a two-digit hexadecimal
|
|
839
|
+
* representation using `Math.round(alpha * 255)`.
|
|
840
|
+
*
|
|
841
|
+
* @param input - Base HEX color (3 or 6 hex digits, with or without `#`).
|
|
842
|
+
* @param alpha - Opacity value between `0` (transparent) and `1` (opaque).
|
|
843
|
+
*
|
|
844
|
+
* @throws {Error}
|
|
845
|
+
* - If `alpha` is outside the `[0, 1]` range.
|
|
846
|
+
* - If `hex` is not a valid 3- or 6-digit hexadecimal color.
|
|
847
|
+
*
|
|
848
|
+
* @returns A normalized 8-digit HEX color in `#RRGGBBAA` format.
|
|
849
|
+
*
|
|
850
|
+
* @example
|
|
851
|
+
* ```ts
|
|
852
|
+
* hexWithAlpha('#ff0000', 0.5) // '#FF000080'
|
|
853
|
+
* hexWithAlpha('0f0', 1) // '#00FF00FF'
|
|
854
|
+
* ```
|
|
855
|
+
*/
|
|
856
|
+
const hexWithAlpha = (input, alpha) => {
|
|
857
|
+
(0,_guards__WEBPACK_IMPORTED_MODULE_0__.assert)(alpha >= 0 && alpha <= 1, `[@react-hive/honey-utils]: Alpha "${alpha}" must be a number between 0 and 1.`);
|
|
858
|
+
const hexRegex = /^#?([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/;
|
|
859
|
+
const match = input.match(hexRegex);
|
|
860
|
+
(0,_guards__WEBPACK_IMPORTED_MODULE_0__.assert)(match, `[@react-hive/honey-utils]: Invalid hex format: ${input}`);
|
|
861
|
+
const cleanHex = match[1];
|
|
862
|
+
// Expand 3-character hex to 6-character hex if necessary
|
|
863
|
+
const fullHex = cleanHex.length === 3
|
|
864
|
+
? cleanHex[0] + cleanHex[0] + cleanHex[1] + cleanHex[1] + cleanHex[2] + cleanHex[2]
|
|
865
|
+
: cleanHex;
|
|
866
|
+
// Convert to 8-character hex with alpha
|
|
867
|
+
const alphaHex = Math.round(alpha * 255)
|
|
868
|
+
.toString(16)
|
|
869
|
+
.toUpperCase()
|
|
870
|
+
.padStart(2, '0');
|
|
871
|
+
return `#${fullHex + alphaHex}`;
|
|
872
|
+
};
|
|
873
|
+
|
|
874
|
+
|
|
875
|
+
/***/ }),
|
|
876
|
+
|
|
877
|
+
/***/ "./src/color/index.ts":
|
|
878
|
+
/*!****************************!*\
|
|
879
|
+
!*** ./src/color/index.ts ***!
|
|
880
|
+
\****************************/
|
|
881
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
882
|
+
|
|
883
|
+
__webpack_require__.r(__webpack_exports__);
|
|
884
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
885
|
+
/* harmony export */ hexWithAlpha: () => (/* reexport safe */ _hex_with_alpha__WEBPACK_IMPORTED_MODULE_0__.hexWithAlpha)
|
|
886
|
+
/* harmony export */ });
|
|
887
|
+
/* harmony import */ var _hex_with_alpha__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./hex-with-alpha */ "./src/color/hex-with-alpha.ts");
|
|
888
|
+
|
|
889
|
+
|
|
890
|
+
|
|
818
891
|
/***/ }),
|
|
819
892
|
|
|
820
893
|
/***/ "./src/dom/dom.ts":
|
|
@@ -2621,6 +2694,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
2621
2694
|
/* harmony export */ isNilOrEmptyString: () => (/* reexport safe */ _is_nil_or_empty_string__WEBPACK_IMPORTED_MODULE_5__.isNilOrEmptyString),
|
|
2622
2695
|
/* harmony export */ isString: () => (/* reexport safe */ _is_string__WEBPACK_IMPORTED_MODULE_0__.isString),
|
|
2623
2696
|
/* harmony export */ parseFileName: () => (/* reexport safe */ _parse_file_name__WEBPACK_IMPORTED_MODULE_6__.parseFileName),
|
|
2697
|
+
/* harmony export */ splitMapJoin: () => (/* reexport safe */ _split_map_join__WEBPACK_IMPORTED_MODULE_10__.splitMapJoin),
|
|
2624
2698
|
/* harmony export */ splitStringIntoWords: () => (/* reexport safe */ _split_string_into_words__WEBPACK_IMPORTED_MODULE_4__.splitStringIntoWords),
|
|
2625
2699
|
/* harmony export */ toKebabCase: () => (/* reexport safe */ _to_kebab_case__WEBPACK_IMPORTED_MODULE_1__.toKebabCase)
|
|
2626
2700
|
/* harmony export */ });
|
|
@@ -2634,6 +2708,8 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
2634
2708
|
/* harmony import */ var _find_char_indices__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./find-char-indices */ "./src/string/find-char-indices.ts");
|
|
2635
2709
|
/* harmony import */ var _for_each_char__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./for-each-char */ "./src/string/for-each-char.ts");
|
|
2636
2710
|
/* harmony import */ var _get_words_initials__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./get-words-initials */ "./src/string/get-words-initials.ts");
|
|
2711
|
+
/* harmony import */ var _split_map_join__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./split-map-join */ "./src/string/split-map-join.ts");
|
|
2712
|
+
|
|
2637
2713
|
|
|
2638
2714
|
|
|
2639
2715
|
|
|
@@ -2734,6 +2810,57 @@ const parseFileName = (fileName) => {
|
|
|
2734
2810
|
};
|
|
2735
2811
|
|
|
2736
2812
|
|
|
2813
|
+
/***/ }),
|
|
2814
|
+
|
|
2815
|
+
/***/ "./src/string/split-map-join.ts":
|
|
2816
|
+
/*!**************************************!*\
|
|
2817
|
+
!*** ./src/string/split-map-join.ts ***!
|
|
2818
|
+
\**************************************/
|
|
2819
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
2820
|
+
|
|
2821
|
+
__webpack_require__.r(__webpack_exports__);
|
|
2822
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
2823
|
+
/* harmony export */ splitMapJoin: () => (/* binding */ splitMapJoin)
|
|
2824
|
+
/* harmony export */ });
|
|
2825
|
+
/**
|
|
2826
|
+
* Splits a string into parts, transforms each part, then joins them back together.
|
|
2827
|
+
*
|
|
2828
|
+
* Common use cases:
|
|
2829
|
+
*
|
|
2830
|
+
* - Transforming selector groups:
|
|
2831
|
+
*
|
|
2832
|
+
* ```ts
|
|
2833
|
+
* splitMapJoin(".a, .b", ",", part => `.scope ${part}`);
|
|
2834
|
+
* // ".scope .a, .scope .b"
|
|
2835
|
+
* ```
|
|
2836
|
+
*
|
|
2837
|
+
* - Normalizing spacing:
|
|
2838
|
+
*
|
|
2839
|
+
* ```ts
|
|
2840
|
+
* splitMapJoin("a , b ,c", ",", part => part);
|
|
2841
|
+
* // "a,b,c"
|
|
2842
|
+
* ```
|
|
2843
|
+
*
|
|
2844
|
+
* - Custom join formatting:
|
|
2845
|
+
*
|
|
2846
|
+
* ```ts
|
|
2847
|
+
* splitMapJoin("a,b,c", ",", part => part.toUpperCase(), ".");
|
|
2848
|
+
* // "A.B.C"
|
|
2849
|
+
* ```
|
|
2850
|
+
*
|
|
2851
|
+
* @param input - The raw input string to process.
|
|
2852
|
+
* @param separator - The delimiter used to split the input (e.g. `","`, `" "`).
|
|
2853
|
+
* @param mapFn - Function applied to each trimmed part.
|
|
2854
|
+
* @param joinWith - Optional join separator (defaults to the same value as `separator`).
|
|
2855
|
+
*
|
|
2856
|
+
* @returns The transformed and re-joined string.
|
|
2857
|
+
*/
|
|
2858
|
+
const splitMapJoin = (input, separator, mapFn, joinWith = separator) => input
|
|
2859
|
+
.split(separator)
|
|
2860
|
+
.map((part, index) => mapFn(part.trim(), index))
|
|
2861
|
+
.join(joinWith);
|
|
2862
|
+
|
|
2863
|
+
|
|
2737
2864
|
/***/ }),
|
|
2738
2865
|
|
|
2739
2866
|
/***/ "./src/string/split-string-into-words.ts":
|
|
@@ -3207,6 +3334,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
3207
3334
|
/* harmony export */ hasXOverflow: () => (/* reexport safe */ _dom__WEBPACK_IMPORTED_MODULE_3__.hasXOverflow),
|
|
3208
3335
|
/* harmony export */ hasYOverflow: () => (/* reexport safe */ _dom__WEBPACK_IMPORTED_MODULE_3__.hasYOverflow),
|
|
3209
3336
|
/* harmony export */ hashString: () => (/* reexport safe */ _math__WEBPACK_IMPORTED_MODULE_11__.hashString),
|
|
3337
|
+
/* harmony export */ hexWithAlpha: () => (/* reexport safe */ _color__WEBPACK_IMPORTED_MODULE_16__.hexWithAlpha),
|
|
3210
3338
|
/* harmony export */ intersection: () => (/* reexport safe */ _array__WEBPACK_IMPORTED_MODULE_1__.intersection),
|
|
3211
3339
|
/* harmony export */ invokeIfFunction: () => (/* reexport safe */ _function__WEBPACK_IMPORTED_MODULE_6__.invokeIfFunction),
|
|
3212
3340
|
/* harmony export */ isAnchorHtmlElement: () => (/* reexport safe */ _dom__WEBPACK_IMPORTED_MODULE_3__.isAnchorHtmlElement),
|
|
@@ -3255,6 +3383,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
3255
3383
|
/* harmony export */ runSequential: () => (/* reexport safe */ _async__WEBPACK_IMPORTED_MODULE_2__.runSequential),
|
|
3256
3384
|
/* harmony export */ searchTree: () => (/* reexport safe */ _tree__WEBPACK_IMPORTED_MODULE_14__.searchTree),
|
|
3257
3385
|
/* harmony export */ someAsync: () => (/* reexport safe */ _async__WEBPACK_IMPORTED_MODULE_2__.someAsync),
|
|
3386
|
+
/* harmony export */ splitMapJoin: () => (/* reexport safe */ _string__WEBPACK_IMPORTED_MODULE_13__.splitMapJoin),
|
|
3258
3387
|
/* harmony export */ splitStringIntoWords: () => (/* reexport safe */ _string__WEBPACK_IMPORTED_MODULE_13__.splitStringIntoWords),
|
|
3259
3388
|
/* harmony export */ timeout: () => (/* reexport safe */ _async__WEBPACK_IMPORTED_MODULE_2__.timeout),
|
|
3260
3389
|
/* harmony export */ toKebabCase: () => (/* reexport safe */ _string__WEBPACK_IMPORTED_MODULE_13__.toKebabCase),
|
|
@@ -3277,6 +3406,8 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
3277
3406
|
/* harmony import */ var _string__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ./string */ "./src/string/index.ts");
|
|
3278
3407
|
/* harmony import */ var _tree__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ./tree */ "./src/tree/index.ts");
|
|
3279
3408
|
/* harmony import */ var _types__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(/*! ./types */ "./src/types.ts");
|
|
3409
|
+
/* harmony import */ var _color__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(/*! ./color */ "./src/color/index.ts");
|
|
3410
|
+
|
|
3280
3411
|
|
|
3281
3412
|
|
|
3282
3413
|
|