nhb-toolbox 1.9.9 → 2.0.7
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 +9 -13
- package/dist/colors/Color.d.ts.map +1 -1
- package/dist/colors/Color.js +7 -19
- package/dist/colors/convert.d.ts +17 -0
- package/dist/colors/convert.d.ts.map +1 -1
- package/dist/colors/convert.js +63 -33
- package/dist/colors/helpers.d.ts.map +1 -1
- package/dist/colors/helpers.js +4 -4
- package/dist/colors/types.d.ts +10 -14
- package/dist/colors/types.d.ts.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -3
- package/dist/object/basics.d.ts +3 -1
- package/dist/object/basics.d.ts.map +1 -1
- package/dist/object/basics.js +10 -4
- package/dist/object/objectify.d.ts +8 -1
- package/dist/object/objectify.d.ts.map +1 -1
- package/dist/object/objectify.js +31 -4
- package/dist/object/types.d.ts +13 -2
- package/dist/object/types.d.ts.map +1 -1
- package/dist/types/index.d.ts +9 -0
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/colors/Color.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
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
|
-
* * It has
|
|
4
|
+
* * It has 1 instance method to apply opacity to `Hex`, `Hex8` `RGB`, `RGBA`, `HSL` or `HSLA` color.
|
|
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.
|
|
5
6
|
*
|
|
6
7
|
* @property {Hex} hex - The color in `Hex` format.
|
|
7
8
|
* @property {RGB} rgb - The color in `RGB` format.
|
|
@@ -21,7 +22,7 @@ export declare class Color {
|
|
|
21
22
|
rgb: RGB | RGBA;
|
|
22
23
|
hsl: HSL | HSLA;
|
|
23
24
|
/** - Iterates over the color representations (Hex, RGB, HSL). */
|
|
24
|
-
[Symbol.iterator](): Generator<Hex6 |
|
|
25
|
+
[Symbol.iterator](): Generator<Hex6 | RGB | HSL | Hex8 | RGBA | HSLA, void, unknown>;
|
|
25
26
|
/**
|
|
26
27
|
* * Creates a new Color instance, optionally converting an input color.
|
|
27
28
|
*
|
|
@@ -47,11 +48,6 @@ export declare class Color {
|
|
|
47
48
|
* console.log(alpha75.hex8); // #ff0000bf
|
|
48
49
|
*/
|
|
49
50
|
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
51
|
/**
|
|
56
52
|
* @static
|
|
57
53
|
* Checks if a color is in `Hex6` format.
|
|
@@ -59,7 +55,7 @@ export declare class Color {
|
|
|
59
55
|
* @param color Color to check.
|
|
60
56
|
* @returns Boolean: `true` if it's a `Hex6` color, `false` if not.
|
|
61
57
|
*/
|
|
62
|
-
static isHex6(color:
|
|
58
|
+
static isHex6(color: string): color is Hex6;
|
|
63
59
|
/**
|
|
64
60
|
* @static
|
|
65
61
|
* Checks if a color is in `Hex8` format.
|
|
@@ -67,7 +63,7 @@ export declare class Color {
|
|
|
67
63
|
* @param color Color to check.
|
|
68
64
|
* @returns Boolean: `true` if it's a `Hex8` color, `false` if not.
|
|
69
65
|
*/
|
|
70
|
-
static isHex8(color:
|
|
66
|
+
static isHex8(color: string): color is Hex8;
|
|
71
67
|
/**
|
|
72
68
|
* @static
|
|
73
69
|
* Checks if a color is in `RGB` format.
|
|
@@ -75,7 +71,7 @@ export declare class Color {
|
|
|
75
71
|
* @param color Color to check.
|
|
76
72
|
* @returns Boolean: `true` if it's an `RGB` color, `false` if not.
|
|
77
73
|
*/
|
|
78
|
-
static isRGB(color:
|
|
74
|
+
static isRGB(color: string): color is RGB;
|
|
79
75
|
/**
|
|
80
76
|
* @static
|
|
81
77
|
* Checks if a color is in `RGBA` format.
|
|
@@ -83,7 +79,7 @@ export declare class Color {
|
|
|
83
79
|
* @param color Color to check.
|
|
84
80
|
* @returns Boolean: `true` if it's an `RGBA` color, `false` if not.
|
|
85
81
|
*/
|
|
86
|
-
static isRGBA(color:
|
|
82
|
+
static isRGBA(color: string): color is RGBA;
|
|
87
83
|
/**
|
|
88
84
|
* @static
|
|
89
85
|
* Checks if a color is in `HSL` format.
|
|
@@ -91,7 +87,7 @@ export declare class Color {
|
|
|
91
87
|
* @param color Color to check.
|
|
92
88
|
* @returns Boolean: `true` if it's an `HSL` color, `false` if not.
|
|
93
89
|
*/
|
|
94
|
-
static isHSL(color:
|
|
90
|
+
static isHSL(color: string): color is HSL;
|
|
95
91
|
/**
|
|
96
92
|
* @static
|
|
97
93
|
* Checks if a color is in `HSLA` format.
|
|
@@ -99,7 +95,7 @@ export declare class Color {
|
|
|
99
95
|
* @param color Color to check.
|
|
100
96
|
* @returns Boolean: `true` if it's an `HSLA` color, `false` if not.
|
|
101
97
|
*/
|
|
102
|
-
static isHSLA(color:
|
|
98
|
+
static isHSLA(color: string): color is HSLA;
|
|
103
99
|
/**
|
|
104
100
|
* - Converts the given color to all other formats while preserving the original.
|
|
105
101
|
*
|
|
@@ -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
|
|
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;;;;;;;;;;;;;;;;;GAiBG;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;;;;;;OAMG;WACW,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,IAAI;IAIlD;;;;;;OAMG;WACW,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,IAAI;IAIlD;;;;;;OAMG;WACW,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,GAAG;IAIhD;;;;;;OAMG;WACW,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,IAAI;IAMlD;;;;;;OAMG;WACW,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,GAAG;IAIhD;;;;;;OAMG;WACW,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,IAAI;IAMlD;;;;;;OAMG;IACH,OAAO,CAAC,qBAAqB;CAuB7B"}
|
package/dist/colors/Color.js
CHANGED
|
@@ -8,7 +8,8 @@ const hsl = (0, random_1.generateRandomHSLColor)();
|
|
|
8
8
|
const hexRGB = (0, convert_1.convertColorCode)(hsl);
|
|
9
9
|
/**
|
|
10
10
|
* * Class representing a color and its conversions between Hex, RGB, and HSL formats.
|
|
11
|
-
* * It has
|
|
11
|
+
* * It has 1 instance method to apply opacity to `Hex`, `Hex8` `RGB`, `RGBA`, `HSL` or `HSLA` color.
|
|
12
|
+
* * It has 6 static methods that can be used to check if a color is in `Hex`, `Hex8` `RGB`, `RGBA`, `HSL` or `HSLA` format.
|
|
12
13
|
*
|
|
13
14
|
* @property {Hex} hex - The color in `Hex` format.
|
|
14
15
|
* @property {RGB} rgb - The color in `RGB` format.
|
|
@@ -106,19 +107,6 @@ class Color {
|
|
|
106
107
|
hsla: `hsla(${hslValues[0]}, ${hslValues[1]}%, ${hslValues[2]}%, ${alphaDecimal})`,
|
|
107
108
|
};
|
|
108
109
|
}
|
|
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);
|
|
116
|
-
}
|
|
117
|
-
if (this.isHex8(hex)) {
|
|
118
|
-
return new Color(hex);
|
|
119
|
-
}
|
|
120
|
-
throw new Error(`Unrecognized Hex Format: ${hex}`);
|
|
121
|
-
}
|
|
122
110
|
/**
|
|
123
111
|
* @static
|
|
124
112
|
* Checks if a color is in `Hex6` format.
|
|
@@ -147,7 +135,7 @@ class Color {
|
|
|
147
135
|
* @returns Boolean: `true` if it's an `RGB` color, `false` if not.
|
|
148
136
|
*/
|
|
149
137
|
static isRGB(color) {
|
|
150
|
-
return /^rgb\(\d{1,3}
|
|
138
|
+
return /^rgb\(\d{1,3},\s*\d{1,3},\s*\d{1,3}\)$/.test(color);
|
|
151
139
|
}
|
|
152
140
|
/**
|
|
153
141
|
* @static
|
|
@@ -157,7 +145,7 @@ class Color {
|
|
|
157
145
|
* @returns Boolean: `true` if it's an `RGBA` color, `false` if not.
|
|
158
146
|
*/
|
|
159
147
|
static isRGBA(color) {
|
|
160
|
-
return /^rgba\(\d{1,3}
|
|
148
|
+
return /^rgba\(\d{1,3},\s*\d{1,3},\s*\d{1,3},\s*(0|1|0?\.\d+)\)$/.test(color);
|
|
161
149
|
}
|
|
162
150
|
/**
|
|
163
151
|
* @static
|
|
@@ -167,7 +155,7 @@ class Color {
|
|
|
167
155
|
* @returns Boolean: `true` if it's an `HSL` color, `false` if not.
|
|
168
156
|
*/
|
|
169
157
|
static isHSL(color) {
|
|
170
|
-
return /^hsl\(\d{1,3}
|
|
158
|
+
return /^hsl\(\d{1,3},\s*\d{1,3}%,\s*\d{1,3}%\)$/.test(color);
|
|
171
159
|
}
|
|
172
160
|
/**
|
|
173
161
|
* @static
|
|
@@ -177,7 +165,7 @@ class Color {
|
|
|
177
165
|
* @returns Boolean: `true` if it's an `HSLA` color, `false` if not.
|
|
178
166
|
*/
|
|
179
167
|
static isHSLA(color) {
|
|
180
|
-
return /^hsla\(\d{1,3}
|
|
168
|
+
return /^hsla\(\d{1,3},\s*\d{1,3}%,\s*\d{1,3}%,\s*(0|1|0?\.\d+)\)$/.test(color);
|
|
181
169
|
}
|
|
182
170
|
/**
|
|
183
171
|
* - Converts the given color to all other formats while preserving the original.
|
|
@@ -211,7 +199,7 @@ class Color {
|
|
|
211
199
|
const { hex8, rgba } = (0, convert_1.convertColorCode)(color);
|
|
212
200
|
return { hex8, rgba, hsla: color };
|
|
213
201
|
}
|
|
214
|
-
throw new Error(`Unrecognized Color Format
|
|
202
|
+
throw new Error(`Unrecognized Color Format! ${color}`);
|
|
215
203
|
}
|
|
216
204
|
}
|
|
217
205
|
exports.Color = Color;
|
package/dist/colors/convert.d.ts
CHANGED
|
@@ -96,6 +96,23 @@ export declare const convertRgbaToHsla: (r: number, g: number, b: number, a?: nu
|
|
|
96
96
|
* @returns A string representing the color in RGBA format (e.g., `rgba(255, 0, 0, 0.5)`).
|
|
97
97
|
*/
|
|
98
98
|
export declare const convertHex8ToRgba: (hex8: Hex8) => RGBA;
|
|
99
|
+
/**
|
|
100
|
+
* * Converts HSLA to Hex8 color format, including alpha channel.
|
|
101
|
+
*
|
|
102
|
+
* @param h - The hue component of the HSL color, in degrees (0 to 360).
|
|
103
|
+
* @param s - The saturation component of the HSL color, as a percentage (0 to 100).
|
|
104
|
+
* @param l - The lightness component of the HSL color, as a percentage (0 to 100).
|
|
105
|
+
* @param a - The alpha (opacity) value, in the range 0 to 1.
|
|
106
|
+
* @returns A string representing the color in Hex8 format (e.g., `#658789DF`).
|
|
107
|
+
*/
|
|
108
|
+
export declare const convertHslaToHex8: (h: number, s: number, l: number, a?: number) => Hex8;
|
|
109
|
+
/**
|
|
110
|
+
* * Converts Hex8 to HSLA color format.
|
|
111
|
+
*
|
|
112
|
+
* @param hex - A string representing the color in Hex format (e.g., `#FF0000DE`).
|
|
113
|
+
* @returns A string representing the color in HSLA format..
|
|
114
|
+
*/
|
|
115
|
+
export declare const convertHex8ToHsla: (hex8: Hex8) => HSLA;
|
|
99
116
|
/**
|
|
100
117
|
* * Converts a `Hex` color code to `RGB` and `HSL` formats.
|
|
101
118
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convert.d.ts","sourceRoot":"","sources":["../../src/colors/convert.ts"],"names":[],"mappings":"AAYA,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,GAyBjE,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,IAIjE,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,eAAe,QAAS,IAAI,GAAG,MAAM,KAAG,GAepD,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,MAAO,MAAM,K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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.convertHex8ToRgba = exports.convertRgbaToHsla = exports.convertHslaToRgba = exports.convertRgbaToHex8 = exports.convertRgbToRgba = exports.convertHexToRgb = exports.convertRgbToHex = exports.convertHexToHsl = exports.convertHslToHex = exports.convertRgbToHsl = exports.convertHslToRgb = void 0;
|
|
3
|
+
exports.convertHex8ToHsla = exports.convertHslaToHex8 = 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
|
/**
|
|
@@ -152,11 +152,12 @@ exports.convertHexToRgb = convertHexToRgb;
|
|
|
152
152
|
* @returns A string representing the color in RGBA format (e.g., `rgba(255, 0, 0, 0.5)`).
|
|
153
153
|
*/
|
|
154
154
|
const convertRgbToRgba = (r, g, b, a = 1) => {
|
|
155
|
+
let newAlpha = a;
|
|
155
156
|
if (!(0, helpers_1._isValidAlpha)(a)) {
|
|
156
|
-
|
|
157
|
-
console.warn(`
|
|
157
|
+
newAlpha = 1;
|
|
158
|
+
console.warn(`Alpha value must be between 0-1, ${a} converted to 1!`);
|
|
158
159
|
}
|
|
159
|
-
return `rgba(${r}, ${g}, ${b}, ${parseFloat(
|
|
160
|
+
return `rgba(${r}, ${g}, ${b}, ${parseFloat(newAlpha.toFixed(1))})`;
|
|
160
161
|
};
|
|
161
162
|
exports.convertRgbToRgba = convertRgbToRgba;
|
|
162
163
|
/**
|
|
@@ -169,17 +170,13 @@ exports.convertRgbToRgba = convertRgbToRgba;
|
|
|
169
170
|
* @returns A string representing the color in Hex8 format (e.g., `#FF000080`).
|
|
170
171
|
*/
|
|
171
172
|
const convertRgbaToHex8 = (r, g, b, a = 1) => {
|
|
173
|
+
let newAlpha = a;
|
|
172
174
|
if (!(0, helpers_1._isValidAlpha)(a)) {
|
|
173
|
-
|
|
174
|
-
console.warn(`
|
|
175
|
+
newAlpha = 1;
|
|
176
|
+
console.warn(`Alpha value must be between 0-1, ${a} converted to 1!`);
|
|
175
177
|
}
|
|
176
|
-
const
|
|
177
|
-
|
|
178
|
-
.padStart(2, '0');
|
|
179
|
-
const hex = [r, g, b]
|
|
180
|
-
.map((v) => v.toString(16).padStart(2, '0'))
|
|
181
|
-
.join('')
|
|
182
|
-
.toUpperCase();
|
|
178
|
+
const hex = (0, exports.convertRgbToHex)(r, g, b);
|
|
179
|
+
const alphaHex = (0, helpers_1._convertOpacityToHex)(Math.round(newAlpha * 100));
|
|
183
180
|
return `#${hex}${alphaHex}`;
|
|
184
181
|
};
|
|
185
182
|
exports.convertRgbaToHex8 = convertRgbaToHex8;
|
|
@@ -193,13 +190,14 @@ exports.convertRgbaToHex8 = convertRgbaToHex8;
|
|
|
193
190
|
* @returns A string representing the color in RGBA format (e.g., `rgba(255, 0, 0, 0.5)`).
|
|
194
191
|
*/
|
|
195
192
|
const convertHslaToRgba = (h, s, l, a = 1) => {
|
|
193
|
+
let newAlpha = a;
|
|
196
194
|
if (!(0, helpers_1._isValidAlpha)(a)) {
|
|
197
|
-
|
|
198
|
-
console.warn(`
|
|
195
|
+
newAlpha = 1;
|
|
196
|
+
console.warn(`Alpha value must be between 0-1, ${a} converted to 1!`);
|
|
199
197
|
}
|
|
200
198
|
const rgb = (0, exports.convertHslToRgb)(h, s, l);
|
|
201
199
|
const rgbNumbers = (0, helpers_1._extractSolidColorValues)(rgb);
|
|
202
|
-
return (0, exports.convertRgbToRgba)(rgbNumbers[0], rgbNumbers[1], rgbNumbers[2], parseFloat(
|
|
200
|
+
return (0, exports.convertRgbToRgba)(rgbNumbers[0], rgbNumbers[1], rgbNumbers[2], parseFloat(newAlpha.toFixed(1)));
|
|
203
201
|
};
|
|
204
202
|
exports.convertHslaToRgba = convertHslaToRgba;
|
|
205
203
|
/**
|
|
@@ -212,13 +210,14 @@ exports.convertHslaToRgba = convertHslaToRgba;
|
|
|
212
210
|
* @returns A string representing the color in HSLA format (e.g., `hsla(0, 100%, 50%, 0.5)`).
|
|
213
211
|
*/
|
|
214
212
|
const convertRgbaToHsla = (r, g, b, a = 1) => {
|
|
213
|
+
let newAlpha = a;
|
|
215
214
|
if (!(0, helpers_1._isValidAlpha)(a)) {
|
|
216
|
-
|
|
217
|
-
console.warn(`
|
|
215
|
+
newAlpha = 1;
|
|
216
|
+
console.warn(`Alpha value must be between 0-1, ${a} converted to 1!`);
|
|
218
217
|
}
|
|
219
218
|
const hsl = (0, exports.convertRgbToHsl)(r, g, b);
|
|
220
219
|
const hslNumbers = (0, helpers_1._extractSolidColorValues)(hsl);
|
|
221
|
-
return `hsla(${hslNumbers[0]}, ${hslNumbers[1]}%, ${hslNumbers[2]}%, ${parseFloat(
|
|
220
|
+
return `hsla(${hslNumbers[0]}, ${hslNumbers[1]}%, ${hslNumbers[2]}%, ${parseFloat(newAlpha.toFixed(1))})`;
|
|
222
221
|
};
|
|
223
222
|
exports.convertRgbaToHsla = convertRgbaToHsla;
|
|
224
223
|
/**
|
|
@@ -236,6 +235,37 @@ const convertHex8ToRgba = (hex8) => {
|
|
|
236
235
|
return `rgba(${r}, ${g}, ${b}, ${parseFloat(a.toFixed(1))})`;
|
|
237
236
|
};
|
|
238
237
|
exports.convertHex8ToRgba = convertHex8ToRgba;
|
|
238
|
+
/**
|
|
239
|
+
* * Converts HSLA to Hex8 color format, including alpha channel.
|
|
240
|
+
*
|
|
241
|
+
* @param h - The hue component of the HSL color, in degrees (0 to 360).
|
|
242
|
+
* @param s - The saturation component of the HSL color, as a percentage (0 to 100).
|
|
243
|
+
* @param l - The lightness component of the HSL color, as a percentage (0 to 100).
|
|
244
|
+
* @param a - The alpha (opacity) value, in the range 0 to 1.
|
|
245
|
+
* @returns A string representing the color in Hex8 format (e.g., `#658789DF`).
|
|
246
|
+
*/
|
|
247
|
+
const convertHslaToHex8 = (h, s, l, a = 1) => {
|
|
248
|
+
let newAlpha = a;
|
|
249
|
+
if (!(0, helpers_1._isValidAlpha)(a)) {
|
|
250
|
+
newAlpha = 1;
|
|
251
|
+
console.warn(`Alpha value must be between 0-1, ${a} converted to 1!`);
|
|
252
|
+
}
|
|
253
|
+
const hex = (0, exports.convertHslToHex)(h, s, l);
|
|
254
|
+
const alphaHex = (0, helpers_1._convertOpacityToHex)(Math.round(newAlpha * 100));
|
|
255
|
+
return `#${hex}${alphaHex}`;
|
|
256
|
+
};
|
|
257
|
+
exports.convertHslaToHex8 = convertHslaToHex8;
|
|
258
|
+
/**
|
|
259
|
+
* * Converts Hex8 to HSLA color format.
|
|
260
|
+
*
|
|
261
|
+
* @param hex - A string representing the color in Hex format (e.g., `#FF0000DE`).
|
|
262
|
+
* @returns A string representing the color in HSLA format..
|
|
263
|
+
*/
|
|
264
|
+
const convertHex8ToHsla = (hex8) => {
|
|
265
|
+
const rgba = (0, exports.convertHex8ToRgba)(hex8);
|
|
266
|
+
return (0, exports.convertRgbaToHsla)(...(0, helpers_1._extractAlphaColorValues)(rgba));
|
|
267
|
+
};
|
|
268
|
+
exports.convertHex8ToHsla = convertHex8ToHsla;
|
|
239
269
|
/**
|
|
240
270
|
* * Converts a color from `Hex`, `RGB`, or `HSL` format to its equivalent representations.
|
|
241
271
|
*
|
|
@@ -251,38 +281,38 @@ function convertColorCode(color) {
|
|
|
251
281
|
};
|
|
252
282
|
}
|
|
253
283
|
if ((0, helpers_1._isRGB)(color)) {
|
|
284
|
+
const rgbValues = (0, helpers_1._extractSolidColorValues)(color);
|
|
254
285
|
return {
|
|
255
|
-
hex: (0, exports.convertRgbToHex)(...
|
|
256
|
-
hsl: (0, exports.convertRgbToHsl)(...
|
|
286
|
+
hex: (0, exports.convertRgbToHex)(...rgbValues),
|
|
287
|
+
hsl: (0, exports.convertRgbToHsl)(...rgbValues),
|
|
257
288
|
};
|
|
258
289
|
}
|
|
259
290
|
if ((0, helpers_1._isHSL)(color)) {
|
|
291
|
+
const hslValues = (0, helpers_1._extractSolidColorValues)(color);
|
|
260
292
|
return {
|
|
261
|
-
hex: (0, exports.convertHslToHex)(...
|
|
262
|
-
rgb: (0, exports.convertHslToRgb)(...
|
|
293
|
+
hex: (0, exports.convertHslToHex)(...hslValues),
|
|
294
|
+
rgb: (0, exports.convertHslToRgb)(...hslValues),
|
|
263
295
|
};
|
|
264
296
|
}
|
|
265
297
|
if ((0, helpers_1._isHex8)(color)) {
|
|
266
|
-
const rgba = (0, exports.convertHex8ToRgba)(color);
|
|
267
298
|
return {
|
|
268
|
-
rgba:
|
|
269
|
-
hsla: (0, exports.
|
|
299
|
+
rgba: (0, exports.convertHex8ToRgba)(color),
|
|
300
|
+
hsla: (0, exports.convertHex8ToHsla)(color),
|
|
270
301
|
};
|
|
271
302
|
}
|
|
272
303
|
if ((0, helpers_1._isRGBA)(color)) {
|
|
304
|
+
const rgbaValues = (0, helpers_1._extractAlphaColorValues)(color);
|
|
273
305
|
return {
|
|
274
|
-
hex8: (0, exports.convertRgbaToHex8)(...
|
|
275
|
-
hsla: (0, exports.convertRgbaToHsla)(...
|
|
306
|
+
hex8: (0, exports.convertRgbaToHex8)(...rgbaValues),
|
|
307
|
+
hsla: (0, exports.convertRgbaToHsla)(...rgbaValues),
|
|
276
308
|
};
|
|
277
309
|
}
|
|
278
310
|
if ((0, helpers_1._isHSLA)(color)) {
|
|
279
311
|
const hslaValues = (0, helpers_1._extractAlphaColorValues)(color);
|
|
280
|
-
const hex = (0, exports.convertHslToHex)(hslaValues[0], hslaValues[1], hslaValues[2]);
|
|
281
|
-
const alphaHex = (0, helpers_1._convertOpacityToHex)(Math.round(hslaValues[3] * 100));
|
|
282
312
|
return {
|
|
283
|
-
hex8:
|
|
284
|
-
rgba: (0, exports.convertHslaToRgba)(...
|
|
313
|
+
hex8: (0, exports.convertHslaToHex8)(...hslaValues),
|
|
314
|
+
rgba: (0, exports.convertHslaToRgba)(...hslaValues),
|
|
285
315
|
};
|
|
286
316
|
}
|
|
287
|
-
throw new Error(`Unrecognized Color Format
|
|
317
|
+
throw new Error(`Unrecognized Color Format! ${color}`);
|
|
288
318
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/colors/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,UAAU,EACV,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,KAA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G;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,CAIpD;AAED;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,IAAI,CAIpD;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,UAAU,CAEhE"}
|
package/dist/colors/helpers.js
CHANGED
|
@@ -112,7 +112,7 @@ function _isHex6(color) {
|
|
|
112
112
|
* @returns Boolean: `true` if it's an `RGB` color, `false` if not.
|
|
113
113
|
*/
|
|
114
114
|
function _isRGB(color) {
|
|
115
|
-
return /^rgb\(\d{1,3}
|
|
115
|
+
return /^rgb\(\d{1,3},\s*\d{1,3},\s*\d{1,3}\)$/.test(color);
|
|
116
116
|
}
|
|
117
117
|
/**
|
|
118
118
|
* * Checks if a color is in `HSL` format.
|
|
@@ -121,7 +121,7 @@ function _isRGB(color) {
|
|
|
121
121
|
* @returns Boolean: `true` if it's an `HSL` color, `false` if not.
|
|
122
122
|
*/
|
|
123
123
|
function _isHSL(color) {
|
|
124
|
-
return /^hsl\(\d{1,3}
|
|
124
|
+
return /^hsl\(\d{1,3},\s*\d{1,3}%,\s*\d{1,3}%\)$/.test(color);
|
|
125
125
|
}
|
|
126
126
|
/**
|
|
127
127
|
* @static
|
|
@@ -141,7 +141,7 @@ function _isHex8(color) {
|
|
|
141
141
|
* @returns Boolean: `true` if it's an `RGBA` color, `false` if not.
|
|
142
142
|
*/
|
|
143
143
|
function _isRGBA(color) {
|
|
144
|
-
return /^rgba\(\d{1,3}
|
|
144
|
+
return /^rgba\(\d{1,3},\s*\d{1,3},\s*\d{1,3},\s*(0|1|0?\.\d+)\)$/.test(color);
|
|
145
145
|
}
|
|
146
146
|
/**
|
|
147
147
|
* @static
|
|
@@ -151,7 +151,7 @@ function _isRGBA(color) {
|
|
|
151
151
|
* @returns Boolean: `true` if it's an `HSLA` color, `false` if not.
|
|
152
152
|
*/
|
|
153
153
|
function _isHSLA(color) {
|
|
154
|
-
return /^hsla\(\d{1,3}
|
|
154
|
+
return /^hsla\(\d{1,3},\s*\d{1,3}%,\s*\d{1,3}%,\s*(0|1|0?\.\d+)\)$/.test(color);
|
|
155
155
|
}
|
|
156
156
|
/**
|
|
157
157
|
* * Type guard to validate alpha value.
|
package/dist/colors/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Branded } from '../types';
|
|
1
2
|
/** - A string, number for generating color. */
|
|
2
3
|
export type ColorInput = string | number;
|
|
3
4
|
/** - An array of strings/numbers or nested arrays of strings/numbers for generating colors. */
|
|
@@ -14,9 +15,7 @@ export type Hex = `#${string}`;
|
|
|
14
15
|
* * Represents a hexadecimal color code.
|
|
15
16
|
* * Format: `#3C6945`
|
|
16
17
|
*/
|
|
17
|
-
export type Hex6 =
|
|
18
|
-
__hex6Brand: never;
|
|
19
|
-
};
|
|
18
|
+
export type Hex6 = Branded<`#${string}`, 'Hex6'>;
|
|
20
19
|
/**
|
|
21
20
|
* * Represents an RGB color string.
|
|
22
21
|
* * Format: `rgb(R, G, B)`
|
|
@@ -25,7 +24,7 @@ export type Hex6 = `#${string}` & {
|
|
|
25
24
|
* - G (Green): 0-255
|
|
26
25
|
* - B (Blue): 0-255
|
|
27
26
|
*/
|
|
28
|
-
export type RGB = `rgb(${number}, ${number}, ${number})`;
|
|
27
|
+
export type RGB = `rgb(${number}, ${number}, ${number})` | `rgb(${number},${number},${number})`;
|
|
29
28
|
/**
|
|
30
29
|
* * Represents an HSL color string.
|
|
31
30
|
* * Format: `hsl(H, S%, L%)`
|
|
@@ -34,28 +33,28 @@ export type RGB = `rgb(${number}, ${number}, ${number})`;
|
|
|
34
33
|
* - S (Saturation): 0-100%
|
|
35
34
|
* - L (Lightness): 0-100%
|
|
36
35
|
*/
|
|
37
|
-
export type HSL = `hsl(${number}, ${number}%, ${number}%)`;
|
|
36
|
+
export type HSL = `hsl(${number}, ${number}%, ${number}%)` | `hsl(${number},${number}%,${number}%)`;
|
|
38
37
|
/**
|
|
39
38
|
* * Represents a hexadecimal color code with optional alpha channel.
|
|
40
39
|
* * Format: `#3C6945FF`
|
|
41
40
|
*/
|
|
42
|
-
export type Hex8 =
|
|
43
|
-
__hex8Brand: never;
|
|
44
|
-
};
|
|
41
|
+
export type Hex8 = Branded<`#${string}`, 'Hex8'>;
|
|
45
42
|
/**
|
|
46
43
|
* * Represents an RGBA color string, now includes optional alpha (opacity).
|
|
47
44
|
* * Format: `rgba(R, G, B, A)`
|
|
48
45
|
*/
|
|
49
|
-
export type RGBA = `rgba(${number}, ${number}, ${number}, ${number})`;
|
|
46
|
+
export type RGBA = `rgba(${number}, ${number}, ${number}, ${number})` | `rgba(${number},${number},${number},${number})`;
|
|
50
47
|
/**
|
|
51
48
|
* * Represents an HSLA color string with optional alpha channel.
|
|
52
49
|
* * Format: `hsla(H, S%, L%, A)`
|
|
53
50
|
*/
|
|
54
|
-
export type HSLA = `hsla(${number}, ${number}%, ${number}%, ${number})`;
|
|
51
|
+
export type HSLA = `hsla(${number}, ${number}%, ${number}%, ${number})` | `hsla(${number},${number}%,${number}%,${number})`;
|
|
55
52
|
/** * Union type representing a color in Hex6, RGB, or HSL format. */
|
|
56
53
|
export type ColorTypeSolid = Hex6 | RGB | HSL;
|
|
57
54
|
/** * Union type representing a color in Hex8, RGBA, or HSLA format. */
|
|
58
55
|
export type ColorTypeAlpha = Hex8 | RGBA | HSLA;
|
|
56
|
+
/** * Union of Alpha & Solid `Hex`, `RGB` and `HSL` */
|
|
57
|
+
export type ColorType = Hex | Hex6 | RGB | HSL | Hex8 | RGBA | HSLA;
|
|
59
58
|
/** - Colors Object that includes `Hex8`, `RGBA` and `HSLA` formats of the same color. */
|
|
60
59
|
export interface SolidColors {
|
|
61
60
|
hex: Hex6;
|
|
@@ -68,7 +67,6 @@ export interface AlphaColors {
|
|
|
68
67
|
rgba: RGBA;
|
|
69
68
|
hsla: HSLA;
|
|
70
69
|
}
|
|
71
|
-
export type ColorType = ColorTypeSolid | ColorTypeAlpha | Hex;
|
|
72
70
|
/** * Represents a tuple of three numerical values corresponding to RGB or HSL color components. */
|
|
73
71
|
export type ColorNumbers = [number, number, number];
|
|
74
72
|
/** * Represents a tuple of three numerical values corresponding to RGB or HSL color components. */
|
|
@@ -97,7 +95,5 @@ export interface ConvertedColors<T extends ColorType> extends Record<string, Col
|
|
|
97
95
|
hsla: T extends HSLA | ColorTypeSolid ? never : HSLA;
|
|
98
96
|
}
|
|
99
97
|
/** Represents an alpha value between 0 and 1 */
|
|
100
|
-
export type AlphaValue = number
|
|
101
|
-
__brand: 'AlphaValue';
|
|
102
|
-
};
|
|
98
|
+
export type AlphaValue = Branded<number, 'AlphaValue'>;
|
|
103
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,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;;;GAGG;AACH,MAAM,MAAM,IAAI,GAAG,IAAI,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/colors/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAExC,+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;;;GAGG;AACH,MAAM,MAAM,IAAI,GAAG,OAAO,CAA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3B,IAAI,EAAE,IAAI,CAAC;IACX,IAAI,EAAE,IAAI,CAAC;IACX,IAAI,EAAE,IAAI,CAAC;CACX;AAED,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;AAED,gDAAgD;AAChD,MAAM,MAAM,UAAU,GAAG,OAAO,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ 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, convertHex8ToRgba, convertHexToHsl, convertHexToRgb, convertHslaToRgba, convertHslToHex, convertHslToRgb, convertRgbaToHex8, convertRgbaToHsla, convertRgbToHex, convertRgbToHsl, convertRgbToRgba, } from './colors/convert';
|
|
10
|
+
export { convertColorCode, convertHex8ToHsla, convertHex8ToRgba, convertHexToHsl, convertHexToRgb, convertHslaToHex8, convertHslaToRgba, convertHslToHex, convertHslToRgb, convertRgbaToHex8, convertRgbaToHsla, convertRgbToHex, convertRgbToHsl, convertRgbToRgba, } from './colors/convert';
|
|
11
11
|
export { Color } from './colors/Color';
|
|
12
12
|
export { filterArrayOfObjects, flattenArray, isValidButEmptyArray, shuffleArray, } from './array/basics';
|
|
13
13
|
export { sortAnArray } from './array/sort';
|
|
@@ -15,7 +15,7 @@ export { createOptionsArray, removeDuplicatesFromArray, } from './array/transfor
|
|
|
15
15
|
export { convertIntoFormData, isEmptyFormData } from './form/convert';
|
|
16
16
|
export { createControlledFormData } from './form/transform';
|
|
17
17
|
export { cloneObject, countObjectFields, generateQueryParams, isEmptyObject, isObject, } from './object/basics';
|
|
18
|
-
export { extractNewFields, extractUpdatedAndNewFields, extractUpdatedFields,
|
|
18
|
+
export { extractNewFields, extractUpdatedAndNewFields, extractUpdatedFields, flattenObjectDotNotation, flattenObjectKeyValue, mergeAndFlattenObjects, mergeObjects, } from './object/objectify';
|
|
19
19
|
export { sanitizeData } from './object/sanitize';
|
|
20
20
|
export { convertObjectValues } from './object/convert';
|
|
21
21
|
export { convertArrayToString, isDeepEqual } from './utils';
|
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,E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ACb,QAAQ,GACR,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACN,gBAAgB,EAChB,0BAA0B,EAC1B,oBAAoB,EACpB,wBAAwB,EACxB,qBAAqB,EACrB,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,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.isDeepEqual = exports.convertArrayToString = exports.convertObjectValues = void 0;
|
|
3
|
+
exports.flattenObjectKeyValue = exports.flattenObjectDotNotation = 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.convertHslaToHex8 = exports.convertHexToRgb = exports.convertHexToHsl = exports.convertHex8ToRgba = exports.convertHex8ToHsla = 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 = exports.sanitizeData = exports.mergeObjects = exports.mergeAndFlattenObjects = void 0;
|
|
5
5
|
var basics_1 = require("./string/basics");
|
|
6
6
|
Object.defineProperty(exports, "capitalizeString", { enumerable: true, get: function () { return basics_1.capitalizeString; } });
|
|
7
7
|
Object.defineProperty(exports, "generateRandomID", { enumerable: true, get: function () { return basics_1.generateRandomID; } });
|
|
@@ -28,9 +28,11 @@ Object.defineProperty(exports, "generateRandomColorInHexRGB", { enumerable: true
|
|
|
28
28
|
Object.defineProperty(exports, "generateRandomHSLColor", { enumerable: true, get: function () { return random_1.generateRandomHSLColor; } });
|
|
29
29
|
var convert_3 = require("./colors/convert");
|
|
30
30
|
Object.defineProperty(exports, "convertColorCode", { enumerable: true, get: function () { return convert_3.convertColorCode; } });
|
|
31
|
+
Object.defineProperty(exports, "convertHex8ToHsla", { enumerable: true, get: function () { return convert_3.convertHex8ToHsla; } });
|
|
31
32
|
Object.defineProperty(exports, "convertHex8ToRgba", { enumerable: true, get: function () { return convert_3.convertHex8ToRgba; } });
|
|
32
33
|
Object.defineProperty(exports, "convertHexToHsl", { enumerable: true, get: function () { return convert_3.convertHexToHsl; } });
|
|
33
34
|
Object.defineProperty(exports, "convertHexToRgb", { enumerable: true, get: function () { return convert_3.convertHexToRgb; } });
|
|
35
|
+
Object.defineProperty(exports, "convertHslaToHex8", { enumerable: true, get: function () { return convert_3.convertHslaToHex8; } });
|
|
34
36
|
Object.defineProperty(exports, "convertHslaToRgba", { enumerable: true, get: function () { return convert_3.convertHslaToRgba; } });
|
|
35
37
|
Object.defineProperty(exports, "convertHslToHex", { enumerable: true, get: function () { return convert_3.convertHslToHex; } });
|
|
36
38
|
Object.defineProperty(exports, "convertHslToRgb", { enumerable: true, get: function () { return convert_3.convertHslToRgb; } });
|
|
@@ -66,7 +68,8 @@ var objectify_1 = require("./object/objectify");
|
|
|
66
68
|
Object.defineProperty(exports, "extractNewFields", { enumerable: true, get: function () { return objectify_1.extractNewFields; } });
|
|
67
69
|
Object.defineProperty(exports, "extractUpdatedAndNewFields", { enumerable: true, get: function () { return objectify_1.extractUpdatedAndNewFields; } });
|
|
68
70
|
Object.defineProperty(exports, "extractUpdatedFields", { enumerable: true, get: function () { return objectify_1.extractUpdatedFields; } });
|
|
69
|
-
Object.defineProperty(exports, "
|
|
71
|
+
Object.defineProperty(exports, "flattenObjectDotNotation", { enumerable: true, get: function () { return objectify_1.flattenObjectDotNotation; } });
|
|
72
|
+
Object.defineProperty(exports, "flattenObjectKeyValue", { enumerable: true, get: function () { return objectify_1.flattenObjectKeyValue; } });
|
|
70
73
|
Object.defineProperty(exports, "mergeAndFlattenObjects", { enumerable: true, get: function () { return objectify_1.mergeAndFlattenObjects; } });
|
|
71
74
|
Object.defineProperty(exports, "mergeObjects", { enumerable: true, get: function () { return objectify_1.mergeObjects; } });
|
|
72
75
|
var sanitize_1 = require("./object/sanitize");
|
package/dist/object/basics.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { GenericObject, QueryObject } from './types';
|
|
|
2
2
|
/**
|
|
3
3
|
* * Utility to generate query parameters from an object.
|
|
4
4
|
*
|
|
5
|
-
* @template T - A generic type extending `
|
|
5
|
+
* @template T - A generic type extending `QueryObject`.
|
|
6
6
|
* @param params - Object containing query parameters.
|
|
7
7
|
* @returns A query string as a URL-encoded string, e.g., `?key1=value1&key2=value2`.
|
|
8
8
|
*
|
|
@@ -10,6 +10,8 @@ import type { GenericObject, QueryObject } from './types';
|
|
|
10
10
|
* generateQueryParams({ key1: 'value1', key2: 42 }); // "?key1=value1&key2=42"
|
|
11
11
|
* generateQueryParams({ key1: ['value1', 'value2'], key2: 42 }); // "?key1=value1&key1=value2&key2=42"
|
|
12
12
|
* generateQueryParams({ key1: '', key2: null }); // ""
|
|
13
|
+
* generateQueryParams({ key1: true, key2: false }); // "?key1=true&key2=false"
|
|
14
|
+
* generateQueryParams({ filters: { category: 'laptop', price: 1000 } }); // "?category=laptop&price=1000"
|
|
13
15
|
*/
|
|
14
16
|
export declare const generateQueryParams: <T extends QueryObject>(params?: T) => string;
|
|
15
17
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"basics.d.ts","sourceRoot":"","sources":["../../src/object/basics.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"basics.d.ts","sourceRoot":"","sources":["../../src/object/basics.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE1D;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,mBAAmB,GAAI,CAAC,SAAS,WAAW,WAChD,CAAC,KACP,MAkCF,CAAC;AACF;;;;;GAKG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS,aAAa,OAAO,CAAC,KAAG,CAE7D,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,aAAa,GAAI,CAAC,SAAS,aAAa,OAAO,CAAC,KAAG,OAE/D,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,GAAI,CAAC,SAAS,aAAa,OAAO,CAAC,KAAG,MAEnE,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,SAAU,OAAO,KAAG,OAExC,CAAC"}
|
package/dist/object/basics.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isObject = exports.countObjectFields = exports.isEmptyObject = exports.cloneObject = exports.generateQueryParams = void 0;
|
|
4
|
+
const objectify_1 = require("./objectify");
|
|
4
5
|
/**
|
|
5
6
|
* * Utility to generate query parameters from an object.
|
|
6
7
|
*
|
|
7
|
-
* @template T - A generic type extending `
|
|
8
|
+
* @template T - A generic type extending `QueryObject`.
|
|
8
9
|
* @param params - Object containing query parameters.
|
|
9
10
|
* @returns A query string as a URL-encoded string, e.g., `?key1=value1&key2=value2`.
|
|
10
11
|
*
|
|
@@ -12,9 +13,14 @@ exports.isObject = exports.countObjectFields = exports.isEmptyObject = exports.c
|
|
|
12
13
|
* generateQueryParams({ key1: 'value1', key2: 42 }); // "?key1=value1&key2=42"
|
|
13
14
|
* generateQueryParams({ key1: ['value1', 'value2'], key2: 42 }); // "?key1=value1&key1=value2&key2=42"
|
|
14
15
|
* generateQueryParams({ key1: '', key2: null }); // ""
|
|
16
|
+
* generateQueryParams({ key1: true, key2: false }); // "?key1=true&key2=false"
|
|
17
|
+
* generateQueryParams({ filters: { category: 'laptop', price: 1000 } }); // "?category=laptop&price=1000"
|
|
15
18
|
*/
|
|
16
19
|
const generateQueryParams = (params = {}) => {
|
|
17
|
-
|
|
20
|
+
// Flatten the nested object into key-value pairs
|
|
21
|
+
const flattenedParams = (0, objectify_1.flattenObjectKeyValue)(params);
|
|
22
|
+
// Generate the query string
|
|
23
|
+
const queryParams = Object.entries(flattenedParams)
|
|
18
24
|
.filter(([_, value]) => value !== undefined &&
|
|
19
25
|
value !== null &&
|
|
20
26
|
!(typeof value === 'string' && value.trim() === ''))
|
|
@@ -23,8 +29,8 @@ const generateQueryParams = (params = {}) => {
|
|
|
23
29
|
.filter((v) => v !== undefined &&
|
|
24
30
|
v !== null &&
|
|
25
31
|
!(typeof v === 'string' && v.trim() === ''))
|
|
26
|
-
.map((v) => `${encodeURIComponent(key)}=${encodeURIComponent(String(v))}`)
|
|
27
|
-
: `${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`)
|
|
32
|
+
.map((v) => `${encodeURIComponent(key)}=${encodeURIComponent(typeof v === 'boolean' ? String(v) : String(v))}`)
|
|
33
|
+
: `${encodeURIComponent(key)}=${encodeURIComponent(typeof value === 'boolean' ? String(value) : String(value))}`)
|
|
28
34
|
.join('&');
|
|
29
35
|
return queryParams ? `?${queryParams}` : '';
|
|
30
36
|
};
|
|
@@ -15,13 +15,20 @@ export declare const mergeObjects: <T extends GenericObject>(...objects: T[]) =>
|
|
|
15
15
|
* @returns Merged object with flattened structure.
|
|
16
16
|
*/
|
|
17
17
|
export declare const mergeAndFlattenObjects: <T extends GenericObject>(...objects: T[]) => GenericObject;
|
|
18
|
+
/**
|
|
19
|
+
* * Flattens a nested object into key-value format.
|
|
20
|
+
*
|
|
21
|
+
* @param object - The `object` to flatten.
|
|
22
|
+
* @returns A `flattened object` in key-value format.
|
|
23
|
+
*/
|
|
24
|
+
export declare const flattenObjectKeyValue: <T extends LooseObject>(object: T) => T;
|
|
18
25
|
/**
|
|
19
26
|
* * Flattens a nested object into a dot notation format.
|
|
20
27
|
*
|
|
21
28
|
* @param object - The `object` to flatten.
|
|
22
29
|
* @returns A `flattened object` with dot notation keys.
|
|
23
30
|
*/
|
|
24
|
-
export declare const
|
|
31
|
+
export declare const flattenObjectDotNotation: <T extends GenericObject>(object: T) => GenericObject;
|
|
25
32
|
/**
|
|
26
33
|
* * Extracts only the fields that have changed between the original and updated object.
|
|
27
34
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"objectify.d.ts","sourceRoot":"","sources":["../../src/object/objectify.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE1D;;;;;GAKG;AACH,eAAO,MAAM,YAAY,GAAI,CAAC,SAAS,aAAa,cAAc,CAAC,EAAE,KAAG,CAuCvE,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,sBAAsB,GAAI,CAAC,SAAS,aAAa,cACjD,CAAC,EAAE,KACb,aAyBF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"objectify.d.ts","sourceRoot":"","sources":["../../src/object/objectify.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE1D;;;;;GAKG;AACH,eAAO,MAAM,YAAY,GAAI,CAAC,SAAS,aAAa,cAAc,CAAC,EAAE,KAAG,CAuCvE,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,sBAAsB,GAAI,CAAC,SAAS,aAAa,cACjD,CAAC,EAAE,KACb,aAyBF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,GAAI,CAAC,SAAS,WAAW,UAAU,CAAC,KAAG,CAmBxE,CAAC;AACF;;;;;GAKG;AACH,eAAO,MAAM,wBAAwB,GAAI,CAAC,SAAS,aAAa,UACvD,CAAC,KACP,aAkCF,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,GAAI,CAAC,SAAS,WAAW,cAC7C,CAAC,iBACE,OAAO,CAAC,CAAC,CAAC,KACvB,OAAO,CAAC,CAAC,CAwBX,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,GAAI,CAAC,SAAS,WAAW,cACzC,CAAC,iBACE,OAAO,CAAC,CAAC,CAAC,KACvB,OAAO,CAAC,CAAC,CAqBX,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,0BAA0B,GAAI,CAAC,SAAS,WAAW,cACnD,CAAC,iBACE,OAAO,CAAC,CAAC,CAAC,GAAG,WAAW,KACrC,OAAO,CAAC,CAAC,CAAC,GAAG,WAwBf,CAAC"}
|
package/dist/object/objectify.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.extractUpdatedAndNewFields = exports.extractNewFields = exports.extractUpdatedFields = exports.
|
|
3
|
+
exports.extractUpdatedAndNewFields = exports.extractNewFields = exports.extractUpdatedFields = exports.flattenObjectDotNotation = exports.flattenObjectKeyValue = exports.mergeAndFlattenObjects = exports.mergeObjects = void 0;
|
|
4
4
|
const utils_1 = require("../utils");
|
|
5
5
|
const basics_1 = require("./basics");
|
|
6
6
|
/**
|
|
@@ -70,13 +70,37 @@ const mergeAndFlattenObjects = (...objects) => {
|
|
|
70
70
|
return result;
|
|
71
71
|
};
|
|
72
72
|
exports.mergeAndFlattenObjects = mergeAndFlattenObjects;
|
|
73
|
+
/**
|
|
74
|
+
* * Flattens a nested object into key-value format.
|
|
75
|
+
*
|
|
76
|
+
* @param object - The `object` to flatten.
|
|
77
|
+
* @returns A `flattened object` in key-value format.
|
|
78
|
+
*/
|
|
79
|
+
const flattenObjectKeyValue = (object) => {
|
|
80
|
+
const flattened = {};
|
|
81
|
+
for (const [key, value] of Object.entries(object)) {
|
|
82
|
+
if (typeof value === 'object' &&
|
|
83
|
+
value !== null &&
|
|
84
|
+
!Array.isArray(value)) {
|
|
85
|
+
// Recursively flatten nested objects
|
|
86
|
+
const nestedFlattened = (0, exports.flattenObjectKeyValue)(value);
|
|
87
|
+
Object.assign(flattened, nestedFlattened);
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
// Directly assign non-object values
|
|
91
|
+
flattened[key] = value;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return flattened;
|
|
95
|
+
};
|
|
96
|
+
exports.flattenObjectKeyValue = flattenObjectKeyValue;
|
|
73
97
|
/**
|
|
74
98
|
* * Flattens a nested object into a dot notation format.
|
|
75
99
|
*
|
|
76
100
|
* @param object - The `object` to flatten.
|
|
77
101
|
* @returns A `flattened object` with dot notation keys.
|
|
78
102
|
*/
|
|
79
|
-
const
|
|
103
|
+
const flattenObjectDotNotation = (object) => {
|
|
80
104
|
/**
|
|
81
105
|
* * Recursively flattens an object, transforming nested structures into dot-notation keys.
|
|
82
106
|
*
|
|
@@ -89,7 +113,10 @@ const flattenObject = (object) => {
|
|
|
89
113
|
for (const [key, value] of Object.entries(source)) {
|
|
90
114
|
// Construct the dot-notation key
|
|
91
115
|
const newKey = prefix ? `${String(prefix)}.${key}` : key;
|
|
92
|
-
if (value &&
|
|
116
|
+
if (value &&
|
|
117
|
+
typeof value === 'object' &&
|
|
118
|
+
!Array.isArray(value) &&
|
|
119
|
+
value !== null) {
|
|
93
120
|
// Recursively process nested objects
|
|
94
121
|
Object.assign(flattened, _flattenObject(value, newKey));
|
|
95
122
|
}
|
|
@@ -103,7 +130,7 @@ const flattenObject = (object) => {
|
|
|
103
130
|
// Call the recursive function with an empty prefix initially
|
|
104
131
|
return _flattenObject(object);
|
|
105
132
|
};
|
|
106
|
-
exports.
|
|
133
|
+
exports.flattenObjectDotNotation = flattenObjectDotNotation;
|
|
107
134
|
/**
|
|
108
135
|
* * Extracts only the fields that have changed between the original and updated object.
|
|
109
136
|
*
|
package/dist/object/types.d.ts
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
|
+
import type { Primitive } from '../types';
|
|
1
2
|
/** - Generic object with `unknown` value */
|
|
2
3
|
export type GenericObject = Record<string, unknown>;
|
|
3
4
|
/** - Generic object but with `any` value */
|
|
4
5
|
export type LooseObject = Record<string, any>;
|
|
5
|
-
/**
|
|
6
|
-
|
|
6
|
+
/**
|
|
7
|
+
* * Represents a value that can be used in a query object.
|
|
8
|
+
* - Can be a primitive, an array of primitives, or a nested query object.
|
|
9
|
+
*/
|
|
10
|
+
export type QueryObjectValue = Primitive | Primitive[] | QueryObject;
|
|
11
|
+
/**
|
|
12
|
+
* * Represents a query object with string keys and `QueryObjectValue` values.
|
|
13
|
+
* - Supports nested objects and arrays.
|
|
14
|
+
*/
|
|
15
|
+
export type QueryObject = {
|
|
16
|
+
[key: string]: QueryObjectValue;
|
|
17
|
+
};
|
|
7
18
|
/** - Dot-notation keys for nested objects */
|
|
8
19
|
export type DotNotationKey<T> = T extends GenericObject ? {
|
|
9
20
|
[K in keyof T & string]: T[K] extends GenericObject ? `${K}` | `${K}.${DotNotationKey<T[K]>}` : `${K}`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/object/types.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAA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AM,WAAW,CAAC,CAAC,IAAI;KAC3B,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,WAAW,CAAC,CAAC,CAAC,EAAE,GACzD,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAC1D,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,GAC5B,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAC1B,MAAM;CACR,CAAC"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
1
|
/** Uncontrolled any to use for edge cases */
|
|
2
2
|
export type UncontrolledAny = any;
|
|
3
|
+
declare const __brand: unique symbol;
|
|
4
|
+
type Brand<B> = {
|
|
5
|
+
[__brand]: B;
|
|
6
|
+
};
|
|
7
|
+
/** Create a branded type. */
|
|
8
|
+
export type Branded<T, B> = T & Brand<B>;
|
|
9
|
+
/** Union of Primitive Types */
|
|
10
|
+
export type Primitive = string | number | boolean | null | undefined;
|
|
11
|
+
export {};
|
|
3
12
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,MAAM,MAAM,eAAe,GAAG,GAAG,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,MAAM,MAAM,eAAe,GAAG,GAAG,CAAC;AAElC,OAAO,CAAC,MAAM,OAAO,EAAE,OAAO,MAAM,CAAC;AACrC,KAAK,KAAK,CAAC,CAAC,IAAI;IAAE,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;CAAE,CAAC;AAEjC,6BAA6B;AAC7B,MAAM,MAAM,OAAO,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;AAEzC,+BAA+B;AAC/B,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC"}
|
package/package.json
CHANGED