Skip to content

Commit f1fee9a

Browse files
authored
Merge branch 'main' into docs-about
2 parents 5e7601f + 0304120 commit f1fee9a

17 files changed

+467
-431
lines changed

LICENSE

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Faker - Copyright (c) 2022
22

3-
This software consists of voluntary contributions made by many individuals.
3+
This software consists of voluntary contributions made by many individuals.
44
For exact contribution history, see the revision history
55
available at https://github.com/faker-js/faker
66

@@ -23,7 +23,7 @@ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
2323
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
2424
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2525

26-
===
26+
===
2727

2828
From: https://github.com/faker-js/faker/commit/a9f98046c7d5eeaabe12fc587024c06d683800b8
2929
To: https://github.com/faker-js/faker/commit/29234378807c4141588861f69421bf20b5ac635e
@@ -58,4 +58,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
5858
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
5959
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
6060
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
61-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
61+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ An in-depth overview of the API methods is available in the [documentation](http
124124
| Commerce | `faker.commerce.product()` | Polo t-shirt |
125125
| Company | `faker.company.companyName()` | Zboncak and Sons |
126126
| Database | `faker.database.engine()` | MyISAM |
127-
| Datatype | `faker.datatype.uuid()` | 1oijf8-3iuhiu-21jddj-1092jf |
127+
| Datatype | `faker.datatype.uuid()` | 7b16dd12-935e-4acc-8381-b1e457bf0176 |
128128
| Date | `faker.date.past()` | Sat Oct 20 2018 04:19:38 GMT-0700 (Pacific Daylight Time) |
129129
| Finance | `faker.finance.amount()` | ¥23400 (After setting locale) |
130130
| Git | `faker.git.commitMessage()` | feat: add products list page |

src/address.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,8 +407,8 @@ export class Address {
407407
latitude(max: number = 90, min: number = -90, precision: number = 4): string {
408408
return this.faker.datatype
409409
.number({
410-
max: max,
411-
min: min,
410+
min,
411+
max,
412412
precision: parseFloat((0.0).toPrecision(precision) + '1'),
413413
})
414414
.toFixed(precision);

src/datatype.ts

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ export class Datatype {
2020
*
2121
* @param options Maximum value or options object.
2222
* @param options.min Lower bound for generated number. Defaults to `0`.
23-
* @param options.max Upper bound for generated number. Defaults to `99999`.
23+
* @param options.max Upper bound for generated number. Defaults to `min + 99999`.
2424
* @param options.precision Precision of the generated number. Defaults to `1`.
2525
*
26+
* @throws When options define `max < min`
27+
*
2628
* @example
2729
* faker.datatype.number() // 55422
2830
* faker.datatype.number(100) // 52
@@ -34,39 +36,27 @@ export class Datatype {
3436
number(
3537
options?: number | { min?: number; max?: number; precision?: number }
3638
): number {
37-
if (typeof options === 'number') {
38-
options = { max: options };
39-
}
39+
const opts = typeof options === 'number' ? { max: options } : options ?? {};
4040

41-
options = options ?? {};
42-
43-
let max = 99999;
44-
let min = 0;
45-
let precision = 1;
46-
if (typeof options.min === 'number') {
47-
min = options.min;
48-
}
49-
50-
if (typeof options.max === 'number') {
51-
max = options.max;
52-
}
41+
const min = typeof opts.min === 'number' ? opts.min : 0;
42+
let max = typeof opts.max === 'number' ? opts.max : min + 99999;
43+
const precision = typeof opts.precision === 'number' ? opts.precision : 1;
5344

54-
if (typeof options.precision === 'number') {
55-
precision = options.precision;
45+
if (max < min) {
46+
throw new Error(`Max ${max} should be larger then min ${min}`);
5647
}
5748

5849
// Make the range inclusive of the max value
5950
if (max >= 0) {
6051
max += precision;
6152
}
6253

63-
let randomNumber = Math.floor(
54+
const randomNumber = Math.floor(
6455
this.faker.mersenne.rand(max / precision, min / precision)
6556
);
66-
// Workaround problem in Float point arithmetics for e.g. 6681493 / 0.01
67-
randomNumber = randomNumber / (1 / precision);
6857

69-
return randomNumber;
58+
// Workaround problem in float point arithmetics for e.g. 6681493 / 0.01
59+
return randomNumber / (1 / precision);
7060
}
7161

7262
/**

src/internet.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Faker } from '.';
2-
import * as random_ua from './vendor/user-agent';
2+
import * as random_ua from './utils/user-agent';
33

44
/**
55
* Module to generate internet related entries.

src/mersenne.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Gen from './vendor/mersenne';
1+
import Gen from './utils/mersenne';
22

33
/**
44
* Module to generate seed based random numbers.

src/random.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,12 @@ export class Random {
107107
arrayElement<T = string>(
108108
array: ReadonlyArray<T> = ['a', 'b', 'c'] as unknown as ReadonlyArray<T>
109109
): T {
110-
const r = this.faker.datatype.number({ max: array.length - 1 });
111-
return array[r];
110+
const index =
111+
array.length > 1
112+
? this.faker.datatype.number({ max: array.length - 1 })
113+
: 0;
114+
115+
return array[index];
112116
}
113117

114118
/**

src/unique.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { RecordKey } from './vendor/unique';
2-
import * as uniqueExec from './vendor/unique';
1+
import type { RecordKey } from './utils/unique';
2+
import * as uniqueExec from './utils/unique';
33

44
/**
55
* Module to generate unique entries.

0 commit comments

Comments
 (0)