nhb-toolbox 1.4.0 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,51 +1,91 @@
1
+ import type { ColorNumbers, Hex, HSL, RGB } from './types';
1
2
  /**
2
- * Converts HSL to RGB color format.
3
+ * * Converts HSL to RGB color format.
3
4
  *
4
5
  * @param h - The hue component of the HSL color, in degrees (0 to 360).
5
6
  * @param s - The saturation component of the HSL color, as a percentage (0 to 100).
6
7
  * @param l - The lightness component of the HSL color, as a percentage (0 to 100).
7
8
  * @returns A string representing the color in RGB format (e.g., `rgb(255, 0, 0)`).
8
9
  */
9
- export declare const convertHslToRgb: (h: number, s: number, l: number) => string;
10
+ export declare const convertHslToRgb: (h: number, s: number, l: number) => RGB;
10
11
  /**
11
- * Converts RGB to HSL color format.
12
+ * * Converts RGB to HSL color format.
12
13
  *
13
14
  * @param r - The red component of the RGB color, in the range 0 to 255.
14
15
  * @param g - The green component of the RGB color, in the range 0 to 255.
15
16
  * @param b - The blue component of the RGB color, in the range 0 to 255.
16
17
  * @returns A string representing the color in HSL format (e.g., `hsl(0, 100%, 50%)`).
17
18
  */
18
- export declare const convertRgbToHsl: (r: number, g: number, b: number) => string;
19
+ export declare const convertRgbToHsl: (r: number, g: number, b: number) => HSL;
19
20
  /**
20
- * Converts HSL to Hex color format.
21
+ * * Converts HSL to Hex color format.
21
22
  *
22
23
  * @param h - The hue component of the HSL color, in degrees (0 to 360).
23
24
  * @param s - The saturation component of the HSL color, as a percentage (0 to 100).
24
25
  * @param l - The lightness component of the HSL color, as a percentage (0 to 100).
25
26
  * @returns A string representing the color in Hex format (e.g., `#FF0000`).
26
27
  */
27
- export declare const convertHslToHex: (h: number, s: number, l: number) => string;
28
+ export declare const convertHslToHex: (h: number, s: number, l: number) => Hex;
28
29
  /**
29
- * Converts Hex to HSL color format.
30
+ * * Converts Hex to HSL color format.
30
31
  *
31
32
  * @param hex - A string representing the color in Hex format (e.g., `#FF0000`).
32
33
  * @returns A string representing the color in HSL format (e.g., `hsl(0, 100%, 50%)`).
33
34
  */
34
- export declare const convertHexToHsl: (hex: string) => string;
35
+ export declare const convertHexToHsl: (hex: Hex | string) => HSL;
35
36
  /**
36
- * Converts RGB to Hex color format.
37
+ * * Converts RGB to Hex color format.
37
38
  *
38
39
  * @param r - The red component of the RGB color, in the range 0 to 255.
39
40
  * @param g - The green component of the RGB color, in the range 0 to 255.
40
41
  * @param b - The blue component of the RGB color, in the range 0 to 255.
42
+ * @param a - The alpha opacity of the RGB color, in the range 0 to 255.
41
43
  * @returns A string representing the color in Hex format (e.g., `#FF0000`).
42
44
  */
43
- export declare const convertRgbToHex: (r: number, g: number, b: number) => string;
45
+ export declare const convertRgbToHex: (r: number, g: number, b: number, a?: number) => Hex;
44
46
  /**
45
- * Converts Hex to RGB color format.
47
+ * * Converts Hex to RGB color format.
46
48
  *
47
49
  * @param hex - A string representing the color in Hex format (e.g., `#FF0000`).
48
50
  * @returns A string representing the color in RGB format (e.g., `rgb(255, 0, 0)`).
49
51
  */
50
- export declare const convertHexToRgb: (hex: string) => string;
52
+ export declare const convertHexToRgb: (hex: Hex | string) => RGB;
53
+ /**
54
+ * * Extracts numbers from a color string like `rgb(66, 103, 69)` or `hsl(120, 42.86%, 41.18%)`.
55
+ * * Converts percentage values to decimal (e.g., `42.86%` → `42.86`).
56
+ *
57
+ * @param colorString The color string in RGB or HSL format.
58
+ * @returns An array of extracted numbers.
59
+ */
60
+ export declare const extractNumbersFromColor: (colorString: HSL | RGB) => ColorNumbers;
61
+ /**
62
+ * * Converts a `Hex` color code to `RGB` and `HSL` formats.
63
+ *
64
+ * @param color The `Hex` color code (e.g., `#3c6945`).
65
+ * @returns An object containing the `RGB` and `HSL` formats of the given `Hex` color.
66
+ */
67
+ export declare function convertColorCode(color: Hex): {
68
+ rgb: RGB;
69
+ hsl: HSL;
70
+ };
71
+ /**
72
+ * * Converts an `RGB` color to `Hex` and `HSL` formats.
73
+ *
74
+ * @param color The `RGB` color string (e.g., `rgb(60, 105, 69)`).
75
+ * @returns An object containing the `Hex` and `HSL` formats of the given `RGB` color.
76
+ */
77
+ export declare function convertColorCode(color: RGB): {
78
+ hex: Hex;
79
+ hsl: HSL;
80
+ };
81
+ /**
82
+ * * Converts an `HSL` color to `Hex` and `RGB` formats.
83
+ *
84
+ * @param color The `HSL` color string (e.g., `hsl(132, 27.27%, 32.35%)`).
85
+ * @returns An object containing the `Hex` and `RGB` formats of the given `HSL` color.
86
+ */
87
+ export declare function convertColorCode(color: HSL): {
88
+ hex: Hex;
89
+ rgb: RGB;
90
+ };
51
91
  //# sourceMappingURL=convert.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"convert.d.ts","sourceRoot":"","sources":["../../src/colors/convert.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,MAAO,MAAM,KAAK,MAAM,KAAK,MAAM,KAAG,MAuCjE,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,MAAO,MAAM,KAAK,MAAM,KAAK,MAAM,KAAG,MAoCjE,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,MAAO,MAAM,KAAK,MAAM,KAAK,MAAM,KAAG,MAKjE,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,eAAe,QAAS,MAAM,KAAG,MAU7C,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,MAAO,MAAM,KAAK,MAAM,KAAK,MAAM,KAAG,MAEjE,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,eAAe,QAAS,MAAM,KAAG,MAU7C,CAAC"}
