Skip to content

Commit cae2ba5

Browse files
Merge pull request #379 from 4lessandrodev/feat/update-core-deps
Feat/update core deps
2 parents b3fb774 + 6f9d1d4 commit cae2ba5

File tree

5 files changed

+513
-725
lines changed

5 files changed

+513
-725
lines changed

lib/utils/color-converter.util.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { HEXColorValueObject, RGBColorValueObject } from '..';
2-
31
const colorConverter = {
42
/**
53
*
@@ -8,8 +6,8 @@ const colorConverter = {
86
* @example #ffffff
97
* @returns rgb(255, 255, 255)
108
*/
11-
HEXToRGB(color: string) {
12-
const isValid = HEXColorValueObject.isValidProps(color);
9+
HEXToRGB(color: string, validate?: (color: string) => boolean) {
10+
const isValid = validate?.(color) ?? true;
1311

1412
if (!isValid) {
1513
return color;
@@ -32,8 +30,8 @@ const colorConverter = {
3230
* @example rgb(255, 255, 255)
3331
* @returns hex color #ffffff
3432
*/
35-
RGBToHEX(color: string) {
36-
const isValid = RGBColorValueObject.isValidProps(color);
33+
RGBToHEX(color: string, validate?: (color: string) => boolean) {
34+
const isValid = validate?.(color) ?? true;
3735

3836
if (!isValid) {
3937
return color;

lib/utils/color-generator.util.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const colorGenerator = {
2929
const color = randomRGBColor();
3030
let hexColor = colorConverter.RGBToHEX(
3131
`rgb(${color.R}, ${color.G}, ${color.B})`,
32+
() => true,
3233
);
3334
hexColor += '000';
3435
return hexColor.slice(0, 7);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
"husky": "^9.0.6",
7373
"jest": "^27.5.1",
7474
"lint-staged": "^15.0.1",
75-
"madge": "^6.0.0",
75+
"madge": "^7.0.0",
7676
"prettier": "^3.0.0",
7777
"rimraf": "^5.0.5",
7878
"ts-jest": "^27.1.4",

tests/utils/color-converter.util.spec.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,28 @@ describe('color-converter', () => {
1717
});
1818

1919
it('should convert from rgb to hex', () => {
20-
const converter = colorConverter.RGBToHEX('rgb(20, 250, 30)');
20+
const converter = colorConverter.RGBToHEX(
21+
'rgb(20, 250, 30)',
22+
() => true,
23+
);
2124
expect(converter).toBe('#14fa1e');
2225
});
2326

2427
it('should convert from hex to rgb', () => {
25-
const converter = colorConverter.HEXToRGB('#ffffff');
28+
const converter = colorConverter.HEXToRGB('#ffffff', () => true);
2629
expect(converter).toBe('rgb(255, 255, 255)');
2730
});
2831

2932
it('should return the same value if provide an invalid rgb color', () => {
30-
const converter = colorConverter.RGBToHEX('rgb(300, 255, 255)');
33+
const converter = colorConverter.RGBToHEX(
34+
'rgb(300, 255, 255)',
35+
() => false,
36+
);
3137
expect(converter).toBe('rgb(300, 255, 255)');
3238
});
3339

3440
it('should return the same value if provide an invalid hex color', () => {
35-
const converter = colorConverter.HEXToRGB('#invalid');
41+
const converter = colorConverter.HEXToRGB('#invalid', () => false);
3642
expect(converter).toBe('#invalid');
3743
});
3844
});

0 commit comments

Comments
 (0)