From 3cbf557e742cb63a0f211ec36f4361c0bcbc5923 Mon Sep 17 00:00:00 2001 From: suyashgulati Date: Sun, 22 Sep 2024 19:58:12 +0530 Subject: [PATCH 1/9] refactor(internet): Renaming userName method to username --- README.md | 2 +- docs/guide/frameworks.md | 4 +- docs/guide/upgrading.md | 2 +- src/modules/git/index.ts | 2 +- src/modules/internet/index.ts | 24 +++++----- .../__snapshots__/internet.spec.ts.snap | 48 +++++++++---------- test/modules/internet.spec.ts | 18 +++---- 7 files changed, 50 insertions(+), 50 deletions(-) diff --git a/README.md b/README.md index 4ae41314474..e69d1c5b438 100644 --- a/README.md +++ b/README.md @@ -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(), email: faker.internet.email(), avatar: faker.image.avatar(), password: faker.internet.password(), diff --git a/docs/guide/frameworks.md b/docs/guide/frameworks.md index 3b0cd6f39c1..ded22f9c722 100644 --- a/docs/guide/frameworks.md +++ b/docs/guide/frameworks.md @@ -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(); @@ -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(); diff --git a/docs/guide/upgrading.md b/docs/guide/upgrading.md index 155107b422f..f2b1c56f736 100644 --- a/docs/guide/upgrading.md +++ b/docs/guide/upgrading.md @@ -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 })` | +| `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 })` | diff --git a/src/modules/git/index.ts b/src/modules/git/index.ts index 8f33f0c5484..22c848b8828 100644 --- a/src/modules/git/index.ts +++ b/src/modules/git/index.ts @@ -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 }); diff --git a/src/modules/internet/index.ts b/src/modules/internet/index.ts index f6884d880aa..24b7dacb4d6 100644 --- a/src/modules/internet/index.ts +++ b/src/modules/internet/index.ts @@ -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). * @@ -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, ''); @@ -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( options: { /** * The optional first name to use. @@ -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' diff --git a/test/modules/__snapshots__/internet.spec.ts.snap b/test/modules/__snapshots__/internet.spec.ts.snap index bb330fbdbb1..b6e0d609d33 100644 --- a/test/modules/__snapshots__/internet.spec.ts.snap +++ b/test/modules/__snapshots__/internet.spec.ts.snap @@ -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"`; @@ -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"`; @@ -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"`; diff --git a/test/modules/internet.spec.ts b/test/modules/internet.spec.ts index 25c5150fe3f..d50358fab2f 100644 --- a/test/modules/internet.spec.ts +++ b/test/modules/internet.spec.ts @@ -51,7 +51,7 @@ describe('internet', () => { }); }); - t.describe('userName', (t) => { + t.describe('username', (t) => { t.it('noArgs') .it('with firstName option', { firstName: 'Jane' }) .it('with lastName option', { lastName: 'Doe' }) @@ -339,9 +339,9 @@ 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'); @@ -349,7 +349,7 @@ describe('internet', () => { }); 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'); @@ -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', }); @@ -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', }); @@ -380,7 +380,7 @@ describe('internet', () => { }); it('should transliterate Cyrillic', () => { - const username = faker.internet.userName({ + const username = faker.internet.username({ firstName: 'Амос', lastName: 'Васильев', }); @@ -388,7 +388,7 @@ describe('internet', () => { }); it('should provide a fallback for Chinese etc', () => { - const username = faker.internet.userName({ + const username = faker.internet.username({ firstName: '大羽', lastName: '陳', }); @@ -396,7 +396,7 @@ describe('internet', () => { }); it('should provide a fallback special unicode characters', () => { - const username = faker.internet.userName({ + const username = faker.internet.username({ firstName: '🐼', lastName: '❤️', }); From 13039d7c058721eff57edfc470d963ed7269848f Mon Sep 17 00:00:00 2001 From: suyashgulati Date: Mon, 23 Sep 2024 02:47:04 +0530 Subject: [PATCH 2/9] Added the userName method back as deprecated --- docs/guide/upgrading.md | 2 +- src/modules/internet/index.ts | 55 ++++++++++++- .../__snapshots__/internet.spec.ts.snap | 48 +++++++++++ test/modules/internet.spec.ts | 79 +++++++++++++++++++ 4 files changed, 182 insertions(+), 2 deletions(-) diff --git a/docs/guide/upgrading.md b/docs/guide/upgrading.md index f2b1c56f736..155107b422f 100644 --- a/docs/guide/upgrading.md +++ b/docs/guide/upgrading.md @@ -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 })` | +| `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 })` | diff --git a/src/modules/internet/index.ts b/src/modules/internet/index.ts index 24b7dacb4d6..c3a8b19d983 100644 --- a/src/modules/internet/index.ts +++ b/src/modules/internet/index.ts @@ -1,3 +1,4 @@ +import { deprecated } from '../../internal/deprecated'; import { ModuleBase } from '../../internal/module-base'; import { charMapping } from './char-mappings'; import * as random_ua from './user-agent'; @@ -173,6 +174,58 @@ export class InternetModule extends ModuleBase { }); } + /** + * 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.username(): 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 2.0.1 + * + * @deprecated Use `faker.internet.username()` instead. Example: `faker.internet.username();` + */ + 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 { + deprecated({ + deprecated: 'faker.internet.userName()', + proposed: 'faker.internet.username()', + since: '2.0.1', + 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. @@ -195,7 +248,7 @@ export class InternetModule extends ModuleBase { * faker.internet.username({ firstName: 'Фёдор', lastName: 'Достоевский' }) // 'Fedor.Dostoevskii50' * faker.internet.username({ firstName: '大羽', lastName: '陳' }) // 'hlzp8d.tpv45' - note neither name is used * - * @since 2.0.1 + * @since 9.1.0 */ username( options: { diff --git a/test/modules/__snapshots__/internet.spec.ts.snap b/test/modules/__snapshots__/internet.spec.ts.snap index b6e0d609d33..dbba8e3ffc6 100644 --- a/test/modules/__snapshots__/internet.spec.ts.snap +++ b/test/modules/__snapshots__/internet.spec.ts.snap @@ -100,6 +100,22 @@ 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 > 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 > 42 > username > noArgs 1`] = `"Garnet.Reynolds-Miller15"`; exports[`internet > 42 > username > with Chinese names 1`] = `"hlzp8d.tpv"`; @@ -216,6 +232,22 @@ 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 > 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 > 1211 > username > noArgs 1`] = `"Tito67"`; exports[`internet > 1211 > username > with Chinese names 1`] = `"hlzp8d_tpv89"`; @@ -332,6 +364,22 @@ 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 > 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"`; + exports[`internet > 1337 > username > noArgs 1`] = `"Devyn.Gottlieb"`; exports[`internet > 1337 > username > with Chinese names 1`] = `"hlzp8d.tpv15"`; diff --git a/test/modules/internet.spec.ts b/test/modules/internet.spec.ts index d50358fab2f..70a4c37c7ec 100644 --- a/test/modules/internet.spec.ts +++ b/test/modules/internet.spec.ts @@ -51,6 +51,20 @@ describe('internet', () => { }); }); + t.describe('userName', (t) => { + t.it('noArgs') + .it('with firstName option', { firstName: 'Jane' }) + .it('with lastName option', { lastName: 'Doe' }) + .it('with all option', { firstName: 'Jane', lastName: 'Doe' }) + .it('with Latin names', { firstName: 'Jane', lastName: 'Doe' }) + .it('with accented names', { firstName: 'Hélene', lastName: 'Müller' }) + .it('with Cyrillic names', { + firstName: 'Фёдор', + lastName: 'Достоевский', + }) + .it('with Chinese names', { firstName: '大羽', lastName: '陳' }); + }); + t.describe('username', (t) => { t.it('noArgs') .it('with firstName option', { firstName: 'Jane' }) @@ -339,6 +353,71 @@ describe('internet', () => { }); }); + describe('userName()', () => { + it('should return a random 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' }); + + expect(userName).toBeTruthy(); + expect(userName).toBeTypeOf('string'); + expect(userName).toMatch(/\w/); + expect(userName).includes('Aiden'); + }); + + it('should return a random userName with given firstName and lastName', () => { + const userName = faker.internet.userName({ + firstName: 'Aiden', + lastName: 'Harann', + }); + + expect(userName).toBeTruthy(); + expect(userName).toBeTypeOf('string'); + expect(userName).includes('Aiden'); + expect(userName).includes('Harann'); + expect(userName).toMatch(/^Aiden[._]Harann\d*/); + }); + + it('should strip accents', () => { + const userName = faker.internet.userName({ + firstName: 'Adèle', + lastName: 'Smith', + }); + expect(userName).includes('Adele'); + expect(userName).includes('Smith'); + }); + + it('should transliterate Cyrillic', () => { + const userName = faker.internet.userName({ + firstName: 'Амос', + lastName: 'Васильев', + }); + expect(userName).includes('Amos'); + }); + + it('should provide a fallback for Chinese etc', () => { + const userName = faker.internet.userName({ + firstName: '大羽', + lastName: '陳', + }); + expect(userName).includes('hlzp8d'); + }); + + it('should provide a fallback special unicode characters', () => { + const userName = faker.internet.userName({ + firstName: '🐼', + lastName: '❤️', + }); + expect(userName).includes('2qt8'); + }); + }); + describe('username()', () => { it('should return a random username', () => { const username = faker.internet.username(); From 6d133b13abab1ef9cfb72b5f3ad9136ecd4b41ba Mon Sep 17 00:00:00 2001 From: suyashgulati Date: Mon, 23 Sep 2024 16:38:26 +0530 Subject: [PATCH 3/9] Linting issues resolved --- test/modules/internet.spec.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/modules/internet.spec.ts b/test/modules/internet.spec.ts index 70a4c37c7ec..3530adb79f1 100644 --- a/test/modules/internet.spec.ts +++ b/test/modules/internet.spec.ts @@ -355,6 +355,7 @@ describe('internet', () => { describe('userName()', () => { it('should return a random userName', () => { + // eslint-disable-next-line @typescript-eslint/no-deprecated const userName = faker.internet.userName(); expect(userName).toBeTruthy(); @@ -363,6 +364,7 @@ describe('internet', () => { }); it('should return a random userName with given firstName', () => { + // eslint-disable-next-line @typescript-eslint/no-deprecated const userName = faker.internet.userName({ firstName: 'Aiden' }); expect(userName).toBeTruthy(); @@ -372,6 +374,7 @@ describe('internet', () => { }); it('should return a random userName with given firstName and lastName', () => { + // eslint-disable-next-line @typescript-eslint/no-deprecated const userName = faker.internet.userName({ firstName: 'Aiden', lastName: 'Harann', @@ -385,6 +388,7 @@ describe('internet', () => { }); it('should strip accents', () => { + // eslint-disable-next-line @typescript-eslint/no-deprecated const userName = faker.internet.userName({ firstName: 'Adèle', lastName: 'Smith', @@ -394,6 +398,7 @@ describe('internet', () => { }); it('should transliterate Cyrillic', () => { + // eslint-disable-next-line @typescript-eslint/no-deprecated const userName = faker.internet.userName({ firstName: 'Амос', lastName: 'Васильев', @@ -402,6 +407,7 @@ describe('internet', () => { }); it('should provide a fallback for Chinese etc', () => { + // eslint-disable-next-line @typescript-eslint/no-deprecated const userName = faker.internet.userName({ firstName: '大羽', lastName: '陳', @@ -410,6 +416,7 @@ describe('internet', () => { }); it('should provide a fallback special unicode characters', () => { + // eslint-disable-next-line @typescript-eslint/no-deprecated const userName = faker.internet.userName({ firstName: '🐼', lastName: '❤️', From 56cf472034cfae8c2e31d9b4d13135b4e43019bd Mon Sep 17 00:00:00 2001 From: suyashgulati Date: Mon, 23 Sep 2024 19:45:06 +0530 Subject: [PATCH 4/9] Wayaround for OS's file system issue with same named methods --- test/scripts/apidocs/verify-jsdoc-tags.spec.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/scripts/apidocs/verify-jsdoc-tags.spec.ts b/test/scripts/apidocs/verify-jsdoc-tags.spec.ts index ea5ed8b9b69..6c26b7c4ed7 100644 --- a/test/scripts/apidocs/verify-jsdoc-tags.spec.ts +++ b/test/scripts/apidocs/verify-jsdoc-tags.spec.ts @@ -36,6 +36,11 @@ function resolvePathToMethodFile( signature: number ): string { const dir = resolveDirToModule(moduleName); + // TODO @ST-DDT 2024-09-23: Remove this in v10 + if (methodName === 'userName') { + methodName = 'userNameDeprecated'; + } + return resolve(dir, `${methodName}_${signature}.ts`); } From dce2c75f78ad69fc5c7d0a563bb76e6104df7ca2 Mon Sep 17 00:00:00 2001 From: suyashgulati Date: Tue, 24 Sep 2024 18:24:44 +0530 Subject: [PATCH 5/9] jsdoc suggested changes --- src/modules/internet/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/internet/index.ts b/src/modules/internet/index.ts index c3a8b19d983..3b33aa97348 100644 --- a/src/modules/internet/index.ts +++ b/src/modules/internet/index.ts @@ -184,7 +184,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 an Unicode display name. + * @see faker.internet.displayName(): For generating an Unicode display name. * * @example * faker.internet.userName() // 'Nettie_Zboncak40' From 62a1b60b524afa8b6b31a4942dd22cd8cba5fc0d Mon Sep 17 00:00:00 2001 From: suyashgulati Date: Tue, 24 Sep 2024 23:57:47 +0530 Subject: [PATCH 6/9] Reviews incorporated --- README.md | 2 +- src/modules/internet/index.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e69d1c5b438..9ff5153c784 100644 --- a/README.md +++ b/README.md @@ -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(), diff --git a/src/modules/internet/index.ts b/src/modules/internet/index.ts index 3b33aa97348..075abd7cbc8 100644 --- a/src/modules/internet/index.ts +++ b/src/modules/internet/index.ts @@ -219,7 +219,7 @@ export class InternetModule extends ModuleBase { deprecated({ deprecated: 'faker.internet.userName()', proposed: 'faker.internet.username()', - since: '2.0.1', + since: '9.1.0', until: '10.0.0', }); From ec0de08668407a6d0a02386a18a4d17053220551 Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Wed, 25 Sep 2024 21:47:04 +0200 Subject: [PATCH 7/9] chore: temporary fix for username collision --- docs/api/ApiIndex.vue | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/api/ApiIndex.vue b/docs/api/ApiIndex.vue index 7b1be7bf174..94085371ad1 100644 --- a/docs/api/ApiIndex.vue +++ b/docs/api/ApiIndex.vue @@ -69,8 +69,13 @@ const filtered = computed(() => {
  • + {{ h.text }} From 1d9d294b89e8f1ee95cc3b565da50419e349e3e9 Mon Sep 17 00:00:00 2001 From: suyashgulati Date: Wed, 25 Sep 2024 10:47:22 +0530 Subject: [PATCH 8/9] guide changes informing deprecation --- docs/guide/frameworks.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/guide/frameworks.md b/docs/guide/frameworks.md index ded22f9c722..1733b4e1f70 100644 --- a/docs/guide/frameworks.md +++ b/docs/guide/frameworks.md @@ -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(); @@ -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(); From 84a7677c418e287dcf69ee270db676a718100f64 Mon Sep 17 00:00:00 2001 From: suyashgulati Date: Thu, 26 Sep 2024 01:25:50 +0530 Subject: [PATCH 9/9] minor jsdoc change --- src/modules/internet/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/internet/index.ts b/src/modules/internet/index.ts index 075abd7cbc8..67b8674300f 100644 --- a/src/modules/internet/index.ts +++ b/src/modules/internet/index.ts @@ -198,7 +198,7 @@ export class InternetModule extends ModuleBase { * * @since 2.0.1 * - * @deprecated Use `faker.internet.username()` instead. Example: `faker.internet.username();` + * @deprecated Use `faker.internet.username()` instead. */ userName( options: {