Skip to content

Commit

Permalink
Merge branch 'next' into docs-category-methods-removed
Browse files Browse the repository at this point in the history
  • Loading branch information
ST-DDT authored Oct 13, 2024
2 parents c380234 + 34cf364 commit a8b9b4c
Show file tree
Hide file tree
Showing 15 changed files with 262 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const { faker } = require('@faker-js/faker');
export function createRandomUser() {
return {
userId: faker.string.uuid(),
username: faker.internet.userName(),
username: faker.internet.username(), // before version 9.1.0, use userName()
email: faker.internet.email(),
avatar: faker.image.avatar(),
password: faker.internet.password(),
Expand Down
7 changes: 6 additions & 1 deletion docs/api/ApiIndex.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,13 @@ const filtered = computed(() => {
</h3>
<ul>
<li v-for="h of item.headers" :key="h.anchor">
<!-- TODO @ST-DDT 2024-09-25: Remove this in v10 -->
<a
:href="item.link + '#' + slugify(h.anchor)"
:href="
item.link +
'#' +
(h.anchor === 'userName' ? 'username-1' : slugify(h.anchor))
"
:class="{ deprecated: h.deprecated }"
>{{ h.text }}</a
>
Expand Down
4 changes: 2 additions & 2 deletions docs/guide/frameworks.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ import { faker } from '@faker-js/faker/locale/en';

describe('Testing the application', () => {
it('should create an account with username and password', () => {
let username = faker.internet.userName();
let username = faker.internet.username(); // before version 9.1.0, use userName()
let password = faker.internet.password();
let email = faker.internet.exampleEmail();

Expand Down Expand Up @@ -111,7 +111,7 @@ test.describe('Testing the application', () => {
test('should create an account with username and password', async ({
page,
}) => {
const username = faker.internet.userName();
const username = faker.internet.username(); // before version 9.1.0, use userName()
const password = faker.internet.password();
const email = faker.internet.exampleEmail();

Expand Down
5 changes: 5 additions & 0 deletions src/definitions/location.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ export type LocationDefinition = LocaleEntry<{
*/
city_suffix: string[];

/**
* The names of all continents.
*/
continent: string[];

/**
* The names of all countries.
*/
Expand Down
9 changes: 9 additions & 0 deletions src/locales/en/location/continent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default [
'Africa',
'Antarctica',
'Asia',
'Australia',
'Europe',
'North America',
'South America',
];
2 changes: 2 additions & 0 deletions src/locales/en/location/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import city_name from './city_name';
import city_pattern from './city_pattern';
import city_prefix from './city_prefix';
import city_suffix from './city_suffix';
import continent from './continent';
import country from './country';
import county from './county';
import direction from './direction';
Expand All @@ -26,6 +27,7 @@ const location: LocationDefinition = {
city_pattern,
city_prefix,
city_suffix,
continent,
country,
county,
direction,
Expand Down
4 changes: 2 additions & 2 deletions src/locales/en_US/location/postcode_by_state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default {
CT: '0{{number.int({"min": 6001,"max": 6389})}}',
DC: '{{number.int({"min": 20001,"max": 20039})}}',
DE: '{{number.int({"min": 19701,"max": 19980})}}',
FL: '{{number.int({"min": 32004,"max": 34997})}}',
FL: '{{helpers.arrayElement(["320","321","322","323","324","325","326","327","328","329","330","331","332","333","334","335","336","337","338","339","341","342","344","346","347","349"])}}{{string.numeric({"length": 2})}}',
GA: '{{number.int({"min": 30001,"max": 31999})}}',
HI: '{{number.int({"min": 96701,"max": 96898})}}',
IA: '{{number.int({"min": 50001,"max": 52809})}}',
Expand Down Expand Up @@ -45,7 +45,7 @@ export default {
TN: '{{number.int({"min": 37010,"max": 38589})}}',
TX: '{{number.int({"min": 75503,"max": 79999})}}',
UT: '{{number.int({"min": 84001,"max": 84784})}}',
VA: '{{number.int({"min": 20040,"max": 20041})}}',
VA: '{{number.int({"min": 22201,"max": 24599})}}',
VT: '0{{number.int({"min": 5001,"max": 5495})}}',
WA: '{{number.int({"min": 98001,"max": 99403})}}',
WI: '{{number.int({"min": 53001,"max": 54990})}}',
Expand Down
2 changes: 1 addition & 1 deletion src/modules/git/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export class GitModule extends ModuleBase {
const firstName = this.faker.person.firstName();
const lastName = this.faker.person.lastName();
const fullName = this.faker.person.fullName({ firstName, lastName });
const username = this.faker.internet.userName({ firstName, lastName });
const username = this.faker.internet.username({ firstName, lastName });
let user = this.faker.helpers.arrayElement([fullName, username]);
const email = this.faker.internet.email({ firstName, lastName });

Expand Down
59 changes: 56 additions & 3 deletions src/modules/internet/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { FakerError } from '../../errors/faker-error';
import { deprecated } from '../../internal/deprecated';
import { ModuleBase } from '../../internal/module-base';
import { charMapping } from './char-mappings';
import * as random_ua from './user-agent';
Expand Down Expand Up @@ -105,7 +106,7 @@ const ipv4Networks: Record<IPv4Network, string> = {
*
* ### Overview
*
* For user accounts, you may need an [`email()`](https://fakerjs.dev/api/internet.html#email) and a [`password()`](https://fakerjs.dev/api/internet.html#password), as well as a ASCII [`userName()`](https://fakerjs.dev/api/internet.html#username) or Unicode [`displayName()`](https://fakerjs.dev/api/internet.html#displayname). Since the emails generated could coincidentally be real email addresses, you should not use these for sending real email addresses. If this is a concern, use [`exampleEmail()`](https://fakerjs.dev/api/internet.html#exampleemail) instead.
* For user accounts, you may need an [`email()`](https://fakerjs.dev/api/internet.html#email) and a [`password()`](https://fakerjs.dev/api/internet.html#password), as well as a ASCII [`username()`](https://fakerjs.dev/api/internet.html#username) or Unicode [`displayName()`](https://fakerjs.dev/api/internet.html#displayname). Since the emails generated could coincidentally be real email addresses, you should not use these for sending real email addresses. If this is a concern, use [`exampleEmail()`](https://fakerjs.dev/api/internet.html#exampleemail) instead.
*
* For websites, you can generate a [`domainName()`](https://fakerjs.dev/api/internet.html#domainname) or a full [`url()`](https://fakerjs.dev/api/internet.html#url).
*
Expand Down Expand Up @@ -169,7 +170,7 @@ export class InternetModule extends ModuleBase {
allowSpecialCharacters = false,
} = options;

let localPart: string = this.userName({ firstName, lastName });
let localPart: string = this.username({ firstName, lastName });
// Strip any special characters from the local part of the email address
// This could happen if invalid chars are passed in manually in the firstName/lastName
localPart = localPart.replaceAll(/[^A-Za-z0-9._+-]+/g, '');
Expand Down Expand Up @@ -273,6 +274,8 @@ export class InternetModule extends ModuleBase {
* faker.internet.userName({ firstName: '大羽', lastName: '陳' }) // 'hlzp8d.tpv45' - note neither name is used
*
* @since 2.0.1
*
* @deprecated Use `faker.internet.username()` instead.
*/
userName(
options: {
Expand All @@ -289,6 +292,56 @@ export class InternetModule extends ModuleBase {
*/
lastName?: string;
} = {}
): string {
deprecated({
deprecated: 'faker.internet.userName()',
proposed: 'faker.internet.username()',
since: '9.1.0',
until: '10.0.0',
});

return this.username(options);
}

/**
* Generates a username using the given person's name as base.
* The resulting username may use neither, one or both of the names provided.
* This will always return a plain ASCII string.
* Some basic stripping of accents and transliteration of characters will be done.
*
* @param options An options object.
* @param options.firstName The optional first name to use. If not specified, a random one will be chosen.
* @param options.lastName The optional last name to use. If not specified, a random one will be chosen.
*
* @see faker.internet.displayName(): For generating an Unicode display name.
*
* @example
* faker.internet.username() // 'Nettie_Zboncak40'
* faker.internet.username({ firstName: 'Jeanne' }) // 'Jeanne98'
* faker.internet.username({ firstName: 'Jeanne' }) // 'Jeanne.Smith98'
* faker.internet.username({ firstName: 'Jeanne', lastName: 'Doe'}) // 'Jeanne_Doe98'
* faker.internet.username({ firstName: 'John', lastName: 'Doe' }) // 'John.Doe'
* faker.internet.username({ firstName: 'Hélene', lastName: 'Müller' }) // 'Helene_Muller11'
* faker.internet.username({ firstName: 'Фёдор', lastName: 'Достоевский' }) // 'Fedor.Dostoevskii50'
* faker.internet.username({ firstName: '大羽', lastName: '陳' }) // 'hlzp8d.tpv45' - note neither name is used
*
* @since 9.1.0
*/
username(
options: {
/**
* The optional first name to use.
*
* @default faker.person.firstName()
*/
firstName?: string;
/**
* The optional last name to use.
*
* @default faker.person.lastName()
*/
lastName?: string;
} = {}
): string {
const {
firstName = this.faker.person.firstName(),
Expand Down Expand Up @@ -348,7 +401,7 @@ export class InternetModule extends ModuleBase {
* @param options.firstName The optional first name to use. If not specified, a random one will be chosen.
* @param options.lastName The optional last name to use. If not specified, a random one will be chosen.
*
* @see faker.internet.userName(): For generating a plain ASCII username.
* @see faker.internet.username(): For generating a plain ASCII username.
*
* @example
* faker.internet.displayName() // 'Nettie_Zboncak40'
Expand Down
14 changes: 14 additions & 0 deletions src/modules/location/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,20 @@ export class LocationModule extends ModuleBase {
);
}

/**
* Returns a random continent name.
*
* @example
* faker.location.continent() // 'Asia'
*
* @since 9.1.0
*/
continent(): string {
return this.faker.helpers.arrayElement(
this.faker.definitions.location.continent
);
}

/**
* Returns a random [ISO_3166-1](https://en.wikipedia.org/wiki/ISO_3166-1) country code.
*
Expand Down
48 changes: 48 additions & 0 deletions test/modules/__snapshots__/internet.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,22 @@ exports[`internet > 42 > userName > with firstName option 1`] = `"Jane_Wiegand59

exports[`internet > 42 > userName > with lastName option 1`] = `"Garnet_Doe"`;

exports[`internet > 42 > username > noArgs 1`] = `"Garnet.Reynolds-Miller15"`;

exports[`internet > 42 > username > with Chinese names 1`] = `"hlzp8d.tpv"`;

exports[`internet > 42 > username > with Cyrillic names 1`] = `"Fedor.Dostoevskii"`;

exports[`internet > 42 > username > with Latin names 1`] = `"Jane.Doe"`;

exports[`internet > 42 > username > with accented names 1`] = `"Helene.Muller"`;

exports[`internet > 42 > username > with all option 1`] = `"Jane.Doe"`;

exports[`internet > 42 > username > with firstName option 1`] = `"Jane_Wiegand59"`;

exports[`internet > 42 > username > with lastName option 1`] = `"Garnet_Doe"`;

exports[`internet > 1211 > color > noArgs 1`] = `"#77721c"`;

exports[`internet > 1211 > color > with all options 1`] = `"#a9a44e"`;
Expand Down Expand Up @@ -240,6 +256,22 @@ exports[`internet > 1211 > userName > with firstName option 1`] = `"Jane99"`;

exports[`internet > 1211 > userName > with lastName option 1`] = `"Tito_Doe"`;

exports[`internet > 1211 > username > noArgs 1`] = `"Tito67"`;

exports[`internet > 1211 > username > with Chinese names 1`] = `"hlzp8d_tpv89"`;

exports[`internet > 1211 > username > with Cyrillic names 1`] = `"Fedor_Dostoevskii89"`;

exports[`internet > 1211 > username > with Latin names 1`] = `"Jane_Doe89"`;

exports[`internet > 1211 > username > with accented names 1`] = `"Helene_Muller89"`;

exports[`internet > 1211 > username > with all option 1`] = `"Jane_Doe89"`;

exports[`internet > 1211 > username > with firstName option 1`] = `"Jane99"`;

exports[`internet > 1211 > username > with lastName option 1`] = `"Tito_Doe"`;

exports[`internet > 1337 > color > noArgs 1`] = `"#211423"`;

exports[`internet > 1337 > color > with all options 1`] = `"#534655"`;
Expand Down Expand Up @@ -359,3 +391,19 @@ exports[`internet > 1337 > userName > with all option 1`] = `"Jane.Doe15"`;
exports[`internet > 1337 > userName > with firstName option 1`] = `"Jane.Cronin45"`;

exports[`internet > 1337 > userName > with lastName option 1`] = `"Devyn.Doe27"`;

exports[`internet > 1337 > username > noArgs 1`] = `"Devyn.Gottlieb"`;

exports[`internet > 1337 > username > with Chinese names 1`] = `"hlzp8d.tpv15"`;

exports[`internet > 1337 > username > with Cyrillic names 1`] = `"Fedor.Dostoevskii15"`;

exports[`internet > 1337 > username > with Latin names 1`] = `"Jane.Doe15"`;

exports[`internet > 1337 > username > with accented names 1`] = `"Helene.Muller15"`;

exports[`internet > 1337 > username > with all option 1`] = `"Jane.Doe15"`;

exports[`internet > 1337 > username > with firstName option 1`] = `"Jane.Cronin45"`;

exports[`internet > 1337 > username > with lastName option 1`] = `"Devyn.Doe27"`;
6 changes: 6 additions & 0 deletions test/modules/__snapshots__/location.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ exports[`location > 42 > cardinalDirection > with abbreviated option 1`] = `"E"`

exports[`location > 42 > city 1`] = `"Fort Moses"`;

exports[`location > 42 > continent 1`] = `"Asia"`;

exports[`location > 42 > country 1`] = `"Guinea"`;

exports[`location > 42 > countryCode > noArgs 1`] = `"GY"`;
Expand Down Expand Up @@ -144,6 +146,8 @@ exports[`location > 1211 > cardinalDirection > with abbreviated option 1`] = `"W

exports[`location > 1211 > city 1`] = `"The Villages"`;

exports[`location > 1211 > continent 1`] = `"South America"`;

exports[`location > 1211 > country 1`] = `"Uganda"`;

exports[`location > 1211 > countryCode > noArgs 1`] = `"UM"`;
Expand Down Expand Up @@ -280,6 +284,8 @@ exports[`location > 1337 > cardinalDirection > with abbreviated option 1`] = `"E

exports[`location > 1337 > city 1`] = `"East Duane"`;

exports[`location > 1337 > continent 1`] = `"Antarctica"`;

exports[`location > 1337 > country 1`] = `"Egypt"`;

exports[`location > 1337 > countryCode > noArgs 1`] = `"EH"`;
Expand Down
Loading

0 comments on commit a8b9b4c

Please # to comment.