aboutsummaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/color/index.ts14
-rw-r--r--src/modules/datatype/index.ts15
-rw-r--r--src/modules/helpers/index.ts4
-rw-r--r--src/modules/number/index.ts22
4 files changed, 31 insertions, 24 deletions
diff --git a/src/modules/color/index.ts b/src/modules/color/index.ts
index 11ebdcd9..167fc225 100644
--- a/src/modules/color/index.ts
+++ b/src/modules/color/index.ts
@@ -322,7 +322,7 @@ export class ColorModule {
}
color = Array.from({ length: 3 }, () => this.faker.number.int(255));
if (includeAlpha) {
- color.push(this.faker.number.float({ max: 1, precision: 0.01 }));
+ color.push(this.faker.number.float());
cssFunction = 'rgba';
}
return toColorFormat(color, format, cssFunction);
@@ -381,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 }, () =>
- this.faker.number.float({ max: 1, precision: 0.01 })
+ this.faker.number.float()
);
return toColorFormat(color, options?.format || 'decimal', 'cmyk');
}
@@ -458,7 +458,7 @@ export class ColorModule {
}): string | number[] {
const hsl: number[] = [this.faker.number.int(360)];
for (let i = 0; i < (options?.includeAlpha ? 3 : 2); i++) {
- hsl.push(this.faker.number.float({ max: 1, precision: 0.01 }));
+ hsl.push(this.faker.number.float());
}
return toColorFormat(
hsl,
@@ -535,7 +535,7 @@ export class ColorModule {
hwb(options?: { format?: ColorFormat }): string | number[] {
const hsl: number[] = [this.faker.number.int(360)];
for (let i = 0; i < 2; i++) {
- hsl.push(this.faker.number.float({ max: 1, precision: 0.01 }));
+ hsl.push(this.faker.number.float());
}
return toColorFormat(hsl, options?.format || 'decimal', 'hwb');
}
@@ -592,7 +592,7 @@ export class ColorModule {
*/
lab(options?: { format?: ColorFormat }): string | number[];
lab(options?: { format?: ColorFormat }): string | number[] {
- const lab = [this.faker.number.float({ max: 1, precision: 0.000001 })];
+ const lab = [this.faker.number.float({ precision: 0.000001 })];
for (let i = 0; i < 2; i++) {
lab.push(
this.faker.number.float({ min: -100, max: 100, precision: 0.0001 })
@@ -665,7 +665,7 @@ export class ColorModule {
*/
lch(options?: { format?: ColorFormat }): string | number[];
lch(options?: { format?: ColorFormat }): string | number[] {
- const lch = [this.faker.number.float({ max: 1, precision: 0.000001 })];
+ const lch = [this.faker.number.float({ precision: 0.000001 })];
for (let i = 0; i < 2; i++) {
lch.push(this.faker.number.float({ max: 230, precision: 0.1 }));
}
@@ -743,7 +743,7 @@ export class ColorModule {
options = { ...options, space: 'sRGB' };
}
const color = Array.from({ length: 3 }, () =>
- this.faker.number.float({ max: 1, precision: 0.0001 })
+ this.faker.number.float({ precision: 0.0001 })
);
return toColorFormat(
color,
diff --git a/src/modules/datatype/index.ts b/src/modules/datatype/index.ts
index b7000dc6..f9c2bac6 100644
--- a/src/modules/datatype/index.ts
+++ b/src/modules/datatype/index.ts
@@ -83,7 +83,7 @@ export class DatatypeModule {
* @deprecated Use `faker.number.float()` instead.
*/
float(
- options?: number | { min?: number; max?: number; precision?: number }
+ options: number | { min?: number; max?: number; precision?: number } = {}
): number {
deprecated({
deprecated: 'faker.datatype.float()',
@@ -91,7 +91,16 @@ export class DatatypeModule {
since: '8.0',
until: '9.0',
});
- return this.faker.number.float(options);
+
+ if (typeof options === 'number') {
+ options = {
+ precision: options,
+ };
+ }
+
+ const { min = 0, max = min + 99999, precision = 0.01 } = options;
+
+ return this.faker.number.float({ min, max, precision });
}
/**
@@ -210,7 +219,7 @@ export class DatatypeModule {
// This check is required to avoid returning false when float() returns 1
return true;
}
- return this.faker.number.float({ max: 1 }) < probability;
+ return this.faker.number.float() < probability;
}
/**
diff --git a/src/modules/helpers/index.ts b/src/modules/helpers/index.ts
index 37487247..4cf9ad38 100644
--- a/src/modules/helpers/index.ts
+++ b/src/modules/helpers/index.ts
@@ -484,9 +484,7 @@ export class HelpersModule {
let index: number;
while (i-- > min) {
- index = Math.floor(
- (i + 1) * this.faker.number.float({ min: 0, max: 0.99 })
- );
+ index = Math.floor((i + 1) * this.faker.number.float({ max: 0.99 }));
temp = arrayCopy[index];
arrayCopy[index] = arrayCopy[i];
arrayCopy[i] = temp;
diff --git a/src/modules/number/index.ts b/src/modules/number/index.ts
index 1f46cb64..292fbcf2 100644
--- a/src/modules/number/index.ts
+++ b/src/modules/number/index.ts
@@ -62,18 +62,18 @@ export class NumberModule {
/**
* Returns a single random floating-point number for a given precision or range and precision.
*
- * @param options Precision or options object. Defaults to `{}`.
- * @param options.min Lower bound for generated number. Defaults to `0`.
- * @param options.max Upper bound for generated number. Defaults to `99999`.
+ * @param options Upper bound or options object. Defaults to `{}`.
+ * @param options.min Lower bound for generated number. Defaults to `0.0`.
+ * @param options.max Upper bound for generated number. Defaults to `1.0`.
* @param options.precision Precision of the generated number. Defaults to `0.01`.
*
* @example
- * faker.number.float() // 51696.36
- * faker.number.float(1) // 52023.2
- * faker.number.float({ min: 1000000 }) // 212859.76
- * faker.number.float({ max: 100 }) // 28.11
- * faker.number.float({ precision: 0.1 }) // 84055.3
- * faker.number.float({ min: 10, max: 100, precision: 0.001 }) // 57.315
+ * faker.number.float() // 0.89
+ * faker.number.float(3) // 1.14
+ * faker.number.float({ min: -1000000 }) // -823469.91
+ * faker.number.float({ max: 100 }) // 27.28
+ * faker.number.float({ precision: 0.1 }) // 0.9
+ * faker.number.float({ min: 10, max: 100, precision: 0.001 }) // 35.415
*
* @since 8.0.0
*/
@@ -82,11 +82,11 @@ export class NumberModule {
): number {
if (typeof options === 'number') {
options = {
- precision: options,
+ max: options,
};
}
- const { min = 0, max = min + 99999, precision = 0.01 } = options;
+ const { min = 0, max = 1, precision = 0.01 } = options;
if (max === min) {
return min;