aboutsummaryrefslogtreecommitdiff
path: root/src/modules/color
diff options
context:
space:
mode:
authorLeyla Jähnig <[email protected]>2022-11-25 16:59:10 +0100
committerGitHub <[email protected]>2022-11-25 16:59:10 +0100
commit7d4d99f00bf1e29c14346bd6a9fab33c8e7d5743 (patch)
tree323754ca575c56ccf688539cfcca66d54c903602 /src/modules/color
parent0af0fff4a410d7531368c709327ba0798a47091a (diff)
downloadfaker-7d4d99f00bf1e29c14346bd6a9fab33c8e7d5743.tar.xz
faker-7d4d99f00bf1e29c14346bd6a9fab33c8e7d5743.zip
feat(number): move methods to new module (#1122)
Co-authored-by: ST-DDT <[email protected]> Co-authored-by: Eric Cheng <[email protected]> Co-authored-by: Leyla Jähnig <[email protected]> Co-authored-by: Shinigami92 <[email protected]>
Diffstat (limited to 'src/modules/color')
-rw-r--r--src/modules/color/index.ts34
1 files changed, 12 insertions, 22 deletions
diff --git a/src/modules/color/index.ts b/src/modules/color/index.ts
index 4fd79a06..b232f649 100644
--- a/src/modules/color/index.ts
+++ b/src/modules/color/index.ts
@@ -320,13 +320,9 @@ export class ColorModule {
color = formatHexColor(color, options);
return color;
}
- color = Array.from({ length: 3 }).map(() =>
- this.faker.datatype.number({ min: 0, max: 255 })
- );
+ color = Array.from({ length: 3 }).map(() => this.faker.number.int(255));
if (includeAlpha) {
- color.push(
- this.faker.datatype.float({ min: 0, max: 1, precision: 0.01 })
- );
+ color.push(this.faker.number.float({ max: 1, precision: 0.01 }));
cssFunction = 'rgba';
}
return toColorFormat(color, format, cssFunction);
@@ -385,7 +381,7 @@ export class ColorModule {
cmyk(options?: { format?: ColorFormat }): string | number[];
cmyk(options?: { format?: ColorFormat }): string | number[] {
const color: string | number[] = Array.from({ length: 4 }).map(() =>
- this.faker.datatype.float({ min: 0, max: 1, precision: 0.01 })
+ this.faker.number.float({ max: 1, precision: 0.01 })
);
return toColorFormat(color, options?.format || 'decimal', 'cmyk');
}
@@ -460,9 +456,9 @@ export class ColorModule {
format?: ColorFormat;
includeAlpha?: boolean;
}): string | number[] {
- const hsl: number[] = [this.faker.datatype.number({ min: 0, max: 360 })];
+ const hsl: number[] = [this.faker.number.int(360)];
for (let i = 0; i < (options?.includeAlpha ? 3 : 2); i++) {
- hsl.push(this.faker.datatype.float({ min: 0, max: 1, precision: 0.01 }));
+ hsl.push(this.faker.number.float({ max: 1, precision: 0.01 }));
}
return toColorFormat(
hsl,
@@ -537,9 +533,9 @@ export class ColorModule {
* @since 7.0.0
*/
hwb(options?: { format?: ColorFormat }): string | number[] {
- const hsl: number[] = [this.faker.datatype.number({ min: 0, max: 360 })];
+ const hsl: number[] = [this.faker.number.int(360)];
for (let i = 0; i < 2; i++) {
- hsl.push(this.faker.datatype.float({ min: 0, max: 1, precision: 0.01 }));
+ hsl.push(this.faker.number.float({ max: 1, precision: 0.01 }));
}
return toColorFormat(hsl, options?.format || 'decimal', 'hwb');
}
@@ -596,12 +592,10 @@ export class ColorModule {
*/
lab(options?: { format?: ColorFormat }): string | number[];
lab(options?: { format?: ColorFormat }): string | number[] {
- const lab = [
- this.faker.datatype.float({ min: 0, max: 1, precision: 0.000001 }),
- ];
+ const lab = [this.faker.number.float({ max: 1, precision: 0.000001 })];
for (let i = 0; i < 2; i++) {
lab.push(
- this.faker.datatype.float({ min: -100, max: 100, precision: 0.0001 })
+ this.faker.number.float({ min: -100, max: 100, precision: 0.0001 })
);
}
return toColorFormat(lab, options?.format || 'decimal', 'lab');
@@ -671,13 +665,9 @@ export class ColorModule {
*/
lch(options?: { format?: ColorFormat }): string | number[];
lch(options?: { format?: ColorFormat }): string | number[] {
- const lch = [
- this.faker.datatype.float({ min: 0, max: 1, precision: 0.000001 }),
- ];
+ const lch = [this.faker.number.float({ max: 1, precision: 0.000001 })];
for (let i = 0; i < 2; i++) {
- lch.push(
- this.faker.datatype.number({ min: 0, max: 230, precision: 0.1 })
- );
+ lch.push(this.faker.number.float({ max: 230, precision: 0.1 }));
}
return toColorFormat(lch, options?.format || 'decimal', 'lch');
}
@@ -753,7 +743,7 @@ export class ColorModule {
options = { ...options, space: 'sRGB' };
}
const color = Array.from({ length: 3 }).map(() =>
- this.faker.datatype.float({ min: 0, max: 1, precision: 0.0001 })
+ this.faker.number.float({ max: 1, precision: 0.0001 })
);
return toColorFormat(
color,