Skip to content

Commit ad69bfd

Browse files
authored
Merge branch 'next' into correct-discover-card-format
2 parents 051c4de + 5436111 commit ad69bfd

File tree

11 files changed

+220
-21
lines changed

11 files changed

+220
-21
lines changed

src/definitions/location.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { Language } from '../modules/location';
12
import type { LocaleEntry } from './definitions';
23

34
/**
@@ -147,4 +148,11 @@ export type LocationDefinition = LocaleEntry<{
147148
* @see [IANA Time Zone Database](https://www.iana.org/time-zones)
148149
*/
149150
time_zone: string[];
151+
152+
/**
153+
* A list of spoken languages.
154+
*
155+
* @see [ISO 639-2 Language Code List](https://www.loc.gov/standards/iso639-2/php/code_list.php)
156+
*/
157+
language: Language[];
150158
}>;

src/locales/en/location/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import continent from './continent';
1212
import country from './country';
1313
import county from './county';
1414
import direction from './direction';
15+
import language from './language';
1516
import postcode from './postcode';
1617
import secondary_address from './secondary_address';
1718
import state from './state';
@@ -31,6 +32,7 @@ const location: LocationDefinition = {
3132
country,
3233
county,
3334
direction,
35+
language,
3436
postcode,
3537
secondary_address,
3638
state,

src/locales/en/location/language.ts

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
export default [
2+
{ name: 'Afrikaans', alpha2: 'af', alpha3: 'afr' },
3+
{ name: 'Azerbaijani', alpha2: 'az', alpha3: 'aze' },
4+
{ name: 'Maldivian', alpha2: 'dv', alpha3: 'div' },
5+
{ name: 'Farsi/Persian', alpha2: 'fa', alpha3: 'fas' },
6+
{ name: 'Latvian', alpha2: 'lv', alpha3: 'lav' },
7+
{ name: 'Indonesian', alpha2: 'id', alpha3: 'ind' },
8+
{ name: 'Nepali', alpha2: 'ne', alpha3: 'nep' },
9+
{ name: 'Thai', alpha2: 'th', alpha3: 'tha' },
10+
{ name: 'Uzbek', alpha2: 'uz', alpha3: 'uzb' },
11+
{ name: 'Yoruba', alpha2: 'yo', alpha3: 'yor' },
12+
{ name: 'Pashto', alpha2: 'ps', alpha3: 'pus' },
13+
{ name: 'English', alpha2: 'en', alpha3: 'eng' },
14+
{ name: 'Urdu', alpha2: 'ur', alpha3: 'urd' },
15+
{ name: 'German', alpha2: 'de', alpha3: 'deu' },
16+
{ name: 'French', alpha2: 'fr', alpha3: 'fra' },
17+
{ name: 'Spanish', alpha2: 'es', alpha3: 'spa' },
18+
{ name: 'Italian', alpha2: 'it', alpha3: 'ita' },
19+
{ name: 'Dutch', alpha2: 'nl', alpha3: 'nld' },
20+
{ name: 'Russian', alpha2: 'ru', alpha3: 'rus' },
21+
{ name: 'Portuguese', alpha2: 'pt', alpha3: 'por' },
22+
{ name: 'Polish', alpha2: 'pl', alpha3: 'pol' },
23+
{ name: 'Arabic', alpha2: 'ar', alpha3: 'ara' },
24+
{ name: 'Japanese', alpha2: 'ja', alpha3: 'jpn' },
25+
{ name: 'Chinese', alpha2: 'zh', alpha3: 'zho' },
26+
{ name: 'Hindi', alpha2: 'hi', alpha3: 'hin' },
27+
{ name: 'Bengali', alpha2: 'bn', alpha3: 'ben' },
28+
{ name: 'Gujarati', alpha2: 'gu', alpha3: 'guj' },
29+
{ name: 'Tamil', alpha2: 'ta', alpha3: 'tam' },
30+
{ name: 'Telugu', alpha2: 'te', alpha3: 'tel' },
31+
{ name: 'Punjabi', alpha2: 'pa', alpha3: 'pan' },
32+
{ name: 'Vietnamese', alpha2: 'vi', alpha3: 'vie' },
33+
{ name: 'Korean', alpha2: 'ko', alpha3: 'kor' },
34+
{ name: 'Turkish', alpha2: 'tr', alpha3: 'tur' },
35+
{ name: 'Swedish', alpha2: 'sv', alpha3: 'swe' },
36+
{ name: 'Greek', alpha2: 'el', alpha3: 'ell' },
37+
{ name: 'Czech', alpha2: 'cs', alpha3: 'ces' },
38+
{ name: 'Hungarian', alpha2: 'hu', alpha3: 'hun' },
39+
{ name: 'Romanian', alpha2: 'ro', alpha3: 'ron' },
40+
{ name: 'Ukrainian', alpha2: 'uk', alpha3: 'ukr' },
41+
{ name: 'Norwegian', alpha2: 'no', alpha3: 'nor' },
42+
{ name: 'Serbian', alpha2: 'sr', alpha3: 'srp' },
43+
{ name: 'Croatian', alpha2: 'hr', alpha3: 'hrv' },
44+
{ name: 'Slovak', alpha2: 'sk', alpha3: 'slk' },
45+
{ name: 'Slovenian', alpha2: 'sl', alpha3: 'slv' },
46+
{ name: 'Icelandic', alpha2: 'is', alpha3: 'isl' },
47+
{ name: 'Finnish', alpha2: 'fi', alpha3: 'fin' },
48+
{ name: 'Danish', alpha2: 'da', alpha3: 'dan' },
49+
{ name: 'Swahili', alpha2: 'sw', alpha3: 'swa' },
50+
{ name: 'Bashkir', alpha2: 'ba', alpha3: 'bak' },
51+
{ name: 'Basque', alpha2: 'eu', alpha3: 'eus' },
52+
{ name: 'Catalan', alpha2: 'ca', alpha3: 'cat' },
53+
{ name: 'Galician', alpha2: 'gl', alpha3: 'glg' },
54+
{ name: 'Esperanto', alpha2: 'eo', alpha3: 'epo' },
55+
{ name: 'Fijian', alpha2: 'fj', alpha3: 'fij' },
56+
{ name: 'Malagasy', alpha2: 'mg', alpha3: 'mlg' },
57+
{ name: 'Maltese', alpha2: 'mt', alpha3: 'mlt' },
58+
{ name: 'Albanian', alpha2: 'sq', alpha3: 'sqi' },
59+
{ name: 'Armenian', alpha2: 'hy', alpha3: 'hye' },
60+
{ name: 'Georgian', alpha2: 'ka', alpha3: 'kat' },
61+
{ name: 'Macedonian', alpha2: 'mk', alpha3: 'mkd' },
62+
{ name: 'Kazakh', alpha2: 'kk', alpha3: 'kaz' },
63+
{ name: 'Haitian Creole', alpha2: 'ht', alpha3: 'hat' },
64+
{ name: 'Mongolian', alpha2: 'mn', alpha3: 'mon' },
65+
{ name: 'Kyrgyz', alpha2: 'ky', alpha3: 'kir' },
66+
{ name: 'Finnish', alpha2: 'fi', alpha3: 'fin' },
67+
{ name: 'Tagalog', alpha2: 'tl', alpha3: 'tgl' },
68+
{ name: 'Malay', alpha2: 'ms', alpha3: 'msa' },
69+
{ name: 'Tajik', alpha2: 'tg', alpha3: 'tgk' },
70+
{ name: 'Swati', alpha2: 'ss', alpha3: 'ssw' },
71+
{ name: 'Tatar', alpha2: 'tt', alpha3: 'tat' },
72+
{ name: 'Zulu', alpha2: 'zu', alpha3: 'zul' },
73+
];

src/locales/ur/location/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import city_prefix from './city_prefix';
1010
import city_suffix from './city_suffix';
1111
import country from './country';
1212
import direction from './direction';
13+
import language from './language';
1314
import postcode from './postcode';
1415
import secondary_address from './secondary_address';
1516
import state from './state';
@@ -26,6 +27,7 @@ const location: LocationDefinition = {
2627
city_suffix,
2728
country,
2829
direction,
30+
language,
2931
postcode,
3032
secondary_address,
3133
state,

src/locales/ur/location/language.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
export default [
2+
{ name: 'پشتو', alpha2: 'ps', alpha3: 'pus' },
3+
{ name: 'اردو', alpha2: 'ur', alpha3: 'urd' },
4+
{ name: 'انگریزی', alpha2: 'en', alpha3: 'eng' },
5+
{ name: 'جرمن', alpha2: 'de', alpha3: 'deu' },
6+
{ name: 'فرانسیسی', alpha2: 'fr', alpha3: 'fra' },
7+
{ name: 'اسپینش', alpha2: 'es', alpha3: 'spa' },
8+
{ name: 'دچ', alpha2: 'nl', alpha3: 'nld' },
9+
{ name: 'روسی', alpha2: 'ru', alpha3: 'rus' },
10+
{ name: 'پرتگالی', alpha2: 'pt', alpha3: 'por' },
11+
{ name: 'پولش', alpha2: 'pl', alpha3: 'pol' },
12+
{ name: 'عربی', alpha2: 'ar', alpha3: 'ara' },
13+
{ name: 'جاپانی', alpha2: 'ja', alpha3: 'jpn' },
14+
{ name: 'چینی', alpha2: 'zh', alpha3: 'zho' },
15+
{ name: 'ہندی', alpha2: 'hi', alpha3: 'hin' },
16+
{ name: 'بنگالی', alpha2: 'bn', alpha3: 'ben' },
17+
{ name: 'تمل', alpha2: 'ta', alpha3: 'tam' },
18+
{ name: 'تلگو', alpha2: 'te', alpha3: 'tel' },
19+
{ name: 'پنجابی', alpha2: 'pa', alpha3: 'pan' },
20+
{ name: 'ترکی', alpha2: 'tr', alpha3: 'tur' },
21+
{ name: 'سویڈش', alpha2: 'sv', alpha3: 'swe' },
22+
{ name: 'یونانی', alpha2: 'el', alpha3: 'ell' },
23+
{ name: 'چیک', alpha2: 'cs', alpha3: 'ces' },
24+
{ name: 'ہنگرین', alpha2: 'hu', alpha3: 'hun' },
25+
{ name: 'نارویجن', alpha2: 'no', alpha3: 'nor' },
26+
{ name: 'کروشیائی', alpha2: 'hr', alpha3: 'hrv' },
27+
{ name: 'سلوواک', alpha2: 'sk', alpha3: 'slk' },
28+
{ name: 'سلووینیائی', alpha2: 'sl', alpha3: 'slv' },
29+
{ name: 'فنش', alpha2: 'fi', alpha3: 'fin' },
30+
{ name: 'دنش', alpha2: 'da', alpha3: 'dan' },
31+
{ name: 'مالٹی', alpha2: 'mt', alpha3: 'mlt' },
32+
{ name: 'تاجک', alpha2: 'tg', alpha3: 'tgk' },
33+
];

src/modules/helpers/index.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -184,18 +184,18 @@ export function legacyReplaceSymbolWithNumber(
184184
string: string = '',
185185
symbol: string = '#'
186186
): string {
187-
let str = '';
187+
let result = '';
188188
for (let i = 0; i < string.length; i++) {
189189
if (string.charAt(i) === symbol) {
190-
str += faker.number.int(9);
190+
result += faker.number.int(9);
191191
} else if (string.charAt(i) === '!') {
192-
str += faker.number.int({ min: 2, max: 9 });
192+
result += faker.number.int({ min: 2, max: 9 });
193193
} else {
194-
str += string.charAt(i);
194+
result += string.charAt(i);
195195
}
196196
}
197197

198-
return str;
198+
return result;
199199
}
200200

201201
/**
@@ -270,23 +270,23 @@ export class SimpleHelpersModule extends SimpleModuleBase {
270270
'Y',
271271
'Z',
272272
];
273-
let str = '';
273+
let result = '';
274274

275275
for (let i = 0; i < string.length; i++) {
276276
if (string.charAt(i) === '#') {
277-
str += this.faker.number.int(9);
277+
result += this.faker.number.int(9);
278278
} else if (string.charAt(i) === '?') {
279-
str += this.arrayElement(alpha);
279+
result += this.arrayElement(alpha);
280280
} else if (string.charAt(i) === '*') {
281-
str += this.faker.datatype.boolean()
281+
result += this.faker.datatype.boolean()
282282
? this.arrayElement(alpha)
283283
: this.faker.number.int(9);
284284
} else {
285-
str += string.charAt(i);
285+
result += string.charAt(i);
286286
}
287287
}
288288

289-
return str;
289+
return result;
290290
}
291291

292292
/**
@@ -700,7 +700,7 @@ export class SimpleHelpersModule extends SimpleModuleBase {
700700
/**
701701
* Replaces the `{{placeholder}}` patterns in the given string mustache style.
702702
*
703-
* @param str The template string to parse.
703+
* @param text The template string to parse.
704704
* @param data The data used to populate the placeholders.
705705
* This is a record where the key is the template placeholder,
706706
* whereas the value is either a string or a function suitable for `String.replace()`.
@@ -714,10 +714,10 @@ export class SimpleHelpersModule extends SimpleModuleBase {
714714
* @since 2.0.1
715715
*/
716716
mustache(
717-
str: string | undefined,
717+
text: string | undefined,
718718
data: Record<string, string | Parameters<string['replace']>[1]>
719719
): string {
720-
if (str == null) {
720+
if (text == null) {
721721
return '';
722722
}
723723

@@ -727,13 +727,13 @@ export class SimpleHelpersModule extends SimpleModuleBase {
727727
if (typeof value === 'string') {
728728
// escape $, source: https://stackoverflow.com/a/6969486/6897682
729729
value = value.replaceAll('$', '$$$$');
730-
str = str.replace(re, value);
730+
text = text.replace(re, value);
731731
} else {
732-
str = str.replace(re, value);
732+
text = text.replace(re, value);
733733
}
734734
}
735735

736-
return str;
736+
return text;
737737
}
738738

739739
/**
@@ -897,7 +897,7 @@ export class SimpleHelpersModule extends SimpleModuleBase {
897897
);
898898
}
899899

900-
const total = array.reduce((acc, { weight }) => acc + weight, 0);
900+
const total = array.reduce((sum, { weight }) => sum + weight, 0);
901901
const random = this.faker.number.float({
902902
min: 0,
903903
max: total,
@@ -1276,10 +1276,10 @@ export class HelpersModule extends SimpleHelpersModule {
12761276

12771277
// Replace the found tag with the returned fake value
12781278
// We cannot use string.replace here because the result might contain evaluated characters
1279-
const res =
1279+
const patched =
12801280
pattern.substring(0, start) + stringified + pattern.substring(end + 2);
12811281

12821282
// return the response recursively until we are done finding all tags
1283-
return this.fake(res);
1283+
return this.fake(patched);
12841284
}
12851285
}

src/modules/location/index.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,26 @@
11
import { FakerError } from '../../errors/faker-error';
22
import { ModuleBase } from '../../internal/module-base';
33

4+
/**
5+
* Represents a language with its full name, 2 character ISO 639-1 code, and 3 character ISO 639-2 code.
6+
*/
7+
export interface Language {
8+
/**
9+
* The full name for the language (e.g. `English`).
10+
*/
11+
name: string;
12+
13+
/**
14+
* The 2 character [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) code.
15+
*/
16+
alpha2: string;
17+
18+
/**
19+
* The 3 character [ISO 639-2](https://en.wikipedia.org/wiki/ISO_639-2) code.
20+
*/
21+
alpha3: string;
22+
}
23+
424
/**
525
* Module to generate addresses and locations. Prior to Faker 8.0.0, this module was known as `faker.address`.
626
*
@@ -628,4 +648,25 @@ export class LocationModule extends ModuleBase {
628648
this.faker.definitions.location.time_zone
629649
);
630650
}
651+
652+
/**
653+
* Returns a random spoken language.
654+
*
655+
* @see [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1)
656+
* @see [ISO 639-2](https://en.wikipedia.org/wiki/ISO_639-2)
657+
* @see [ISO 639-2 Language Code List](https://www.loc.gov/standards/iso639-2/php/code_list.php)
658+
*
659+
* @example
660+
* faker.location.language() // { alpha2: 'de', alpha3: 'deu', name: 'German' }
661+
* faker.location.language().name // German
662+
* faker.location.language().alpha2 // de
663+
* faker.location.language().alpha3 // deu
664+
*
665+
* @since 9.4.0
666+
*/
667+
language(): Language {
668+
return this.faker.helpers.arrayElement(
669+
this.faker.definitions.location.language
670+
);
671+
}
631672
}

src/randomizer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* Instances are expected to be ready for use before being passed to any Faker constructor,
1010
* this includes being `seed()`ed with either a random or fixed value.
1111
*
12-
* For more information please refer to the [documentation](https://fakerjs.dev/api/randomizer.html).
12+
* For more information please refer to the [documentation](https://fakerjs.dev/guide/randomizer.html).
1313
*
1414
* @example
1515
* import { Faker, Randomizer, SimpleFaker } from '@faker-js/faker';

test/modules/__snapshots__/location.spec.ts.snap

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ exports[`location > 42 > direction > noArgs 1`] = `"South"`;
3232

3333
exports[`location > 42 > direction > with abbreviated option 1`] = `"S"`;
3434

35+
exports[`location > 42 > language 1`] = `
36+
{
37+
"alpha2": "gu",
38+
"alpha3": "guj",
39+
"name": "Gujarati",
40+
}
41+
`;
42+
3543
exports[`location > 42 > latitude > noArgs 1`] = `-22.5828`;
3644

3745
exports[`location > 42 > latitude > with max and min option 1`] = `-2.5092`;
@@ -170,6 +178,14 @@ exports[`location > 1211 > direction > noArgs 1`] = `"Southwest"`;
170178

171179
exports[`location > 1211 > direction > with abbreviated option 1`] = `"SW"`;
172180

181+
exports[`location > 1211 > language 1`] = `
182+
{
183+
"alpha2": "tl",
184+
"alpha3": "tgl",
185+
"name": "Tagalog",
186+
}
187+
`;
188+
173189
exports[`location > 1211 > latitude > noArgs 1`] = `77.1337`;
174190

175191
exports[`location > 1211 > latitude > with max and min option 1`] = `8.5704`;
@@ -308,6 +324,14 @@ exports[`location > 1337 > direction > noArgs 1`] = `"South"`;
308324

309325
exports[`location > 1337 > direction > with abbreviated option 1`] = `"S"`;
310326

327+
exports[`location > 1337 > language 1`] = `
328+
{
329+
"alpha2": "ru",
330+
"alpha3": "rus",
331+
"name": "Russian",
332+
}
333+
`;
334+
311335
exports[`location > 1337 > latitude > noArgs 1`] = `-42.8356`;
312336

313337
exports[`location > 1337 > latitude > with max and min option 1`] = `-4.7595`;

0 commit comments

Comments
 (0)