Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(internet): rename userName method to username #3130

Merged
merged 12 commits into from
Oct 12, 2024
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(),
suyashgulati marked this conversation as resolved.
Show resolved Hide resolved
email: faker.internet.email(),
avatar: faker.image.avatar(),
password: faker.internet.password(),
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();
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();
const password = faker.internet.password();
const email = faker.internet.exampleEmail();

Expand Down
2 changes: 1 addition & 1 deletion docs/guide/upgrading.md
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ Removed deprecated internet methods
| `faker.internet.avatar()` | `faker.image.avatarLegacy()` or `faker.image.avatar()` |
| `faker.internet.email(firstName, lastName, provider, options)` | `faker.internet.email({ firstName, lastName, provider, ... })` |
| `faker.internet.exampleEmail(firstName, lastName, options)` | `faker.internet.exampleEmail({ firstName, lastName, ... })` |
| `faker.internet.userName(firstName, lastName)` | `faker.internet.userName({ firstName, lastName })` |
ST-DDT marked this conversation as resolved.
Show resolved Hide resolved
| `faker.internet.username(firstName, lastName)` | `faker.internet.username({ firstName, lastName })` |
| `faker.internet.displayName(firstName, lastName)` | `faker.internet.displayName({ firstName, lastName })` |
| `faker.internet.color(redBase, greenBase, blueBase)` | `faker.internet.color({ redBase, greenBase, blueBase })` |
| `faker.internet.password(length, memorable, pattern, prefix)` | `faker.internet.password({ length, memorable, pattern, prefix })` |
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
24 changes: 12 additions & 12 deletions src/modules/internet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export type HTTPProtocolType = 'http' | 'https';
*
* ### 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 @@ -92,7 +92,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 @@ -186,18 +186,18 @@ export class InternetModule extends ModuleBase {
* @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
* 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 2.0.1
*/
userName(
username(
suyashgulati marked this conversation as resolved.
Show resolved Hide resolved
options: {
/**
* The optional first name to use.
Expand Down Expand Up @@ -271,7 +271,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
48 changes: 24 additions & 24 deletions test/modules/__snapshots__/internet.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -100,21 +100,21 @@ exports[`internet > 42 > url > without slash appended and with http protocol 1`]

exports[`internet > 42 > userAgent 1`] = `"Mozilla/5.0 (X11; Linux i686; rv:13.5) Gecko/20100101 Firefox/13.5.1"`;

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

exports[`internet > 42 > userName > with Chinese names 1`] = `"hlzp8d.tpv"`;
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 Cyrillic names 1`] = `"Fedor.Dostoevskii"`;

exports[`internet > 42 > userName > with Latin names 1`] = `"Jane.Doe"`;
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 accented names 1`] = `"Helene.Muller"`;

exports[`internet > 42 > userName > with all option 1`] = `"Jane.Doe"`;
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 firstName option 1`] = `"Jane_Wiegand59"`;

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

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

Expand Down Expand Up @@ -216,21 +216,21 @@ exports[`internet > 1211 > url > without slash appended and with http protocol 1

exports[`internet > 1211 > userAgent 1`] = `"Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko"`;

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

exports[`internet > 1211 > userName > with Chinese names 1`] = `"hlzp8d_tpv89"`;
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 Cyrillic names 1`] = `"Fedor_Dostoevskii89"`;

exports[`internet > 1211 > userName > with Latin names 1`] = `"Jane_Doe89"`;
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 accented names 1`] = `"Helene_Muller89"`;

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

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

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

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

Expand Down Expand Up @@ -332,18 +332,18 @@ exports[`internet > 1337 > url > without slash appended and with http protocol 1

exports[`internet > 1337 > userAgent 1`] = `"Mozilla/5.0 (Windows NT 5.3; WOW64; rv:8.4) Gecko/20100101 Firefox/8.4.3"`;

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

exports[`internet > 1337 > userName > with Chinese names 1`] = `"hlzp8d.tpv15"`;
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 Cyrillic names 1`] = `"Fedor.Dostoevskii15"`;

exports[`internet > 1337 > userName > with Latin names 1`] = `"Jane.Doe15"`;
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 accented names 1`] = `"Helene.Muller15"`;

exports[`internet > 1337 > userName > with all option 1`] = `"Jane.Doe15"`;
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 firstName option 1`] = `"Jane.Cronin45"`;

exports[`internet > 1337 > userName > with lastName option 1`] = `"Devyn.Doe27"`;
exports[`internet > 1337 > username > with lastName option 1`] = `"Devyn.Doe27"`;
18 changes: 9 additions & 9 deletions test/modules/internet.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('internet', () => {
});
});

t.describe('userName', (t) => {
t.describe('username', (t) => {
suyashgulati marked this conversation as resolved.
Show resolved Hide resolved
t.it('noArgs')
.it('with firstName option', { firstName: 'Jane' })
.it('with lastName option', { lastName: 'Doe' })
Expand Down Expand Up @@ -339,17 +339,17 @@ describe('internet', () => {
});
});

describe('userName()', () => {
describe('username()', () => {
it('should return a random username', () => {
const username = faker.internet.userName();
const username = faker.internet.username();

expect(username).toBeTruthy();
expect(username).toBeTypeOf('string');
expect(username).toMatch(/\w/);
});

it('should return a random username with given firstName', () => {
const username = faker.internet.userName({ firstName: 'Aiden' });
const username = faker.internet.username({ firstName: 'Aiden' });

expect(username).toBeTruthy();
expect(username).toBeTypeOf('string');
Expand All @@ -358,7 +358,7 @@ describe('internet', () => {
});

it('should return a random username with given firstName and lastName', () => {
const username = faker.internet.userName({
const username = faker.internet.username({
firstName: 'Aiden',
lastName: 'Harann',
});
Expand All @@ -371,7 +371,7 @@ describe('internet', () => {
});

it('should strip accents', () => {
const username = faker.internet.userName({
const username = faker.internet.username({
firstName: 'Adèle',
lastName: 'Smith',
});
Expand All @@ -380,23 +380,23 @@ describe('internet', () => {
});

it('should transliterate Cyrillic', () => {
const username = faker.internet.userName({
const username = faker.internet.username({
firstName: 'Амос',
lastName: 'Васильев',
});
expect(username).includes('Amos');
});

it('should provide a fallback for Chinese etc', () => {
const username = faker.internet.userName({
const username = faker.internet.username({
firstName: '大羽',
lastName: '陳',
});
expect(username).includes('hlzp8d');
});

it('should provide a fallback special unicode characters', () => {
const username = faker.internet.userName({
const username = faker.internet.username({
firstName: '🐼',
lastName: '❤️',
});
Expand Down