Skip to content

Commit 6f9d1d4

Browse files
committed
fix: solve error on merge
1 parent e5f7008 commit 6f9d1d4

File tree

4 files changed

+16
-16
lines changed

4 files changed

+16
-16
lines changed

lib/utils/color-converter.util.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ const colorConverter = {
66
* @example #ffffff
77
* @returns rgb(255, 255, 255)
88
*/
9-
HEXToRGB(color: string, validate: (color: string) => boolean) {
10-
const isValid = validate(color);
9+
HEXToRGB(color: string, validate?: (color: string) => boolean) {
10+
const isValid = validate?.(color) ?? true;
1111

1212
if (!isValid) {
1313
return color;
@@ -30,8 +30,8 @@ const colorConverter = {
3030
* @example rgb(255, 255, 255)
3131
* @returns hex color #ffffff
3232
*/
33-
RGBToHEX(color: string, validate: (color: string) => boolean) {
34-
const isValid = validate(color);
33+
RGBToHEX(color: string, validate?: (color: string) => boolean) {
34+
const isValid = validate?.(color) ?? true;
3535

3636
if (!isValid) {
3737
return color;

lib/utils/hex-color.value-object.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,7 @@ class HEXColorValueObject extends ValueObject<Prop> {
4949
* @example rgb(255, 255, 255)
5050
*/
5151
getAsRGB(): string {
52-
return colorConverter.HEXToRGB(
53-
this.props.value,
54-
HEXColorValueObject.isValidProps,
55-
);
52+
return colorConverter.HEXToRGB(this.props.value);
5653
}
5754

5855
/**

lib/utils/rgb-color.value-object.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,7 @@ class RGBColorValueObject extends ValueObject<Prop> {
5151
* @example #ffffff
5252
*/
5353
getAsHex(): string {
54-
return colorConverter.RGBToHEX(
55-
this.props.value,
56-
RGBColorValueObject.isValidProps,
57-
);
54+
return colorConverter.RGBToHEX(this.props.value);
5855
}
5956

6057
/**

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)