Skip to content

Commit d095e96

Browse files
authored
Merge branch 'main' into add-alternative-cdn-links
2 parents fa0d743 + 5642470 commit d095e96

17 files changed

+524
-118
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pnpm install @faker-js/faker -D
4646
<script>
4747
const randomName = faker.name.findName(); // Caitlyn Kerluke
4848
const randomEmail = faker.internet.email(); // [email protected]
49-
const randomCard = faker.helpers.createCard(); // random contact card containing many properties
49+
const randomPhoneNumber = faker.phone.phoneNumber(); // (746) 637-3344 x8083
5050
</script>
5151
```
5252

@@ -56,7 +56,7 @@ pnpm install @faker-js/faker -D
5656
const { faker } = require('@faker-js/faker');
5757
const randomName = faker.name.findName(); // Rowan Nikolaus
5858
const randomEmail = faker.internet.email(); // [email protected]
59-
const randomCard = faker.helpers.createCard(); // random contact card containing many properties
59+
const randomPhoneNumber = faker.phone.phoneNumber(); // (279) 329-8663 x30233
6060
```
6161

6262
### CDN/Deno
@@ -66,7 +66,7 @@ import { faker } from 'https://cdn.skypack.dev/@faker-js/faker';
6666

6767
const randomName = faker.name.findName(); // Willie Bahringer
6868
const randomEmail = faker.internet.email(); // [email protected]
69-
const randomCard = faker.helpers.createCard(); // random contact card containing many properties
69+
const randomPhoneNumber = faker.phone.phoneNumber(); // 938-672-1359 x418
7070
```
7171

7272
#### Alternative CDN links

src/datatype.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,32 +47,31 @@ export class Datatype {
4747

4848
options = options ?? {};
4949

50-
if (typeof options.min === 'undefined') {
51-
options.min = 0;
50+
let max = 99999;
51+
let min = 0;
52+
let precision = 1;
53+
if (typeof options.min === 'number') {
54+
min = options.min;
5255
}
5356

54-
if (typeof options.max === 'undefined') {
55-
options.max = 99999;
57+
if (typeof options.max === 'number') {
58+
max = options.max;
5659
}
5760

58-
if (typeof options.precision === 'undefined') {
59-
options.precision = 1;
61+
if (typeof options.precision === 'number') {
62+
precision = options.precision;
6063
}
6164

6265
// Make the range inclusive of the max value
63-
let max = options.max;
6466
if (max >= 0) {
65-
max += options.precision;
67+
max += precision;
6668
}
6769

6870
let randomNumber = Math.floor(
69-
this.faker.mersenne.rand(
70-
max / options.precision,
71-
options.min / options.precision
72-
)
71+
this.faker.mersenne.rand(max / precision, min / precision)
7372
);
7473
// Workaround problem in Float point arithmetics for e.g. 6681493 / 0.01
75-
randomNumber = randomNumber / (1 / options.precision);
74+
randomNumber = randomNumber / (1 / precision);
7675

7776
return randomNumber;
7877
}

src/finance.ts

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -258,32 +258,17 @@ export class Finance {
258258
*/
259259
creditCardNumber(provider = ''): string {
260260
let format: string;
261-
let formats: string | string[];
262261
const localeFormat = this.faker.definitions.finance.credit_card;
263262
if (provider in localeFormat) {
264-
formats = localeFormat[provider]; // there could be multiple formats
265-
if (typeof formats === 'string') {
266-
format = formats;
267-
} else {
268-
format = this.faker.random.arrayElement(formats);
269-
}
263+
format = this.faker.random.arrayElement(localeFormat[provider]);
270264
} else if (provider.match(/#/)) {
271265
// The user chose an optional scheme
272266
format = provider;
273267
} else {
274268
// Choose a random provider
275-
// TODO ST-DDT 2022-01-30: #375 This is impossible to access
276-
if (typeof localeFormat === 'string') {
277-
format = localeFormat;
278-
} else if (typeof localeFormat === 'object') {
279-
// Credit cards are in a object structure
280-
formats = this.faker.random.objectElement(localeFormat, 'value'); // There could be multiple formats
281-
if (typeof formats === 'string') {
282-
format = formats;
283-
} else {
284-
format = this.faker.random.arrayElement(formats);
285-
}
286-
}
269+
// Credit cards are in an object structure
270+
const formats = this.faker.random.objectElement(localeFormat, 'value'); // There could be multiple formats
271+
format = this.faker.random.arrayElement(formats);
287272
}
288273
format = format.replace(/\//g, '');
289274
return this.Helpers.replaceCreditCardSymbols(format);

src/helpers.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,15 @@ export class Helpers {
137137
* @example
138138
* faker.helpers.randomize() // 'c'
139139
* faker.helpers.randomize([1, 2, 3]) // '2'
140+
*
141+
* @deprecated
140142
*/
141-
// TODO ST-DDT 2022-02-06: Mark as deprecated
142143
randomize<T = string>(
143144
array: ReadonlyArray<T> = ['a', 'b', 'c'] as unknown as ReadonlyArray<T>
144145
): T {
146+
console.warn(
147+
'Deprecation Warning: faker.helpers.randomize is now located in faker.random.arrayElement'
148+
);
145149
return this.faker.random.arrayElement(array);
146150
}
147151

@@ -504,8 +508,12 @@ export class Helpers {
504508
* // address: {
505509
* // streetA: 'Drake Avenue',
506510
* // ...
511+
* @deprecated If you need some specific object you should create your own method.
507512
*/
508513
createCard(): Card {
514+
console.warn(
515+
'Deprecation Warning: If you need some specific object you should create your own method.'
516+
);
509517
return {
510518
name: this.faker.name.findName(),
511519
username: this.faker.internet.userName(),
@@ -571,8 +579,12 @@ export class Helpers {
571579
* // email: 'Eveline.Brekke56.Hoppe@yahoo.com',
572580
* // dob: 1964-05-06T05:14:37.874Z,
573581
* // ...
582+
* @deprecated If you need some specific object you should create your own method.
574583
*/
575584
contextualCard(): ContextualCard {
585+
console.warn(
586+
'Deprecation Warning: If you need some specific object you should create your own method.'
587+
);
576588
const name = this.faker.name.firstName();
577589
const userName = this.faker.internet.userName(name);
578590
return {
@@ -618,8 +630,12 @@ export class Helpers {
618630
* // address: {
619631
* // street: 'McKenzie Estates',
620632
* // ....
633+
* @deprecated If you need some specific object you should create your own method.
621634
*/
622635
userCard(): UserCard {
636+
console.warn(
637+
'Deprecation Warning: If you need some specific object you should create your own method.'
638+
);
623639
return {
624640
name: this.faker.name.findName(),
625641
username: this.faker.internet.userName(),

src/iban.ts

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,15 +1147,13 @@ export = {
11471147
},
11481148
],
11491149
iso3166: [
1150-
'AC',
11511150
'AD',
11521151
'AE',
11531152
'AF',
11541153
'AG',
11551154
'AI',
11561155
'AL',
11571156
'AM',
1158-
'AN',
11591157
'AO',
11601158
'AQ',
11611159
'AR',
@@ -1182,15 +1180,13 @@ export = {
11821180
'BR',
11831181
'BS',
11841182
'BT',
1185-
'BU',
11861183
'BV',
11871184
'BW',
11881185
'BY',
11891186
'BZ',
11901187
'CA',
11911188
'CC',
11921189
'CD',
1193-
'CE',
11941190
'CF',
11951191
'CG',
11961192
'CH',
@@ -1200,40 +1196,32 @@ export = {
12001196
'CM',
12011197
'CN',
12021198
'CO',
1203-
'CP',
12041199
'CR',
1205-
'CS',
1206-
'CS',
12071200
'CU',
12081201
'CV',
12091202
'CW',
12101203
'CX',
12111204
'CY',
12121205
'CZ',
1213-
'DD',
12141206
'DE',
1215-
'DG',
12161207
'DJ',
12171208
'DK',
12181209
'DM',
12191210
'DO',
12201211
'DZ',
1221-
'EA',
12221212
'EC',
12231213
'EE',
12241214
'EG',
12251215
'EH',
12261216
'ER',
12271217
'ES',
12281218
'ET',
1229-
'EU',
12301219
'FI',
12311220
'FJ',
12321221
'FK',
12331222
'FM',
12341223
'FO',
12351224
'FR',
1236-
'FX',
12371225
'GA',
12381226
'GB',
12391227
'GD',
@@ -1259,7 +1247,6 @@ export = {
12591247
'HR',
12601248
'HT',
12611249
'HU',
1262-
'IC',
12631250
'ID',
12641251
'IE',
12651252
'IL',
@@ -1329,7 +1316,6 @@ export = {
13291316
'NO',
13301317
'NP',
13311318
'NR',
1332-
'NT',
13331319
'NU',
13341320
'NZ',
13351321
'OM',
@@ -1370,12 +1356,10 @@ export = {
13701356
'SR',
13711357
'SS',
13721358
'ST',
1373-
'SU',
13741359
'SV',
13751360
'SX',
13761361
'SY',
13771362
'SZ',
1378-
'TA',
13791363
'TC',
13801364
'TD',
13811365
'TF',
@@ -1407,12 +1391,11 @@ export = {
14071391
'VU',
14081392
'WF',
14091393
'WS',
1394+
'XK',
14101395
'YE',
14111396
'YT',
1412-
'YU',
14131397
'ZA',
14141398
'ZM',
1415-
'ZR',
14161399
'ZW',
14171400
],
14181401
};

0 commit comments

Comments
 (0)