1
+ {"version":3,"file":"convert.d.ts","sourceRoot":"","sources":["../../src/colors/convert.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEX,YAAY,EAEZ,GAAG,EACH,GAAG,EACH,GAAG,EACH,MAAM,SAAS,CAAC;AAEjB;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,MAAO,MAAM,KAAK,MAAM,KAAK,MAAM,KAAG,GAwBjE,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,MAAO,MAAM,KAAK,MAAM,KAAK,MAAM,KAAG,GAkCjE,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,MAAO,MAAM,KAAK,MAAM,KAAK,MAAM,KAAG,GAIjE,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,eAAe,QAAS,GAAG,GAAG,MAAM,KAAG,GAenD,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,eAAe,MACxB,MAAM,KACN,MAAM,KACN,MAAM,MACL,MAAM,KACR,GAcF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,eAAe,QAAS,GAAG,GAAG,MAAM,KAAG,GAgBnD,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,uBAAuB,gBACtB,GAAG,GAAG,GAAG,KACpB,YAIF,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,GAAG,GAAG;IAC7C,GAAG,EAAE,GAAG,CAAC;IACT,GAAG,EAAE,GAAG,CAAC;CACT,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,GAAG,GAAG;IAC7C,GAAG,EAAE,GAAG,CAAC;IACT,GAAG,EAAE,GAAG,CAAC;CACT,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,GAAG,GAAG;IAC7C,GAAG,EAAE,GAAG,CAAC;IACT,GAAG,EAAE,GAAG,CAAC;CACT,CAAC"}
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.convertHexToRgb = exports.convertRgbToHex = exports.convertHexToHsl = exports.convertHslToHex = exports.convertRgbToHsl = exports.convertHslToRgb = void 0;
3
+ exports.extractNumbersFromColor = exports.convertHexToRgb = exports.convertRgbToHex = exports.convertHexToHsl = exports.convertHslToHex = exports.convertRgbToHsl = exports.convertHslToRgb = void 0;
4
+ exports.convertColorCode = convertColorCode;
4
5
  /**
5
- * Converts HSL to RGB color format.
6
+ * * Converts HSL to RGB color format.
6
7
  *
7
8
  * @param h - The hue component of the HSL color, in degrees (0 to 360).
8
9
  * @param s - The saturation component of the HSL color, as a percentage (0 to 100).
@@ -17,31 +18,18 @@ const convertHslToRgb = (h, s, l) => {
17
18
  const x = c * (1 - Math.abs(((h / 60) % 2) - 1));
18
19
  const m = l - c / 2;
19
20
  let r = 0, g = 0, b = 0;
20
- if (h >= 0 && h < 60) {
21
- r = c;
22
- g = x;
23
- }
24
- else if (h >= 60 && h < 120) {
25
- r = x;
26
- g = c;
27
- }
28
- else if (h >= 120 && h < 180) {
29
- g = c;
30
- b = x;
31
- }
32
- else if (h >= 180 && h < 240) {
33
- g = x;
34
- b = c;
35
- }
36
- else if (h >= 240 && h < 300) {
37
- r = x;
38
- b = c;
39
- }
40
- else if (h >= 300 && h < 360) {
41
- r = c;
42
- b = x;
43
- }
44
- // Convert RGB to 0-255 range and apply m
21
+ if (h >= 0 && h < 60)
22
+ [r, g] = [c, x];
23
+ else if (h >= 60 && h < 120)
24
+ [r, g] = [x, c];
25
+ else if (h >= 120 && h < 180)
26
+ [g, b] = [c, x];
27
+ else if (h >= 180 && h < 240)
28
+ [g, b] = [x, c];
29
+ else if (h >= 240 && h < 300)
30
+ [r, b] = [x, c];
31
+ else if (h >= 300 && h < 360)
32
+ [r, b] = [c, x];
45
33
  r = Math.round((r + m) * 255);
46
34
  g = Math.round((g + m) * 255);
47
35
  b = Math.round((b + m) * 255);
@@ -49,7 +37,7 @@ const convertHslToRgb = (h, s, l) => {
49
37
  };
50
38
  exports.convertHslToRgb = convertHslToRgb;
51
39
  /**
52
- * Converts RGB to HSL color format.
40
+ * * Converts RGB to HSL color format.
53
41
  *
54
42
  * @param r - The red component of the RGB color, in the range 0 to 255.
55
43
  * @param g - The green component of the RGB color, in the range 0 to 255.
@@ -57,40 +45,34 @@ exports.convertHslToRgb = convertHslToRgb;
57
45
  * @returns A string representing the color in HSL format (e.g., `hsl(0, 100%, 50%)`).
58
46
  */
59
47
  const convertRgbToHsl = (r, g, b) => {
60
- // Normalize the RGB values
61
48
  r /= 255;
62
49
  g /= 255;
63
50
  b /= 255;
64
51
  const max = Math.max(r, g, b);
65
52
  const min = Math.min(r, g, b);
66
- const delta = max - min;
67
- let h = 0, s = 0, l = (max + min) / 2;
68
- if (delta !== 0) {
69
- if (max === r) {
70
- h = (g - b) / delta;
53
+ let h = 0, s = 0;
54
+ const l = (max + min) / 2;
55
+ if (max !== min) {
56
+ const diff = max - min;
57
+ s = l > 0.5 ? diff / (2 - max - min) : diff / (max + min);
58
+ switch (max) {
59
+ case r:
60
+ h = (g - b) / diff + (g < b ? 6 : 0);
61
+ break;
62
+ case g:
63
+ h = (b - r) / diff + 2;
64
+ break;
65
+ case b:
66
+ h = (r - g) / diff + 4;
67
+ break;
71
68
  }
72
- else if (max === g) {
73
- h = (b - r) / delta + 2;
74
- }
75
- else {
76
- h = (r - g) / delta + 4;
77
- }
78
- s = delta / (1 - Math.abs(2 * l - 1));
79
69
  h *= 60;
80
- if (s === 0)
81
- l = Math.round(l * 100); // for pure colors
82
- }
83
- else {
84
- s = 0;
85
70
  }
86
- h = Math.round(h);
87
- s = Math.round(s * 100);
88
- l = Math.round(l * 100);
89
- return `hsl(${h}, ${s}%, ${l}%)`;
71
+ return `hsl(${Math.round(h)}, ${Number((s * 100).toFixed(2))}%, ${Number((l * 100).toFixed(2))}%)`;
90
72
  };
91
73
  exports.convertRgbToHsl = convertRgbToHsl;
92
74
  /**
93
- * Converts HSL to Hex color format.
75
+ * * Converts HSL to Hex color format.
94
76
  *
95
77
  * @param h - The hue component of the HSL color, in degrees (0 to 360).
96
78
  * @param s - The saturation component of the HSL color, as a percentage (0 to 100).
@@ -98,52 +80,110 @@ exports.convertRgbToHsl = convertRgbToHsl;
98
80
  * @returns A string representing the color in Hex format (e.g., `#FF0000`).
99
81
  */
100
82
  const convertHslToHex = (h, s, l) => {
101
- const rgb = (0, exports.convertHslToRgb)(h, s, l);
102
- const [r, g, b] = rgb.match(/\d+/g).map((value) => parseInt(value, 10));
103
- return `#${((1 << 24) | (r << 16) | (g << 8) | b).toString(16).slice(1).toUpperCase().padStart(6, '0')}`;
83
+ const rgb = (0, exports.convertHslToRgb)(h, s, l).match(/\d+/g).map(Number);
84
+ return (0, exports.convertRgbToHex)(rgb[0], rgb[1], rgb[2]);
104
85
  };
105
86
  exports.convertHslToHex = convertHslToHex;
106
87
  /**
107
- * Converts Hex to HSL color format.
88
+ * * Converts Hex to HSL color format.
108
89
  *
109
90
  * @param hex - A string representing the color in Hex format (e.g., `#FF0000`).
110
91
  * @returns A string representing the color in HSL format (e.g., `hsl(0, 100%, 50%)`).
111
92
  */
112
93
  const convertHexToHsl = (hex) => {
113
- const hexCode = hex.replace('#', '');
114
- // Parse the hex value
115
- const r = parseInt(hexCode.slice(0, 2), 16);
116
- const g = parseInt(hexCode.slice(2, 4), 16);
117
- const b = parseInt(hexCode.slice(4, 6), 16);
118
- // Convert RGB to HSL
94
+ let newHex = hex.replace('#', '');
95
+ if (newHex.length === 3) {
96
+ newHex = newHex
97
+ .split('')
98
+ .map((char) => char + char)
99
+ .join('');
100
+ }
101
+ const r = parseInt(newHex.slice(0, 2), 16);
102
+ const g = parseInt(newHex.slice(2, 4), 16);
103
+ const b = parseInt(newHex.slice(4, 6), 16);
119
104
  return (0, exports.convertRgbToHsl)(r, g, b);
120
105
  };
121
106
  exports.convertHexToHsl = convertHexToHsl;
122
107
  /**
123
- * Converts RGB to Hex color format.
108
+ * * Converts RGB to Hex color format.
124
109
  *
125
110
  * @param r - The red component of the RGB color, in the range 0 to 255.
126
111
  * @param g - The green component of the RGB color, in the range 0 to 255.
127
112
  * @param b - The blue component of the RGB color, in the range 0 to 255.
113
+ * @param a - The alpha opacity of the RGB color, in the range 0 to 255.
128
114
  * @returns A string representing the color in Hex format (e.g., `#FF0000`).
129
115
  */
130
- const convertRgbToHex = (r, g, b) => {
131
- return `#${((1 << 24) | (r << 16) | (g << 8) | b).toString(16).slice(1).toUpperCase().padStart(6, '0')}`;
116
+ const convertRgbToHex = (r, g, b, a) => {
117
+ let hex = [r, g, b]
118
+ .map((v) => v.toString(16).padStart(2, '0'))
119
+ .join('')
120
+ .toUpperCase();
121
+ if (a !== undefined) {
122
+ const alphaHex = Math.round(a * 255)
123
+ .toString(16)
124
+ .padStart(2, '0');
125
+ hex += alphaHex;
126
+ }
127
+ return `#${hex}`;
132
128
  };
133
129
  exports.convertRgbToHex = convertRgbToHex;
134
130
  /**
135
- * Converts Hex to RGB color format.
131
+ * * Converts Hex to RGB color format.
136
132
  *
137
133
  * @param hex - A string representing the color in Hex format (e.g., `#FF0000`).
138
134
  * @returns A string representing the color in RGB format (e.g., `rgb(255, 0, 0)`).
139
135
  */
140
136
  const convertHexToRgb = (hex) => {
141
137
  // Remove the # if present
142
- hex = hex.replace('#', '');
143
- // Parse the hex value
144
- const r = parseInt(hex.slice(0, 2), 16);
145
- const g = parseInt(hex.slice(2, 4), 16);
146
- const b = parseInt(hex.slice(4, 6), 16);
138
+ let newHex = hex.replace('#', '');
139
+ if (newHex.length === 3) {
140
+ newHex = newHex
141
+ .split('')
142
+ .map((char) => char + char)
143
+ .join('');
144
+ }
145
+ const r = parseInt(newHex.slice(0, 2), 16);
146
+ const g = parseInt(newHex.slice(2, 4), 16);
147
+ const b = parseInt(newHex.slice(4, 6), 16);
147
148
  return `rgb(${r}, ${g}, ${b})`;
148
149
  };
149
150
  exports.convertHexToRgb = convertHexToRgb;
151
+ /**
152
+ * * Extracts numbers from a color string like `rgb(66, 103, 69)` or `hsl(120, 42.86%, 41.18%)`.
153
+ * * Converts percentage values to decimal (e.g., `42.86%` → `42.86`).
154
+ *
155
+ * @param colorString The color string in RGB or HSL format.
156
+ * @returns An array of extracted numbers.
157
+ */
158
+ const extractNumbersFromColor = (colorString) => {
159
+ return (colorString.match(/[\d.]+%?/g) || []).map((value) => parseFloat(value));
160
+ };
161
+ exports.extractNumbersFromColor = extractNumbersFromColor;
162
+ /**
163
+ * * Converts a color from `Hex`, `RGB`, or `HSL` format to its equivalent representations.
164
+ *
165
+ * @param color The color string in `Hex`, `RGB`, or `HSL` format.
166
+ * @returns The converted color representations excluding the input format.
167
+ * @throws If the color format is unrecognized throws `Error`.
168
+ */
169
+ function convertColorCode(color) {
170
+ if (color.startsWith('#')) {
171
+ return {
172
+ rgb: (0, exports.convertHexToRgb)(color),
173
+ hsl: (0, exports.convertHexToHsl)(color),
174
+ };
175
+ }
176
+ if (color.startsWith('rgb')) {
177
+ return {
178
+ hex: (0, exports.convertRgbToHex)(...(0, exports.extractNumbersFromColor)(color)),
179
+ hsl: (0, exports.convertRgbToHsl)(...(0, exports.extractNumbersFromColor)(color)),
180
+ };
181
+ }
182
+ if (color.startsWith('hsl')) {
183
+ return {
184
+ hex: (0, exports.convertHslToHex)(...(0, exports.extractNumbersFromColor)(color)),
185
+ rgb: (0, exports.convertHslToRgb)(...(0, exports.extractNumbersFromColor)(color)),
186
+ };
187
+ }
188
+ throw new Error(`Unrecognized Color Format: ${color}`);
189
+ }
@@ -5,4 +5,50 @@ export interface ColorInputArray extends Array<ColorInput | ColorInputArray> {
5
5
  }
6
6
  /** - Opacity options */
7
7
  export type OpacityValue = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100;
8
+ /**
9
+ * * Represents a hexadecimal color code.
10
+ * Format: `#3C6945`
11
+ */
12
+ export type Hex = `#${string}`;
13
+ /**
14
+ * * Represents an RGB color string.
15
+ * * Format: `rgb(R, G, B)`
16
+ *
17
+ * - R (Red): 0-255
18
+ * - G (Green): 0-255
19
+ * - B (Blue): 0-255
20
+ */
21
+ export type RGB = `rgb(${number}, ${number}, ${number})`;
22
+ /**
23
+ * * Represents an HSL color string.
24
+ * * Format: `hsl(H, S%, L%)`
25
+ *
26
+ * - H (Hue): 0-360
27
+ * - S (Saturation): 0-100%
28
+ * - L (Lightness): 0-100%
29
+ */
30
+ export type HSL = `hsl(${number}, ${number}%, ${number}%)`;
31
+ export type RGBA = `rgba(${number}, ${number}, ${number}, ${number})`;
32
+ export type HSLA = `hsla(${number}, ${number}%, ${number}%, ${number})`;
33
+ /** * Union type representing a color in Hex, RGB, or HSL format. */
34
+ export type Color = Hex | RGB | HSL | RGBA | HSLA;
35
+ /** * Represents a tuple of three numerical values corresponding to RGB or HSL color components. */
36
+ export type ColorNumbers = [number, number, number];
37
+ /**
38
+ * * Represents the converted color formats for a given color type.
39
+ *
40
+ * - If the input is `Hex`, the output includes `RGB` and `HSL`.
41
+ * - If the input is `RGB`, the output includes `Hex` and `HSL`.
42
+ * - If the input is `HSL`, the output includes `Hex` and `RGB`.
43
+ *
44
+ * @template T The input color type (`Hex`, `RGB`, or `HSL`).
45
+ */
46
+ export interface ConvertedColors<T extends Color> extends Record<string, Hex | RGB | HSL> {
47
+ /** - The Hex representation (excluded if the input is already Hex). */
48
+ hex: T extends Hex ? never : Hex;
49
+ /** - The RGB representation (excluded if the input is already RGB). */
50
+ rgb: T extends RGB ? never : RGB;
51
+ /** - The HSL representation (excluded if the input is already HSL). */
52
+ hsl: T extends HSL ? never : HSL;
53
+ }
8
54
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/colors/types.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,MAAM,CAAC;AAEzC,+FAA+F;AAC/F,MAAM,WAAW,eAAgB,SAAQ,KAAK,CAAC,UAAU,GAAG,eAAe,CAAC;CAAG;AAE/E,wBAAwB;AACxB,MAAM,MAAM,YAAY,GACrB,CAAC,GACD,CAAC,GACD,CAAC,GACD,CAAC,GACD,CAAC,GACD,CAAC,GACD,CAAC,GACD,CAAC,GACD,CAAC,GACD,CAAC,GACD,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,GAAG,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/colors/types.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,MAAM,CAAC;AAEzC,+FAA+F;AAC/F,MAAM,WAAW,eAAgB,SAAQ,KAAK,CAAC,UAAU,GAAG,eAAe,CAAC;CAAG;AAE/E,wBAAwB;AACxB,MAAM,MAAM,YAAY,GACrB,CAAC,GACD,CAAC,GACD,CAAC,GACD,CAAC,GACD,CAAC,GACD,CAAC,GACD,CAAC,GACD,CAAC,GACD,CAAC,GACD,CAAC,GACD,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,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ACvE,GAAG,EAAE,CAAC,SAAS,GAAG,GAAG,KAAK,GAAG,GAAG,CAAC;IACjC,uEAAuE;IACvE,GAAG,EAAE,CAAC,SAAS,GAAG,GAAG,KAAK,GAAG,GAAG,CAAC;CACjC"}
package/dist/index.d.ts CHANGED
@@ -2,12 +2,14 @@ export { capitalizeString, generateRandomID, trimString, truncateString, } from
2
2
  export { generateAnagrams } from './string/anagram';
3
3
  export { convertToDecimal, getRandomNumber } from './number/basics';
4
4
  export { numberToWords } from './number/convert';
5
- export { isPrime, findPrimeNumbers } from './number/prime';
5
+ export { findPrimeNumbers, isPrime } from './number/prime';
6
6
  export { getColorForInitial } from './colors/initials';
7
7
  export { generateRandomColor } from './colors/random';
8
- export { convertHexToHsl, convertHexToRgb, convertHslToHex, convertHslToRgb, convertRgbToHex, convertRgbToHsl, } from './colors/convert';
8
+ export { convertColorCode, convertHexToHsl, convertHexToRgb, convertHslToHex, convertHslToRgb, convertRgbToHex, convertRgbToHsl, extractNumbersFromColor, } from './colors/convert';
9
9
  export { createOptionsArray, filterArrayOfObjects, flattenArray, sortAnArray, } from './array/basics';
10
- export { cloneObject, countObjectFields, flattenObject, generateQueryParams, isDeepEqual, isEmptyObject, mergeAndFlattenObjects, mergeObjects, } from './object/basics';
10
+ export { cloneObject, countObjectFields, generateQueryParams, isEmptyObject, isObject, } from './object/basics';
11
+ export { extractNewFields, extractUpdatedAndNewFields, extractUpdatedFields, flattenObject, mergeAndFlattenObjects, mergeObjects, } from './object/objectify';
11
12
  export { sanitizeData } from './object/sanitize';
12
13
  export { convertObjectValues } from './object/convert';
14
+ export { isDeepEqual } from './utils';
13
15
  //# sourceMappingURL=index.d.ts.map
@@ -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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AAE,MAAM,iBAAiB,CAAC;AAEtD,OAAO,EACN,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,eAAe,EACf,eAAe,EACf,eAAe,EACf,eAAe,EACf,uBAAuB,GACvB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EACN,kBAAkB,EAClB,oBAAoB,EACpB,YAAY,EACZ,WAAW,GACX,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACN,WAAW,EACX,iBAAiB,EACjB,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,WAAW,EAAE,MAAM,SAAS,CAAC"}
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.convertObjectValues = exports.sanitizeData = exports.mergeObjects = exports.mergeAndFlattenObjects = exports.isEmptyObject = exports.isDeepEqual = exports.generateQueryParams = exports.flattenObject = exports.countObjectFields = exports.cloneObject = exports.sortAnArray = exports.flattenArray = exports.filterArrayOfObjects = exports.createOptionsArray = exports.convertRgbToHsl = exports.convertRgbToHex = exports.convertHslToRgb = exports.convertHslToHex = exports.convertHexToRgb = exports.convertHexToHsl = exports.generateRandomColor = exports.getColorForInitial = exports.findPrimeNumbers = exports.isPrime = exports.numberToWords = exports.getRandomNumber = exports.convertToDecimal = exports.generateAnagrams = exports.truncateString = exports.trimString = exports.generateRandomID = exports.capitalizeString = void 0;
3
+ exports.isDeepEqual = exports.convertObjectValues = 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.sortAnArray = exports.flattenArray = exports.filterArrayOfObjects = exports.createOptionsArray = exports.extractNumbersFromColor = exports.convertRgbToHsl = exports.convertRgbToHex = exports.convertHslToRgb = exports.convertHslToHex = exports.convertHexToRgb = exports.convertHexToHsl = exports.convertColorCode = exports.generateRandomColor = exports.getColorForInitial = exports.isPrime = exports.findPrimeNumbers = exports.numberToWords = exports.getRandomNumber = exports.convertToDecimal = exports.generateAnagrams = exports.truncateString = exports.trimString = exports.generateRandomID = exports.capitalizeString = void 0;
4
4
  var basics_1 = require("./string/basics");
5
5
  Object.defineProperty(exports, "capitalizeString", { enumerable: true, get: function () { return basics_1.capitalizeString; } });
6
6
  Object.defineProperty(exports, "generateRandomID", { enumerable: true, get: function () { return basics_1.generateRandomID; } });
@@ -14,19 +14,21 @@ Object.defineProperty(exports, "getRandomNumber", { enumerable: true, get: funct
14
14
  var convert_1 = require("./number/convert");
15
15
  Object.defineProperty(exports, "numberToWords", { enumerable: true, get: function () { return convert_1.numberToWords; } });
16
16
  var prime_1 = require("./number/prime");
17
- Object.defineProperty(exports, "isPrime", { enumerable: true, get: function () { return prime_1.isPrime; } });
18
17
  Object.defineProperty(exports, "findPrimeNumbers", { enumerable: true, get: function () { return prime_1.findPrimeNumbers; } });
18
+ Object.defineProperty(exports, "isPrime", { enumerable: true, get: function () { return prime_1.isPrime; } });
19
19
  var initials_1 = require("./colors/initials");
20
20
  Object.defineProperty(exports, "getColorForInitial", { enumerable: true, get: function () { return initials_1.getColorForInitial; } });
21
21
  var random_1 = require("./colors/random");
22
22
  Object.defineProperty(exports, "generateRandomColor", { enumerable: true, get: function () { return random_1.generateRandomColor; } });
23
23
  var convert_2 = require("./colors/convert");
24
+ Object.defineProperty(exports, "convertColorCode", { enumerable: true, get: function () { return convert_2.convertColorCode; } });
24
25
  Object.defineProperty(exports, "convertHexToHsl", { enumerable: true, get: function () { return convert_2.convertHexToHsl; } });
25
26
  Object.defineProperty(exports, "convertHexToRgb", { enumerable: true, get: function () { return convert_2.convertHexToRgb; } });
26
27
  Object.defineProperty(exports, "convertHslToHex", { enumerable: true, get: function () { return convert_2.convertHslToHex; } });
27
28
  Object.defineProperty(exports, "convertHslToRgb", { enumerable: true, get: function () { return convert_2.convertHslToRgb; } });
28
29
  Object.defineProperty(exports, "convertRgbToHex", { enumerable: true, get: function () { return convert_2.convertRgbToHex; } });
29
30
  Object.defineProperty(exports, "convertRgbToHsl", { enumerable: true, get: function () { return convert_2.convertRgbToHsl; } });
31
+ Object.defineProperty(exports, "extractNumbersFromColor", { enumerable: true, get: function () { return convert_2.extractNumbersFromColor; } });
30
32
  var basics_3 = require("./array/basics");
31
33
  Object.defineProperty(exports, "createOptionsArray", { enumerable: true, get: function () { return basics_3.createOptionsArray; } });
32
34
  Object.defineProperty(exports, "filterArrayOfObjects", { enumerable: true, get: function () { return basics_3.filterArrayOfObjects; } });
@@ -35,13 +37,19 @@ Object.defineProperty(exports, "sortAnArray", { enumerable: true, get: function
35
37
  var basics_4 = require("./object/basics");
36
38
  Object.defineProperty(exports, "cloneObject", { enumerable: true, get: function () { return basics_4.cloneObject; } });
37
39
  Object.defineProperty(exports, "countObjectFields", { enumerable: true, get: function () { return basics_4.countObjectFields; } });
38
- Object.defineProperty(exports, "flattenObject", { enumerable: true, get: function () { return basics_4.flattenObject; } });
39
40
  Object.defineProperty(exports, "generateQueryParams", { enumerable: true, get: function () { return basics_4.generateQueryParams; } });
40
- Object.defineProperty(exports, "isDeepEqual", { enumerable: true, get: function () { return basics_4.isDeepEqual; } });
41
41
  Object.defineProperty(exports, "isEmptyObject", { enumerable: true, get: function () { return basics_4.isEmptyObject; } });
42
- Object.defineProperty(exports, "mergeAndFlattenObjects", { enumerable: true, get: function () { return basics_4.mergeAndFlattenObjects; } });
43
- Object.defineProperty(exports, "mergeObjects", { enumerable: true, get: function () { return basics_4.mergeObjects; } });
42
+ Object.defineProperty(exports, "isObject", { enumerable: true, get: function () { return basics_4.isObject; } });
43
+ var objectify_1 = require("./object/objectify");
44
+ Object.defineProperty(exports, "extractNewFields", { enumerable: true, get: function () { return objectify_1.extractNewFields; } });
45
+ Object.defineProperty(exports, "extractUpdatedAndNewFields", { enumerable: true, get: function () { return objectify_1.extractUpdatedAndNewFields; } });
46
+ Object.defineProperty(exports, "extractUpdatedFields", { enumerable: true, get: function () { return objectify_1.extractUpdatedFields; } });
47
+ Object.defineProperty(exports, "flattenObject", { enumerable: true, get: function () { return objectify_1.flattenObject; } });
48
+ Object.defineProperty(exports, "mergeAndFlattenObjects", { enumerable: true, get: function () { return objectify_1.mergeAndFlattenObjects; } });
49
+ Object.defineProperty(exports, "mergeObjects", { enumerable: true, get: function () { return objectify_1.mergeObjects; } });
44
50
  var sanitize_1 = require("./object/sanitize");
45
51
  Object.defineProperty(exports, "sanitizeData", { enumerable: true, get: function () { return sanitize_1.sanitizeData; } });
46
52
  var convert_3 = require("./object/convert");
47
53
  Object.defineProperty(exports, "convertObjectValues", { enumerable: true, get: function () { return convert_3.convertObjectValues; } });
54
+ var utils_1 = require("./utils");
55
+ Object.defineProperty(exports, "isDeepEqual", { enumerable: true, get: function () { return utils_1.isDeepEqual; } });
@@ -34,34 +34,10 @@ export declare const isEmptyObject: <T extends GenericObject>(obj: T) => boolean
34
34
  */
35
35
  export declare const countObjectFields: <T extends GenericObject>(obj: T) => number;
36
36
  /**
37
- * * Deeply merge two or more objects using `Map`.
37
+ * * Check whether data is object and not array.
38
38
  *
39
- * @param objects Objects to merge.
40
- * @returns Merged object.
39
+ * @param data Data to check if its an object and not array.
40
+ * @returns Boolean: `true` if it's an object, `false` if not.
41
41
  */
42
- export declare const mergeObjects: <T extends GenericObject>(...objects: T[]) => T;
43
- /**
44
- * * Deeply merge objects and flatten nested objects.
45
- * * Useful for flattening a single object or merging multiple objects with duplicate key(s).
46
- * * If keys are duplicated, the last object's value will be used.
47
- *
48
- * @param objects Objects to merge.
49
- * @returns Merged object with flattened structure.
50
- */
51
- export declare const mergeAndFlattenObjects: <T extends GenericObject>(...objects: T[]) => GenericObject;
52
- /**
53
- * * Flattens a nested object into a dot notation format.
54
- *
55
- * @param object - The `object` to flatten.
56
- * @returns A `flattened object` with dot notation keys.
57
- */
58
- export declare const flattenObject: <T extends GenericObject>(object: T) => GenericObject;
59
- /**
60
- * * Deeply compare two values (arrays, objects, or primitive values).
61
- *
62
- * @param a First value to compare.
63
- * @param b Second value to compare.
64
- * @returns Whether the values are deeply equal.
65
- */
66
- export declare const isDeepEqual: <T>(a: T, b: T) => boolean;
42
+ export declare const isObject: (data: unknown) => boolean;
67
43
  //# sourceMappingURL=basics.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"basics.d.ts","sourceRoot":"","sources":["../../src/object/basics.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE1D;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,mBAAmB,GAAI,CAAC,SAAS,WAAW,WAChD,CAAC,KACP,MA4BF,CAAC;AAEF;;;;;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,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,aAAa,GAAI,CAAC,SAAS,aAAa,UAC5C,CAAC,KACP,aA6BF,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,KAAK,CAAC,KAAK,CAAC,KAAG,OA6B3C,CAAC"}
1
+ {"version":3,"file":"basics.d.ts","sourceRoot":"","sources":["../../src/object/basics.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE1D;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,mBAAmB,GAAI,CAAC,SAAS,WAAW,WAChD,CAAC,KACP,MA4BF,CAAC;AAEF;;;;;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"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isDeepEqual = exports.flattenObject = exports.mergeAndFlattenObjects = exports.mergeObjects = exports.countObjectFields = exports.isEmptyObject = exports.cloneObject = exports.generateQueryParams = void 0;
3
+ exports.isObject = exports.countObjectFields = exports.isEmptyObject = exports.cloneObject = exports.generateQueryParams = void 0;
4
4
  /**
5
5
  * * Utility to generate query parameters from an object.
6
6
  *
@@ -46,7 +46,7 @@ exports.cloneObject = cloneObject;
46
46
  * @returns Whether the object is empty.
47
47
  */
48
48
  const isEmptyObject = (obj) => {
49
- return Object.keys(obj).length === 0 && obj.constructor === Object;
49
+ return (0, exports.countObjectFields)(obj) === 0;
50
50
  };
51
51
  exports.isEmptyObject = isEmptyObject;
52
52
  /**
@@ -60,137 +60,12 @@ const countObjectFields = (obj) => {
60
60
  };
61
61
  exports.countObjectFields = countObjectFields;
62
62
  /**
63
- * * Deeply merge two or more objects using `Map`.
63
+ * * Check whether data is object and not array.
64
64
  *
65
- * @param objects Objects to merge.
66
- * @returns Merged object.
65
+ * @param data Data to check if its an object and not array.
66
+ * @returns Boolean: `true` if it's an object, `false` if not.
67
67
  */
68
- const mergeObjects = (...objects) => {
69
- const map = new Map();
70
- objects.forEach((obj) => {
71
- for (const key in obj) {
72
- const existingValue = map.get(key);
73
- if (obj[key] instanceof Object && !Array.isArray(obj[key])) {
74
- // If the key already exists in the map and both are objects, merge them
75
- if (existingValue &&
76
- existingValue instanceof Object &&
77
- !Array.isArray(existingValue)) {
78
- map.set(key, (0, exports.mergeObjects)(existingValue, obj[key]));
79
- }
80
- else {
81
- // Otherwise, just set the value
82
- map.set(key, obj[key]);
83
- }
84
- }
85
- else {
86
- // If it's not an object, just set the value
87
- map.set(key, obj[key]);
88
- }
89
- }
90
- });
91
- const result = {};
92
- map.forEach((value, key) => {
93
- result[key] = value;
94
- });
95
- return result;
68
+ const isObject = (data) => {
69
+ return typeof data === 'object' && !Array.isArray(data);
96
70
  };
97
- exports.mergeObjects = mergeObjects;
98
- /**
99
- * * Deeply merge objects and flatten nested objects.
100
- * * Useful for flattening a single object or merging multiple objects with duplicate key(s).
101
- * * If keys are duplicated, the last object's value will be used.
102
- *
103
- * @param objects Objects to merge.
104
- * @returns Merged object with flattened structure.
105
- */
106
- const mergeAndFlattenObjects = (...objects) => {
107
- const map = new Map();
108
- const _flattenObject = (obj, parentKey = '') => {
109
- for (const key in obj) {
110
- const newKey = parentKey ? `${String(parentKey)}.${key}` : key;
111
- if (obj[key] instanceof Object && !Array.isArray(obj[key])) {
112
- // Recursively flatten nested objects
113
- _flattenObject(obj[key], newKey);
114
- }
115
- else {
116
- // Set the flattened key
117
- map.set(newKey, obj[key]);
118
- }
119
- }
120
- };
121
- objects.forEach((obj) => _flattenObject(obj));
122
- const result = {};
123
- map.forEach((value, key) => {
124
- result[key] = value;
125
- });
126
- return result;
127
- };
128
- exports.mergeAndFlattenObjects = mergeAndFlattenObjects;
129
- /**
130
- * * Flattens a nested object into a dot notation format.
131
- *
132
- * @param object - The `object` to flatten.
133
- * @returns A `flattened object` with dot notation keys.
134
- */
135
- const flattenObject = (object) => {
136
- /**
137
- * * Recursively flattens an object, transforming nested structures into dot-notation keys.
138
- *
139
- * @param source - The `object` to be flattened.
140
- * @param prefix - The prefix to prepend to each key. Used for nested objects.
141
- * @returns A flattened version of the input object.
142
- */
143
- const _flattenObject = (source, prefix = '') => {
144
- const flattened = {};
145
- for (const [key, value] of Object.entries(source)) {
146
- // Construct the dot-notation key
147
- const newKey = prefix ? `${String(prefix)}.${key}` : key;
148
- if (value && typeof value === 'object' && !Array.isArray(value)) {
149
- // Recursively process nested objects
150
- Object.assign(flattened, _flattenObject(value, newKey));
151
- }
152
- else {
153
- // Directly assign non-object values
154
- flattened[newKey] = value;
155
- }
156
- }
157
- return flattened;
158
- };
159
- // Call the recursive function with an empty prefix initially
160
- return _flattenObject(object);
161
- };
162
- exports.flattenObject = flattenObject;
163
- /**
164
- * * Deeply compare two values (arrays, objects, or primitive values).
165
- *
166
- * @param a First value to compare.
167
- * @param b Second value to compare.
168
- * @returns Whether the values are deeply equal.
169
- */
170
- const isDeepEqual = (a, b) => {
171
- // If both values are strictly equal (handles primitive types and same references)
172
- if (a === b)
173
- return true;
174
- // If the types of the two values are different
175
- if (typeof a !== typeof b)
176
- return false;
177
- // If either is null or undefined, they must both be null or undefined
178
- if (a === null || b === null)
179
- return a === b;
180
- // Check for array equality
181
- if (Array.isArray(a) && Array.isArray(b)) {
182
- if (a.length !== b.length)
183
- return false;
184
- return a.every((element, index) => (0, exports.isDeepEqual)(element, b[index]));
185
- }
186
- // Check for object equality
187
- if (typeof a === 'object' && typeof b === 'object') {
188
- const aKeys = Object.keys(a);
189
- const bKeys = Object.keys(b);
190
- if (aKeys.length !== bKeys.length)
191
- return false;
192
- return aKeys.every((key) => (0, exports.isDeepEqual)(a[key], b[key]));
193
- }
194
- return false;
195
- };
196
- exports.isDeepEqual = isDeepEqual;
71
+ exports.isObject = isObject;
@@ -0,0 +1,49 @@
1
+ import type { GenericObject, LooseObject } from './types';
2
+ /**
3
+ * * Deeply merge two or more objects using `Map`.
4
+ *
5
+ * @param objects Objects to merge.
6
+ * @returns Merged object.
7
+ */
8
+ export declare const mergeObjects: <T extends GenericObject>(...objects: T[]) => T;
9
+ /**
10
+ * * Deeply merge objects and flatten nested objects.
11
+ * * Useful for flattening a single object or merging multiple objects with duplicate key(s).
12
+ * * If keys are duplicated, the last object's value will be used.
13
+ *
14
+ * @param objects Objects to merge.
15
+ * @returns Merged object with flattened structure.
16
+ */
17
+ export declare const mergeAndFlattenObjects: <T extends GenericObject>(...objects: T[]) => GenericObject;
18
+ /**
19
+ * * Flattens a nested object into a dot notation format.
20
+ *
21
+ * @param object - The `object` to flatten.
22
+ * @returns A `flattened object` with dot notation keys.
23
+ */
24
+ export declare const flattenObject: <T extends GenericObject>(object: T) => GenericObject;
25
+ /**
26
+ * * Extracts only the fields that have changed between the original and updated object.
27
+ *
28
+ * @param baseObject The original object to compare against.
29
+ * @param updatedObject The modified object containing potential updates.
30
+ * @returns A new object containing only the changed fields.
31
+ */
32
+ export declare const extractUpdatedFields: <T extends LooseObject>(baseObject: T, updatedObject: Partial<T>) => Partial<T>;
33
+ /**
34
+ * * Extracts only new fields that exist in updatedObject but not in baseObject.
35
+ *
36
+ * @param baseObject The original object to compare against.
37
+ * @param updatedObject The modified object containing potential new fields.
38
+ * @returns A new object containing only the new fields.
39
+ */
40
+ export declare const extractNewFields: <T extends LooseObject>(baseObject: T, updatedObject: Partial<T>) => Partial<T>;
41
+ /**
42
+ * * Extracts changed fields from the updated object while also identifying newly added keys.
43
+ *
44
+ * @param baseObject The original object to compare against.
45
+ * @param updatedObject The modified object containing potential updates.
46
+ * @returns An object containing modified fields and new fields separately.
47
+ */
48
+ export declare const extractUpdatedAndNewFields: <T extends LooseObject>(baseObject: T, updatedObject: Partial<T> & LooseObject) => Partial<T> & LooseObject;
49
+ //# sourceMappingURL=objectify.d.ts.map
@@ -0,0 +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,aAAa,GAAI,CAAC,SAAS,aAAa,UAC5C,CAAC,KACP,aA6BF,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"}
@@ -0,0 +1,186 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.extractUpdatedAndNewFields = exports.extractNewFields = exports.extractUpdatedFields = exports.flattenObject = exports.mergeAndFlattenObjects = exports.mergeObjects = void 0;
4
+ const utils_1 = require("../utils");
5
+ const basics_1 = require("./basics");
6
+ /**
7
+ * * Deeply merge two or more objects using `Map`.
8
+ *
9
+ * @param objects Objects to merge.
10
+ * @returns Merged object.
11
+ */
12
+ const mergeObjects = (...objects) => {
13
+ const map = new Map();
14
+ objects.forEach((obj) => {
15
+ for (const key in obj) {
16
+ const existingValue = map.get(key);
17
+ if (obj[key] instanceof Object && !Array.isArray(obj[key])) {
18
+ // If the key already exists in the map and both are objects, merge them
19
+ if (existingValue &&
20
+ existingValue instanceof Object &&
21
+ !Array.isArray(existingValue)) {
22
+ map.set(key, (0, exports.mergeObjects)(existingValue, obj[key]));
23
+ }
24
+ else {
25
+ // Otherwise, just set the value
26
+ map.set(key, obj[key]);
27
+ }
28
+ }
29
+ else {
30
+ // If it's not an object, just set the value
31
+ map.set(key, obj[key]);
32
+ }
33
+ }
34
+ });
35
+ const result = {};
36
+ map.forEach((value, key) => {
37
+ result[key] = value;
38
+ });
39
+ return result;
40
+ };
41
+ exports.mergeObjects = mergeObjects;
42
+ /**
43
+ * * Deeply merge objects and flatten nested objects.
44
+ * * Useful for flattening a single object or merging multiple objects with duplicate key(s).
45
+ * * If keys are duplicated, the last object's value will be used.
46
+ *
47
+ * @param objects Objects to merge.
48
+ * @returns Merged object with flattened structure.
49
+ */
50
+ const mergeAndFlattenObjects = (...objects) => {
51
+ const map = new Map();
52
+ const _flattenObject = (obj, parentKey = '') => {
53
+ for (const key in obj) {
54
+ const newKey = parentKey ? `${String(parentKey)}.${key}` : key;
55
+ if (obj[key] instanceof Object && !Array.isArray(obj[key])) {
56
+ // Recursively flatten nested objects
57
+ _flattenObject(obj[key], newKey);
58
+ }
59
+ else {
60
+ // Set the flattened key
61
+ map.set(newKey, obj[key]);
62
+ }
63
+ }
64
+ };
65
+ objects.forEach((obj) => _flattenObject(obj));
66
+ const result = {};
67
+ map.forEach((value, key) => {
68
+ result[key] = value;
69
+ });
70
+ return result;
71
+ };
72
+ exports.mergeAndFlattenObjects = mergeAndFlattenObjects;
73
+ /**
74
+ * * Flattens a nested object into a dot notation format.
75
+ *
76
+ * @param object - The `object` to flatten.
77
+ * @returns A `flattened object` with dot notation keys.
78
+ */
79
+ const flattenObject = (object) => {
80
+ /**
81
+ * * Recursively flattens an object, transforming nested structures into dot-notation keys.
82
+ *
83
+ * @param source - The `object` to be flattened.
84
+ * @param prefix - The prefix to prepend to each key. Used for nested objects.
85
+ * @returns A flattened version of the input object.
86
+ */
87
+ const _flattenObject = (source, prefix = '') => {
88
+ const flattened = {};
89
+ for (const [key, value] of Object.entries(source)) {
90
+ // Construct the dot-notation key
91
+ const newKey = prefix ? `${String(prefix)}.${key}` : key;
92
+ if (value && typeof value === 'object' && !Array.isArray(value)) {
93
+ // Recursively process nested objects
94
+ Object.assign(flattened, _flattenObject(value, newKey));
95
+ }
96
+ else {
97
+ // Directly assign non-object values
98
+ flattened[newKey] = value;
99
+ }
100
+ }
101
+ return flattened;
102
+ };
103
+ // Call the recursive function with an empty prefix initially
104
+ return _flattenObject(object);
105
+ };
106
+ exports.flattenObject = flattenObject;
107
+ /**
108
+ * * Extracts only the fields that have changed between the original and updated object.
109
+ *
110
+ * @param baseObject The original object to compare against.
111
+ * @param updatedObject The modified object containing potential updates.
112
+ * @returns A new object containing only the changed fields.
113
+ */
114
+ const extractUpdatedFields = (baseObject, updatedObject) => {
115
+ const updatedFields = {};
116
+ for (const key in updatedObject) {
117
+ if (key in baseObject &&
118
+ !(0, utils_1.isDeepEqual)(updatedObject[key], baseObject[key])) {
119
+ if (updatedObject[key] && (0, basics_1.isObject)(updatedObject[key])) {
120
+ updatedFields[key] = (0, exports.extractUpdatedFields)(baseObject[key], updatedObject[key]);
121
+ if (updatedFields[key] && (0, basics_1.isEmptyObject)(updatedFields[key])) {
122
+ delete updatedFields[key];
123
+ }
124
+ }
125
+ else {
126
+ updatedFields[key] = updatedObject[key];
127
+ }
128
+ }
129
+ }
130
+ return updatedFields;
131
+ };
132
+ exports.extractUpdatedFields = extractUpdatedFields;
133
+ /**
134
+ * * Extracts only new fields that exist in updatedObject but not in baseObject.
135
+ *
136
+ * @param baseObject The original object to compare against.
137
+ * @param updatedObject The modified object containing potential new fields.
138
+ * @returns A new object containing only the new fields.
139
+ */
140
+ const extractNewFields = (baseObject, updatedObject) => {
141
+ const newFields = {};
142
+ for (const key in updatedObject) {
143
+ if (!(key in baseObject)) {
144
+ // Directly assign new fields
145
+ newFields[key] = updatedObject[key];
146
+ }
147
+ else if ((0, basics_1.isObject)(updatedObject[key]) && (0, basics_1.isObject)(baseObject[key])) {
148
+ // Recursively extract new fields inside nested objects
149
+ const nestedNewFields = (0, exports.extractNewFields)(baseObject[key], updatedObject[key]);
150
+ if (!(0, basics_1.isEmptyObject)(nestedNewFields)) {
151
+ newFields[key] = nestedNewFields;
152
+ }
153
+ }
154
+ }
155
+ return newFields;
156
+ };
157
+ exports.extractNewFields = extractNewFields;
158
+ /**
159
+ * * Extracts changed fields from the updated object while also identifying newly added keys.
160
+ *
161
+ * @param baseObject The original object to compare against.
162
+ * @param updatedObject The modified object containing potential updates.
163
+ * @returns An object containing modified fields and new fields separately.
164
+ */
165
+ const extractUpdatedAndNewFields = (baseObject, updatedObject) => {
166
+ const updatedFields = {};
167
+ const newFields = {};
168
+ for (const key in updatedObject) {
169
+ if (!(key in baseObject)) {
170
+ newFields[key] = updatedObject[key];
171
+ }
172
+ else if (!(0, utils_1.isDeepEqual)(updatedObject[key], baseObject[key])) {
173
+ if (updatedObject[key] && (0, basics_1.isObject)(updatedObject[key])) {
174
+ updatedFields[key] = (0, exports.extractUpdatedAndNewFields)(baseObject[key], updatedObject[key]);
175
+ if (updatedFields[key] && (0, basics_1.isEmptyObject)(updatedFields[key])) {
176
+ delete updatedFields[key];
177
+ }
178
+ }
179
+ else {
180
+ updatedFields[key] = updatedObject[key];
181
+ }
182
+ }
183
+ }
184
+ return { ...updatedFields, ...newFields };
185
+ };
186
+ exports.extractUpdatedAndNewFields = extractUpdatedAndNewFields;
@@ -1,5 +1,7 @@
1
- /** - Generic object type */
1
+ /** - Generic object with `unknown` value */
2
2
  export type GenericObject = Record<string, unknown>;
3
+ /** - Generic object but with `any` value */
4
+ export type LooseObject = Record<string, any>;
3
5
  /** - Query object type `Record<string, string | number | string[] | number[]` */
4
6
  export type QueryObject = Record<string, string | number | null | undefined | (string | number | null | undefined)[]>;
5
7
  /** - Dot-notation keys for nested objects */
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/object/types.ts"],"names":[],"mappings":"AAAA,4BAA4B;AAC5B,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEpD,iFAAiF;AACjF,MAAM,MAAM,WAAW,GAAG,MAAM,CAC/B,MAAM,EACN,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,CAAC,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,EAAE,CAC3E,CAAC;AAEF,6CAA6C;AAC7C,MAAM,MAAM,cAAc,CAAC,CAAC,IAC3B,CAAC,SAAS,aAAa,GACtB;KACE,CAAC,IAAI,MAAM,CAAC,GAAG,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,aAAa,GAClD,GAAG,CAAC,EAAE,GAAG,GAAG,CAAC,IAAI,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,GACtC,GAAG,CAAC,EAAE;CACR,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,GAClB,KAAK,CAAC;AAET,mCAAmC;AACnC,MAAM,WAAW,eAAe,CAAC,CAAC,SAAS,aAAa;IACvD,qBAAqB;IACrB,YAAY,CAAC,EAAE,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC;IACnC,wDAAwD;IACxD,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,iFAAiF;IACjF,aAAa,CAAC,EAAE,OAAO,CAAC;CACxB;AAED,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,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,GAAG,MAAM,GACrC,CAAC,CAAC,CAAC,CAAC;CACN,CAAC;AAEF,iDAAiD;AACjD,MAAM,MAAM,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"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * * Deeply compare two values (arrays, objects, or primitive values).
3
+ *
4
+ * @param a First value to compare.
5
+ * @param b Second value to compare.
6
+ * @returns Whether the values are deeply equal.
7
+ */
8
+ export declare const isDeepEqual: <T>(a: T, b: T) => boolean;
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,KAAK,CAAC,KAAK,CAAC,KAAG,OA6B3C,CAAC"}
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isDeepEqual = void 0;
4
+ /**
5
+ * * Deeply compare two values (arrays, objects, or primitive values).
6
+ *
7
+ * @param a First value to compare.
8
+ * @param b Second value to compare.
9
+ * @returns Whether the values are deeply equal.
10
+ */
11
+ const isDeepEqual = (a, b) => {
12
+ // If both values are strictly equal (handles primitive types and same references)
13
+ if (a === b)
14
+ return true;
15
+ // If the types of the two values are different
16
+ if (typeof a !== typeof b)
17
+ return false;
18
+ // If either is null or undefined, they must both be null or undefined
19
+ if (a === null || b === null)
20
+ return a === b;
21
+ // Check for array equality
22
+ if (Array.isArray(a) && Array.isArray(b)) {
23
+ if (a.length !== b.length)
24
+ return false;
25
+ return a.every((element, index) => (0, exports.isDeepEqual)(element, b[index]));
26
+ }
27
+ // Check for object equality
28
+ if (typeof a === 'object' && typeof b === 'object') {
29
+ const aKeys = Object.keys(a);
30
+ const bKeys = Object.keys(b);
31
+ if (aKeys.length !== bKeys.length)
32
+ return false;
33
+ return aKeys.every((key) => (0, exports.isDeepEqual)(a[key], b[key]));
34
+ }
35
+ return false;
36
+ };
37
+ exports.isDeepEqual = isDeepEqual;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nhb-toolbox",
3
- "version": "1.4.0",
3
+ "version": "1.6.0",
4
4
  "description": "A versatile collection of smart, efficient, and reusable utility functions for everyday development needs.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",