Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: datatype number #798

Merged
merged 9 commits into from
Apr 8, 2022
19 changes: 6 additions & 13 deletions src/datatype.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,15 @@ export class Datatype {
* faker.datatype.number({ min: 10, max: 100, precision: 0.01 }) // 36.94
*/
number(
options?: number | { min?: number; max?: number; precision?: number }
options: number | { min?: number; max?: number; precision?: number } = 99999
): number {
let min: number;
let max: number;
let precision: number;

if (typeof options === 'object') {
min = options.min ?? 0;
max = options.max ?? min + 99999;
precision = options.precision ?? 1;
} else {
min = 0;
max = options ?? 99999;
precision = 1;
if (typeof options === 'number') {
options = { max: options };
}

const { min = 0, precision = 1 } = options;
let max = options.max ?? min + 99999;
ST-DDT marked this conversation as resolved.
Show resolved Hide resolved

if (max === min) {
return min;
}
Expand Down