nhb-toolbox 1.4.0 → 1.5.1
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/convert.d.ts +51 -12
- package/dist/colors/convert.d.ts.map +1 -1
- package/dist/colors/convert.js +104 -69
- package/dist/colors/types.d.ts +44 -0
- package/dist/colors/types.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/package.json +1 -1
package/dist/colors/convert.d.ts
CHANGED
|
@@ -1,51 +1,90 @@
|
|
|
1
|
+
import type { ColorNumbers, Hex, HSL, RGB } from './types';
|
|
1
2
|
/**
|
|
2
|
-
* Converts HSL to RGB color format.
|
|
3
|
+
* * Converts HSL to RGB color format.
|
|
3
4
|
*
|
|
4
5
|
* @param h - The hue component of the HSL color, in degrees (0 to 360).
|
|
5
6
|
* @param s - The saturation component of the HSL color, as a percentage (0 to 100).
|
|
6
7
|
* @param l - The lightness component of the HSL color, as a percentage (0 to 100).
|
|
7
8
|
* @returns A string representing the color in RGB format (e.g., `rgb(255, 0, 0)`).
|
|
8
9
|
*/
|
|
9
|
-
export declare const convertHslToRgb: (h: number, s: number, l: number) =>
|
|
10
|
+
export declare const convertHslToRgb: (h: number, s: number, l: number) => RGB;
|
|
10
11
|
/**
|
|
11
|
-
* Converts RGB to HSL color format.
|
|
12
|
+
* * Converts RGB to HSL color format.
|
|
12
13
|
*
|
|
13
14
|
* @param r - The red component of the RGB color, in the range 0 to 255.
|
|
14
15
|
* @param g - The green component of the RGB color, in the range 0 to 255.
|
|
15
16
|
* @param b - The blue component of the RGB color, in the range 0 to 255.
|
|
16
17
|
* @returns A string representing the color in HSL format (e.g., `hsl(0, 100%, 50%)`).
|
|
17
18
|
*/
|
|
18
|
-
export declare const convertRgbToHsl: (r: number, g: number, b: number) =>
|
|
19
|
+
export declare const convertRgbToHsl: (r: number, g: number, b: number) => HSL;
|
|
19
20
|
/**
|
|
20
|
-
* Converts HSL to Hex color format.
|
|
21
|
+
* * Converts HSL to Hex color format.
|
|
21
22
|
*
|
|
22
23
|
* @param h - The hue component of the HSL color, in degrees (0 to 360).
|
|
23
24
|
* @param s - The saturation component of the HSL color, as a percentage (0 to 100).
|
|
24
25
|
* @param l - The lightness component of the HSL color, as a percentage (0 to 100).
|
|
25
26
|
* @returns A string representing the color in Hex format (e.g., `#FF0000`).
|
|
26
27
|
*/
|
|
27
|
-
export declare const convertHslToHex: (h: number, s: number, l: number) =>
|
|
28
|
+
export declare const convertHslToHex: (h: number, s: number, l: number) => Hex;
|
|
28
29
|
/**
|
|
29
|
-
* Converts Hex to HSL color format.
|
|
30
|
+
* * Converts Hex to HSL color format.
|
|
30
31
|
*
|
|
31
32
|
* @param hex - A string representing the color in Hex format (e.g., `#FF0000`).
|
|
32
33
|
* @returns A string representing the color in HSL format (e.g., `hsl(0, 100%, 50%)`).
|
|
33
34
|
*/
|
|
34
|
-
export declare const convertHexToHsl: (hex: string) =>
|
|
35
|
+
export declare const convertHexToHsl: (hex: Hex | string) => HSL;
|
|
35
36
|
/**
|
|
36
|
-
* Converts RGB to Hex color format.
|
|
37
|
+
* * Converts RGB to Hex color format.
|
|
37
38
|
*
|
|
38
39
|
* @param r - The red component of the RGB color, in the range 0 to 255.
|
|
39
40
|
* @param g - The green component of the RGB color, in the range 0 to 255.
|
|
40
41
|
* @param b - The blue component of the RGB color, in the range 0 to 255.
|
|
41
42
|
* @returns A string representing the color in Hex format (e.g., `#FF0000`).
|
|
42
43
|
*/
|
|
43
|
-
export declare const convertRgbToHex: (r: number, g: number, b: number) =>
|
|
44
|
+
export declare const convertRgbToHex: (r: number, g: number, b: number) => Hex;
|
|
44
45
|
/**
|
|
45
|
-
* Converts Hex to RGB color format.
|
|
46
|
+
* * Converts Hex to RGB color format.
|
|
46
47
|
*
|
|
47
48
|
* @param hex - A string representing the color in Hex format (e.g., `#FF0000`).
|
|
48
49
|
* @returns A string representing the color in RGB format (e.g., `rgb(255, 0, 0)`).
|
|
49
50
|
*/
|
|
50
|
-
export declare const convertHexToRgb: (hex: string) =>
|
|
51
|
+
export declare const convertHexToRgb: (hex: Hex | string) => RGB;
|
|
52
|
+
/**
|
|
53
|
+
* * Extracts numbers from a color string like `rgb(66, 103, 69)` or `hsl(120, 42.86%, 41.18%)`.
|
|
54
|
+
* * Converts percentage values to decimal (e.g., `42.86%` → `42.86`).
|
|
55
|
+
*
|
|
56
|
+
* @param colorString The color string in RGB or HSL format.
|
|
57
|
+
* @returns An array of extracted numbers.
|
|
58
|
+
*/
|
|
59
|
+
export declare const extractNumbersFromColor: (colorString: HSL | RGB) => ColorNumbers;
|
|
60
|
+
/**
|
|
61
|
+
* * Converts a `Hex` color code to `RGB` and `HSL` formats.
|
|
62
|
+
*
|
|
63
|
+
* @param color The `Hex` color code (e.g., `#3c6945`).
|
|
64
|
+
* @returns An object containing the `RGB` and `HSL` formats of the given `Hex` color.
|
|
65
|
+
*/
|
|
66
|
+
export declare function convertColorCode(color: Hex): {
|
|
67
|
+
rgb: RGB;
|
|
68
|
+
hsl: HSL;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* * Converts an `RGB` color to `Hex` and `HSL` formats.
|
|
72
|
+
*
|
|
73
|
+
* @param color The `RGB` color string (e.g., `rgb(60, 105, 69)`).
|
|
74
|
+
* @returns An object containing the `Hex` and `HSL` formats of the given `RGB` color.
|
|
75
|
+
*/
|
|
76
|
+
export declare function convertColorCode(color: RGB): {
|
|
77
|
+
hex: Hex;
|
|
78
|
+
hsl: HSL;
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* * Converts an `HSL` color to `Hex` and `RGB` formats.
|
|
82
|
+
*
|
|
83
|
+
* @param color The `HSL` color string (e.g., `hsl(132, 27.27%, 32.35%)`).
|
|
84
|
+
* @returns An object containing the `Hex` and `RGB` formats of the given `HSL` color.
|
|
85
|
+
*/
|
|
86
|
+
export declare function convertColorCode(color: HSL): {
|
|
87
|
+
hex: Hex;
|
|
88
|
+
rgb: RGB;
|
|
89
|
+
};
|
|
51
90
|
//# sourceMappingURL=convert.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convert.d.ts","sourceRoot":"","sources":["../../src/colors/convert.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,MAAO,MAAM,KAAK,MAAM,KAAK,MAAM,KAAG,
|
|
1
|
+
{"version":3,"file":"convert.d.ts","sourceRoot":"","sources":["../../src/colors/convert.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEX,YAAY,EAEZ,GAAG,EACH,GAAG,EACH,GAAG,EACH,MAAM,SAAS,CAAC;AAEjB;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,MAAO,MAAM,KAAK,MAAM,KAAK,MAAM,KAAG,GAwBjE,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,MAAO,MAAM,KAAK,MAAM,KAAK,MAAM,KAAG,GAkCjE,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,MAAO,MAAM,KAAK,MAAM,KAAK,MAAM,KAAG,GAIjE,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,eAAe,QAAS,GAAG,GAAG,MAAM,KAAG,GAenD,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,MAAO,MAAM,KAAK,MAAM,KAAK,MAAM,KAAG,GAKjE,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,eAAe,QAAS,GAAG,GAAG,MAAM,KAAG,GAgBnD,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,uBAAuB,gBACtB,GAAG,GAAG,GAAG,KACpB,YAIF,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,GAAG,GAAG;IAC7C,GAAG,EAAE,GAAG,CAAC;IACT,GAAG,EAAE,GAAG,CAAC;CACT,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,GAAG,GAAG;IAC7C,GAAG,EAAE,GAAG,CAAC;IACT,GAAG,EAAE,GAAG,CAAC;CACT,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,GAAG,GAAG;IAC7C,GAAG,EAAE,GAAG,CAAC;IACT,GAAG,EAAE,GAAG,CAAC;CACT,CAAC"}
|
package/dist/colors/convert.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.convertHexToRgb = exports.convertRgbToHex = exports.convertHexToHsl = exports.convertHslToHex = exports.convertRgbToHsl = exports.convertHslToRgb = void 0;
|
|
3
|
+
exports.extractNumbersFromColor = exports.convertHexToRgb = exports.convertRgbToHex = exports.convertHexToHsl = exports.convertHslToHex = exports.convertRgbToHsl = exports.convertHslToRgb = void 0;
|
|
4
|
+
exports.convertColorCode = convertColorCode;
|
|
4
5
|
/**
|
|
5
|
-
* Converts HSL to RGB color format.
|
|
6
|
+
* * Converts HSL to RGB color format.
|
|
6
7
|
*
|
|
7
8
|
* @param h - The hue component of the HSL color, in degrees (0 to 360).
|
|
8
9
|
* @param s - The saturation component of the HSL color, as a percentage (0 to 100).
|
|
@@ -17,31 +18,18 @@ const convertHslToRgb = (h, s, l) => {
|
|
|
17
18
|
const x = c * (1 - Math.abs(((h / 60) % 2) - 1));
|
|
18
19
|
const m = l - c / 2;
|
|
19
20
|
let r = 0, g = 0, b = 0;
|
|
20
|
-
if (h >= 0 && h < 60)
|
|
21
|
-
r = c;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
else if (h >=
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
else if (h >=
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
else if (h >= 180 && h < 240) {
|
|
33
|
-
g = x;
|
|
34
|
-
b = c;
|
|
35
|
-
}
|
|
36
|
-
else if (h >= 240 && h < 300) {
|
|
37
|
-
r = x;
|
|
38
|
-
b = c;
|
|
39
|
-
}
|
|
40
|
-
else if (h >= 300 && h < 360) {
|
|
41
|
-
r = c;
|
|
42
|
-
b = x;
|
|
43
|
-
}
|
|
44
|
-
// Convert RGB to 0-255 range and apply m
|
|
21
|
+
if (h >= 0 && h < 60)
|
|
22
|
+
[r, g] = [c, x];
|
|
23
|
+
else if (h >= 60 && h < 120)
|
|
24
|
+
[r, g] = [x, c];
|
|
25
|
+
else if (h >= 120 && h < 180)
|
|
26
|
+
[g, b] = [c, x];
|
|
27
|
+
else if (h >= 180 && h < 240)
|
|
28
|
+
[g, b] = [x, c];
|
|
29
|
+
else if (h >= 240 && h < 300)
|
|
30
|
+
[r, b] = [x, c];
|
|
31
|
+
else if (h >= 300 && h < 360)
|
|
32
|
+
[r, b] = [c, x];
|
|
45
33
|
r = Math.round((r + m) * 255);
|
|
46
34
|
g = Math.round((g + m) * 255);
|
|
47
35
|
b = Math.round((b + m) * 255);
|
|
@@ -49,7 +37,7 @@ const convertHslToRgb = (h, s, l) => {
|
|
|
49
37
|
};
|
|
50
38
|
exports.convertHslToRgb = convertHslToRgb;
|
|
51
39
|
/**
|
|
52
|
-
* Converts RGB to HSL color format.
|
|
40
|
+
* * Converts RGB to HSL color format.
|
|
53
41
|
*
|
|
54
42
|
* @param r - The red component of the RGB color, in the range 0 to 255.
|
|
55
43
|
* @param g - The green component of the RGB color, in the range 0 to 255.
|
|
@@ -57,40 +45,34 @@ exports.convertHslToRgb = convertHslToRgb;
|
|
|
57
45
|
* @returns A string representing the color in HSL format (e.g., `hsl(0, 100%, 50%)`).
|
|
58
46
|
*/
|
|
59
47
|
const convertRgbToHsl = (r, g, b) => {
|
|
60
|
-
// Normalize the RGB values
|
|
61
48
|
r /= 255;
|
|
62
49
|
g /= 255;
|
|
63
50
|
b /= 255;
|
|
64
51
|
const max = Math.max(r, g, b);
|
|
65
52
|
const min = Math.min(r, g, b);
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
if (
|
|
69
|
-
|
|
70
|
-
|
|
53
|
+
let h = 0, s = 0;
|
|
54
|
+
const l = (max + min) / 2;
|
|
55
|
+
if (max !== min) {
|
|
56
|
+
const diff = max - min;
|
|
57
|
+
s = l > 0.5 ? diff / (2 - max - min) : diff / (max + min);
|
|
58
|
+
switch (max) {
|
|
59
|
+
case r:
|
|
60
|
+
h = (g - b) / diff + (g < b ? 6 : 0);
|
|
61
|
+
break;
|
|
62
|
+
case g:
|
|
63
|
+
h = (b - r) / diff + 2;
|
|
64
|
+
break;
|
|
65
|
+
case b:
|
|
66
|
+
h = (r - g) / diff + 4;
|
|
67
|
+
break;
|
|
71
68
|
}
|
|
72
|
-
else if (max === g) {
|
|
73
|
-
h = (b - r) / delta + 2;
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
h = (r - g) / delta + 4;
|
|
77
|
-
}
|
|
78
|
-
s = delta / (1 - Math.abs(2 * l - 1));
|
|
79
69
|
h *= 60;
|
|
80
|
-
if (s === 0)
|
|
81
|
-
l = Math.round(l * 100); // for pure colors
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
s = 0;
|
|
85
70
|
}
|
|
86
|
-
|
|
87
|
-
s = Math.round(s * 100);
|
|
88
|
-
l = Math.round(l * 100);
|
|
89
|
-
return `hsl(${h}, ${s}%, ${l}%)`;
|
|
71
|
+
return `hsl(${Math.round(h)}, ${Number((s * 100).toFixed(2))}%, ${Number((l * 100).toFixed(2))}%)`;
|
|
90
72
|
};
|
|
91
73
|
exports.convertRgbToHsl = convertRgbToHsl;
|
|
92
74
|
/**
|
|
93
|
-
* Converts HSL to Hex color format.
|
|
75
|
+
* * Converts HSL to Hex color format.
|
|
94
76
|
*
|
|
95
77
|
* @param h - The hue component of the HSL color, in degrees (0 to 360).
|
|
96
78
|
* @param s - The saturation component of the HSL color, as a percentage (0 to 100).
|
|
@@ -98,29 +80,32 @@ exports.convertRgbToHsl = convertRgbToHsl;
|
|
|
98
80
|
* @returns A string representing the color in Hex format (e.g., `#FF0000`).
|
|
99
81
|
*/
|
|
100
82
|
const convertHslToHex = (h, s, l) => {
|
|
101
|
-
const rgb = (0, exports.convertHslToRgb)(h, s, l);
|
|
102
|
-
|
|
103
|
-
return `#${((1 << 24) | (r << 16) | (g << 8) | b).toString(16).slice(1).toUpperCase().padStart(6, '0')}`;
|
|
83
|
+
const rgb = (0, exports.convertHslToRgb)(h, s, l).match(/\d+/g).map(Number);
|
|
84
|
+
return (0, exports.convertRgbToHex)(rgb[0], rgb[1], rgb[2]);
|
|
104
85
|
};
|
|
105
86
|
exports.convertHslToHex = convertHslToHex;
|
|
106
87
|
/**
|
|
107
|
-
* Converts Hex to HSL color format.
|
|
88
|
+
* * Converts Hex to HSL color format.
|
|
108
89
|
*
|
|
109
90
|
* @param hex - A string representing the color in Hex format (e.g., `#FF0000`).
|
|
110
91
|
* @returns A string representing the color in HSL format (e.g., `hsl(0, 100%, 50%)`).
|
|
111
92
|
*/
|
|
112
93
|
const convertHexToHsl = (hex) => {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
94
|
+
let newHex = hex.replace('#', '');
|
|
95
|
+
if (newHex.length === 3) {
|
|
96
|
+
newHex = newHex
|
|
97
|
+
.split('')
|
|
98
|
+
.map((char) => char + char)
|
|
99
|
+
.join('');
|
|
100
|
+
}
|
|
101
|
+
const r = parseInt(newHex.slice(0, 2), 16);
|
|
102
|
+
const g = parseInt(newHex.slice(2, 4), 16);
|
|
103
|
+
const b = parseInt(newHex.slice(4, 6), 16);
|
|
119
104
|
return (0, exports.convertRgbToHsl)(r, g, b);
|
|
120
105
|
};
|
|
121
106
|
exports.convertHexToHsl = convertHexToHsl;
|
|
122
107
|
/**
|
|
123
|
-
* Converts RGB to Hex color format.
|
|
108
|
+
* * Converts RGB to Hex color format.
|
|
124
109
|
*
|
|
125
110
|
* @param r - The red component of the RGB color, in the range 0 to 255.
|
|
126
111
|
* @param g - The green component of the RGB color, in the range 0 to 255.
|
|
@@ -128,22 +113,72 @@ exports.convertHexToHsl = convertHexToHsl;
|
|
|
128
113
|
* @returns A string representing the color in Hex format (e.g., `#FF0000`).
|
|
129
114
|
*/
|
|
130
115
|
const convertRgbToHex = (r, g, b) => {
|
|
131
|
-
return `#${
|
|
116
|
+
return `#${[r, g, b]
|
|
117
|
+
.map((v) => v.toString(16).padStart(2, '0'))
|
|
118
|
+
.join('')
|
|
119
|
+
.toUpperCase()}`;
|
|
132
120
|
};
|
|
133
121
|
exports.convertRgbToHex = convertRgbToHex;
|
|
134
122
|
/**
|
|
135
|
-
* Converts Hex to RGB color format.
|
|
123
|
+
* * Converts Hex to RGB color format.
|
|
136
124
|
*
|
|
137
125
|
* @param hex - A string representing the color in Hex format (e.g., `#FF0000`).
|
|
138
126
|
* @returns A string representing the color in RGB format (e.g., `rgb(255, 0, 0)`).
|
|
139
127
|
*/
|
|
140
128
|
const convertHexToRgb = (hex) => {
|
|
141
129
|
// Remove the # if present
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
130
|
+
let newHex = hex.replace('#', '');
|
|
131
|
+
if (newHex.length === 3) {
|
|
132
|
+
newHex = newHex
|
|
133
|
+
.split('')
|
|
134
|
+
.map((char) => char + char)
|
|
135
|
+
.join('');
|
|
136
|
+
}
|
|
137
|
+
const r = parseInt(newHex.slice(0, 2), 16);
|
|
138
|
+
const g = parseInt(newHex.slice(2, 4), 16);
|
|
139
|
+
const b = parseInt(newHex.slice(4, 6), 16);
|
|
147
140
|
return `rgb(${r}, ${g}, ${b})`;
|
|
148
141
|
};
|
|
149
142
|
exports.convertHexToRgb = convertHexToRgb;
|
|
143
|
+
/**
|
|
144
|
+
* * Extracts numbers from a color string like `rgb(66, 103, 69)` or `hsl(120, 42.86%, 41.18%)`.
|
|
145
|
+
* * Converts percentage values to decimal (e.g., `42.86%` → `42.86`).
|
|
146
|
+
*
|
|
147
|
+
* @param colorString The color string in RGB or HSL format.
|
|
148
|
+
* @returns An array of extracted numbers.
|
|
149
|
+
*/
|
|
150
|
+
const extractNumbersFromColor = (colorString) => {
|
|
151
|
+
return (colorString.match(/[\d.]+%?/g) || []).map((value) => parseFloat(value));
|
|
152
|
+
};
|
|
153
|
+
exports.extractNumbersFromColor = extractNumbersFromColor;
|
|
154
|
+
/**
|
|
155
|
+
* * Converts a color from `Hex`, `RGB`, or `HSL` format to its equivalent representations.
|
|
156
|
+
*
|
|
157
|
+
* @param color The color string in `Hex`, `RGB`, or `HSL` format.
|
|
158
|
+
* @returns The converted color representations excluding the input format.
|
|
159
|
+
* @throws If the color format is unrecognized throws `Error`.
|
|
160
|
+
*/
|
|
161
|
+
function convertColorCode(color) {
|
|
162
|
+
if (color.startsWith('#')) {
|
|
163
|
+
return {
|
|
164
|
+
rgb: (0, exports.convertHexToRgb)(color),
|
|
165
|
+
hsl: (0, exports.convertHexToHsl)(color),
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
if (color.startsWith('rgb')) {
|
|
169
|
+
return {
|
|
170
|
+
hex: (0, exports.convertRgbToHex)(...(0, exports.extractNumbersFromColor)(color)),
|
|
171
|
+
hsl: (0, exports.convertRgbToHsl)(...(0, exports.extractNumbersFromColor)(color)),
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
if (color.startsWith('hsl')) {
|
|
175
|
+
return {
|
|
176
|
+
hex: (0, exports.convertHslToHex)(...(0, exports.extractNumbersFromColor)(color)),
|
|
177
|
+
rgb: (0, exports.convertHslToRgb)(...(0, exports.extractNumbersFromColor)(color)),
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
throw new Error(`Unrecognized Color Format: ${color}`);
|
|
181
|
+
}
|
|
182
|
+
console.info(convertColorCode('#3c6945'));
|
|
183
|
+
console.info(convertColorCode('rgb(60, 105, 69)'));
|
|
184
|
+
console.info(convertColorCode('hsl(132, 27.27%, 32.35%)'));
|
package/dist/colors/types.d.ts
CHANGED
|
@@ -5,4 +5,48 @@ export interface ColorInputArray extends Array<ColorInput | ColorInputArray> {
|
|
|
5
5
|
}
|
|
6
6
|
/** - Opacity options */
|
|
7
7
|
export type OpacityValue = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100;
|
|
8
|
+
/**
|
|
9
|
+
* * Represents a hexadecimal color code.
|
|
10
|
+
* Format: `#3C6945`
|
|
11
|
+
*/
|
|
12
|
+
export type Hex = `#${string}`;
|
|
13
|
+
/**
|
|
14
|
+
* * Represents an RGB color string.
|
|
15
|
+
* * Format: `rgb(R, G, B)`
|
|
16
|
+
*
|
|
17
|
+
* - R (Red): 0-255
|
|
18
|
+
* - G (Green): 0-255
|
|
19
|
+
* - B (Blue): 0-255
|
|
20
|
+
*/
|
|
21
|
+
export type RGB = `rgb(${number}, ${number}, ${number})`;
|
|
22
|
+
/**
|
|
23
|
+
* * Represents an HSL color string.
|
|
24
|
+
* * Format: `hsl(H, S%, L%)`
|
|
25
|
+
*
|
|
26
|
+
* - H (Hue): 0-360
|
|
27
|
+
* - S (Saturation): 0-100%
|
|
28
|
+
* - L (Lightness): 0-100%
|
|
29
|
+
*/
|
|
30
|
+
export type HSL = `hsl(${number}, ${number}%, ${number}%)`;
|
|
31
|
+
/** * Union type representing a color in Hex, RGB, or HSL format. */
|
|
32
|
+
export type Color = Hex | RGB | HSL;
|
|
33
|
+
/** * Represents a tuple of three numerical values corresponding to RGB or HSL color components. */
|
|
34
|
+
export type ColorNumbers = [number, number, number];
|
|
35
|
+
/**
|
|
36
|
+
* * Represents the converted color formats for a given color type.
|
|
37
|
+
*
|
|
38
|
+
* - If the input is `Hex`, the output includes `RGB` and `HSL`.
|
|
39
|
+
* - If the input is `RGB`, the output includes `Hex` and `HSL`.
|
|
40
|
+
* - If the input is `HSL`, the output includes `Hex` and `RGB`.
|
|
41
|
+
*
|
|
42
|
+
* @template T The input color type (`Hex`, `RGB`, or `HSL`).
|
|
43
|
+
*/
|
|
44
|
+
export interface ConvertedColors<T extends Color> extends Record<string, Hex | RGB | HSL> {
|
|
45
|
+
/** - The Hex representation (excluded if the input is already Hex). */
|
|
46
|
+
hex: T extends Hex ? never : Hex;
|
|
47
|
+
/** - The RGB representation (excluded if the input is already RGB). */
|
|
48
|
+
rgb: T extends RGB ? never : RGB;
|
|
49
|
+
/** - The HSL representation (excluded if the input is already HSL). */
|
|
50
|
+
hsl: T extends HSL ? never : HSL;
|
|
51
|
+
}
|
|
8
52
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/colors/types.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,MAAM,CAAC;AAEzC,+FAA+F;AAC/F,MAAM,WAAW,eAAgB,SAAQ,KAAK,CAAC,UAAU,GAAG,eAAe,CAAC;CAAG;AAE/E,wBAAwB;AACxB,MAAM,MAAM,YAAY,GACrB,CAAC,GACD,CAAC,GACD,CAAC,GACD,CAAC,GACD,CAAC,GACD,CAAC,GACD,CAAC,GACD,CAAC,GACD,CAAC,GACD,CAAC,GACD,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,GAAG,CAAC"}
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/colors/types.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,MAAM,CAAC;AAEzC,+FAA+F;AAC/F,MAAM,WAAW,eAAgB,SAAQ,KAAK,CAAC,UAAU,GAAG,eAAe,CAAC;CAAG;AAE/E,wBAAwB;AACxB,MAAM,MAAM,YAAY,GACrB,CAAC,GACD,CAAC,GACD,CAAC,GACD,CAAC,GACD,CAAC,GACD,CAAC,GACD,CAAC,GACD,CAAC,GACD,CAAC,GACD,CAAC,GACD,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,GAAG,CAAC;AAEP;;;GAGG;AACH,MAAM,MAAM,GAAG,GAAG,IAAI,MAAM,EAAE,CAAC;AAE/B;;;;;;;GAOG;AACH,MAAM,MAAM,GAAG,GAAG,OAAO,MAAM,KAAK,MAAM,KAAK,MAAM,GAAG,CAAC;AAEzD;;;;;;;GAOG;AACH,MAAM,MAAM,GAAG,GAAG,OAAO,MAAM,KAAK,MAAM,MAAM,MAAM,IAAI,CAAC;AAE3D,oEAAoE;AACpE,MAAM,MAAM,KAAK,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;AAEpC,mGAAmG;AACnG,MAAM,MAAM,YAAY,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAEpD;;;;;;;;GAQG;AACH,MAAM,WAAW,eAAe,CAAC,CAAC,SAAS,KAAK,CAC/C,SAAQ,MAAM,CAAC,MAAM,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;IACvC,uEAAuE;IACvE,GAAG,EAAE,CAAC,SAAS,GAAG,GAAG,KAAK,GAAG,GAAG,CAAC;IACjC,uEAAuE;IACvE,GAAG,EAAE,CAAC,SAAS,GAAG,GAAG,KAAK,GAAG,GAAG,CAAC;IACjC,uEAAuE;IACvE,GAAG,EAAE,CAAC,SAAS,GAAG,GAAG,KAAK,GAAG,GAAG,CAAC;CACjC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export { numberToWords } from './number/convert';
|
|
|
5
5
|
export { isPrime, findPrimeNumbers } from './number/prime';
|
|
6
6
|
export { getColorForInitial } from './colors/initials';
|
|
7
7
|
export { generateRandomColor } from './colors/random';
|
|
8
|
-
export { convertHexToHsl, convertHexToRgb, convertHslToHex, convertHslToRgb, convertRgbToHex, convertRgbToHsl, } from './colors/convert';
|
|
8
|
+
export { convertHexToHsl, convertHexToRgb, convertHslToHex, convertHslToRgb, convertRgbToHex, convertRgbToHsl, convertColorCode, extractNumbersFromColor, } from './colors/convert';
|
|
9
9
|
export { createOptionsArray, filterArrayOfObjects, flattenArray, sortAnArray, } from './array/basics';
|
|
10
10
|
export { cloneObject, countObjectFields, flattenObject, generateQueryParams, isDeepEqual, isEmptyObject, mergeAndFlattenObjects, mergeObjects, } from './object/basics';
|
|
11
11
|
export { sanitizeData } from './object/sanitize';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,gBAAgB,EAChB,gBAAgB,EAChB,UAAU,EACV,cAAc,GACd,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEpD,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAEpE,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAE3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAEvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEtD,OAAO,EACN,eAAe,EACf,eAAe,EACf,eAAe,EACf,eAAe,EACf,eAAe,EACf,eAAe,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,gBAAgB,EAChB,gBAAgB,EAChB,UAAU,EACV,cAAc,GACd,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEpD,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAEpE,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAE3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAEvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEtD,OAAO,EACN,eAAe,EACf,eAAe,EACf,eAAe,EACf,eAAe,EACf,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,uBAAuB,GACvB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EACN,kBAAkB,EAClB,oBAAoB,EACpB,YAAY,EACZ,WAAW,GACX,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACN,WAAW,EACX,iBAAiB,EACjB,aAAa,EACb,mBAAmB,EACnB,WAAW,EACX,aAAa,EACb,sBAAsB,EACtB,YAAY,GACZ,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.convertObjectValues = exports.sanitizeData = exports.mergeObjects = exports.mergeAndFlattenObjects = exports.isEmptyObject = exports.isDeepEqual = exports.generateQueryParams = exports.flattenObject = exports.countObjectFields = exports.cloneObject = exports.sortAnArray = exports.flattenArray = exports.filterArrayOfObjects = exports.createOptionsArray = exports.convertRgbToHsl = exports.convertRgbToHex = exports.convertHslToRgb = exports.convertHslToHex = exports.convertHexToRgb = exports.convertHexToHsl = exports.generateRandomColor = exports.getColorForInitial = exports.findPrimeNumbers = exports.isPrime = exports.numberToWords = exports.getRandomNumber = exports.convertToDecimal = exports.generateAnagrams = exports.truncateString = exports.trimString = exports.generateRandomID = exports.capitalizeString = void 0;
|
|
3
|
+
exports.convertObjectValues = exports.sanitizeData = exports.mergeObjects = exports.mergeAndFlattenObjects = exports.isEmptyObject = exports.isDeepEqual = exports.generateQueryParams = exports.flattenObject = exports.countObjectFields = exports.cloneObject = exports.sortAnArray = exports.flattenArray = exports.filterArrayOfObjects = exports.createOptionsArray = exports.extractNumbersFromColor = exports.convertColorCode = exports.convertRgbToHsl = exports.convertRgbToHex = exports.convertHslToRgb = exports.convertHslToHex = exports.convertHexToRgb = exports.convertHexToHsl = exports.generateRandomColor = exports.getColorForInitial = exports.findPrimeNumbers = exports.isPrime = exports.numberToWords = exports.getRandomNumber = exports.convertToDecimal = exports.generateAnagrams = exports.truncateString = exports.trimString = exports.generateRandomID = exports.capitalizeString = void 0;
|
|
4
4
|
var basics_1 = require("./string/basics");
|
|
5
5
|
Object.defineProperty(exports, "capitalizeString", { enumerable: true, get: function () { return basics_1.capitalizeString; } });
|
|
6
6
|
Object.defineProperty(exports, "generateRandomID", { enumerable: true, get: function () { return basics_1.generateRandomID; } });
|
|
@@ -27,6 +27,8 @@ Object.defineProperty(exports, "convertHslToHex", { enumerable: true, get: funct
|
|
|
27
27
|
Object.defineProperty(exports, "convertHslToRgb", { enumerable: true, get: function () { return convert_2.convertHslToRgb; } });
|
|
28
28
|
Object.defineProperty(exports, "convertRgbToHex", { enumerable: true, get: function () { return convert_2.convertRgbToHex; } });
|
|
29
29
|
Object.defineProperty(exports, "convertRgbToHsl", { enumerable: true, get: function () { return convert_2.convertRgbToHsl; } });
|
|
30
|
+
Object.defineProperty(exports, "convertColorCode", { enumerable: true, get: function () { return convert_2.convertColorCode; } });
|
|
31
|
+
Object.defineProperty(exports, "extractNumbersFromColor", { enumerable: true, get: function () { return convert_2.extractNumbersFromColor; } });
|
|
30
32
|
var basics_3 = require("./array/basics");
|
|
31
33
|
Object.defineProperty(exports, "createOptionsArray", { enumerable: true, get: function () { return basics_3.createOptionsArray; } });
|
|
32
34
|
Object.defineProperty(exports, "filterArrayOfObjects", { enumerable: true, get: function () { return basics_3.filterArrayOfObjects; } });
|
package/package.json
CHANGED