aboutsummaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
authorST-DDT <[email protected]>2024-03-04 01:20:23 +0100
committerGitHub <[email protected]>2024-03-04 00:20:23 +0000
commit82cdf0f1fff28d78e3fdc43b820827ccc7d54aac (patch)
treec8f53ad620e09af98d4b8729aa40737a075ca6e6 /src/modules
parent2b15f2ee7eeba7147c75a24d71042ee996966c92 (diff)
downloadfaker-82cdf0f1fff28d78e3fdc43b820827ccc7d54aac.tar.xz
faker-82cdf0f1fff28d78e3fdc43b820827ccc7d54aac.zip
refactor(color): use signature level defaults (#2703)
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/color/index.ts74
1 files changed, 37 insertions, 37 deletions
diff --git a/src/modules/color/index.ts b/src/modules/color/index.ts
index 712f9799..779bd20b 100644
--- a/src/modules/color/index.ts
+++ b/src/modules/color/index.ts
@@ -466,11 +466,12 @@ export class ColorModule extends ModuleBase {
*/
format?: ColorFormat;
}): string | number[];
- cmyk(options?: { format?: ColorFormat }): string | number[] {
+ cmyk(options: { format?: ColorFormat } = {}): string | number[] {
+ const { format = 'decimal' } = options;
const color: string | number[] = Array.from({ length: 4 }, () =>
this.faker.number.float({ multipleOf: 0.01 })
);
- return toColorFormat(color, options?.format || 'decimal', 'cmyk');
+ return toColorFormat(color, format, 'cmyk');
}
/**
@@ -572,20 +573,19 @@ export class ColorModule extends ModuleBase {
*/
includeAlpha?: boolean;
}): string | number[];
- hsl(options?: {
- format?: ColorFormat;
- includeAlpha?: boolean;
- }): string | number[] {
+ hsl(
+ options: {
+ format?: ColorFormat;
+ includeAlpha?: boolean;
+ } = {}
+ ): string | number[] {
+ const { format = 'decimal', includeAlpha = false } = options;
const hsl: number[] = [this.faker.number.int(360)];
for (let i = 0; i < (options?.includeAlpha ? 3 : 2); i++) {
hsl.push(this.faker.number.float({ multipleOf: 0.01 }));
}
- return toColorFormat(
- hsl,
- options?.format || 'decimal',
- options?.includeAlpha ? 'hsla' : 'hsl'
- );
+ return toColorFormat(hsl, format, includeAlpha ? 'hsla' : 'hsl');
}
/**
@@ -674,20 +674,23 @@ export class ColorModule extends ModuleBase {
*
* @since 7.0.0
*/
- hwb(options?: {
- /**
- * Format of generated RGB color.
- *
- * @default 'decimal'
- */
- format?: ColorFormat;
- }): string | number[] {
+ hwb(
+ options: {
+ /**
+ * Format of generated RGB color.
+ *
+ * @default 'decimal'
+ */
+ format?: ColorFormat;
+ } = {}
+ ): string | number[] {
+ const { format = 'decimal' } = options;
const hsl: number[] = [this.faker.number.int(360)];
for (let i = 0; i < 2; i++) {
hsl.push(this.faker.number.float({ multipleOf: 0.01 }));
}
- return toColorFormat(hsl, options?.format || 'decimal', 'hwb');
+ return toColorFormat(hsl, format, 'hwb');
}
/**
@@ -762,7 +765,8 @@ export class ColorModule extends ModuleBase {
*/
format?: ColorFormat;
}): string | number[];
- lab(options?: { format?: ColorFormat }): string | number[] {
+ lab(options: { format?: ColorFormat } = {}): string | number[] {
+ const { format = 'decimal' } = options;
const lab = [this.faker.number.float({ multipleOf: 0.000001 })];
for (let i = 0; i < 2; i++) {
lab.push(
@@ -770,7 +774,7 @@ export class ColorModule extends ModuleBase {
);
}
- return toColorFormat(lab, options?.format || 'decimal', 'lab');
+ return toColorFormat(lab, format, 'lab');
}
/**
@@ -857,13 +861,14 @@ export class ColorModule extends ModuleBase {
*/
format?: ColorFormat;
}): string | number[];
- lch(options?: { format?: ColorFormat }): string | number[] {
+ lch(options: { format?: ColorFormat } = {}): string | number[] {
+ const { format = 'decimal' } = options;
const lch = [this.faker.number.float({ multipleOf: 0.000001 })];
for (let i = 0; i < 2; i++) {
lch.push(this.faker.number.float({ max: 230, multipleOf: 0.1 }));
}
- return toColorFormat(lch, options?.format || 'decimal', 'lch');
+ return toColorFormat(lch, format, 'lch');
}
/**
@@ -959,22 +964,17 @@ export class ColorModule extends ModuleBase {
*/
space?: CssSpaceType;
}): string | number[];
- colorByCSSColorSpace(options?: {
- format?: ColorFormat;
- space?: CssSpaceType;
- }): string | number[] {
- if (options?.format === 'css' && !options?.space) {
- options = { ...options, space: 'sRGB' };
- }
+ colorByCSSColorSpace(
+ options: {
+ format?: ColorFormat;
+ space?: CssSpaceType;
+ } = {}
+ ): string | number[] {
+ const { format = 'decimal', space = 'sRGB' } = options;
const color = Array.from({ length: 3 }, () =>
this.faker.number.float({ multipleOf: 0.0001 })
);
- return toColorFormat(
- color,
- options?.format || 'decimal',
- 'color',
- options?.space
- );
+ return toColorFormat(color, format, 'color', space);
}
}