Skip to content

Commit 75bec9e

Browse files
committed
Remove nullToZero
1 parent 744cd7f commit 75bec9e

1 file changed

Lines changed: 8 additions & 16 deletions

File tree

lib/src/value/color.ts

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,6 @@ function getColorSpace(options: ChannelOptions): KnownColorSpace {
117117
throw valueError('No color space found');
118118
}
119119

120-
/**
121-
* Convert from the ColorJS representation of a missing component (`null`) to
122-
* `0`.
123-
*/
124-
function nullToZero(val: number | null): number {
125-
return val ?? 0;
126-
}
127-
128120
/** Convert from sRGB (0-1) to RGB (0-255) units. */
129121
function coordToRgb(val: number | null): number | null {
130122
return val === null ? val : val * 255;
@@ -583,7 +575,7 @@ export class SassColor extends Value {
583575

584576
/** This color's alpha channel, between `0` and `1`. */
585577
get alpha(): number {
586-
return nullToZero(this.color.alpha);
578+
return this.color.alpha ?? 0;
587579
}
588580

589581
/** The name of this color's color space. */
@@ -632,7 +624,7 @@ export class SassColor extends Value {
632624
number | null,
633625
];
634626
}
635-
return List(coords.map(nullToZero));
627+
return List(coords.map(val => val ?? 0));
636628
}
637629

638630
/**
@@ -672,7 +664,7 @@ export class SassColor extends Value {
672664
*/
673665
get hue(): number {
674666
emitColor4ApiGetterDeprecation('hue');
675-
return nullToZero(this.color.hsl.hue);
667+
return this.color.hsl.hue ?? 0;
676668
}
677669

678670
/**
@@ -682,7 +674,7 @@ export class SassColor extends Value {
682674
*/
683675
get saturation(): number {
684676
emitColor4ApiGetterDeprecation('saturation');
685-
return nullToZero(this.color.hsl.saturation);
677+
return this.color.hsl.saturation ?? 0;
686678
}
687679

688680
/**
@@ -692,7 +684,7 @@ export class SassColor extends Value {
692684
*/
693685
get lightness(): number {
694686
emitColor4ApiGetterDeprecation('lightness');
695-
return nullToZero(this.color.hsl.lightness);
687+
return this.color.hsl.lightness ?? 0;
696688
}
697689

698690
/**
@@ -702,7 +694,7 @@ export class SassColor extends Value {
702694
*/
703695
get whiteness(): number {
704696
emitColor4ApiGetterDeprecation('whiteness');
705-
return nullToZero(this.color.hwb.whiteness);
697+
return this.color.hwb.whiteness ?? 0;
706698
}
707699

708700
/**
@@ -712,7 +704,7 @@ export class SassColor extends Value {
712704
*/
713705
get blackness(): number {
714706
emitColor4ApiGetterDeprecation('blackness');
715-
return nullToZero(this.color.hwb.blackness);
707+
return this.color.hwb.blackness ?? 0;
716708
}
717709

718710
assertColor(): SassColor {
@@ -789,7 +781,7 @@ export class SassColor extends Value {
789781
});
790782
}
791783
if (space === 'rgb') val = coordToRgb(val);
792-
return nullToZero(val);
784+
return val ?? 0;
793785
}
794786

795787
/**

0 commit comments

Comments
 (0)