nhb-toolbox 0.9.5 → 0.9.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/colors/convert.d.ts +51 -0
- package/dist/colors/convert.d.ts.map +1 -0
- package/dist/colors/convert.js +149 -0
- package/dist/colors/helpers.d.ts +15 -0
- package/dist/colors/helpers.d.ts.map +1 -1
- package/dist/colors/helpers.js +42 -1
- package/dist/colors/random.d.ts +7 -0
- package/dist/colors/random.d.ts.map +1 -0
- package/dist/colors/random.js +30 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -1
- package/dist/number/index.d.ts +11 -0
- package/dist/number/index.d.ts.map +1 -0
- package/dist/number/index.js +45 -0
- package/dist/number/types.d.ts +12 -0
- package/dist/number/types.d.ts.map +1 -0
- package/dist/number/types.js +2 -0
- package/package.json +1 -1
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts HSL to RGB color format.
|
|
3
|
+
*
|
|
4
|
+
* @param h - The hue component of the HSL color, in degrees (0 to 360).
|
|
5
|
+
* @param s - The saturation component of the HSL color, as a percentage (0 to 100).
|
|
6
|
+
* @param l - The lightness component of the HSL color, as a percentage (0 to 100).
|
|
7
|
+
* @returns A string representing the color in RGB format (e.g., `rgb(255, 0, 0)`).
|
|
8
|
+
*/
|
|
9
|
+
export declare const convertHslToRgb: (h: number, s: number, l: number) => string;
|
|
10
|
+
/**
|
|
11
|
+
* Converts RGB to HSL color format.
|
|
12
|
+
*
|
|
13
|
+
* @param r - The red component of the RGB color, in the range 0 to 255.
|
|
14
|
+
* @param g - The green component of the RGB color, in the range 0 to 255.
|
|
15
|
+
* @param b - The blue component of the RGB color, in the range 0 to 255.
|
|
16
|
+
* @returns A string representing the color in HSL format (e.g., `hsl(0, 100%, 50%)`).
|
|
17
|
+
*/
|
|
18
|
+
export declare const convertRgbToHsl: (r: number, g: number, b: number) => string;
|
|
19
|
+
/**
|
|
20
|
+
* Converts HSL to Hex color format.
|
|
21
|
+
*
|
|
22
|
+
* @param h - The hue component of the HSL color, in degrees (0 to 360).
|
|
23
|
+
* @param s - The saturation component of the HSL color, as a percentage (0 to 100).
|
|
24
|
+
* @param l - The lightness component of the HSL color, as a percentage (0 to 100).
|
|
25
|
+
* @returns A string representing the color in Hex format (e.g., `#FF0000`).
|
|
26
|
+
*/
|
|
27
|
+
export declare const convertHslToHex: (h: number, s: number, l: number) => string;
|
|
28
|
+
/**
|
|
29
|
+
* Converts Hex to HSL color format.
|
|
30
|
+
*
|
|
31
|
+
* @param hex - A string representing the color in Hex format (e.g., `#FF0000`).
|
|
32
|
+
* @returns A string representing the color in HSL format (e.g., `hsl(0, 100%, 50%)`).
|
|
33
|
+
*/
|
|
34
|
+
export declare const convertHexToHsl: (hex: string) => string;
|
|
35
|
+
/**
|
|
36
|
+
* Converts RGB to Hex color format.
|
|
37
|
+
*
|
|
38
|
+
* @param r - The red component of the RGB color, in the range 0 to 255.
|
|
39
|
+
* @param g - The green component of the RGB color, in the range 0 to 255.
|
|
40
|
+
* @param b - The blue component of the RGB color, in the range 0 to 255.
|
|
41
|
+
* @returns A string representing the color in Hex format (e.g., `#FF0000`).
|
|
42
|
+
*/
|
|
43
|
+
export declare const convertRgbToHex: (r: number, g: number, b: number) => string;
|
|
44
|
+
/**
|
|
45
|
+
* Converts Hex to RGB color format.
|
|
46
|
+
*
|
|
47
|
+
* @param hex - A string representing the color in Hex format (e.g., `#FF0000`).
|
|
48
|
+
* @returns A string representing the color in RGB format (e.g., `rgb(255, 0, 0)`).
|
|
49
|
+
*/
|
|
50
|
+
export declare const convertHexToRgb: (hex: string) => string;
|
|
51
|
+
//# sourceMappingURL=convert.d.ts.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertHexToRgb = exports.convertRgbToHex = exports.convertHexToHsl = exports.convertHslToHex = exports.convertRgbToHsl = exports.convertHslToRgb = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Converts HSL to RGB color format.
|
|
6
|
+
*
|
|
7
|
+
* @param h - The hue component of the HSL color, in degrees (0 to 360).
|
|
8
|
+
* @param s - The saturation component of the HSL color, as a percentage (0 to 100).
|
|
9
|
+
* @param l - The lightness component of the HSL color, as a percentage (0 to 100).
|
|
10
|
+
* @returns A string representing the color in RGB format (e.g., `rgb(255, 0, 0)`).
|
|
11
|
+
*/
|
|
12
|
+
const convertHslToRgb = (h, s, l) => {
|
|
13
|
+
// Normalize the HSL values
|
|
14
|
+
s /= 100;
|
|
15
|
+
l /= 100;
|
|
16
|
+
const c = (1 - Math.abs(2 * l - 1)) * s;
|
|
17
|
+
const x = c * (1 - Math.abs(((h / 60) % 2) - 1));
|
|
18
|
+
const m = l - c / 2;
|
|
19
|
+
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
|
|
45
|
+
r = Math.round((r + m) * 255);
|
|
46
|
+
g = Math.round((g + m) * 255);
|
|
47
|
+
b = Math.round((b + m) * 255);
|
|
48
|
+
return `rgb(${r}, ${g}, ${b})`;
|
|
49
|
+
};
|
|
50
|
+
exports.convertHslToRgb = convertHslToRgb;
|
|
51
|
+
/**
|
|
52
|
+
* Converts RGB to HSL color format.
|
|
53
|
+
*
|
|
54
|
+
* @param r - The red component of the RGB color, in the range 0 to 255.
|
|
55
|
+
* @param g - The green component of the RGB color, in the range 0 to 255.
|
|
56
|
+
* @param b - The blue component of the RGB color, in the range 0 to 255.
|
|
57
|
+
* @returns A string representing the color in HSL format (e.g., `hsl(0, 100%, 50%)`).
|
|
58
|
+
*/
|
|
59
|
+
const convertRgbToHsl = (r, g, b) => {
|
|
60
|
+
// Normalize the RGB values
|
|
61
|
+
r /= 255;
|
|
62
|
+
g /= 255;
|
|
63
|
+
b /= 255;
|
|
64
|
+
const max = Math.max(r, g, b);
|
|
65
|
+
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;
|
|
71
|
+
}
|
|
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
|
+
h *= 60;
|
|
80
|
+
if (s === 0)
|
|
81
|
+
l = Math.round(l * 100); // for pure colors
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
s = 0;
|
|
85
|
+
}
|
|
86
|
+
h = Math.round(h);
|
|
87
|
+
s = Math.round(s * 100);
|
|
88
|
+
l = Math.round(l * 100);
|
|
89
|
+
return `hsl(${h}, ${s}%, ${l}%)`;
|
|
90
|
+
};
|
|
91
|
+
exports.convertRgbToHsl = convertRgbToHsl;
|
|
92
|
+
/**
|
|
93
|
+
* Converts HSL to Hex color format.
|
|
94
|
+
*
|
|
95
|
+
* @param h - The hue component of the HSL color, in degrees (0 to 360).
|
|
96
|
+
* @param s - The saturation component of the HSL color, as a percentage (0 to 100).
|
|
97
|
+
* @param l - The lightness component of the HSL color, as a percentage (0 to 100).
|
|
98
|
+
* @returns A string representing the color in Hex format (e.g., `#FF0000`).
|
|
99
|
+
*/
|
|
100
|
+
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')}`;
|
|
104
|
+
};
|
|
105
|
+
exports.convertHslToHex = convertHslToHex;
|
|
106
|
+
/**
|
|
107
|
+
* Converts Hex to HSL color format.
|
|
108
|
+
*
|
|
109
|
+
* @param hex - A string representing the color in Hex format (e.g., `#FF0000`).
|
|
110
|
+
* @returns A string representing the color in HSL format (e.g., `hsl(0, 100%, 50%)`).
|
|
111
|
+
*/
|
|
112
|
+
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
|
|
119
|
+
return (0, exports.convertRgbToHsl)(r, g, b);
|
|
120
|
+
};
|
|
121
|
+
exports.convertHexToHsl = convertHexToHsl;
|
|
122
|
+
/**
|
|
123
|
+
* Converts RGB to Hex color format.
|
|
124
|
+
*
|
|
125
|
+
* @param r - The red component of the RGB color, in the range 0 to 255.
|
|
126
|
+
* @param g - The green component of the RGB color, in the range 0 to 255.
|
|
127
|
+
* @param b - The blue component of the RGB color, in the range 0 to 255.
|
|
128
|
+
* @returns A string representing the color in Hex format (e.g., `#FF0000`).
|
|
129
|
+
*/
|
|
130
|
+
const convertRgbToHex = (r, g, b) => {
|
|
131
|
+
return `#${((1 << 24) | (r << 16) | (g << 8) | b).toString(16).slice(1).toUpperCase().padStart(6, '0')}`;
|
|
132
|
+
};
|
|
133
|
+
exports.convertRgbToHex = convertRgbToHex;
|
|
134
|
+
/**
|
|
135
|
+
* Converts Hex to RGB color format.
|
|
136
|
+
*
|
|
137
|
+
* @param hex - A string representing the color in Hex format (e.g., `#FF0000`).
|
|
138
|
+
* @returns A string representing the color in RGB format (e.g., `rgb(255, 0, 0)`).
|
|
139
|
+
*/
|
|
140
|
+
const convertHexToRgb = (hex) => {
|
|
141
|
+
// 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);
|
|
147
|
+
return `rgb(${r}, ${g}, ${b})`;
|
|
148
|
+
};
|
|
149
|
+
exports.convertHexToRgb = convertHexToRgb;
|
package/dist/colors/helpers.d.ts
CHANGED
|
@@ -13,4 +13,19 @@ export declare const convertOpacityToHex: (opacity: OpacityValue) => string;
|
|
|
13
13
|
* @returns The color string with the opacity value applied.
|
|
14
14
|
*/
|
|
15
15
|
export declare const applyOpacity: (color: string, opacity: string) => string;
|
|
16
|
+
/**
|
|
17
|
+
* * Helper function to generate a random HSL color.
|
|
18
|
+
*
|
|
19
|
+
* @returns A random HSL color string.
|
|
20
|
+
*/
|
|
21
|
+
export declare const generateColorHSL: () => string;
|
|
22
|
+
/**
|
|
23
|
+
* * Helper function to check if the new color is visually too similar to the previous one.
|
|
24
|
+
* * It compares the hue, saturation, and lightness difference between the new color and the last one generated.
|
|
25
|
+
*
|
|
26
|
+
* @param recentColors - Array of recently generated colors.
|
|
27
|
+
* @param newColor - The new color to compare.
|
|
28
|
+
* @returns `Boolean` : `true` if the new color is similar to the previous one.
|
|
29
|
+
*/
|
|
30
|
+
export declare const isSimilarToLast: (recentColors: string[], newColor: string) => boolean;
|
|
16
31
|
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/colors/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,YAAa,YAAY,KAAG,MAO3D,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,YAAY,UAAW,MAAM,WAAW,MAAM,KAAG,MAE7D,CAAC"}
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/colors/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,YAAa,YAAY,KAAG,MAO3D,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,YAAY,UAAW,MAAM,WAAW,MAAM,KAAG,MAE7D,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,QAAO,MAKnC,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,iBACb,MAAM,EAAE,YACZ,MAAM,KACd,OA2BF,CAAC"}
|
package/dist/colors/helpers.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.applyOpacity = exports.convertOpacityToHex = void 0;
|
|
3
|
+
exports.isSimilarToLast = exports.generateColorHSL = exports.applyOpacity = exports.convertOpacityToHex = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* * Converts opacity percentage (0-100) to a 2-digit hex string.
|
|
6
6
|
*
|
|
@@ -26,3 +26,44 @@ const applyOpacity = (color, opacity) => {
|
|
|
26
26
|
return color.concat(opacity);
|
|
27
27
|
};
|
|
28
28
|
exports.applyOpacity = applyOpacity;
|
|
29
|
+
/**
|
|
30
|
+
* * Helper function to generate a random HSL color.
|
|
31
|
+
*
|
|
32
|
+
* @returns A random HSL color string.
|
|
33
|
+
*/
|
|
34
|
+
const generateColorHSL = () => {
|
|
35
|
+
const hue = Math.floor(Math.random() * 360);
|
|
36
|
+
const saturation = 75 + Math.floor(Math.random() * 25);
|
|
37
|
+
const lightness = 50 + Math.floor(Math.random() * 15);
|
|
38
|
+
return `hsl(${hue}, ${saturation}%, ${lightness}%)`;
|
|
39
|
+
};
|
|
40
|
+
exports.generateColorHSL = generateColorHSL;
|
|
41
|
+
/**
|
|
42
|
+
* * Helper function to check if the new color is visually too similar to the previous one.
|
|
43
|
+
* * It compares the hue, saturation, and lightness difference between the new color and the last one generated.
|
|
44
|
+
*
|
|
45
|
+
* @param recentColors - Array of recently generated colors.
|
|
46
|
+
* @param newColor - The new color to compare.
|
|
47
|
+
* @returns `Boolean` : `true` if the new color is similar to the previous one.
|
|
48
|
+
*/
|
|
49
|
+
const isSimilarToLast = (recentColors, newColor) => {
|
|
50
|
+
if (recentColors.length === 0)
|
|
51
|
+
return false;
|
|
52
|
+
const newHSL = newColor.match(/hsl\((\d+), (\d+)%, (\d+)%\)/);
|
|
53
|
+
const lastHSL = recentColors[recentColors.length - 1].match(/hsl\((\d+), (\d+)%, (\d+)%\)/);
|
|
54
|
+
if (!newHSL || !lastHSL)
|
|
55
|
+
return false;
|
|
56
|
+
const newHue = parseInt(newHSL[1], 10);
|
|
57
|
+
const newSaturation = parseInt(newHSL[2], 10);
|
|
58
|
+
const newLightness = parseInt(newHSL[3], 10);
|
|
59
|
+
const lastHue = parseInt(lastHSL[1], 10);
|
|
60
|
+
const lastSaturation = parseInt(lastHSL[2], 10);
|
|
61
|
+
const lastLightness = parseInt(lastHSL[3], 10);
|
|
62
|
+
const hueDifference = Math.abs(newHue - lastHue);
|
|
63
|
+
const saturationDifference = Math.abs(newSaturation - lastSaturation);
|
|
64
|
+
const lightnessDifference = Math.abs(newLightness - lastLightness);
|
|
65
|
+
return (hueDifference < 48 &&
|
|
66
|
+
saturationDifference < 24 &&
|
|
67
|
+
lightnessDifference < 16);
|
|
68
|
+
};
|
|
69
|
+
exports.isSimilarToLast = isSimilarToLast;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* * Utility to generate a unique random HSL color.
|
|
3
|
+
* @param maxColors - The maximum number of recent colors to store in memory.
|
|
4
|
+
* @returns Generated unique random color.
|
|
5
|
+
*/
|
|
6
|
+
export declare const generateRandomColor: (maxColors?: number) => string;
|
|
7
|
+
//# sourceMappingURL=random.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"random.d.ts","sourceRoot":"","sources":["../../src/colors/random.ts"],"names":[],"mappings":"AAQA;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,eAAe,MAAM,KAAQ,MAqB5D,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateRandomColor = void 0;
|
|
4
|
+
const helpers_1 = require("./helpers");
|
|
5
|
+
/** Track previously generated colors. */
|
|
6
|
+
const generatedColors = new Set();
|
|
7
|
+
/** Array of recently generated colors */
|
|
8
|
+
const recentColors = [];
|
|
9
|
+
/**
|
|
10
|
+
* * Utility to generate a unique random HSL color.
|
|
11
|
+
* @param maxColors - The maximum number of recent colors to store in memory.
|
|
12
|
+
* @returns Generated unique random color.
|
|
13
|
+
*/
|
|
14
|
+
const generateRandomColor = (maxColors = 16) => {
|
|
15
|
+
let color;
|
|
16
|
+
// Keep generating until a unique color is found that is also different from the last one
|
|
17
|
+
do {
|
|
18
|
+
color = (0, helpers_1.generateColorHSL)();
|
|
19
|
+
} while (generatedColors.has(color) ||
|
|
20
|
+
(0, helpers_1.isSimilarToLast)(recentColors, color));
|
|
21
|
+
// Add the newly generated color to the set and recent colors
|
|
22
|
+
generatedColors.add(color);
|
|
23
|
+
recentColors.push(color);
|
|
24
|
+
// Limit the recent colors to the last `maxColors` to avoid excessive memory usage
|
|
25
|
+
if (recentColors.length > maxColors) {
|
|
26
|
+
recentColors.shift();
|
|
27
|
+
}
|
|
28
|
+
return color;
|
|
29
|
+
};
|
|
30
|
+
exports.generateRandomColor = generateRandomColor;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
export { capitalizeString, truncateString, generateRandomID } from './string';
|
|
2
|
+
export { getRandomNumber } from './number';
|
|
2
3
|
export { getColorForFirstCharacter } from './colors';
|
|
4
|
+
export { generateRandomColor } from './colors/random';
|
|
5
|
+
export { convertHexToHsl, convertHexToRgb, convertHslToHex, convertHslToRgb, convertRgbToHex, convertRgbToHsl, } from './colors/convert';
|
|
3
6
|
export { flattenArray, createSelectOptions } from './array';
|
|
4
7
|
export { generateQueryParams } from './object';
|
|
5
8
|
//# sourceMappingURL=index.d.ts.map
|
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,EAAE,gBAAgB,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE9E,OAAO,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AAErD,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAE5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE9E,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAE3C,OAAO,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AAErD,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEtD,OAAO,EACN,eAAe,EACf,eAAe,EACf,eAAe,EACf,eAAe,EACf,eAAe,EACf,eAAe,GACf,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAE5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateQueryParams = exports.createSelectOptions = exports.flattenArray = exports.getColorForFirstCharacter = exports.generateRandomID = exports.truncateString = exports.capitalizeString = void 0;
|
|
3
|
+
exports.generateQueryParams = exports.createSelectOptions = exports.flattenArray = exports.convertRgbToHsl = exports.convertRgbToHex = exports.convertHslToRgb = exports.convertHslToHex = exports.convertHexToRgb = exports.convertHexToHsl = exports.generateRandomColor = exports.getColorForFirstCharacter = exports.getRandomNumber = exports.generateRandomID = exports.truncateString = exports.capitalizeString = void 0;
|
|
4
4
|
var string_1 = require("./string");
|
|
5
5
|
Object.defineProperty(exports, "capitalizeString", { enumerable: true, get: function () { return string_1.capitalizeString; } });
|
|
6
6
|
Object.defineProperty(exports, "truncateString", { enumerable: true, get: function () { return string_1.truncateString; } });
|
|
7
7
|
Object.defineProperty(exports, "generateRandomID", { enumerable: true, get: function () { return string_1.generateRandomID; } });
|
|
8
|
+
var number_1 = require("./number");
|
|
9
|
+
Object.defineProperty(exports, "getRandomNumber", { enumerable: true, get: function () { return number_1.getRandomNumber; } });
|
|
8
10
|
var colors_1 = require("./colors");
|
|
9
11
|
Object.defineProperty(exports, "getColorForFirstCharacter", { enumerable: true, get: function () { return colors_1.getColorForFirstCharacter; } });
|
|
12
|
+
var random_1 = require("./colors/random");
|
|
13
|
+
Object.defineProperty(exports, "generateRandomColor", { enumerable: true, get: function () { return random_1.generateRandomColor; } });
|
|
14
|
+
var convert_1 = require("./colors/convert");
|
|
15
|
+
Object.defineProperty(exports, "convertHexToHsl", { enumerable: true, get: function () { return convert_1.convertHexToHsl; } });
|
|
16
|
+
Object.defineProperty(exports, "convertHexToRgb", { enumerable: true, get: function () { return convert_1.convertHexToRgb; } });
|
|
17
|
+
Object.defineProperty(exports, "convertHslToHex", { enumerable: true, get: function () { return convert_1.convertHslToHex; } });
|
|
18
|
+
Object.defineProperty(exports, "convertHslToRgb", { enumerable: true, get: function () { return convert_1.convertHslToRgb; } });
|
|
19
|
+
Object.defineProperty(exports, "convertRgbToHex", { enumerable: true, get: function () { return convert_1.convertRgbToHex; } });
|
|
20
|
+
Object.defineProperty(exports, "convertRgbToHsl", { enumerable: true, get: function () { return convert_1.convertRgbToHsl; } });
|
|
10
21
|
var array_1 = require("./array");
|
|
11
22
|
Object.defineProperty(exports, "flattenArray", { enumerable: true, get: function () { return array_1.flattenArray; } });
|
|
12
23
|
Object.defineProperty(exports, "createSelectOptions", { enumerable: true, get: function () { return array_1.createSelectOptions; } });
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { RandomNumberOptions } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* * Utility to generate a random number between a given range.
|
|
4
|
+
* * If no options are provided, it will generate a random number between `0` and `100` (inclusive).
|
|
5
|
+
* * If `min` is greater than `max`, it will swap the values and generate a random number.
|
|
6
|
+
*
|
|
7
|
+
* @param options - Options for configuring random number generator.
|
|
8
|
+
* @returns Random number.
|
|
9
|
+
*/
|
|
10
|
+
export declare const getRandomNumber: (options?: RandomNumberOptions) => number;
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/number/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAEnD;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,aAAc,mBAAmB,KAAG,MA+C/D,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getRandomNumber = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* * Utility to generate a random number between a given range.
|
|
6
|
+
* * If no options are provided, it will generate a random number between `0` and `100` (inclusive).
|
|
7
|
+
* * If `min` is greater than `max`, it will swap the values and generate a random number.
|
|
8
|
+
*
|
|
9
|
+
* @param options - Options for configuring random number generator.
|
|
10
|
+
* @returns Random number.
|
|
11
|
+
*/
|
|
12
|
+
const getRandomNumber = (options) => {
|
|
13
|
+
const { min = 0, max = 100, includeMin = true, includeMax = true, } = options || {};
|
|
14
|
+
let minimum = min, maximum = max;
|
|
15
|
+
if (min > max) {
|
|
16
|
+
[minimum, maximum] = [max, min];
|
|
17
|
+
return (0, exports.getRandomNumber)({
|
|
18
|
+
min: minimum,
|
|
19
|
+
max: maximum,
|
|
20
|
+
includeMin,
|
|
21
|
+
includeMax,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
if (min === max) {
|
|
25
|
+
return min;
|
|
26
|
+
}
|
|
27
|
+
if (includeMin && includeMax) {
|
|
28
|
+
// Generate random number between min and max, inclusive
|
|
29
|
+
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
30
|
+
}
|
|
31
|
+
if (!includeMin && !includeMax) {
|
|
32
|
+
// Generate random number between min and max, exclusive
|
|
33
|
+
return Math.floor(Math.random() * (max - min - 1)) + min + 1;
|
|
34
|
+
}
|
|
35
|
+
if (includeMin && !includeMax) {
|
|
36
|
+
// Generate random number between min and max, inclusive of min but exclusive of max
|
|
37
|
+
return Math.floor(Math.random() * (max - min)) + min;
|
|
38
|
+
}
|
|
39
|
+
if (!includeMin && includeMax) {
|
|
40
|
+
// Generate random number between min and max, exclusive of min but inclusive of max
|
|
41
|
+
return Math.floor(Math.random() * (max - min)) + min + 1;
|
|
42
|
+
}
|
|
43
|
+
return 0;
|
|
44
|
+
};
|
|
45
|
+
exports.getRandomNumber = getRandomNumber;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** - Options for random number generator */
|
|
2
|
+
export interface RandomNumberOptions {
|
|
3
|
+
/** Minimum number to start with. */
|
|
4
|
+
min?: number;
|
|
5
|
+
/** Maximum number to end with. */
|
|
6
|
+
max?: number;
|
|
7
|
+
/** Whether to include the minimum number. */
|
|
8
|
+
includeMin?: boolean;
|
|
9
|
+
/** Whether to include the maximum number. */
|
|
10
|
+
includeMax?: boolean;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/number/types.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,MAAM,WAAW,mBAAmB;IACnC,oCAAoC;IACpC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,kCAAkC;IAClC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,6CAA6C;IAC7C,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,6CAA6C;IAC7C,UAAU,CAAC,EAAE,OAAO,CAAC;CACrB"}
|
package/package.json
CHANGED