diff options
| author | ST-DDT <[email protected]> | 2022-12-10 10:38:58 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-12-10 09:38:58 +0000 |
| commit | e4839a9fc91d0ffc36c2015b34fcba33a6797bb4 (patch) | |
| tree | 947f803cb092c43d54dcf6cb719d9bfa5aa91591 /src/modules | |
| parent | e1811509e5823b0d9879116bdf3d8781dd1d7912 (diff) | |
| download | faker-e4839a9fc91d0ffc36c2015b34fcba33a6797bb4.tar.xz faker-e4839a9fc91d0ffc36c2015b34fcba33a6797bb4.zip | |
fix(number): values out of bounds (#1648)
Diffstat (limited to 'src/modules')
| -rw-r--r-- | src/modules/number/index.ts | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/modules/number/index.ts b/src/modules/number/index.ts index 292fbcf2..cef0b27c 100644 --- a/src/modules/number/index.ts +++ b/src/modules/number/index.ts @@ -43,12 +43,19 @@ export class NumberModule { } const { min = 0, max = min + 99999 } = options; + const effectiveMin = Math.ceil(min); + const effectiveMax = Math.floor(max); - if (max === min) { - return min; + if (effectiveMin === effectiveMax) { + return effectiveMin; } - if (max < min) { + if (effectiveMax < effectiveMin) { + if (max >= min) { + throw new FakerError( + `No integer value between ${min} and ${max} found.` + ); + } throw new FakerError(`Max ${max} should be greater than min ${min}.`); } @@ -56,7 +63,7 @@ export class NumberModule { // @ts-expect-error: access private member field this.faker._mersenne; - return mersenne.next({ min, max: max + 1 }); + return mersenne.next({ min: effectiveMin, max: effectiveMax + 1 }); } /** |
