nhb-toolbox 3.9.39 → 3.9.60
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/colors/Color.d.ts +38 -24
- package/dist/colors/Color.d.ts.map +1 -1
- package/dist/colors/Color.js +19 -17
- package/dist/date/Chronos.d.ts +233 -116
- package/dist/date/Chronos.d.ts.map +1 -1
- package/dist/date/Chronos.js +225 -154
- package/dist/date/chronos-fn.d.ts +24 -32
- package/dist/date/chronos-fn.d.ts.map +1 -1
- package/dist/date/chronos-fn.js +61 -6
- package/dist/date/constants.d.ts +3 -1
- package/dist/date/constants.d.ts.map +1 -1
- package/dist/date/constants.js +9 -0
- package/dist/date/types.d.ts +101 -12
- package/dist/date/types.d.ts.map +1 -1
- package/dist/date/utils.js +1 -1
- package/package.json +1 -1
package/dist/colors/Color.d.ts
CHANGED
|
@@ -4,24 +4,47 @@ import type { AlphaColors, ColorType, Hex6, Hex8, HSL, HSLA, OpacityValue, RGB,
|
|
|
4
4
|
* * It has 1 instance method `applyOpacity()` to apply opacity to `Hex`, `Hex8` `RGB`, `RGBA`, `HSL` or `HSLA` color.
|
|
5
5
|
* * It has 6 static methods that can be used to check if a color is in `Hex`, `Hex8` `RGB`, `RGBA`, `HSL` or `HSLA` format.
|
|
6
6
|
*
|
|
7
|
-
* @property
|
|
8
|
-
* @property
|
|
9
|
-
* @property
|
|
10
|
-
* @property
|
|
11
|
-
* @property
|
|
12
|
-
* @property
|
|
7
|
+
* @property hex - The color in `Hex` format.
|
|
8
|
+
* @property hex8 - The color in `Hex8` format.
|
|
9
|
+
* @property rgb - The color in `RGB` format.
|
|
10
|
+
* @property rgba - The color in `RGBA` format.
|
|
11
|
+
* @property hsl - The color in `HSL` format.
|
|
12
|
+
* @property hsla - The color in `HSLA` format.
|
|
13
13
|
*/
|
|
14
14
|
export declare class Color {
|
|
15
|
+
#private;
|
|
15
16
|
hex: Hex6;
|
|
16
17
|
hex8: Hex8;
|
|
17
18
|
rgb: RGB;
|
|
18
19
|
rgba: RGBA;
|
|
19
20
|
hsl: HSL;
|
|
20
21
|
hsla: HSLA;
|
|
21
|
-
/** - Iterates over the color representations (Hex, RGB, HSL). */
|
|
22
|
-
[Symbol.iterator](): Generator<Hex6 | RGB | HSL | Hex8 | RGBA | HSLA, void, unknown>;
|
|
23
22
|
/**
|
|
24
|
-
* * Creates a new `Color` instance and automatically converts the
|
|
23
|
+
* * Creates a new `Color` instance with a random color and automatically converts the generated color to all other supported formats: `Hex`, `Hex8`, `RGB`, `RGBA`, `HSL`, and `HSLA`.
|
|
24
|
+
*
|
|
25
|
+
* @description
|
|
26
|
+
* The `Color` class generates a random color in six common color representations:
|
|
27
|
+
* - `Hex` (e.g., `#ff5733`)
|
|
28
|
+
* - `Hex8` (Hex with opacity, e.g., `#ff573380`)
|
|
29
|
+
* - `RGB` (e.g., `rgb(255, 87, 51)`)
|
|
30
|
+
* - `RGBA` (e.g., `rgba(255, 87, 51, 1)`)
|
|
31
|
+
* - `HSL` (e.g., `hsl(14, 100%, 60%)`)
|
|
32
|
+
* - `HSLA` (e.g., `hsla(14, 100%, 60%, 1)`)
|
|
33
|
+
*
|
|
34
|
+
* Additionally:
|
|
35
|
+
* - Use `.applyOpacity(opacity)` to modify or add opacity to the color.
|
|
36
|
+
* - Use static methods like `Color.isHex6(color)` to validate color strings.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* // Generate a random color
|
|
40
|
+
* const randomColor = new Color();
|
|
41
|
+
* console.log(randomColor.hex, randomColor.rgb, randomColor.hsl);
|
|
42
|
+
*
|
|
43
|
+
* @returns Instance of `Color`.
|
|
44
|
+
*/
|
|
45
|
+
constructor();
|
|
46
|
+
/**
|
|
47
|
+
* * Creates a new `Color` instance with the input color and automatically converts it to all other supported formats: `Hex`, `Hex8`, `RGB`, `RGBA`, `HSL`, and `HSLA`.
|
|
25
48
|
*
|
|
26
49
|
* @description
|
|
27
50
|
* The `Color` class allows seamless transformation between six common color representations:
|
|
@@ -33,13 +56,12 @@ export declare class Color {
|
|
|
33
56
|
* - `HSLA` (e.g., `hsla(14, 100%, 60%, 1)`)
|
|
34
57
|
*
|
|
35
58
|
* You can create a color from any of these formats, and the class will populate the rest.
|
|
36
|
-
* If no color is passed, a random color will be generated.
|
|
37
59
|
*
|
|
38
60
|
* Additionally:
|
|
39
61
|
* - Use `.applyOpacity(opacity)` to modify or add opacity to the color.
|
|
40
|
-
* - Use static methods like `Color.isHex6(color)` to validate color strings.
|
|
62
|
+
* - Use available 6 static methods like `Color.isHex6(color)` to validate color strings.
|
|
41
63
|
*
|
|
42
|
-
* @param toConvert -
|
|
64
|
+
* @param toConvert - A color string in any supported format (`Hex`, `Hex8`, `RGB`, `RGBA`, `HSL`, or `HSLA`) to convert in all other formats (includes the current format).
|
|
43
65
|
*
|
|
44
66
|
* @example
|
|
45
67
|
* // Convert an existing Hex color to all other formats
|
|
@@ -56,12 +78,11 @@ export declare class Color {
|
|
|
56
78
|
* console.log(alphaColor.hex8); // '#FF000080'
|
|
57
79
|
* console.log(alphaColor.hsla); // 'hsla(0, 100%, 50%, 0.5)'
|
|
58
80
|
*
|
|
59
|
-
* @
|
|
60
|
-
* // Generate a random color
|
|
61
|
-
* const randomColor = new Color();
|
|
62
|
-
* console.log(randomColor.hex, randomColor.rgb, randomColor.hsl);
|
|
81
|
+
* @returns Instance of `Color`.
|
|
63
82
|
*/
|
|
64
|
-
constructor(toConvert
|
|
83
|
+
constructor(toConvert: ColorType);
|
|
84
|
+
/** - Iterates over the color representations (Hex, RGB, HSL). */
|
|
85
|
+
[Symbol.iterator](): Generator<Hex6 | RGB | HSL | Hex8 | RGBA | HSLA, void, unknown>;
|
|
65
86
|
/**
|
|
66
87
|
* * Applies or modifies the opacity of a color.
|
|
67
88
|
* - For solid colors (Hex6/RGB/HSL): Adds an alpha channel with the specified opacity
|
|
@@ -123,12 +144,5 @@ export declare class Color {
|
|
|
123
144
|
* @returns Boolean: `true` if it's an `HSLA` color, `false` if not.
|
|
124
145
|
*/
|
|
125
146
|
static isHSLA(color: string): color is HSLA;
|
|
126
|
-
/**
|
|
127
|
-
* @private Converts the given color to all other formats while preserving the original.
|
|
128
|
-
*
|
|
129
|
-
* @param color - The color to convert.
|
|
130
|
-
* @returns An object containing Hex, RGB, and HSL representations.
|
|
131
|
-
*/
|
|
132
|
-
private _convertColorToOthers;
|
|
133
147
|
}
|
|
134
148
|
//# sourceMappingURL=Color.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Color.d.ts","sourceRoot":"","sources":["../../src/colors/Color.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACX,WAAW,EACX,SAAS,EACT,IAAI,EACJ,IAAI,EACJ,GAAG,EACH,IAAI,EACJ,YAAY,EACZ,GAAG,EACH,IAAI,EACJ,WAAW,EACX,MAAM,SAAS,CAAC;AAKjB;;;;;;;;;;;GAWG;AACH,qBAAa,KAAK
|
|
1
|
+
{"version":3,"file":"Color.d.ts","sourceRoot":"","sources":["../../src/colors/Color.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACX,WAAW,EACX,SAAS,EACT,IAAI,EACJ,IAAI,EACJ,GAAG,EACH,IAAI,EACJ,YAAY,EACZ,GAAG,EACH,IAAI,EACJ,WAAW,EACX,MAAM,SAAS,CAAC;AAKjB;;;;;;;;;;;GAWG;AACH,qBAAa,KAAK;;IACV,GAAG,EAAE,IAAI,CAAC;IACV,IAAI,EAAE,IAAI,CAAC;IACX,GAAG,EAAE,GAAG,CAAC;IACT,IAAI,EAAE,IAAI,CAAC;IACX,GAAG,EAAE,GAAG,CAAC;IACT,IAAI,EAAE,IAAI,CAAC;IAElB;;;;;;;;;;;;;;;;;;;;;;OAsBG;;IAGH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAoCG;gBACS,SAAS,EAAE,SAAS;IAwFhC,iEAAiE;IAChE,CAAC,MAAM,CAAC,QAAQ,CAAC;IASlB;;;;;;;;;;;;;;;;;OAiBG;IACH,YAAY,CAAC,OAAO,EAAE,YAAY,GAAG,WAAW,GAAG,WAAW;IAkB9D;;;;;OAKG;IACH,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,IAAI;IAI3C;;;;;OAKG;IACH,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,IAAI;IAI3C;;;;;OAKG;IACH,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,GAAG;IAIzC;;;;;OAKG;IACH,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,IAAI;IAM3C;;;;;OAKG;IACH,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,GAAG;IAIzC;;;;;OAKG;IACH,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,IAAI;CAmC3C"}
|
package/dist/colors/Color.js
CHANGED
|
@@ -8,12 +8,12 @@ const { hex, rgb } = convertColorCode(hsl);
|
|
|
8
8
|
* * It has 1 instance method `applyOpacity()` to apply opacity to `Hex`, `Hex8` `RGB`, `RGBA`, `HSL` or `HSLA` color.
|
|
9
9
|
* * It has 6 static methods that can be used to check if a color is in `Hex`, `Hex8` `RGB`, `RGBA`, `HSL` or `HSLA` format.
|
|
10
10
|
*
|
|
11
|
-
* @property
|
|
12
|
-
* @property
|
|
13
|
-
* @property
|
|
14
|
-
* @property
|
|
15
|
-
* @property
|
|
16
|
-
* @property
|
|
11
|
+
* @property hex - The color in `Hex` format.
|
|
12
|
+
* @property hex8 - The color in `Hex8` format.
|
|
13
|
+
* @property rgb - The color in `RGB` format.
|
|
14
|
+
* @property rgba - The color in `RGBA` format.
|
|
15
|
+
* @property hsl - The color in `HSL` format.
|
|
16
|
+
* @property hsla - The color in `HSLA` format.
|
|
17
17
|
*/
|
|
18
18
|
export class Color {
|
|
19
19
|
hex;
|
|
@@ -22,15 +22,6 @@ export class Color {
|
|
|
22
22
|
rgba;
|
|
23
23
|
hsl;
|
|
24
24
|
hsla;
|
|
25
|
-
/** - Iterates over the color representations (Hex, RGB, HSL). */
|
|
26
|
-
*[Symbol.iterator]() {
|
|
27
|
-
yield this.hex;
|
|
28
|
-
yield this.hex8;
|
|
29
|
-
yield this.rgb;
|
|
30
|
-
yield this.rgba;
|
|
31
|
-
yield this.hsl;
|
|
32
|
-
yield this.hsla;
|
|
33
|
-
}
|
|
34
25
|
/**
|
|
35
26
|
* * Creates a new `Color` instance and automatically converts the input color to all other supported formats: `Hex`, `Hex8`, `RGB`, `RGBA`, `HSL`, and `HSLA`.
|
|
36
27
|
*
|
|
@@ -71,10 +62,12 @@ export class Color {
|
|
|
71
62
|
* // Generate a random color
|
|
72
63
|
* const randomColor = new Color();
|
|
73
64
|
* console.log(randomColor.hex, randomColor.rgb, randomColor.hsl);
|
|
65
|
+
*
|
|
66
|
+
* @returns Instance of `Color`.
|
|
74
67
|
*/
|
|
75
68
|
constructor(toConvert) {
|
|
76
69
|
if (toConvert) {
|
|
77
|
-
const colors = this
|
|
70
|
+
const colors = this.#convertColorToOthers(toConvert);
|
|
78
71
|
if ('hex8' in colors) {
|
|
79
72
|
// Extract alpha color values (Hex8, RGBA, HSLA)
|
|
80
73
|
const rgbaValues = _extractAlphaColorValues(colors.rgba);
|
|
@@ -112,6 +105,15 @@ export class Color {
|
|
|
112
105
|
this.hsla = `hsla(${hslValues[0]}, ${hslValues[1]}%, ${hslValues[2]}%, 1)`;
|
|
113
106
|
}
|
|
114
107
|
}
|
|
108
|
+
/** - Iterates over the color representations (Hex, RGB, HSL). */
|
|
109
|
+
*[Symbol.iterator]() {
|
|
110
|
+
yield this.hex;
|
|
111
|
+
yield this.hex8;
|
|
112
|
+
yield this.rgb;
|
|
113
|
+
yield this.rgba;
|
|
114
|
+
yield this.hsl;
|
|
115
|
+
yield this.hsla;
|
|
116
|
+
}
|
|
115
117
|
/**
|
|
116
118
|
* * Applies or modifies the opacity of a color.
|
|
117
119
|
* - For solid colors (Hex6/RGB/HSL): Adds an alpha channel with the specified opacity
|
|
@@ -205,7 +207,7 @@ export class Color {
|
|
|
205
207
|
* @param color - The color to convert.
|
|
206
208
|
* @returns An object containing Hex, RGB, and HSL representations.
|
|
207
209
|
*/
|
|
208
|
-
|
|
210
|
+
#convertColorToOthers(color) {
|
|
209
211
|
if (Color.isHex6(color)) {
|
|
210
212
|
const { rgb, hsl } = convertColorCode(color);
|
|
211
213
|
return { hex: color, rgb, hsl };
|