nhb-toolbox 1.8.4 → 1.9.6
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/array/transform.d.ts +7 -0
- package/dist/array/transform.d.ts.map +1 -1
- package/dist/array/transform.js +11 -0
- package/dist/colors/Color.d.ts +63 -15
- package/dist/colors/Color.d.ts.map +1 -1
- package/dist/colors/Color.js +131 -28
- package/dist/colors/convert.d.ts +85 -9
- package/dist/colors/convert.d.ts.map +1 -1
- package/dist/colors/convert.js +108 -15
- package/dist/colors/helpers.d.ts +37 -5
- package/dist/colors/helpers.d.ts.map +1 -1
- package/dist/colors/helpers.js +49 -5
- package/dist/colors/random.d.ts +2 -2
- package/dist/colors/random.d.ts.map +1 -1
- package/dist/colors/types.d.ts +51 -11
- package/dist/colors/types.d.ts.map +1 -1
- package/dist/index.d.ts +2 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -3
- package/package.json +1 -1
|
@@ -8,4 +8,11 @@ import type { OptionInput, OptionsConfig } from './types';
|
|
|
8
8
|
* @returns An array of options, where each option has `value` and `label` fields as default or as specified by user in the config options.
|
|
9
9
|
*/
|
|
10
10
|
export declare const createOptionsArray: <T extends OptionInput, K1 extends string = "value", K2 extends string = "label">(data: T[], config: OptionsConfig<T, K1, K2>) => { [P in K1 | K2]: string; }[];
|
|
11
|
+
/**
|
|
12
|
+
* * Removes duplicate values from an array, supporting deep comparison for objects and arrays.
|
|
13
|
+
*
|
|
14
|
+
* @param array - The array from which duplicates need to be removed.
|
|
15
|
+
* @returns A new array with duplicates removed.
|
|
16
|
+
*/
|
|
17
|
+
export declare function removeDuplicatesFromArray<T>(array: T[]): T[];
|
|
11
18
|
//# sourceMappingURL=transform.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../src/array/transform.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../src/array/transform.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE1D;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,GAC9B,CAAC,SAAS,WAAW,EACrB,EAAE,SAAS,MAAM,YACjB,EAAE,SAAS,MAAM,kBAEX,CAAC,EAAE,UACD,aAAa,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,KAC9B,GAAG,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,MAAM,GAAE,EAe5B,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,CAK5D"}
|
package/dist/array/transform.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createOptionsArray = void 0;
|
|
4
|
+
exports.removeDuplicatesFromArray = removeDuplicatesFromArray;
|
|
5
|
+
const utils_1 = require("../utils");
|
|
4
6
|
/**
|
|
5
7
|
* * Converts an array of objects into a formatted array of options.
|
|
6
8
|
*
|
|
@@ -22,3 +24,12 @@ const createOptionsArray = (data, config) => {
|
|
|
22
24
|
}
|
|
23
25
|
};
|
|
24
26
|
exports.createOptionsArray = createOptionsArray;
|
|
27
|
+
/**
|
|
28
|
+
* * Removes duplicate values from an array, supporting deep comparison for objects and arrays.
|
|
29
|
+
*
|
|
30
|
+
* @param array - The array from which duplicates need to be removed.
|
|
31
|
+
* @returns A new array with duplicates removed.
|
|
32
|
+
*/
|
|
33
|
+
function removeDuplicatesFromArray(array) {
|
|
34
|
+
return array.filter((item, index, self) => index === self.findIndex((el) => (0, utils_1.isDeepEqual)(el, item)));
|
|
35
|
+
}
|
package/dist/colors/Color.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ColorType,
|
|
1
|
+
import type { AlphaColors, ColorType, Hex6, Hex8, HSL, HSLA, OpacityValue, RGB, RGBA, SolidColors } from './types';
|
|
2
2
|
/**
|
|
3
3
|
* * Class representing a color and its conversions between Hex, RGB, and HSL formats.
|
|
4
4
|
* * It has 3 static methods that can be used to check if a color is in `Hex`, `RGB` or `HSL` format.
|
|
@@ -17,11 +17,11 @@ import type { ColorType, Hex, HSL, RGB } from './types';
|
|
|
17
17
|
* console.log(randomColor.hex, randomColor.rgb, randomColor.hsl);
|
|
18
18
|
*/
|
|
19
19
|
export declare class Color {
|
|
20
|
-
hex:
|
|
21
|
-
rgb: RGB;
|
|
22
|
-
hsl: HSL;
|
|
20
|
+
hex: Hex6 | Hex8;
|
|
21
|
+
rgb: RGB | RGBA;
|
|
22
|
+
hsl: HSL | HSLA;
|
|
23
23
|
/** - Iterates over the color representations (Hex, RGB, HSL). */
|
|
24
|
-
[Symbol.iterator](): Generator
|
|
24
|
+
[Symbol.iterator](): Generator<Hex6 | `rgb(${number}, ${number}, ${number})` | `hsl(${number}, ${number}%, ${number}%)` | Hex8 | `rgba(${number}, ${number}, ${number}, ${number})` | `hsla(${number}, ${number}%, ${number}%, ${number})`, void, unknown>;
|
|
25
25
|
/**
|
|
26
26
|
* * Creates a new Color instance, optionally converting an input color.
|
|
27
27
|
*
|
|
@@ -29,21 +29,45 @@ export declare class Color {
|
|
|
29
29
|
*/
|
|
30
30
|
constructor(toConvert?: ColorType);
|
|
31
31
|
/**
|
|
32
|
-
*
|
|
32
|
+
* * Applies or modifies the opacity of a color.
|
|
33
|
+
* - For solid colors (Hex6/RGB/HSL): Adds an alpha channel with the specified opacity
|
|
34
|
+
* - For alpha colors (Hex8/RGBA/HSLA): Updates the existing alpha channel
|
|
33
35
|
*
|
|
34
|
-
* @
|
|
35
|
-
* @
|
|
36
|
-
*
|
|
36
|
+
* @param opacity - A number between 0-100 representing the opacity percentage
|
|
37
|
+
* @returns An object containing all color formats with the applied opacity
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* const color = new Color("#ff0000");
|
|
41
|
+
* const alpha50 = color.applyOpacity(50); // 50% opacity
|
|
42
|
+
* console.log(alpha50.rgba); // rgba(255, 0, 0, 0.5)
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* const alphaColor = new Color("#ff000080"); // Color with 50% opacity
|
|
46
|
+
* const alpha75 = alphaColor.applyOpacity(75); // Change to 75% opacity
|
|
47
|
+
* console.log(alpha75.hex8); // #ff0000bf
|
|
37
48
|
*/
|
|
38
|
-
|
|
49
|
+
applyOpacity(opacity: OpacityValue): SolidColors & AlphaColors;
|
|
50
|
+
/**
|
|
51
|
+
* Creates a new Color instance from a hex string
|
|
52
|
+
* @param hex The hex color string
|
|
53
|
+
*/
|
|
54
|
+
static fromHex(hex: string): Color;
|
|
55
|
+
/**
|
|
56
|
+
* @static
|
|
57
|
+
* Checks if a color is in `Hex6` format.
|
|
58
|
+
*
|
|
59
|
+
* @param color Color to check.
|
|
60
|
+
* @returns Boolean: `true` if it's a `Hex6` color, `false` if not.
|
|
61
|
+
*/
|
|
62
|
+
static isHex6(color: ColorType): color is Hex6;
|
|
39
63
|
/**
|
|
40
64
|
* @static
|
|
41
|
-
* Checks if a color is in `
|
|
65
|
+
* Checks if a color is in `Hex8` format.
|
|
42
66
|
*
|
|
43
67
|
* @param color Color to check.
|
|
44
|
-
* @returns Boolean: `true` if it's a `
|
|
68
|
+
* @returns Boolean: `true` if it's a `Hex8` color, `false` if not.
|
|
45
69
|
*/
|
|
46
|
-
static
|
|
70
|
+
static isHex8(color: ColorType): color is Hex8;
|
|
47
71
|
/**
|
|
48
72
|
* @static
|
|
49
73
|
* Checks if a color is in `RGB` format.
|
|
@@ -51,7 +75,15 @@ export declare class Color {
|
|
|
51
75
|
* @param color Color to check.
|
|
52
76
|
* @returns Boolean: `true` if it's an `RGB` color, `false` if not.
|
|
53
77
|
*/
|
|
54
|
-
static isRGB(color:
|
|
78
|
+
static isRGB(color: ColorType): color is RGB;
|
|
79
|
+
/**
|
|
80
|
+
* @static
|
|
81
|
+
* Checks if a color is in `RGBA` format.
|
|
82
|
+
*
|
|
83
|
+
* @param color Color to check.
|
|
84
|
+
* @returns Boolean: `true` if it's an `RGBA` color, `false` if not.
|
|
85
|
+
*/
|
|
86
|
+
static isRGBA(color: ColorType): color is RGBA;
|
|
55
87
|
/**
|
|
56
88
|
* @static
|
|
57
89
|
* Checks if a color is in `HSL` format.
|
|
@@ -59,6 +91,22 @@ export declare class Color {
|
|
|
59
91
|
* @param color Color to check.
|
|
60
92
|
* @returns Boolean: `true` if it's an `HSL` color, `false` if not.
|
|
61
93
|
*/
|
|
62
|
-
static isHSL(color:
|
|
94
|
+
static isHSL(color: ColorType): color is HSL;
|
|
95
|
+
/**
|
|
96
|
+
* @static
|
|
97
|
+
* Checks if a color is in `HSLA` format.
|
|
98
|
+
*
|
|
99
|
+
* @param color Color to check.
|
|
100
|
+
* @returns Boolean: `true` if it's an `HSLA` color, `false` if not.
|
|
101
|
+
*/
|
|
102
|
+
static isHSLA(color: ColorType): color is HSLA;
|
|
103
|
+
/**
|
|
104
|
+
* - Converts the given color to all other formats while preserving the original.
|
|
105
|
+
*
|
|
106
|
+
* @private
|
|
107
|
+
* @param color - The color to convert.
|
|
108
|
+
* @returns An object containing Hex, RGB, and HSL representations.
|
|
109
|
+
*/
|
|
110
|
+
private _convertColorToOthers;
|
|
63
111
|
}
|
|
64
112
|
//# sourceMappingURL=Color.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Color.d.ts","sourceRoot":"","sources":["../../src/colors/Color.ts"],"names":[],"mappings":"
|
|
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;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,KAAK;IACV,GAAG,EAAE,IAAI,GAAG,IAAI,CAAC;IACjB,GAAG,EAAE,GAAG,GAAG,IAAI,CAAC;IAChB,GAAG,EAAE,GAAG,GAAG,IAAI,CAAC;IAEvB,iEAAiE;IAChE,CAAC,MAAM,CAAC,QAAQ,CAAC;IAMlB;;;;OAIG;gBACS,SAAS,CAAC,EAAE,SAAS;IAuBjC;;;;;;;;;;;;;;;;;OAiBG;IACH,YAAY,CAAC,OAAO,EAAE,YAAY,GAAG,WAAW,GAAG,WAAW;IAgC9D;;;OAGG;WACW,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK;IAUzC;;;;;;OAMG;WACW,MAAM,CAAC,KAAK,EAAE,SAAS,GAAG,KAAK,IAAI,IAAI;IAIrD;;;;;;OAMG;WACW,MAAM,CAAC,KAAK,EAAE,SAAS,GAAG,KAAK,IAAI,IAAI;IAIrD;;;;;;OAMG;WACW,KAAK,CAAC,KAAK,EAAE,SAAS,GAAG,KAAK,IAAI,GAAG;IAInD;;;;;;OAMG;WACW,MAAM,CAAC,KAAK,EAAE,SAAS,GAAG,KAAK,IAAI,IAAI;IAIrD;;;;;;OAMG;WACW,KAAK,CAAC,KAAK,EAAE,SAAS,GAAG,KAAK,IAAI,GAAG;IAInD;;;;;;OAMG;WACW,MAAM,CAAC,KAAK,EAAE,SAAS,GAAG,KAAK,IAAI,IAAI;IAMrD;;;;;;OAMG;IACH,OAAO,CAAC,qBAAqB;CAuB7B"}
|
package/dist/colors/Color.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Color = void 0;
|
|
4
4
|
const convert_1 = require("./convert");
|
|
5
|
+
const helpers_1 = require("./helpers");
|
|
5
6
|
const random_1 = require("./random");
|
|
6
7
|
const hsl = (0, random_1.generateRandomHSLColor)();
|
|
7
8
|
const hexRGB = (0, convert_1.convertColorCode)(hsl);
|
|
@@ -39,57 +40,105 @@ class Color {
|
|
|
39
40
|
*/
|
|
40
41
|
constructor(toConvert) {
|
|
41
42
|
if (toConvert) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
const converted = this._convertColorToOthers(toConvert);
|
|
44
|
+
if ('hex8' in converted) {
|
|
45
|
+
// Handle alpha colors (Hex8, RGBA, HSLA)
|
|
46
|
+
this.hex = converted.hex8;
|
|
47
|
+
this.rgb = converted.rgba;
|
|
48
|
+
this.hsl = converted.hsla;
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
// Handle solid colors (Hex, RGB, HSL)
|
|
52
|
+
this.hex = converted.hex;
|
|
53
|
+
this.rgb = converted.rgb;
|
|
54
|
+
this.hsl = converted.hsl;
|
|
55
|
+
}
|
|
45
56
|
}
|
|
46
57
|
else {
|
|
58
|
+
// Generate random color
|
|
47
59
|
this.hex = hexRGB.hex;
|
|
48
60
|
this.rgb = hexRGB.rgb;
|
|
49
61
|
this.hsl = hsl;
|
|
50
62
|
}
|
|
51
63
|
}
|
|
52
64
|
/**
|
|
53
|
-
*
|
|
65
|
+
* * Applies or modifies the opacity of a color.
|
|
66
|
+
* - For solid colors (Hex6/RGB/HSL): Adds an alpha channel with the specified opacity
|
|
67
|
+
* - For alpha colors (Hex8/RGBA/HSLA): Updates the existing alpha channel
|
|
54
68
|
*
|
|
55
|
-
* @
|
|
56
|
-
* @
|
|
57
|
-
*
|
|
69
|
+
* @param opacity - A number between 0-100 representing the opacity percentage
|
|
70
|
+
* @returns An object containing all color formats with the applied opacity
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* const color = new Color("#ff0000");
|
|
74
|
+
* const alpha50 = color.applyOpacity(50); // 50% opacity
|
|
75
|
+
* console.log(alpha50.rgba); // rgba(255, 0, 0, 0.5)
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* const alphaColor = new Color("#ff000080"); // Color with 50% opacity
|
|
79
|
+
* const alpha75 = alphaColor.applyOpacity(75); // Change to 75% opacity
|
|
80
|
+
* console.log(alpha75.hex8); // #ff0000bf
|
|
58
81
|
*/
|
|
59
|
-
|
|
60
|
-
|
|
82
|
+
applyOpacity(opacity) {
|
|
83
|
+
const validOpacity = Math.min(100, Math.max(0, opacity));
|
|
84
|
+
const alphaHex = (0, helpers_1._convertOpacityToHex)(opacity);
|
|
85
|
+
const alphaDecimal = validOpacity / 100;
|
|
86
|
+
if (Color.isHex8(this.hex)) {
|
|
87
|
+
const rgbaValues = (0, helpers_1._extractAlphaColorValues)(this.rgb);
|
|
88
|
+
const hslaValues = (0, helpers_1._extractAlphaColorValues)(this.hsl);
|
|
61
89
|
return {
|
|
62
|
-
hex:
|
|
63
|
-
|
|
64
|
-
|
|
90
|
+
hex: this.hex.slice(0, 7),
|
|
91
|
+
hex8: `${this.hex.slice(0, 7)}${alphaHex}`,
|
|
92
|
+
rgb: `rgba(${rgbaValues[0]}, ${rgbaValues[1]}, ${rgbaValues[2]})`,
|
|
93
|
+
rgba: `rgba(${rgbaValues[0]}, ${rgbaValues[1]}, ${rgbaValues[2]}, ${alphaDecimal})`,
|
|
94
|
+
hsl: `hsla(${hslaValues[0]}, ${hslaValues[1]}%, ${hslaValues[2]}%)`,
|
|
95
|
+
hsla: `hsla(${hslaValues[0]}, ${hslaValues[1]}%, ${hslaValues[2]}%, ${alphaDecimal})`,
|
|
65
96
|
};
|
|
66
97
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
98
|
+
const rgbValues = (0, helpers_1._extractSolidColorValues)(this.rgb);
|
|
99
|
+
const hslValues = (0, helpers_1._extractSolidColorValues)(this.hsl);
|
|
100
|
+
return {
|
|
101
|
+
hex: this.hex,
|
|
102
|
+
hex8: `${this.hex}${alphaHex}`,
|
|
103
|
+
rgb: this.rgb,
|
|
104
|
+
rgba: `rgba(${rgbValues[0]}, ${rgbValues[1]}, ${rgbValues[2]}, ${alphaDecimal})`,
|
|
105
|
+
hsl: this.hsl,
|
|
106
|
+
hsla: `hsla(${hslValues[0]}, ${hslValues[1]}%, ${hslValues[2]}%, ${alphaDecimal})`,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Creates a new Color instance from a hex string
|
|
111
|
+
* @param hex The hex color string
|
|
112
|
+
*/
|
|
113
|
+
static fromHex(hex) {
|
|
114
|
+
if (this.isHex6(hex)) {
|
|
115
|
+
return new Color(hex);
|
|
73
116
|
}
|
|
74
|
-
|
|
75
|
-
return
|
|
76
|
-
hex: (0, convert_1.convertColorCode)(color).hex,
|
|
77
|
-
rgb: (0, convert_1.convertColorCode)(color).rgb,
|
|
78
|
-
hsl: color,
|
|
79
|
-
};
|
|
117
|
+
if (this.isHex8(hex)) {
|
|
118
|
+
return new Color(hex);
|
|
80
119
|
}
|
|
81
|
-
throw new Error(`Unrecognized
|
|
120
|
+
throw new Error(`Unrecognized Hex Format: ${hex}`);
|
|
82
121
|
}
|
|
83
122
|
/**
|
|
84
123
|
* @static
|
|
85
|
-
* Checks if a color is in `
|
|
124
|
+
* Checks if a color is in `Hex6` format.
|
|
86
125
|
*
|
|
87
126
|
* @param color Color to check.
|
|
88
|
-
* @returns Boolean: `true` if it's a `
|
|
127
|
+
* @returns Boolean: `true` if it's a `Hex6` color, `false` if not.
|
|
89
128
|
*/
|
|
90
|
-
static
|
|
129
|
+
static isHex6(color) {
|
|
91
130
|
return /^#[0-9A-Fa-f]{6}$/.test(color);
|
|
92
131
|
}
|
|
132
|
+
/**
|
|
133
|
+
* @static
|
|
134
|
+
* Checks if a color is in `Hex8` format.
|
|
135
|
+
*
|
|
136
|
+
* @param color Color to check.
|
|
137
|
+
* @returns Boolean: `true` if it's a `Hex8` color, `false` if not.
|
|
138
|
+
*/
|
|
139
|
+
static isHex8(color) {
|
|
140
|
+
return /^#[0-9A-Fa-f]{8}$/.test(color);
|
|
141
|
+
}
|
|
93
142
|
/**
|
|
94
143
|
* @static
|
|
95
144
|
* Checks if a color is in `RGB` format.
|
|
@@ -100,6 +149,16 @@ class Color {
|
|
|
100
149
|
static isRGB(color) {
|
|
101
150
|
return /^rgb\(\d{1,3}, \d{1,3}, \d{1,3}\)$/.test(color);
|
|
102
151
|
}
|
|
152
|
+
/**
|
|
153
|
+
* @static
|
|
154
|
+
* Checks if a color is in `RGBA` format.
|
|
155
|
+
*
|
|
156
|
+
* @param color Color to check.
|
|
157
|
+
* @returns Boolean: `true` if it's an `RGBA` color, `false` if not.
|
|
158
|
+
*/
|
|
159
|
+
static isRGBA(color) {
|
|
160
|
+
return /^rgba\(\d{1,3}, \d{1,3}, \d{1,3}, (0|1|0?\.\d+)\)$/.test(color);
|
|
161
|
+
}
|
|
103
162
|
/**
|
|
104
163
|
* @static
|
|
105
164
|
* Checks if a color is in `HSL` format.
|
|
@@ -110,5 +169,49 @@ class Color {
|
|
|
110
169
|
static isHSL(color) {
|
|
111
170
|
return /^hsl\(\d{1,3}, \d{1,3}%, \d{1,3}%\)$/.test(color);
|
|
112
171
|
}
|
|
172
|
+
/**
|
|
173
|
+
* @static
|
|
174
|
+
* Checks if a color is in `HSLA` format.
|
|
175
|
+
*
|
|
176
|
+
* @param color Color to check.
|
|
177
|
+
* @returns Boolean: `true` if it's an `HSLA` color, `false` if not.
|
|
178
|
+
*/
|
|
179
|
+
static isHSLA(color) {
|
|
180
|
+
return /^hsla\(\d{1,3}, \d{1,3}%, \d{1,3}%, (0|1|0?\.\d+)\)$/.test(color);
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* - Converts the given color to all other formats while preserving the original.
|
|
184
|
+
*
|
|
185
|
+
* @private
|
|
186
|
+
* @param color - The color to convert.
|
|
187
|
+
* @returns An object containing Hex, RGB, and HSL representations.
|
|
188
|
+
*/
|
|
189
|
+
_convertColorToOthers(color) {
|
|
190
|
+
if (Color.isHex6(color)) {
|
|
191
|
+
const { rgb, hsl } = (0, convert_1.convertColorCode)(color);
|
|
192
|
+
return { hex: color, rgb: rgb, hsl: hsl };
|
|
193
|
+
}
|
|
194
|
+
else if (Color.isRGB(color)) {
|
|
195
|
+
const { hex, hsl } = (0, convert_1.convertColorCode)(color);
|
|
196
|
+
return { hex: hex, rgb: color, hsl: hsl };
|
|
197
|
+
}
|
|
198
|
+
else if (Color.isHSL(color)) {
|
|
199
|
+
const { hex, rgb } = (0, convert_1.convertColorCode)(color);
|
|
200
|
+
return { hex: hex, rgb: rgb, hsl: color };
|
|
201
|
+
}
|
|
202
|
+
else if (Color.isHex8(color)) {
|
|
203
|
+
const { rgba, hsla } = (0, convert_1.convertColorCode)(color);
|
|
204
|
+
return { hex8: color, rgba: rgba, hsla: hsla };
|
|
205
|
+
}
|
|
206
|
+
else if (Color.isHSLA(color)) {
|
|
207
|
+
const { hex8, rgba } = (0, convert_1.convertColorCode)(color);
|
|
208
|
+
return { hex8: hex8, rgba: rgba, hsla: color };
|
|
209
|
+
}
|
|
210
|
+
else if (Color.isRGBA(color)) {
|
|
211
|
+
const { hex8, hsla } = (0, convert_1.convertColorCode)(color);
|
|
212
|
+
return { hex8: hex8, rgba: color, hsla: hsla };
|
|
213
|
+
}
|
|
214
|
+
throw new Error(`Unrecognized Color Format: ${color}`);
|
|
215
|
+
}
|
|
113
216
|
}
|
|
114
217
|
exports.Color = Color;
|
package/dist/colors/convert.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Hex6, Hex8, HSL, HSLA, RGB, RGBA } from './types';
|
|
2
2
|
/**
|
|
3
3
|
* * Converts HSL to RGB color format.
|
|
4
4
|
*
|
|
@@ -25,38 +25,84 @@ export declare const convertRgbToHsl: (r: number, g: number, b: number) => HSL;
|
|
|
25
25
|
* @param l - The lightness component of the HSL color, as a percentage (0 to 100).
|
|
26
26
|
* @returns A string representing the color in Hex format (e.g., `#FF0000`).
|
|
27
27
|
*/
|
|
28
|
-
export declare const convertHslToHex: (h: number, s: number, l: number) =>
|
|
28
|
+
export declare const convertHslToHex: (h: number, s: number, l: number) => Hex6;
|
|
29
29
|
/**
|
|
30
30
|
* * Converts Hex to HSL color format.
|
|
31
31
|
*
|
|
32
32
|
* @param hex - A string representing the color in Hex format (e.g., `#FF0000`).
|
|
33
33
|
* @returns A string representing the color in HSL format (e.g., `hsl(0, 100%, 50%)`).
|
|
34
34
|
*/
|
|
35
|
-
export declare const convertHexToHsl: (hex:
|
|
35
|
+
export declare const convertHexToHsl: (hex: Hex6 | string) => HSL;
|
|
36
36
|
/**
|
|
37
37
|
* * Converts RGB to Hex color format.
|
|
38
38
|
*
|
|
39
39
|
* @param r - The red component of the RGB color, in the range 0 to 255.
|
|
40
40
|
* @param g - The green component of the RGB color, in the range 0 to 255.
|
|
41
41
|
* @param b - The blue component of the RGB color, in the range 0 to 255.
|
|
42
|
-
* @param a - The alpha opacity of the RGB color, in the range 0 to 255.
|
|
43
42
|
* @returns A string representing the color in Hex format (e.g., `#FF0000`).
|
|
44
43
|
*/
|
|
45
|
-
export declare const convertRgbToHex: (r: number, g: number, b: number
|
|
44
|
+
export declare const convertRgbToHex: (r: number, g: number, b: number) => Hex6;
|
|
46
45
|
/**
|
|
47
46
|
* * Converts Hex to RGB color format.
|
|
48
47
|
*
|
|
49
48
|
* @param hex - A string representing the color in Hex format (e.g., `#FF0000`).
|
|
50
49
|
* @returns A string representing the color in RGB format (e.g., `rgb(255, 0, 0)`).
|
|
51
50
|
*/
|
|
52
|
-
export declare const convertHexToRgb: (hex:
|
|
51
|
+
export declare const convertHexToRgb: (hex: Hex6 | string) => RGB;
|
|
52
|
+
/**
|
|
53
|
+
* * Converts RGB to RGBA format, adding alpha (opacity).
|
|
54
|
+
*
|
|
55
|
+
* @param r - The red component of the RGB color, in the range 0 to 255.
|
|
56
|
+
* @param g - The green component of the RGB color, in the range 0 to 255.
|
|
57
|
+
* @param b - The blue component of the RGB color, in the range 0 to 255.
|
|
58
|
+
* @param a - The alpha (opacity) value, in the range 0 to 1.
|
|
59
|
+
* @returns A string representing the color in RGBA format (e.g., `rgba(255, 0, 0, 0.5)`).
|
|
60
|
+
*/
|
|
61
|
+
export declare const convertRgbToRgba: (r: number, g: number, b: number, a?: number) => RGBA;
|
|
62
|
+
/**
|
|
63
|
+
* * Converts RGBA to Hex format, including alpha channel as part of Hex8.
|
|
64
|
+
*
|
|
65
|
+
* @param r - The red component of the RGB color, in the range 0 to 255.
|
|
66
|
+
* @param g - The green component of the RGB color, in the range 0 to 255.
|
|
67
|
+
* @param b - The blue component of the RGB color, in the range 0 to 255.
|
|
68
|
+
* @param a - The alpha (opacity) value, in the range 0 to 1.
|
|
69
|
+
* @returns A string representing the color in Hex8 format (e.g., `#FF000080`).
|
|
70
|
+
*/
|
|
71
|
+
export declare const convertRgbaToHex8: (r: number, g: number, b: number, a?: number) => Hex8;
|
|
72
|
+
/**
|
|
73
|
+
* * Converts HSLA to RGBA color format, including alpha channel.
|
|
74
|
+
*
|
|
75
|
+
* @param h - The hue component of the HSL color, in degrees (0 to 360).
|
|
76
|
+
* @param s - The saturation component of the HSL color, as a percentage (0 to 100).
|
|
77
|
+
* @param l - The lightness component of the HSL color, as a percentage (0 to 100).
|
|
78
|
+
* @param a - The alpha (opacity) value, in the range 0 to 1.
|
|
79
|
+
* @returns A string representing the color in RGBA format (e.g., `rgba(255, 0, 0, 0.5)`).
|
|
80
|
+
*/
|
|
81
|
+
export declare const convertHslaToRgba: (h: number, s: number, l: number, a?: number) => RGBA;
|
|
82
|
+
/**
|
|
83
|
+
* * Converts RGBA to HSLA color format, including alpha channel.
|
|
84
|
+
*
|
|
85
|
+
* @param r - The red component of the RGB color, in the range 0 to 255.
|
|
86
|
+
* @param g - The green component of the RGB color, in the range 0 to 255.
|
|
87
|
+
* @param b - The blue component of the RGB color, in the range 0 to 255.
|
|
88
|
+
* @param a - The alpha (opacity) value, in the range 0 to 1.
|
|
89
|
+
* @returns A string representing the color in HSLA format (e.g., `hsla(0, 100%, 50%, 0.5)`).
|
|
90
|
+
*/
|
|
91
|
+
export declare const convertRgbaToHsla: (r: number, g: number, b: number, a?: number) => HSLA;
|
|
92
|
+
/**
|
|
93
|
+
* * Converts Hex8 to RGBA color format, including alpha channel.
|
|
94
|
+
*
|
|
95
|
+
* @param hex8 - A string representing the color in Hex8 format (e.g., `#FF000080`).
|
|
96
|
+
* @returns A string representing the color in RGBA format (e.g., `rgba(255, 0, 0, 0.5)`).
|
|
97
|
+
*/
|
|
98
|
+
export declare const convertHex8ToRgba: (hex8: Hex8) => RGBA;
|
|
53
99
|
/**
|
|
54
100
|
* * Converts a `Hex` color code to `RGB` and `HSL` formats.
|
|
55
101
|
*
|
|
56
102
|
* @param color The `Hex` color code (e.g., `#3c6945`).
|
|
57
103
|
* @returns An object containing the `RGB` and `HSL` formats of the given `Hex` color.
|
|
58
104
|
*/
|
|
59
|
-
export declare function convertColorCode(color:
|
|
105
|
+
export declare function convertColorCode(color: Hex6): {
|
|
60
106
|
rgb: RGB;
|
|
61
107
|
hsl: HSL;
|
|
62
108
|
};
|
|
@@ -67,7 +113,7 @@ export declare function convertColorCode(color: Hex): {
|
|
|
67
113
|
* @returns An object containing the `Hex` and `HSL` formats of the given `RGB` color.
|
|
68
114
|
*/
|
|
69
115
|
export declare function convertColorCode(color: RGB): {
|
|
70
|
-
hex:
|
|
116
|
+
hex: Hex6;
|
|
71
117
|
hsl: HSL;
|
|
72
118
|
};
|
|
73
119
|
/**
|
|
@@ -77,7 +123,37 @@ export declare function convertColorCode(color: RGB): {
|
|
|
77
123
|
* @returns An object containing the `Hex` and `RGB` formats of the given `HSL` color.
|
|
78
124
|
*/
|
|
79
125
|
export declare function convertColorCode(color: HSL): {
|
|
80
|
-
hex:
|
|
126
|
+
hex: Hex6;
|
|
81
127
|
rgb: RGB;
|
|
82
128
|
};
|
|
129
|
+
/**
|
|
130
|
+
* * Converts a `Hex8` color code to `RGB` and `HSL` formats.
|
|
131
|
+
*
|
|
132
|
+
* @param color The `Hex8` color code (e.g., `#3c6945`).
|
|
133
|
+
* @returns An object containing the `RGB` and `HSL` formats of the given `Hex8` color.
|
|
134
|
+
*/
|
|
135
|
+
export declare function convertColorCode(color: Hex8): {
|
|
136
|
+
rgba: RGBA;
|
|
137
|
+
hsla: HSLA;
|
|
138
|
+
};
|
|
139
|
+
/**
|
|
140
|
+
* * Converts an `RGBA` color to `Hex8` and `HSLA` formats.
|
|
141
|
+
*
|
|
142
|
+
* @param color The `RGBA` color string (e.g., `rgb(60, 105, 69)`).
|
|
143
|
+
* @returns An object containing the `Hex8` and `HSLA` formats of the given `RGBA` color.
|
|
144
|
+
*/
|
|
145
|
+
export declare function convertColorCode(color: RGBA): {
|
|
146
|
+
hex8: Hex8;
|
|
147
|
+
hsla: HSLA;
|
|
148
|
+
};
|
|
149
|
+
/**
|
|
150
|
+
* * Converts an `HSLA` color to `Hex8` and `RGBA` formats.
|
|
151
|
+
*
|
|
152
|
+
* @param color The `HSLA` color string (e.g., `hsl(132, 27.27%, 32.35%)`).
|
|
153
|
+
* @returns An object containing the `Hex8` and `RGBA` formats of the given `HSLA` color.
|
|
154
|
+
*/
|
|
155
|
+
export declare function convertColorCode(color: HSLA): {
|
|
156
|
+
hex8: Hex8;
|
|
157
|
+
rgba: RGBA;
|
|
158
|
+
};
|
|
83
159
|
//# sourceMappingURL=convert.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convert.d.ts","sourceRoot":"","sources":["../../src/colors/convert.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"convert.d.ts","sourceRoot":"","sources":["../../src/colors/convert.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAGX,IAAI,EACJ,IAAI,EACJ,GAAG,EACH,IAAI,EAEJ,GAAG,EACH,IAAI,EACJ,MAAM,SAAS,CAAC;AAEjB;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,MAAO,MAAM,KAAK,MAAM,KAAK,MAAM,KAAG,GA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E,GAAG,CAAC;CACT,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,GAAG,GAAG;IAC7C,GAAG,EAAE,IAAI,CAAC;IACV,GAAG,EAAE,GAAG,CAAC;CACT,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,IAAI,GAAG;IAC9C,IAAI,EAAE,IAAI,CAAC;IACX,IAAI,EAAE,IAAI,CAAC;CACX,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,IAAI,GAAG;IAC9C,IAAI,EAAE,IAAI,CAAC;IACX,IAAI,EAAE,IAAI,CAAC;CACX,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,IAAI,GAAG;IAC9C,IAAI,EAAE,IAAI,CAAC;IACX,IAAI,EAAE,IAAI,CAAC;CACX,CAAC"}
|
package/dist/colors/convert.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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.convertHex8ToRgba = exports.convertRgbaToHsla = exports.convertHslaToRgba = exports.convertRgbaToHex8 = exports.convertRgbToRgba = exports.convertHexToRgb = exports.convertRgbToHex = exports.convertHexToHsl = exports.convertHslToHex = exports.convertRgbToHsl = exports.convertHslToRgb = void 0;
|
|
4
4
|
exports.convertColorCode = convertColorCode;
|
|
5
5
|
const helpers_1 = require("./helpers");
|
|
6
6
|
/**
|
|
@@ -111,20 +111,13 @@ exports.convertHexToHsl = convertHexToHsl;
|
|
|
111
111
|
* @param r - The red component of the RGB color, in the range 0 to 255.
|
|
112
112
|
* @param g - The green component of the RGB color, in the range 0 to 255.
|
|
113
113
|
* @param b - The blue component of the RGB color, in the range 0 to 255.
|
|
114
|
-
* @param a - The alpha opacity of the RGB color, in the range 0 to 255.
|
|
115
114
|
* @returns A string representing the color in Hex format (e.g., `#FF0000`).
|
|
116
115
|
*/
|
|
117
|
-
const convertRgbToHex = (r, g, b
|
|
118
|
-
|
|
116
|
+
const convertRgbToHex = (r, g, b) => {
|
|
117
|
+
const hex = [r, g, b]
|
|
119
118
|
.map((v) => v.toString(16).padStart(2, '0'))
|
|
120
119
|
.join('')
|
|
121
120
|
.toUpperCase();
|
|
122
|
-
if (a !== undefined) {
|
|
123
|
-
const alphaHex = Math.round(a * 255)
|
|
124
|
-
.toString(16)
|
|
125
|
-
.padStart(2, '0');
|
|
126
|
-
hex += alphaHex;
|
|
127
|
-
}
|
|
128
121
|
return `#${hex}`;
|
|
129
122
|
};
|
|
130
123
|
exports.convertRgbToHex = convertRgbToHex;
|
|
@@ -149,6 +142,84 @@ const convertHexToRgb = (hex) => {
|
|
|
149
142
|
return `rgb(${r}, ${g}, ${b})`;
|
|
150
143
|
};
|
|
151
144
|
exports.convertHexToRgb = convertHexToRgb;
|
|
145
|
+
/**
|
|
146
|
+
* * Converts RGB to RGBA format, adding alpha (opacity).
|
|
147
|
+
*
|
|
148
|
+
* @param r - The red component of the RGB color, in the range 0 to 255.
|
|
149
|
+
* @param g - The green component of the RGB color, in the range 0 to 255.
|
|
150
|
+
* @param b - The blue component of the RGB color, in the range 0 to 255.
|
|
151
|
+
* @param a - The alpha (opacity) value, in the range 0 to 1.
|
|
152
|
+
* @returns A string representing the color in RGBA format (e.g., `rgba(255, 0, 0, 0.5)`).
|
|
153
|
+
*/
|
|
154
|
+
const convertRgbToRgba = (r, g, b, a = 1) => {
|
|
155
|
+
return `rgba(${r}, ${g}, ${b}, ${a})`;
|
|
156
|
+
};
|
|
157
|
+
exports.convertRgbToRgba = convertRgbToRgba;
|
|
158
|
+
/**
|
|
159
|
+
* * Converts RGBA to Hex format, including alpha channel as part of Hex8.
|
|
160
|
+
*
|
|
161
|
+
* @param r - The red component of the RGB color, in the range 0 to 255.
|
|
162
|
+
* @param g - The green component of the RGB color, in the range 0 to 255.
|
|
163
|
+
* @param b - The blue component of the RGB color, in the range 0 to 255.
|
|
164
|
+
* @param a - The alpha (opacity) value, in the range 0 to 1.
|
|
165
|
+
* @returns A string representing the color in Hex8 format (e.g., `#FF000080`).
|
|
166
|
+
*/
|
|
167
|
+
const convertRgbaToHex8 = (r, g, b, a = 1) => {
|
|
168
|
+
const alphaHex = Math.round(a * 255)
|
|
169
|
+
.toString(16)
|
|
170
|
+
.padStart(2, '0');
|
|
171
|
+
const hex = [r, g, b]
|
|
172
|
+
.map((v) => v.toString(16).padStart(2, '0'))
|
|
173
|
+
.join('')
|
|
174
|
+
.toUpperCase();
|
|
175
|
+
return `#${hex}${alphaHex}`;
|
|
176
|
+
};
|
|
177
|
+
exports.convertRgbaToHex8 = convertRgbaToHex8;
|
|
178
|
+
/**
|
|
179
|
+
* * Converts HSLA to RGBA color format, including alpha channel.
|
|
180
|
+
*
|
|
181
|
+
* @param h - The hue component of the HSL color, in degrees (0 to 360).
|
|
182
|
+
* @param s - The saturation component of the HSL color, as a percentage (0 to 100).
|
|
183
|
+
* @param l - The lightness component of the HSL color, as a percentage (0 to 100).
|
|
184
|
+
* @param a - The alpha (opacity) value, in the range 0 to 1.
|
|
185
|
+
* @returns A string representing the color in RGBA format (e.g., `rgba(255, 0, 0, 0.5)`).
|
|
186
|
+
*/
|
|
187
|
+
const convertHslaToRgba = (h, s, l, a = 1) => {
|
|
188
|
+
const rgb = (0, exports.convertHslToRgb)(h, s, l);
|
|
189
|
+
const rgbNumbers = (0, helpers_1._extractSolidColorValues)(rgb);
|
|
190
|
+
return (0, exports.convertRgbToRgba)(rgbNumbers[0], rgbNumbers[1], rgbNumbers[2], a);
|
|
191
|
+
};
|
|
192
|
+
exports.convertHslaToRgba = convertHslaToRgba;
|
|
193
|
+
/**
|
|
194
|
+
* * Converts RGBA to HSLA color format, including alpha channel.
|
|
195
|
+
*
|
|
196
|
+
* @param r - The red component of the RGB color, in the range 0 to 255.
|
|
197
|
+
* @param g - The green component of the RGB color, in the range 0 to 255.
|
|
198
|
+
* @param b - The blue component of the RGB color, in the range 0 to 255.
|
|
199
|
+
* @param a - The alpha (opacity) value, in the range 0 to 1.
|
|
200
|
+
* @returns A string representing the color in HSLA format (e.g., `hsla(0, 100%, 50%, 0.5)`).
|
|
201
|
+
*/
|
|
202
|
+
const convertRgbaToHsla = (r, g, b, a = 1) => {
|
|
203
|
+
const hsl = (0, exports.convertRgbToHsl)(r, g, b);
|
|
204
|
+
const hslNumbers = (0, helpers_1._extractSolidColorValues)(hsl);
|
|
205
|
+
return `hsla(${hslNumbers[0]}, ${hslNumbers[1]}%, ${hslNumbers[2]}%, ${a})`;
|
|
206
|
+
};
|
|
207
|
+
exports.convertRgbaToHsla = convertRgbaToHsla;
|
|
208
|
+
/**
|
|
209
|
+
* * Converts Hex8 to RGBA color format, including alpha channel.
|
|
210
|
+
*
|
|
211
|
+
* @param hex8 - A string representing the color in Hex8 format (e.g., `#FF000080`).
|
|
212
|
+
* @returns A string representing the color in RGBA format (e.g., `rgba(255, 0, 0, 0.5)`).
|
|
213
|
+
*/
|
|
214
|
+
const convertHex8ToRgba = (hex8) => {
|
|
215
|
+
const hex = hex8.replace('#', '');
|
|
216
|
+
const r = parseInt(hex.slice(0, 2), 16);
|
|
217
|
+
const g = parseInt(hex.slice(2, 4), 16);
|
|
218
|
+
const b = parseInt(hex.slice(4, 6), 16);
|
|
219
|
+
const a = parseInt(hex.slice(6, 8), 16) / 255;
|
|
220
|
+
return `rgba(${r}, ${g}, ${b}, ${a})`;
|
|
221
|
+
};
|
|
222
|
+
exports.convertHex8ToRgba = convertHex8ToRgba;
|
|
152
223
|
/**
|
|
153
224
|
* * Converts a color from `Hex`, `RGB`, or `HSL` format to its equivalent representations.
|
|
154
225
|
*
|
|
@@ -157,7 +228,7 @@ exports.convertHexToRgb = convertHexToRgb;
|
|
|
157
228
|
* @throws If the color format is unrecognized throws `Error`.
|
|
158
229
|
*/
|
|
159
230
|
function convertColorCode(color) {
|
|
160
|
-
if ((0, helpers_1.
|
|
231
|
+
if ((0, helpers_1._isHex6)(color)) {
|
|
161
232
|
return {
|
|
162
233
|
rgb: (0, exports.convertHexToRgb)(color),
|
|
163
234
|
hsl: (0, exports.convertHexToHsl)(color),
|
|
@@ -165,14 +236,36 @@ function convertColorCode(color) {
|
|
|
165
236
|
}
|
|
166
237
|
if ((0, helpers_1._isRGB)(color)) {
|
|
167
238
|
return {
|
|
168
|
-
hex: (0, exports.convertRgbToHex)(...(0, helpers_1.
|
|
169
|
-
hsl: (0, exports.convertRgbToHsl)(...(0, helpers_1.
|
|
239
|
+
hex: (0, exports.convertRgbToHex)(...(0, helpers_1._extractSolidColorValues)(color)),
|
|
240
|
+
hsl: (0, exports.convertRgbToHsl)(...(0, helpers_1._extractSolidColorValues)(color)),
|
|
170
241
|
};
|
|
171
242
|
}
|
|
172
243
|
if ((0, helpers_1._isHSL)(color)) {
|
|
173
244
|
return {
|
|
174
|
-
hex: (0, exports.convertHslToHex)(...(0, helpers_1.
|
|
175
|
-
rgb: (0, exports.convertHslToRgb)(...(0, helpers_1.
|
|
245
|
+
hex: (0, exports.convertHslToHex)(...(0, helpers_1._extractSolidColorValues)(color)),
|
|
246
|
+
rgb: (0, exports.convertHslToRgb)(...(0, helpers_1._extractSolidColorValues)(color)),
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
if ((0, helpers_1._isHex8)(color)) {
|
|
250
|
+
const rgba = (0, exports.convertHex8ToRgba)(color);
|
|
251
|
+
return {
|
|
252
|
+
rgba: rgba,
|
|
253
|
+
hsla: (0, exports.convertRgbaToHsla)(...(0, helpers_1._extractAlphaColorValues)(rgba)),
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
if ((0, helpers_1._isRGBA)(color)) {
|
|
257
|
+
return {
|
|
258
|
+
hex8: (0, exports.convertRgbaToHex8)(...(0, helpers_1._extractAlphaColorValues)(color)),
|
|
259
|
+
hsla: (0, exports.convertRgbaToHsla)(...(0, helpers_1._extractAlphaColorValues)(color)),
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
if ((0, helpers_1._isHSLA)(color)) {
|
|
263
|
+
const hslaValues = (0, helpers_1._extractAlphaColorValues)(color);
|
|
264
|
+
const hex = (0, exports.convertHslToHex)(hslaValues[0], hslaValues[1], hslaValues[2]);
|
|
265
|
+
const alphaHex = (0, helpers_1._convertOpacityToHex)(Math.round(hslaValues[3] * 100));
|
|
266
|
+
return {
|
|
267
|
+
hex8: `#${hex}${alphaHex}`,
|
|
268
|
+
rgba: (0, exports.convertHslaToRgba)(...(0, helpers_1._extractAlphaColorValues)(color)),
|
|
176
269
|
};
|
|
177
270
|
}
|
|
178
271
|
throw new Error(`Unrecognized Color Format: ${color}`);
|
package/dist/colors/helpers.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ColorNumbers,
|
|
1
|
+
import type { ColorNumbers, ColorNumbersAlpha, Hex6, Hex8, HSL, HSLA, OpacityValue, RGB, RGBA } from './types';
|
|
2
2
|
/**
|
|
3
3
|
* * Converts opacity percentage (0-100) to a 2-digit hex string.
|
|
4
4
|
*
|
|
@@ -35,26 +35,58 @@ export declare const _isSimilarToLast: (recentColors: string[], newColor: string
|
|
|
35
35
|
* @param colorString The color string in RGB or HSL format.
|
|
36
36
|
* @returns An array of extracted numbers.
|
|
37
37
|
*/
|
|
38
|
-
export declare const
|
|
38
|
+
export declare const _extractSolidColorValues: (colorString: HSL | RGB) => ColorNumbers;
|
|
39
|
+
/**
|
|
40
|
+
* * Extracts numbers from a color string like `rgba(66, 103, 69, 0.6)` or `hsla(120, 42.86%, 41.18%, 0.9)`.
|
|
41
|
+
* * Converts percentage values to decimal (e.g., `42.86%` → `42.86`).
|
|
42
|
+
*
|
|
43
|
+
* @param colorString The color string in RGB or HSL format.
|
|
44
|
+
* @returns An array of extracted numbers.
|
|
45
|
+
*/
|
|
46
|
+
export declare const _extractAlphaColorValues: (colorString: HSLA | RGBA) => ColorNumbersAlpha;
|
|
39
47
|
/**
|
|
40
48
|
* * Checks if a color is in `Hex` format.
|
|
41
49
|
*
|
|
42
50
|
* @param color Color to check.
|
|
43
51
|
* @returns Boolean: `true` if it's a `Hex` color, `false` if not.
|
|
44
52
|
*/
|
|
45
|
-
export declare function
|
|
53
|
+
export declare function _isHex6(color: string): color is Hex6;
|
|
46
54
|
/**
|
|
47
55
|
* * Checks if a color is in `RGB` format.
|
|
48
56
|
*
|
|
49
57
|
* @param color Color to check.
|
|
50
58
|
* @returns Boolean: `true` if it's an `RGB` color, `false` if not.
|
|
51
59
|
*/
|
|
52
|
-
export declare function _isRGB(color:
|
|
60
|
+
export declare function _isRGB(color: string): color is RGB;
|
|
53
61
|
/**
|
|
54
62
|
* * Checks if a color is in `HSL` format.
|
|
55
63
|
*
|
|
56
64
|
* @param color Color to check.
|
|
57
65
|
* @returns Boolean: `true` if it's an `HSL` color, `false` if not.
|
|
58
66
|
*/
|
|
59
|
-
export declare function _isHSL(color:
|
|
67
|
+
export declare function _isHSL(color: string): color is HSL;
|
|
68
|
+
/**
|
|
69
|
+
* @static
|
|
70
|
+
* Checks if a color is in `Hex8` format.
|
|
71
|
+
*
|
|
72
|
+
* @param color Color to check.
|
|
73
|
+
* @returns Boolean: `true` if it's a `Hex8` color, `false` if not.
|
|
74
|
+
*/
|
|
75
|
+
export declare function _isHex8(color: string): color is Hex8;
|
|
76
|
+
/**
|
|
77
|
+
* @static
|
|
78
|
+
* Checks if a color is in `RGBA` format.
|
|
79
|
+
*
|
|
80
|
+
* @param color Color to check.
|
|
81
|
+
* @returns Boolean: `true` if it's an `RGBA` color, `false` if not.
|
|
82
|
+
*/
|
|
83
|
+
export declare function _isRGBA(color: string): color is RGBA;
|
|
84
|
+
/**
|
|
85
|
+
* @static
|
|
86
|
+
* Checks if a color is in `HSLA` format.
|
|
87
|
+
*
|
|
88
|
+
* @param color Color to check.
|
|
89
|
+
* @returns Boolean: `true` if it's an `HSLA` color, `false` if not.
|
|
90
|
+
*/
|
|
91
|
+
export declare function _isHSLA(color: string): color is HSLA;
|
|
60
92
|
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/colors/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,YAAY,EACZ,
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/colors/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,YAAY,EACZ,iBAAiB,EACjB,IAAI,EACJ,IAAI,EACJ,GAAG,EACH,IAAI,EACJ,YAAY,EACZ,GAAG,EACH,IAAI,EACJ,MAAM,SAAS,CAAC;AAEjB;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,YAAa,YAAY,KAAG,MAO5D,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,aAAa,UAAW,MAAM,WAAW,MAAM,KAAG,MAE9D,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,QAAO,GAKrC,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,iBACd,MAAM,EAAE,YACZ,MAAM,KACd,OA2BF,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,wBAAwB,gBACvB,GAAG,GAAG,GAAG,KACpB,YAIF,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,wBAAwB,gBACvB,IAAI,GAAG,IAAI,KACtB,iBAIF,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,IAAI,CAEpD;AAED;;;;;GAKG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,GAAG,CAElD;AAED;;;;;GAKG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,GAAG,CAElD;AAED;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,IAAI,CAEpD;AAED;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,IAAI,CAEpD;AAED;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,IAAI,CAEpD"}
|
package/dist/colors/helpers.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.
|
|
3
|
+
exports._extractAlphaColorValues = exports._extractSolidColorValues = exports._isSimilarToLast = exports._generateRandomHSL = exports._applyOpacity = exports._convertOpacityToHex = void 0;
|
|
4
|
+
exports._isHex6 = _isHex6;
|
|
5
5
|
exports._isRGB = _isRGB;
|
|
6
6
|
exports._isHSL = _isHSL;
|
|
7
|
+
exports._isHex8 = _isHex8;
|
|
8
|
+
exports._isRGBA = _isRGBA;
|
|
9
|
+
exports._isHSLA = _isHSLA;
|
|
7
10
|
/**
|
|
8
11
|
* * Converts opacity percentage (0-100) to a 2-digit hex string.
|
|
9
12
|
*
|
|
@@ -77,17 +80,28 @@ exports._isSimilarToLast = _isSimilarToLast;
|
|
|
77
80
|
* @param colorString The color string in RGB or HSL format.
|
|
78
81
|
* @returns An array of extracted numbers.
|
|
79
82
|
*/
|
|
80
|
-
const
|
|
83
|
+
const _extractSolidColorValues = (colorString) => {
|
|
81
84
|
return (colorString.match(/[\d.]+%?/g) || []).map((value) => parseFloat(value));
|
|
82
85
|
};
|
|
83
|
-
exports.
|
|
86
|
+
exports._extractSolidColorValues = _extractSolidColorValues;
|
|
87
|
+
/**
|
|
88
|
+
* * Extracts numbers from a color string like `rgba(66, 103, 69, 0.6)` or `hsla(120, 42.86%, 41.18%, 0.9)`.
|
|
89
|
+
* * Converts percentage values to decimal (e.g., `42.86%` → `42.86`).
|
|
90
|
+
*
|
|
91
|
+
* @param colorString The color string in RGB or HSL format.
|
|
92
|
+
* @returns An array of extracted numbers.
|
|
93
|
+
*/
|
|
94
|
+
const _extractAlphaColorValues = (colorString) => {
|
|
95
|
+
return (colorString.match(/[\d.]+%?/g) || []).map((value) => parseFloat(value));
|
|
96
|
+
};
|
|
97
|
+
exports._extractAlphaColorValues = _extractAlphaColorValues;
|
|
84
98
|
/**
|
|
85
99
|
* * Checks if a color is in `Hex` format.
|
|
86
100
|
*
|
|
87
101
|
* @param color Color to check.
|
|
88
102
|
* @returns Boolean: `true` if it's a `Hex` color, `false` if not.
|
|
89
103
|
*/
|
|
90
|
-
function
|
|
104
|
+
function _isHex6(color) {
|
|
91
105
|
return /^#[0-9A-Fa-f]{6}$/.test(color);
|
|
92
106
|
}
|
|
93
107
|
/**
|
|
@@ -108,3 +122,33 @@ function _isRGB(color) {
|
|
|
108
122
|
function _isHSL(color) {
|
|
109
123
|
return /^hsl\(\d{1,3}, \d{1,3}%, \d{1,3}%\)$/.test(color);
|
|
110
124
|
}
|
|
125
|
+
/**
|
|
126
|
+
* @static
|
|
127
|
+
* Checks if a color is in `Hex8` format.
|
|
128
|
+
*
|
|
129
|
+
* @param color Color to check.
|
|
130
|
+
* @returns Boolean: `true` if it's a `Hex8` color, `false` if not.
|
|
131
|
+
*/
|
|
132
|
+
function _isHex8(color) {
|
|
133
|
+
return /^#[0-9A-Fa-f]{8}$/.test(color);
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* @static
|
|
137
|
+
* Checks if a color is in `RGBA` format.
|
|
138
|
+
*
|
|
139
|
+
* @param color Color to check.
|
|
140
|
+
* @returns Boolean: `true` if it's an `RGBA` color, `false` if not.
|
|
141
|
+
*/
|
|
142
|
+
function _isRGBA(color) {
|
|
143
|
+
return /^rgba\(\d{1,3}, \d{1,3}, \d{1,3}, (0|1|0?\.\d+)\)$/.test(color);
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* @static
|
|
147
|
+
* Checks if a color is in `HSLA` format.
|
|
148
|
+
*
|
|
149
|
+
* @param color Color to check.
|
|
150
|
+
* @returns Boolean: `true` if it's an `HSLA` color, `false` if not.
|
|
151
|
+
*/
|
|
152
|
+
function _isHSLA(color) {
|
|
153
|
+
return /^hsla\(\d{1,3}, \d{1,3}%, \d{1,3}%, (0|1|0?\.\d+)\)$/.test(color);
|
|
154
|
+
}
|
package/dist/colors/random.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Hex6, HSL, RGB } from './types';
|
|
2
2
|
/**
|
|
3
3
|
* * Utility to generate a unique random HSL color.
|
|
4
4
|
*
|
|
@@ -13,7 +13,7 @@ export declare const generateRandomHSLColor: (maxColors?: number) => HSL;
|
|
|
13
13
|
* @returns An object of generated unique random color in both `Hex` and `RGB` formats.
|
|
14
14
|
*/
|
|
15
15
|
export declare const generateRandomColorInHexRGB: (maxColors?: number) => {
|
|
16
|
-
hex:
|
|
16
|
+
hex: Hex6;
|
|
17
17
|
rgb: RGB;
|
|
18
18
|
};
|
|
19
19
|
//# sourceMappingURL=random.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"random.d.ts","sourceRoot":"","sources":["../../src/colors/random.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"random.d.ts","sourceRoot":"","sources":["../../src/colors/random.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,SAAS,CAAC;AAQ9C;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,eAAe,MAAM,KAAQ,GAqB/D,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,eAC5B,MAAM,KACf;IACF,GAAG,EAAE,IAAI,CAAC;IACV,GAAG,EAAE,GAAG,CAAC;CAGT,CAAC"}
|
package/dist/colors/types.d.ts
CHANGED
|
@@ -5,12 +5,18 @@ 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
|
-
export type ColorNumber = 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 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255;
|
|
9
8
|
/**
|
|
10
9
|
* * Represents a hexadecimal color code.
|
|
11
10
|
* * Format: `#3C6945`
|
|
12
11
|
*/
|
|
13
12
|
export type Hex = `#${string}`;
|
|
13
|
+
/**
|
|
14
|
+
* * Represents a hexadecimal color code.
|
|
15
|
+
* * Format: `#3C6945`
|
|
16
|
+
*/
|
|
17
|
+
export type Hex6 = `#${string}` & {
|
|
18
|
+
__hex6Brand: never;
|
|
19
|
+
};
|
|
14
20
|
/**
|
|
15
21
|
* * Represents an RGB color string.
|
|
16
22
|
* * Format: `rgb(R, G, B)`
|
|
@@ -29,16 +35,44 @@ export type RGB = `rgb(${number}, ${number}, ${number})`;
|
|
|
29
35
|
* - L (Lightness): 0-100%
|
|
30
36
|
*/
|
|
31
37
|
export type HSL = `hsl(${number}, ${number}%, ${number}%)`;
|
|
32
|
-
/**
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
38
|
+
/**
|
|
39
|
+
* * Represents a hexadecimal color code with optional alpha channel.
|
|
40
|
+
* * Format: `#3C6945FF`
|
|
41
|
+
*/
|
|
42
|
+
export type Hex8 = `#${string}` & {
|
|
43
|
+
__hex8Brand: never;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* * Represents an RGBA color string, now includes optional alpha (opacity).
|
|
47
|
+
* * Format: `rgba(R, G, B, A)`
|
|
48
|
+
*/
|
|
49
|
+
export type RGBA = `rgba(${number}, ${number}, ${number}, ${number})`;
|
|
50
|
+
/**
|
|
51
|
+
* * Represents an HSLA color string with optional alpha channel.
|
|
52
|
+
* * Format: `hsla(H, S%, L%, A)`
|
|
53
|
+
*/
|
|
54
|
+
export type HSLA = `hsla(${number}, ${number}%, ${number}%, ${number})`;
|
|
55
|
+
/** * Union type representing a color in Hex6, RGB, or HSL format. */
|
|
56
|
+
export type ColorTypeSolid = Hex6 | RGB | HSL;
|
|
57
|
+
/** * Union type representing a color in Hex8, RGBA, or HSLA format. */
|
|
58
|
+
export type ColorTypeAlpha = Hex8 | RGBA | HSLA;
|
|
59
|
+
/** - Colors Object that includes `Hex8`, `RGBA` and `HSLA` formats of the same color. */
|
|
60
|
+
export interface SolidColors {
|
|
61
|
+
hex: Hex6;
|
|
37
62
|
rgb: RGB;
|
|
38
63
|
hsl: HSL;
|
|
39
64
|
}
|
|
65
|
+
/** - Colors Object that includes `Hex`, `RGB` and `HSL` formats of the same color. */
|
|
66
|
+
export interface AlphaColors {
|
|
67
|
+
hex8: Hex8;
|
|
68
|
+
rgba: RGBA;
|
|
69
|
+
hsla: HSLA;
|
|
70
|
+
}
|
|
71
|
+
export type ColorType = ColorTypeSolid | ColorTypeAlpha | Hex;
|
|
72
|
+
/** * Represents a tuple of three numerical values corresponding to RGB or HSL color components. */
|
|
73
|
+
export type ColorNumbers = [number, number, number];
|
|
40
74
|
/** * Represents a tuple of three numerical values corresponding to RGB or HSL color components. */
|
|
41
|
-
export type
|
|
75
|
+
export type ColorNumbersAlpha = [number, number, number, number];
|
|
42
76
|
/**
|
|
43
77
|
* * Represents the converted color formats for a given color type.
|
|
44
78
|
*
|
|
@@ -48,12 +82,18 @@ export type ColorNumbers = [ColorNumber, ColorNumber, ColorNumber];
|
|
|
48
82
|
*
|
|
49
83
|
* @template T The input color type (`Hex`, `RGB`, or `HSL`).
|
|
50
84
|
*/
|
|
51
|
-
export interface ConvertedColors<T extends ColorType> extends Record<string,
|
|
85
|
+
export interface ConvertedColors<T extends ColorType> extends Record<string, ColorType> {
|
|
52
86
|
/** - The Hex representation (excluded if the input is already Hex). */
|
|
53
|
-
hex: T extends
|
|
87
|
+
hex: T extends Hex6 | ColorTypeAlpha ? never : Hex6;
|
|
54
88
|
/** - The RGB representation (excluded if the input is already RGB). */
|
|
55
|
-
rgb: T extends RGB ? never : RGB;
|
|
89
|
+
rgb: T extends RGB | ColorTypeAlpha ? never : RGB;
|
|
56
90
|
/** - The HSL representation (excluded if the input is already HSL). */
|
|
57
|
-
hsl: T extends HSL ? never : HSL;
|
|
91
|
+
hsl: T extends HSL | ColorTypeAlpha ? never : HSL;
|
|
92
|
+
/** - The Hex8 representation with opacity (excluded if the input is already Hex8). */
|
|
93
|
+
hex8: T extends Hex8 | ColorTypeSolid ? never : Hex8;
|
|
94
|
+
/** - The RGBA representation (excluded if the input is already RGBA). */
|
|
95
|
+
rgba: T extends RGBA | ColorTypeSolid ? never : RGBA;
|
|
96
|
+
/** - The HSLA representation (excluded if the input is already HSLA). */
|
|
97
|
+
hsla: T extends HSLA | ColorTypeSolid ? never : HSLA;
|
|
58
98
|
}
|
|
59
99
|
//# 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,MA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AAE,GACF,GAAG,CAAC;AAEP,MAAM,MAAM,
|
|
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,GAC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AE,IAAI,CAAC;IACX,IAAI,EAAE,IAAI,CAAC;IACX,IAAI,EAAE,IAAI,CAAC;CACX;AAED,MAAM,MAAM,SAAS,GAAG,cAAc,GAAG,cAAc,GAAG,GAAG,CAAC;AAE9D,mGAAmG;AACnG,MAAM,MAAM,YAAY,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAEpD,mGAAmG;AACnG,MAAM,MAAM,iBAAiB,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAEjE;;;;;;;;GAQG;AACH,MAAM,WAAW,eAAe,CAAC,CAAC,SAAS,SAAS,CACnD,SAAQ,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC;IACjC,uEAAuE;IACvE,GAAG,EAAE,CAAC,SAAS,IAAI,GAAG,cAAc,GAAG,KAAK,GAAG,IAAI,CAAC;IACpD,uEAAuE;IACvE,GAAG,EAAE,CAAC,SAAS,GAAG,GAAG,cAAc,GAAG,KAAK,GAAG,GAAG,CAAC;IAClD,uEAAuE;IACvE,GAAG,EAAE,CAAC,SAAS,GAAG,GAAG,cAAc,GAAG,KAAK,GAAG,GAAG,CAAC;IAClD,sFAAsF;IACtF,IAAI,EAAE,CAAC,SAAS,IAAI,GAAG,cAAc,GAAG,KAAK,GAAG,IAAI,CAAC;IACrD,yEAAyE;IACzE,IAAI,EAAE,CAAC,SAAS,IAAI,GAAG,cAAc,GAAG,KAAK,GAAG,IAAI,CAAC;IACrD,yEAAyE;IACzE,IAAI,EAAE,CAAC,SAAS,IAAI,GAAG,cAAc,GAAG,KAAK,GAAG,IAAI,CAAC;CACrD"}
|
package/dist/index.d.ts
CHANGED
|
@@ -7,12 +7,11 @@ export { findPrimeNumbers, isPrime } from './number/prime';
|
|
|
7
7
|
export { getNumbersInRange } from './number/range';
|
|
8
8
|
export { getColorForInitial } from './colors/initials';
|
|
9
9
|
export { generateRandomColorInHexRGB, generateRandomHSLColor, } from './colors/random';
|
|
10
|
-
export { convertColorCode, convertHexToHsl, convertHexToRgb, convertHslToHex, convertHslToRgb, convertRgbToHex, convertRgbToHsl, } from './colors/convert';
|
|
10
|
+
export { convertColorCode, convertHex8ToRgba, convertHexToHsl, convertHexToRgb, convertHslaToRgba, convertHslToHex, convertHslToRgb, convertRgbaToHex8, convertRgbaToHsla, convertRgbToHex, convertRgbToHsl, convertRgbToRgba, } from './colors/convert';
|
|
11
11
|
export { Color } from './colors/Color';
|
|
12
|
-
export { extractNumbersFromColor } from './colors/helpers';
|
|
13
12
|
export { filterArrayOfObjects, flattenArray, isValidButEmptyArray, shuffleArray, } from './array/basics';
|
|
14
13
|
export { sortAnArray } from './array/sort';
|
|
15
|
-
export { createOptionsArray } from './array/transform';
|
|
14
|
+
export { createOptionsArray, removeDuplicatesFromArray, } from './array/transform';
|
|
16
15
|
export { convertIntoFormData, isEmptyFormData } from './form/convert';
|
|
17
16
|
export { createControlledFormData } from './form/transform';
|
|
18
17
|
export { cloneObject, countObjectFields, generateQueryParams, isEmptyObject, isObject, } from './object/basics';
|
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,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAEpE,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,OAAO,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAE3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAEnD,OAAO,EAAE,kBA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ClB,yBAAyB,GACzB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEtE,OAAO,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAE5D,OAAO,EACN,WAAW,EACX,iBAAiB,EACjB,mBAAmB,EACnB,aAAa,EACb,QAAQ,GACR,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACN,gBAAgB,EAChB,0BAA0B,EAC1B,oBAAoB,EACpB,aAAa,EACb,sBAAsB,EACtB,YAAY,GACZ,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAEvD,OAAO,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.sanitizeData = exports.mergeObjects = exports.mergeAndFlattenObjects = exports.flattenObject = exports.extractUpdatedFields = exports.extractUpdatedAndNewFields = exports.extractNewFields = exports.isObject = exports.isEmptyObject = exports.generateQueryParams = exports.countObjectFields = exports.cloneObject = exports.createControlledFormData = exports.isEmptyFormData = exports.convertIntoFormData = exports.removeDuplicatesFromArray = exports.createOptionsArray = exports.sortAnArray = exports.shuffleArray = exports.isValidButEmptyArray = exports.flattenArray = exports.filterArrayOfObjects = exports.Color = exports.convertRgbToRgba = exports.convertRgbToHsl = exports.convertRgbToHex = exports.convertRgbaToHsla = exports.convertRgbaToHex8 = exports.convertHslToRgb = exports.convertHslToHex = exports.convertHslaToRgba = exports.convertHexToRgb = exports.convertHexToHsl = exports.convertHex8ToRgba = exports.convertColorCode = exports.generateRandomHSLColor = exports.generateRandomColorInHexRGB = exports.getColorForInitial = exports.getNumbersInRange = exports.isPrime = exports.findPrimeNumbers = exports.numberToWords = exports.getRandomNumber = exports.convertToDecimal = exports.convertStringCase = exports.generateAnagrams = exports.truncateString = exports.trimString = exports.generateRandomID = exports.capitalizeString = void 0;
|
|
4
|
+
exports.isDeepEqual = exports.convertArrayToString = exports.convertObjectValues = void 0;
|
|
4
5
|
var basics_1 = require("./string/basics");
|
|
5
6
|
Object.defineProperty(exports, "capitalizeString", { enumerable: true, get: function () { return basics_1.capitalizeString; } });
|
|
6
7
|
Object.defineProperty(exports, "generateRandomID", { enumerable: true, get: function () { return basics_1.generateRandomID; } });
|
|
@@ -27,16 +28,19 @@ Object.defineProperty(exports, "generateRandomColorInHexRGB", { enumerable: true
|
|
|
27
28
|
Object.defineProperty(exports, "generateRandomHSLColor", { enumerable: true, get: function () { return random_1.generateRandomHSLColor; } });
|
|
28
29
|
var convert_3 = require("./colors/convert");
|
|
29
30
|
Object.defineProperty(exports, "convertColorCode", { enumerable: true, get: function () { return convert_3.convertColorCode; } });
|
|
31
|
+
Object.defineProperty(exports, "convertHex8ToRgba", { enumerable: true, get: function () { return convert_3.convertHex8ToRgba; } });
|
|
30
32
|
Object.defineProperty(exports, "convertHexToHsl", { enumerable: true, get: function () { return convert_3.convertHexToHsl; } });
|
|
31
33
|
Object.defineProperty(exports, "convertHexToRgb", { enumerable: true, get: function () { return convert_3.convertHexToRgb; } });
|
|
34
|
+
Object.defineProperty(exports, "convertHslaToRgba", { enumerable: true, get: function () { return convert_3.convertHslaToRgba; } });
|
|
32
35
|
Object.defineProperty(exports, "convertHslToHex", { enumerable: true, get: function () { return convert_3.convertHslToHex; } });
|
|
33
36
|
Object.defineProperty(exports, "convertHslToRgb", { enumerable: true, get: function () { return convert_3.convertHslToRgb; } });
|
|
37
|
+
Object.defineProperty(exports, "convertRgbaToHex8", { enumerable: true, get: function () { return convert_3.convertRgbaToHex8; } });
|
|
38
|
+
Object.defineProperty(exports, "convertRgbaToHsla", { enumerable: true, get: function () { return convert_3.convertRgbaToHsla; } });
|
|
34
39
|
Object.defineProperty(exports, "convertRgbToHex", { enumerable: true, get: function () { return convert_3.convertRgbToHex; } });
|
|
35
40
|
Object.defineProperty(exports, "convertRgbToHsl", { enumerable: true, get: function () { return convert_3.convertRgbToHsl; } });
|
|
41
|
+
Object.defineProperty(exports, "convertRgbToRgba", { enumerable: true, get: function () { return convert_3.convertRgbToRgba; } });
|
|
36
42
|
var Color_1 = require("./colors/Color");
|
|
37
43
|
Object.defineProperty(exports, "Color", { enumerable: true, get: function () { return Color_1.Color; } });
|
|
38
|
-
var helpers_1 = require("./colors/helpers");
|
|
39
|
-
Object.defineProperty(exports, "extractNumbersFromColor", { enumerable: true, get: function () { return helpers_1.extractNumbersFromColor; } });
|
|
40
44
|
var basics_3 = require("./array/basics");
|
|
41
45
|
Object.defineProperty(exports, "filterArrayOfObjects", { enumerable: true, get: function () { return basics_3.filterArrayOfObjects; } });
|
|
42
46
|
Object.defineProperty(exports, "flattenArray", { enumerable: true, get: function () { return basics_3.flattenArray; } });
|
|
@@ -46,6 +50,7 @@ var sort_1 = require("./array/sort");
|
|
|
46
50
|
Object.defineProperty(exports, "sortAnArray", { enumerable: true, get: function () { return sort_1.sortAnArray; } });
|
|
47
51
|
var transform_1 = require("./array/transform");
|
|
48
52
|
Object.defineProperty(exports, "createOptionsArray", { enumerable: true, get: function () { return transform_1.createOptionsArray; } });
|
|
53
|
+
Object.defineProperty(exports, "removeDuplicatesFromArray", { enumerable: true, get: function () { return transform_1.removeDuplicatesFromArray; } });
|
|
49
54
|
var convert_4 = require("./form/convert");
|
|
50
55
|
Object.defineProperty(exports, "convertIntoFormData", { enumerable: true, get: function () { return convert_4.convertIntoFormData; } });
|
|
51
56
|
Object.defineProperty(exports, "isEmptyFormData", { enumerable: true, get: function () { return convert_4.isEmptyFormData; } });
|
package/package.json
CHANGED