diff options
| author | Leyla Jähnig <[email protected]> | 2022-11-25 16:59:10 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-11-25 16:59:10 +0100 |
| commit | 7d4d99f00bf1e29c14346bd6a9fab33c8e7d5743 (patch) | |
| tree | 323754ca575c56ccf688539cfcca66d54c903602 /src/modules/location | |
| parent | 0af0fff4a410d7531368c709327ba0798a47091a (diff) | |
| download | faker-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/location')
| -rw-r--r-- | src/modules/location/index.ts | 20 |
1 files changed, 5 insertions, 15 deletions
diff --git a/src/modules/location/index.ts b/src/modules/location/index.ts index fcb8aabd..a4e6ef9e 100644 --- a/src/modules/location/index.ts +++ b/src/modules/location/index.ts @@ -60,7 +60,7 @@ export class LocationModule { zipCodeByState(state: string): string { const zipRange = this.faker.definitions.location.postcode_by_state?.[state]; if (zipRange) { - return String(this.faker.datatype.number(zipRange)); + return String(this.faker.number.int(zipRange)); } return this.zipCode(); } @@ -269,11 +269,7 @@ export class LocationModule { */ // TODO @xDivisionByZerox 2022-06-12 this signature should probably be an object for easier maintainability latitude(max: number = 90, min: number = -90, precision: number = 4): number { - return this.faker.datatype.number({ - min, - max, - precision: parseFloat(`${(0.0).toPrecision(precision)}1`), - }); + return this.faker.number.float({ min, max, precision: 10 ** -precision }); } /** @@ -295,11 +291,7 @@ export class LocationModule { min: number = -180, precision: number = 4 ): number { - return this.faker.datatype.number({ - max: max, - min: min, - precision: parseFloat(`${(0.0).toPrecision(precision)}1`), - }); + return this.faker.number.float({ max, min, precision: 10 ** -precision }); } /** @@ -399,8 +391,7 @@ export class LocationModule { return [this.latitude(), this.longitude()]; } - const angleRadians = this.faker.datatype.float({ - min: 0, + const angleRadians = this.faker.number.float({ max: 2 * Math.PI, precision: 0.00001, }); // in ° radians @@ -408,8 +399,7 @@ export class LocationModule { const radiusMetric = isMetric ? radius : radius * 1.60934; // in km const errorCorrection = 0.995; // avoid float issues const distanceInKm = - this.faker.datatype.float({ - min: 0, + this.faker.number.float({ max: radiusMetric, precision: 0.001, }) * errorCorrection; // in km |
