From d6e48058d3f2226b855ad5fc32509d0ccde8cec9 Mon Sep 17 00:00:00 2001 From: Austin Millwood Date: Fri, 27 Oct 2023 15:08:43 -0400 Subject: [PATCH 1/5] chore(internet): username method to return value that always includes last name if provided --- src/modules/internet/index.ts | 11 +++- test/modules/__snapshots__/git.spec.ts.snap | 30 ++++----- .../__snapshots__/internet.spec.ts.snap | 62 +++++++++---------- test/modules/internet.spec.ts | 1 + 4 files changed, 55 insertions(+), 49 deletions(-) diff --git a/src/modules/internet/index.ts b/src/modules/internet/index.ts index aecdb302a48..2aec00d4738 100644 --- a/src/modules/internet/index.ts +++ b/src/modules/internet/index.ts @@ -254,7 +254,7 @@ export class InternetModule { const { firstName = this.faker.person.firstName(), - lastName = legacyLastName ?? this.faker.person.lastName(), + lastName = legacyLastName, provider = legacyProvider ?? this.faker.helpers.arrayElement( this.faker.definitions.internet.free_email @@ -460,7 +460,7 @@ export class InternetModule { const { firstName = this.faker.person.firstName(), - lastName = legacyLastName ?? this.faker.person.lastName(), + lastName = legacyLastName, allowSpecialCharacters = legacyOptions?.allowSpecialCharacters ?? false, } = options; @@ -616,7 +616,12 @@ export class InternetModule { } = options; let result: string; - switch (this.faker.number.int(2)) { + switch ( + this.faker.number.int({ + min: options.lastName || legacyLastName ? 1 : 0, + max: 2, + }) + ) { case 0: result = `${firstName}${this.faker.number.int(99)}`; break; diff --git a/test/modules/__snapshots__/git.spec.ts.snap b/test/modules/__snapshots__/git.spec.ts.snap index 9e52bd15e82..21901b89f2e 100644 --- a/test/modules/__snapshots__/git.spec.ts.snap +++ b/test/modules/__snapshots__/git.spec.ts.snap @@ -10,28 +10,28 @@ exports[`git > 42 > commitDate > with only string refDate 1`] = `"Tue Dec 31 15: exports[`git > 42 > commitEntry > with only Date refDate 1`] = ` "commit be4abdd39321ad7d3fe01ffce404f4d6db0906bd -Author: Gregg Beahan III -Date: Tue Dec 31 14:49:14 2019 +0100 +Author: Gregg Beahan III +Date: Tue Dec 31 11:39:29 2019 +1200 -    parse multi-byte sensor +    quantify online protocol " `; exports[`git > 42 > commitEntry > with only number refDate 1`] = ` "commit be4abdd39321ad7d3fe01ffce404f4d6db0906bd -Author: Gregg Beahan III -Date: Tue Dec 31 14:49:14 2019 +0100 +Author: Gregg Beahan III +Date: Tue Dec 31 11:39:29 2019 +1200 -    parse multi-byte sensor +    quantify online protocol " `; exports[`git > 42 > commitEntry > with only string refDate 1`] = ` "commit be4abdd39321ad7d3fe01ffce404f4d6db0906bd -Author: Gregg Beahan III -Date: Tue Dec 31 14:49:14 2019 +0100 +Author: Gregg Beahan III +Date: Tue Dec 31 11:39:29 2019 +1200 -    parse multi-byte sensor +    quantify online protocol " `; @@ -53,7 +53,7 @@ exports[`git > 1211 > commitDate > with only string refDate 1`] = `"Tue Dec 31 0 exports[`git > 1211 > commitEntry > with only Date refDate 1`] = ` "commit adb42f0e3f4a973fab0aeefce96dfcf49cd438df -Author: Imani Anderson +Author: Imani Anderson Date: Tue Dec 31 10:07:32 2019 -0400     override wireless interface @@ -62,7 +62,7 @@ Date: Tue Dec 31 10:07:32 2019 -0400 exports[`git > 1211 > commitEntry > with only number refDate 1`] = ` "commit adb42f0e3f4a973fab0aeefce96dfcf49cd438df -Author: Imani Anderson +Author: Imani Anderson Date: Tue Dec 31 10:07:32 2019 -0400     override wireless interface @@ -71,7 +71,7 @@ Date: Tue Dec 31 10:07:32 2019 -0400 exports[`git > 1211 > commitEntry > with only string refDate 1`] = ` "commit adb42f0e3f4a973fab0aeefce96dfcf49cd438df -Author: Imani Anderson +Author: Imani Anderson Date: Tue Dec 31 10:07:32 2019 -0400     override wireless interface @@ -96,7 +96,7 @@ exports[`git > 1337 > commitDate > with only string refDate 1`] = `"Tue Dec 31 1 exports[`git > 1337 > commitEntry > with only Date refDate 1`] = ` "commit c346ba075bd57f5a62b82d72af39cbbb07a98cba -Author: Miss Friedrich Krajcik +Author: Miss Friedrich Krajcik Date: Tue Dec 31 04:18:56 2019 -0700     reboot haptic capacitor @@ -105,7 +105,7 @@ Date: Tue Dec 31 04:18:56 2019 -0700 exports[`git > 1337 > commitEntry > with only number refDate 1`] = ` "commit c346ba075bd57f5a62b82d72af39cbbb07a98cba -Author: Miss Friedrich Krajcik +Author: Miss Friedrich Krajcik Date: Tue Dec 31 04:18:56 2019 -0700     reboot haptic capacitor @@ -114,7 +114,7 @@ Date: Tue Dec 31 04:18:56 2019 -0700 exports[`git > 1337 > commitEntry > with only string refDate 1`] = ` "commit c346ba075bd57f5a62b82d72af39cbbb07a98cba -Author: Miss Friedrich Krajcik +Author: Miss Friedrich Krajcik Date: Tue Dec 31 04:18:56 2019 -0700     reboot haptic capacitor diff --git a/test/modules/__snapshots__/internet.spec.ts.snap b/test/modules/__snapshots__/internet.spec.ts.snap index c8c6d8bbc36..8cfe698c69c 100644 --- a/test/modules/__snapshots__/internet.spec.ts.snap +++ b/test/modules/__snapshots__/internet.spec.ts.snap @@ -38,13 +38,13 @@ exports[`internet > 42 > domainSuffix 1`] = `"info"`; exports[`internet > 42 > domainWord 1`] = `"hasty-sherbet"`; -exports[`internet > 42 > email > noArgs 1`] = `"Garnet_Wiegand59@gmail.com"`; +exports[`internet > 42 > email > noArgs 1`] = `"Garnet_Deckow-Reynolds59@hotmail.com"`; exports[`internet > 42 > email > with all options 1`] = `"Jane_Doe@fakerjs.dev"`; -exports[`internet > 42 > email > with allowSpecialCharacters option 1`] = `"Garnet$Wiegand59@gmail.com"`; +exports[`internet > 42 > email > with allowSpecialCharacters option 1`] = `"Garnet_Deckow-Reynolds59@hotmail.com"`; -exports[`internet > 42 > email > with firstName option 1`] = `"Jane73@hotmail.com"`; +exports[`internet > 42 > email > with firstName option 1`] = `"Jane73@yahoo.com"`; exports[`internet > 42 > email > with lastName option 1`] = `"Garnet.Doe73@hotmail.com"`; @@ -60,13 +60,13 @@ exports[`internet > 42 > emoji > noArgs 1`] = `"🕸️"`; exports[`internet > 42 > emoji > with options 1`] = `"🦔"`; -exports[`internet > 42 > exampleEmail > noArgs 1`] = `"Garnet_Wiegand59@example.org"`; +exports[`internet > 42 > exampleEmail > noArgs 1`] = `"Garnet_Deckow-Reynolds59@example.net"`; exports[`internet > 42 > exampleEmail > with all options 1`] = `"Jane_Doe18@example.com"`; -exports[`internet > 42 > exampleEmail > with allowSpecialCharacters option 1`] = `"Garnet$Wiegand59@example.org"`; +exports[`internet > 42 > exampleEmail > with allowSpecialCharacters option 1`] = `"Garnet_Deckow-Reynolds59@example.net"`; -exports[`internet > 42 > exampleEmail > with firstName option 1`] = `"Jane73@example.net"`; +exports[`internet > 42 > exampleEmail > with firstName option 1`] = `"Jane73@example.com"`; exports[`internet > 42 > exampleEmail > with lastName option 1`] = `"Garnet.Doe73@example.net"`; @@ -180,13 +180,13 @@ exports[`internet > 1211 > domainSuffix 1`] = `"org"`; exports[`internet > 1211 > domainWord 1`] = `"vicious-infrastructure"`; -exports[`internet > 1211 > email > noArgs 1`] = `"Tito12@hotmail.com"`; +exports[`internet > 1211 > email > noArgs 1`] = `"Tito12@yahoo.com"`; exports[`internet > 1211 > email > with all options 1`] = `"Jane.Doe89@fakerjs.dev"`; -exports[`internet > 1211 > email > with allowSpecialCharacters option 1`] = `"Tito12@hotmail.com"`; +exports[`internet > 1211 > email > with allowSpecialCharacters option 1`] = `"Tito12@yahoo.com"`; -exports[`internet > 1211 > email > with firstName option 1`] = `"Jane.Koelpin12@hotmail.com"`; +exports[`internet > 1211 > email > with firstName option 1`] = `"Jane.Trantow12@hotmail.com"`; exports[`internet > 1211 > email > with lastName option 1`] = `"Tito_Doe22@yahoo.com"`; @@ -202,13 +202,13 @@ exports[`internet > 1211 > emoji > noArgs 1`] = `"🇮🇸"`; exports[`internet > 1211 > emoji > with options 1`] = `"🌲"`; -exports[`internet > 1211 > exampleEmail > noArgs 1`] = `"Tito12@example.net"`; +exports[`internet > 1211 > exampleEmail > noArgs 1`] = `"Tito12@example.com"`; exports[`internet > 1211 > exampleEmail > with all options 1`] = `"Jane_Doe@example.net"`; -exports[`internet > 1211 > exampleEmail > with allowSpecialCharacters option 1`] = `"Tito12@example.net"`; +exports[`internet > 1211 > exampleEmail > with allowSpecialCharacters option 1`] = `"Tito12@example.com"`; -exports[`internet > 1211 > exampleEmail > with firstName option 1`] = `"Jane.Koelpin12@example.net"`; +exports[`internet > 1211 > exampleEmail > with firstName option 1`] = `"Jane.Trantow12@example.net"`; exports[`internet > 1211 > exampleEmail > with lastName option 1`] = `"Tito_Doe22@example.com"`; @@ -322,19 +322,19 @@ exports[`internet > 1337 > domainSuffix 1`] = `"biz"`; exports[`internet > 1337 > domainWord 1`] = `"fair-mile"`; -exports[`internet > 1337 > email > noArgs 1`] = `"Devyn54@gmail.com"`; +exports[`internet > 1337 > email > noArgs 1`] = `"Devyn54@yahoo.com"`; -exports[`internet > 1337 > email > with all options 1`] = `"Jane56@fakerjs.dev"`; +exports[`internet > 1337 > email > with all options 1`] = `"Jane_Doe@fakerjs.dev"`; -exports[`internet > 1337 > email > with allowSpecialCharacters option 1`] = `"Devyn54@gmail.com"`; +exports[`internet > 1337 > email > with allowSpecialCharacters option 1`] = `"Devyn54@yahoo.com"`; exports[`internet > 1337 > email > with firstName option 1`] = `"Jane27@gmail.com"`; -exports[`internet > 1337 > email > with lastName option 1`] = `"Devyn21@yahoo.com"`; +exports[`internet > 1337 > email > with lastName option 1`] = `"Devyn.Doe@yahoo.com"`; -exports[`internet > 1337 > email > with legacy names 1`] = `"Jane.Doe@gmail.com"`; +exports[`internet > 1337 > email > with legacy names 1`] = `"Jane.Doe21@gmail.com"`; -exports[`internet > 1337 > email > with legacy names and provider 1`] = `"Jane56@fakerjs.dev"`; +exports[`internet > 1337 > email > with legacy names and provider 1`] = `"Jane_Doe@fakerjs.dev"`; exports[`internet > 1337 > email > with legacy provider 1`] = `"Devyn27@fakerjs.dev"`; @@ -344,19 +344,19 @@ exports[`internet > 1337 > emoji > noArgs 1`] = `"💇🏼‍♀️"`; exports[`internet > 1337 > emoji > with options 1`] = `"🐪"`; -exports[`internet > 1337 > exampleEmail > noArgs 1`] = `"Devyn54@example.org"`; +exports[`internet > 1337 > exampleEmail > noArgs 1`] = `"Devyn54@example.com"`; -exports[`internet > 1337 > exampleEmail > with all options 1`] = `"Jane&Doe@example.org"`; +exports[`internet > 1337 > exampleEmail > with all options 1`] = `"Jane/Doe21@example.org"`; -exports[`internet > 1337 > exampleEmail > with allowSpecialCharacters option 1`] = `"Devyn54@example.org"`; +exports[`internet > 1337 > exampleEmail > with allowSpecialCharacters option 1`] = `"Devyn54@example.com"`; exports[`internet > 1337 > exampleEmail > with firstName option 1`] = `"Jane27@example.org"`; -exports[`internet > 1337 > exampleEmail > with lastName option 1`] = `"Devyn21@example.com"`; +exports[`internet > 1337 > exampleEmail > with lastName option 1`] = `"Devyn.Doe@example.com"`; -exports[`internet > 1337 > exampleEmail > with legacy names 1`] = `"Jane.Doe@example.org"`; +exports[`internet > 1337 > exampleEmail > with legacy names 1`] = `"Jane.Doe21@example.org"`; -exports[`internet > 1337 > exampleEmail > with legacy names and options 1`] = `"Jane&Doe@example.org"`; +exports[`internet > 1337 > exampleEmail > with legacy names and options 1`] = `"Jane/Doe21@example.org"`; exports[`internet > 1337 > httpMethod 1`] = `"POST"`; @@ -410,18 +410,18 @@ exports[`internet > 1337 > userAgent 1`] = `"Mozilla/5.0 (Macintosh; U; Intel Ma exports[`internet > 1337 > userName > noArgs 1`] = `"Devyn27"`; -exports[`internet > 1337 > userName > with Chinese names 1`] = `"hlzp8d56"`; +exports[`internet > 1337 > userName > with Chinese names 1`] = `"hlzp8d_tpv"`; -exports[`internet > 1337 > userName > with Cyrillic names 1`] = `"Fedor56"`; +exports[`internet > 1337 > userName > with Cyrillic names 1`] = `"Fedor_Dostoevskii"`; -exports[`internet > 1337 > userName > with Latin names 1`] = `"Jane56"`; +exports[`internet > 1337 > userName > with Latin names 1`] = `"Jane_Doe"`; -exports[`internet > 1337 > userName > with accented names 1`] = `"Helene56"`; +exports[`internet > 1337 > userName > with accented names 1`] = `"Helene_Muller"`; -exports[`internet > 1337 > userName > with all option 1`] = `"Jane56"`; +exports[`internet > 1337 > userName > with all option 1`] = `"Jane_Doe"`; exports[`internet > 1337 > userName > with firstName option 1`] = `"Jane21"`; -exports[`internet > 1337 > userName > with lastName option 1`] = `"Devyn.Doe"`; +exports[`internet > 1337 > userName > with lastName option 1`] = `"Devyn.Doe21"`; -exports[`internet > 1337 > userName > with legacy names 1`] = `"Jane56"`; +exports[`internet > 1337 > userName > with legacy names 1`] = `"Jane_Doe"`; diff --git a/test/modules/internet.spec.ts b/test/modules/internet.spec.ts index 79d329de3ea..26e29d52d6f 100644 --- a/test/modules/internet.spec.ts +++ b/test/modules/internet.spec.ts @@ -252,6 +252,7 @@ describe('internet', () => { const [prefix, suffix] = email.split('@'); expect(prefix).includes('Aiden'); + expect(prefix).includes('Harann'); expect(prefix).toMatch( /^Aiden((\d{1,2})|([._]Harann\d{1,2})|([._](Harann)))/ ); From aa3d6e13c70123a2fcb10146767a8e3f7957941d Mon Sep 17 00:00:00 2001 From: Austin Millwood Date: Thu, 2 Nov 2023 08:44:41 -0400 Subject: [PATCH 2/5] internet: refactored username logic, updated JSDocs --- src/modules/internet/index.ts | 61 ++++--- test/modules/__snapshots__/git.spec.ts.snap | 54 +++---- .../__snapshots__/internet.spec.ts.snap | 150 +++++++++--------- 3 files changed, 140 insertions(+), 125 deletions(-) diff --git a/src/modules/internet/index.ts b/src/modules/internet/index.ts index 2aec00d4738..48503b1a098 100644 --- a/src/modules/internet/index.ts +++ b/src/modules/internet/index.ts @@ -70,7 +70,9 @@ export class InternetModule { * * @example * faker.internet.email() // 'Kassandra4@hotmail.com' - * faker.internet.email({ firstName: 'Jeanne', lastName: 'Doe' }) // 'Jeanne63@yahoo.com' + * faker.internet.email({ firstName: 'Jeanne'}) // 'Jeanne63@yahoo.com' + * faker.internet.email({ firstName: 'Jeanne'}) // 'Jeanne_Smith63@yahoo.com' + * faker.internet.email({ firstName: 'Jeanne', lastName: 'Doe' }) // 'Jeanne.Doe63@yahoo.com' * faker.internet.email({ firstName: 'Jeanne', lastName: 'Doe', provider: 'example.fakerjs.dev' }) // 'Jeanne_Doe88@example.fakerjs.dev' * faker.internet.email({ firstName: 'Jeanne', lastName: 'Doe', provider: 'example.fakerjs.dev', allowSpecialCharacters: true }) // 'Jeanne%Doe88@example.fakerjs.dev' * @@ -112,7 +114,9 @@ export class InternetModule { * * @example * faker.internet.email() // 'Kassandra4@hotmail.com' - * faker.internet.email('Jeanne', 'Doe') // 'Jeanne63@yahoo.com' + * faker.internet.email('Jeanne') // 'Jeanne63@yahoo.com' + * faker.internet.email('Jeanne') // 'Jeanne.Smith63@yahoo.com' + * faker.internet.email('Jeanne', 'Doe') // 'Jeanne_Doe63@yahoo.com' * faker.internet.email('Jeanne', 'Doe', 'example.fakerjs.dev') // 'Jeanne_Doe88@example.fakerjs.dev' * faker.internet.email('Jeanne', 'Doe', 'example.fakerjs.dev', { allowSpecialCharacters: true }) // 'Jeanne%Doe88@example.fakerjs.dev' * @@ -150,7 +154,9 @@ export class InternetModule { * * @example * faker.internet.email() // 'Kassandra4@hotmail.com' - * faker.internet.email({ firstName: 'Jeanne', lastName: 'Doe' }) // 'Jeanne63@yahoo.com' + * faker.internet.email({ firstName: 'Jeanne' }) // 'Jeanne63@yahoo.com' + * faker.internet.email({ firstName: 'Jeanne' }) // 'Jeanne.Smith63@yahoo.com' + * faker.internet.email({ firstName: 'Jeanne', lastName: 'Doe' }) // 'Jeanne_Doe63@yahoo.com' * faker.internet.email({ firstName: 'Jeanne', lastName: 'Doe', provider: 'example.fakerjs.dev' }) // 'Jeanne_Doe88@example.fakerjs.dev' * faker.internet.email({ firstName: 'Jeanne', lastName: 'Doe', provider: 'example.fakerjs.dev', allowSpecialCharacters: true }) // 'Jeanne%Doe88@example.fakerjs.dev' * @@ -300,7 +306,9 @@ export class InternetModule { * * @example * faker.internet.exampleEmail() // 'Helmer.Graham23@example.com' - * faker.internet.exampleEmail({ firstName: 'Jeanne', lastName: 'Doe' }) // 'Jeanne96@example.net' + * faker.internet.exampleEmail({ firstName: 'Jeanne' }) // 'Jeanne96@example.net' + * faker.internet.exampleEmail({ firstName: 'Jeanne' }) // 'Jeanne.Smith96@example.net' + * faker.internet.exampleEmail({ firstName: 'Jeanne', lastName: 'Doe' }) // 'Jeanne_Doe96@example.net' * faker.internet.exampleEmail({ firstName: 'Jeanne', lastName: 'Doe', allowSpecialCharacters: true }) // 'Jeanne%Doe88@example.com' * * @since 3.1.0 @@ -336,7 +344,9 @@ export class InternetModule { * * @example * faker.internet.exampleEmail() // 'Helmer.Graham23@example.com' - * faker.internet.exampleEmail('Jeanne', 'Doe') // 'Jeanne96@example.net' + * faker.internet.exampleEmail('Jeanne') // 'Jeanne96@example.net' + * faker.internet.exampleEmail('Jeanne') // 'Jeanne.Smith96@example.net' + * faker.internet.exampleEmail('Jeanne', 'Doe') // 'Jeanne_Doe96@example.net' * faker.internet.exampleEmail('Jeanne', 'Doe', { allowSpecialCharacters: true }) // 'Jeanne%Doe88@example.com' * * @since 3.1.0 @@ -370,7 +380,9 @@ export class InternetModule { * * @example * faker.internet.exampleEmail() // 'Helmer.Graham23@example.com' - * faker.internet.exampleEmail({ firstName: 'Jeanne', lastName: 'Doe' }) // 'Jeanne96@example.net' + * faker.internet.exampleEmail({ firstName: 'Jeanne' }) // 'Jeanne96@example.net' + * faker.internet.exampleEmail({ firstName: 'Jeanne' }) // 'Jeanne.Smith96@example.net' + * faker.internet.exampleEmail({ firstName: 'Jeanne', lastName: 'Doe' }) // 'Jeanne_Doe96@example.net' * faker.internet.exampleEmail({ firstName: 'Jeanne', lastName: 'Doe', allowSpecialCharacters: true }) // 'Jeanne%Doe88@example.com' * * @since 3.1.0 @@ -478,7 +490,7 @@ export class InternetModule { /** * Generates a username using the given person's name as base. - * The resulting username may use neither, one or both of the names provided. + * The resulting username will use the names provided or choose a random name if one is not provided. * This will always return a plain ASCII string. * Some basic stripping of accents and transliteration of characters will be done. * @@ -490,7 +502,9 @@ export class InternetModule { * * @example * faker.internet.userName() // 'Nettie_Zboncak40' - * faker.internet.userName({ firstName: 'Jeanne', lastName: 'Doe'}) // 'Jeanne98' - note surname is not used + * 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' @@ -514,7 +528,7 @@ export class InternetModule { }): string; /** * Generates a username using the given person's name as base. - * The resulting username may use neither, one or both of the names provided. + * The resulting username will use the names provided or choose a random name if one is not provided. * This will always return a plain ASCII string. * Some basic stripping of accents and transliteration of characters will be done. * @@ -525,7 +539,9 @@ export class InternetModule { * * @example * faker.internet.userName() // 'Nettie_Zboncak40' - * faker.internet.userName('Jeanne', 'Doe') // 'Jeanne98' - note surname is not used + * faker.internet.userName('Jeanne') // 'Jeanne98' + * faker.internet.userName('Jeanne') // 'Jeanne.Smith98' + * faker.internet.userName('Jeanne', 'Doe') // 'Jeanne_Doe98' * faker.internet.userName('John', 'Doe') // 'John.Doe' * faker.internet.userName('Hélene', 'Müller') // 'Helene_Muller11' * faker.internet.userName('Фёдор', 'Достоевский') // 'Fedor.Dostoevskii50' @@ -538,7 +554,7 @@ export class InternetModule { userName(firstName?: string, lastName?: string): string; /** * Generates a username using the given person's name as base. - * The resulting username may use neither, one or both of the names provided. + * The resulting username will use the names provided or choose a random name if one is not provided. * This will always return a plain ASCII string. * Some basic stripping of accents and transliteration of characters will be done. * @@ -551,7 +567,9 @@ export class InternetModule { * * @example * faker.internet.userName() // 'Nettie_Zboncak40' - * faker.internet.userName({ firstName: 'Jeanne', lastName: 'Doe'}) // 'Jeanne98' - note surname is not used + * 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' @@ -616,24 +634,21 @@ export class InternetModule { } = options; let result: string; - switch ( - this.faker.number.int({ - min: options.lastName || legacyLastName ? 1 : 0, - max: 2, - }) - ) { + const hasLastName = options.lastName || legacyLastName; + const strategy = this.faker.number.int(hasLastName ? 1 : 2); + switch (strategy) { case 0: - result = `${firstName}${this.faker.number.int(99)}`; + result = `${firstName}${this.faker.helpers.arrayElement([ + '.', + '_', + ])}${lastName}${this.faker.number.int(99)}`; break; case 1: result = firstName + this.faker.helpers.arrayElement(['.', '_']) + lastName; break; case 2: - result = `${firstName}${this.faker.helpers.arrayElement([ - '.', - '_', - ])}${lastName}${this.faker.number.int(99)}`; + result = `${firstName}${this.faker.number.int(99)}`; break; } diff --git a/test/modules/__snapshots__/git.spec.ts.snap b/test/modules/__snapshots__/git.spec.ts.snap index 21901b89f2e..2294d6fcc5f 100644 --- a/test/modules/__snapshots__/git.spec.ts.snap +++ b/test/modules/__snapshots__/git.spec.ts.snap @@ -10,28 +10,28 @@ exports[`git > 42 > commitDate > with only string refDate 1`] = `"Tue Dec 31 15: exports[`git > 42 > commitEntry > with only Date refDate 1`] = ` "commit be4abdd39321ad7d3fe01ffce404f4d6db0906bd -Author: Gregg Beahan III -Date: Tue Dec 31 11:39:29 2019 +1200 +Author: Gregg.Beahan9 +Date: Tue Dec 31 00:24:08 2019 +0300 -    quantify online protocol +    connect auxiliary bus " `; exports[`git > 42 > commitEntry > with only number refDate 1`] = ` "commit be4abdd39321ad7d3fe01ffce404f4d6db0906bd -Author: Gregg Beahan III -Date: Tue Dec 31 11:39:29 2019 +1200 +Author: Gregg.Beahan9 +Date: Tue Dec 31 00:24:08 2019 +0300 -    quantify online protocol +    connect auxiliary bus " `; exports[`git > 42 > commitEntry > with only string refDate 1`] = ` "commit be4abdd39321ad7d3fe01ffce404f4d6db0906bd -Author: Gregg Beahan III -Date: Tue Dec 31 11:39:29 2019 +1200 +Author: Gregg.Beahan9 +Date: Tue Dec 31 00:24:08 2019 +0300 -    quantify online protocol +    connect auxiliary bus " `; @@ -53,28 +53,28 @@ exports[`git > 1211 > commitDate > with only string refDate 1`] = `"Tue Dec 31 0 exports[`git > 1211 > commitEntry > with only Date refDate 1`] = ` "commit adb42f0e3f4a973fab0aeefce96dfcf49cd438df -Author: Imani Anderson -Date: Tue Dec 31 10:07:32 2019 -0400 +Author: Imani.Anderson +Date: Tue Dec 31 18:36:59 2019 +0200 -    override wireless interface +    copy digital feed " `; exports[`git > 1211 > commitEntry > with only number refDate 1`] = ` "commit adb42f0e3f4a973fab0aeefce96dfcf49cd438df -Author: Imani Anderson -Date: Tue Dec 31 10:07:32 2019 -0400 +Author: Imani.Anderson +Date: Tue Dec 31 18:36:59 2019 +0200 -    override wireless interface +    copy digital feed " `; exports[`git > 1211 > commitEntry > with only string refDate 1`] = ` "commit adb42f0e3f4a973fab0aeefce96dfcf49cd438df -Author: Imani Anderson -Date: Tue Dec 31 10:07:32 2019 -0400 +Author: Imani.Anderson +Date: Tue Dec 31 18:36:59 2019 +0200 -    override wireless interface +    copy digital feed " `; @@ -96,28 +96,28 @@ exports[`git > 1337 > commitDate > with only string refDate 1`] = `"Tue Dec 31 1 exports[`git > 1337 > commitEntry > with only Date refDate 1`] = ` "commit c346ba075bd57f5a62b82d72af39cbbb07a98cba -Author: Miss Friedrich Krajcik -Date: Tue Dec 31 04:18:56 2019 -0700 +Author: Miss Friedrich Krajcik +Date: Tue Dec 31 02:27:22 2019 +0100 -    reboot haptic capacitor +    reboot neural pixel " `; exports[`git > 1337 > commitEntry > with only number refDate 1`] = ` "commit c346ba075bd57f5a62b82d72af39cbbb07a98cba -Author: Miss Friedrich Krajcik -Date: Tue Dec 31 04:18:56 2019 -0700 +Author: Miss Friedrich Krajcik +Date: Tue Dec 31 02:27:22 2019 +0100 -    reboot haptic capacitor +    reboot neural pixel " `; exports[`git > 1337 > commitEntry > with only string refDate 1`] = ` "commit c346ba075bd57f5a62b82d72af39cbbb07a98cba -Author: Miss Friedrich Krajcik -Date: Tue Dec 31 04:18:56 2019 -0700 +Author: Miss Friedrich Krajcik +Date: Tue Dec 31 02:27:22 2019 +0100 -    reboot haptic capacitor +    reboot neural pixel " `; diff --git a/test/modules/__snapshots__/internet.spec.ts.snap b/test/modules/__snapshots__/internet.spec.ts.snap index 8cfe698c69c..54e63fe4679 100644 --- a/test/modules/__snapshots__/internet.spec.ts.snap +++ b/test/modules/__snapshots__/internet.spec.ts.snap @@ -38,41 +38,41 @@ exports[`internet > 42 > domainSuffix 1`] = `"info"`; exports[`internet > 42 > domainWord 1`] = `"hasty-sherbet"`; -exports[`internet > 42 > email > noArgs 1`] = `"Garnet_Deckow-Reynolds59@hotmail.com"`; +exports[`internet > 42 > email > noArgs 1`] = `"Garnet59@hotmail.com"`; -exports[`internet > 42 > email > with all options 1`] = `"Jane_Doe@fakerjs.dev"`; +exports[`internet > 42 > email > with all options 1`] = `"Jane_Doe95@fakerjs.dev"`; -exports[`internet > 42 > email > with allowSpecialCharacters option 1`] = `"Garnet_Deckow-Reynolds59@hotmail.com"`; +exports[`internet > 42 > email > with allowSpecialCharacters option 1`] = `"Garnet59@hotmail.com"`; -exports[`internet > 42 > email > with firstName option 1`] = `"Jane73@yahoo.com"`; +exports[`internet > 42 > email > with firstName option 1`] = `"Jane_Wiegand77@yahoo.com"`; -exports[`internet > 42 > email > with lastName option 1`] = `"Garnet.Doe73@hotmail.com"`; +exports[`internet > 42 > email > with lastName option 1`] = `"Garnet.Doe@hotmail.com"`; -exports[`internet > 42 > email > with legacy names 1`] = `"Jane_Doe18@yahoo.com"`; +exports[`internet > 42 > email > with legacy names 1`] = `"Jane_Doe@yahoo.com"`; -exports[`internet > 42 > email > with legacy names and provider 1`] = `"Jane_Doe@fakerjs.dev"`; +exports[`internet > 42 > email > with legacy names and provider 1`] = `"Jane_Doe95@fakerjs.dev"`; -exports[`internet > 42 > email > with legacy provider 1`] = `"Garnet73@fakerjs.dev"`; +exports[`internet > 42 > email > with legacy provider 1`] = `"Garnet_Wiegand77@fakerjs.dev"`; -exports[`internet > 42 > email > with provider option 1`] = `"Garnet73@fakerjs.dev"`; +exports[`internet > 42 > email > with provider option 1`] = `"Garnet_Wiegand77@fakerjs.dev"`; exports[`internet > 42 > emoji > noArgs 1`] = `"🕸️"`; exports[`internet > 42 > emoji > with options 1`] = `"🦔"`; -exports[`internet > 42 > exampleEmail > noArgs 1`] = `"Garnet_Deckow-Reynolds59@example.net"`; +exports[`internet > 42 > exampleEmail > noArgs 1`] = `"Garnet59@example.net"`; -exports[`internet > 42 > exampleEmail > with all options 1`] = `"Jane_Doe18@example.com"`; +exports[`internet > 42 > exampleEmail > with all options 1`] = `"Jane_Doe@example.com"`; -exports[`internet > 42 > exampleEmail > with allowSpecialCharacters option 1`] = `"Garnet_Deckow-Reynolds59@example.net"`; +exports[`internet > 42 > exampleEmail > with allowSpecialCharacters option 1`] = `"Garnet59@example.net"`; -exports[`internet > 42 > exampleEmail > with firstName option 1`] = `"Jane73@example.com"`; +exports[`internet > 42 > exampleEmail > with firstName option 1`] = `"Jane_Wiegand77@example.com"`; -exports[`internet > 42 > exampleEmail > with lastName option 1`] = `"Garnet.Doe73@example.net"`; +exports[`internet > 42 > exampleEmail > with lastName option 1`] = `"Garnet.Doe@example.net"`; -exports[`internet > 42 > exampleEmail > with legacy names 1`] = `"Jane_Doe18@example.com"`; +exports[`internet > 42 > exampleEmail > with legacy names 1`] = `"Jane_Doe@example.com"`; -exports[`internet > 42 > exampleEmail > with legacy names and options 1`] = `"Jane_Doe18@example.com"`; +exports[`internet > 42 > exampleEmail > with legacy names and options 1`] = `"Jane_Doe@example.com"`; exports[`internet > 42 > httpMethod 1`] = `"POST"`; @@ -124,23 +124,23 @@ exports[`internet > 42 > url > without slash appended and with http protocol 1`] exports[`internet > 42 > userAgent 1`] = `"Mozilla/5.0 (X11; Linux x86_64; rv:15.1) Gecko/20100101 Firefox/15.1.7"`; -exports[`internet > 42 > userName > noArgs 1`] = `"Garnet73"`; +exports[`internet > 42 > userName > noArgs 1`] = `"Garnet_Wiegand77"`; -exports[`internet > 42 > userName > with Chinese names 1`] = `"hlzp8d_tpv"`; +exports[`internet > 42 > userName > with Chinese names 1`] = `"hlzp8d_tpv95"`; -exports[`internet > 42 > userName > with Cyrillic names 1`] = `"Fedor_Dostoevskii"`; +exports[`internet > 42 > userName > with Cyrillic names 1`] = `"Fedor_Dostoevskii95"`; -exports[`internet > 42 > userName > with Latin names 1`] = `"Jane_Doe"`; +exports[`internet > 42 > userName > with Latin names 1`] = `"Jane_Doe95"`; -exports[`internet > 42 > userName > with accented names 1`] = `"Helene_Muller"`; +exports[`internet > 42 > userName > with accented names 1`] = `"Helene_Muller95"`; -exports[`internet > 42 > userName > with all option 1`] = `"Jane_Doe"`; +exports[`internet > 42 > userName > with all option 1`] = `"Jane_Doe95"`; -exports[`internet > 42 > userName > with firstName option 1`] = `"Jane.Schinner73"`; +exports[`internet > 42 > userName > with firstName option 1`] = `"Jane18"`; -exports[`internet > 42 > userName > with lastName option 1`] = `"Garnet_Doe18"`; +exports[`internet > 42 > userName > with lastName option 1`] = `"Garnet_Doe"`; -exports[`internet > 42 > userName > with legacy names 1`] = `"Jane_Doe"`; +exports[`internet > 42 > userName > with legacy names 1`] = `"Jane_Doe95"`; exports[`internet > 1211 > avatar 1`] = `"https://cloudflare-ipfs.com/ipfs/Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye/avatar/1160.jpg"`; @@ -180,41 +180,41 @@ exports[`internet > 1211 > domainSuffix 1`] = `"org"`; exports[`internet > 1211 > domainWord 1`] = `"vicious-infrastructure"`; -exports[`internet > 1211 > email > noArgs 1`] = `"Tito12@yahoo.com"`; +exports[`internet > 1211 > email > noArgs 1`] = `"Tito.Satterfield99@yahoo.com"`; -exports[`internet > 1211 > email > with all options 1`] = `"Jane.Doe89@fakerjs.dev"`; +exports[`internet > 1211 > email > with all options 1`] = `"Jane.Doe@fakerjs.dev"`; -exports[`internet > 1211 > email > with allowSpecialCharacters option 1`] = `"Tito12@yahoo.com"`; +exports[`internet > 1211 > email > with allowSpecialCharacters option 1`] = `"Tito^Satterfield99@yahoo.com"`; -exports[`internet > 1211 > email > with firstName option 1`] = `"Jane.Trantow12@hotmail.com"`; +exports[`internet > 1211 > email > with firstName option 1`] = `"Jane22@hotmail.com"`; -exports[`internet > 1211 > email > with lastName option 1`] = `"Tito_Doe22@yahoo.com"`; +exports[`internet > 1211 > email > with lastName option 1`] = `"Tito_Doe@yahoo.com"`; -exports[`internet > 1211 > email > with legacy names 1`] = `"Jane_Doe@hotmail.com"`; +exports[`internet > 1211 > email > with legacy names 1`] = `"Jane_Doe77@hotmail.com"`; -exports[`internet > 1211 > email > with legacy names and provider 1`] = `"Jane.Doe89@fakerjs.dev"`; +exports[`internet > 1211 > email > with legacy names and provider 1`] = `"Jane.Doe@fakerjs.dev"`; -exports[`internet > 1211 > email > with legacy provider 1`] = `"Tito.Trantow12@fakerjs.dev"`; +exports[`internet > 1211 > email > with legacy provider 1`] = `"Tito22@fakerjs.dev"`; -exports[`internet > 1211 > email > with provider option 1`] = `"Tito.Trantow12@fakerjs.dev"`; +exports[`internet > 1211 > email > with provider option 1`] = `"Tito22@fakerjs.dev"`; exports[`internet > 1211 > emoji > noArgs 1`] = `"🇮🇸"`; exports[`internet > 1211 > emoji > with options 1`] = `"🌲"`; -exports[`internet > 1211 > exampleEmail > noArgs 1`] = `"Tito12@example.com"`; +exports[`internet > 1211 > exampleEmail > noArgs 1`] = `"Tito.Satterfield99@example.com"`; -exports[`internet > 1211 > exampleEmail > with all options 1`] = `"Jane_Doe@example.net"`; +exports[`internet > 1211 > exampleEmail > with all options 1`] = `"Jane_Doe77@example.net"`; -exports[`internet > 1211 > exampleEmail > with allowSpecialCharacters option 1`] = `"Tito12@example.com"`; +exports[`internet > 1211 > exampleEmail > with allowSpecialCharacters option 1`] = `"Tito^Satterfield99@example.com"`; -exports[`internet > 1211 > exampleEmail > with firstName option 1`] = `"Jane.Trantow12@example.net"`; +exports[`internet > 1211 > exampleEmail > with firstName option 1`] = `"Jane22@example.net"`; -exports[`internet > 1211 > exampleEmail > with lastName option 1`] = `"Tito_Doe22@example.com"`; +exports[`internet > 1211 > exampleEmail > with lastName option 1`] = `"Tito_Doe@example.com"`; -exports[`internet > 1211 > exampleEmail > with legacy names 1`] = `"Jane_Doe@example.net"`; +exports[`internet > 1211 > exampleEmail > with legacy names 1`] = `"Jane_Doe77@example.net"`; -exports[`internet > 1211 > exampleEmail > with legacy names and options 1`] = `"Jane_Doe@example.net"`; +exports[`internet > 1211 > exampleEmail > with legacy names and options 1`] = `"Jane_Doe77@example.net"`; exports[`internet > 1211 > httpMethod 1`] = `"PATCH"`; @@ -266,23 +266,23 @@ exports[`internet > 1211 > url > without slash appended and with http protocol 1 exports[`internet > 1211 > userAgent 1`] = `"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.3; Trident/4.0)"`; -exports[`internet > 1211 > userName > noArgs 1`] = `"Tito.Trantow12"`; +exports[`internet > 1211 > userName > noArgs 1`] = `"Tito22"`; -exports[`internet > 1211 > userName > with Chinese names 1`] = `"hlzp8d.tpv89"`; +exports[`internet > 1211 > userName > with Chinese names 1`] = `"hlzp8d.tpv"`; -exports[`internet > 1211 > userName > with Cyrillic names 1`] = `"Fedor.Dostoevskii89"`; +exports[`internet > 1211 > userName > with Cyrillic names 1`] = `"Fedor.Dostoevskii"`; -exports[`internet > 1211 > userName > with Latin names 1`] = `"Jane.Doe89"`; +exports[`internet > 1211 > userName > with Latin names 1`] = `"Jane.Doe"`; -exports[`internet > 1211 > userName > with accented names 1`] = `"Helene.Muller89"`; +exports[`internet > 1211 > userName > with accented names 1`] = `"Helene.Muller"`; -exports[`internet > 1211 > userName > with all option 1`] = `"Jane.Doe89"`; +exports[`internet > 1211 > userName > with all option 1`] = `"Jane.Doe"`; -exports[`internet > 1211 > userName > with firstName option 1`] = `"Jane_Koelpin22"`; +exports[`internet > 1211 > userName > with firstName option 1`] = `"Jane77"`; -exports[`internet > 1211 > userName > with lastName option 1`] = `"Tito_Doe"`; +exports[`internet > 1211 > userName > with lastName option 1`] = `"Tito_Doe77"`; -exports[`internet > 1211 > userName > with legacy names 1`] = `"Jane.Doe89"`; +exports[`internet > 1211 > userName > with legacy names 1`] = `"Jane.Doe"`; exports[`internet > 1337 > avatar 1`] = `"https://cloudflare-ipfs.com/ipfs/Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye/avatar/327.jpg"`; @@ -322,41 +322,41 @@ exports[`internet > 1337 > domainSuffix 1`] = `"biz"`; exports[`internet > 1337 > domainWord 1`] = `"fair-mile"`; -exports[`internet > 1337 > email > noArgs 1`] = `"Devyn54@yahoo.com"`; +exports[`internet > 1337 > email > noArgs 1`] = `"Devyn_Effertz45@yahoo.com"`; -exports[`internet > 1337 > email > with all options 1`] = `"Jane_Doe@fakerjs.dev"`; +exports[`internet > 1337 > email > with all options 1`] = `"Jane_Doe15@fakerjs.dev"`; -exports[`internet > 1337 > email > with allowSpecialCharacters option 1`] = `"Devyn54@yahoo.com"`; +exports[`internet > 1337 > email > with allowSpecialCharacters option 1`] = `"Devyn_Effertz45@yahoo.com"`; -exports[`internet > 1337 > email > with firstName option 1`] = `"Jane27@gmail.com"`; +exports[`internet > 1337 > email > with firstName option 1`] = `"Jane.Cronin54@gmail.com"`; -exports[`internet > 1337 > email > with lastName option 1`] = `"Devyn.Doe@yahoo.com"`; +exports[`internet > 1337 > email > with lastName option 1`] = `"Devyn.Doe27@yahoo.com"`; -exports[`internet > 1337 > email > with legacy names 1`] = `"Jane.Doe21@gmail.com"`; +exports[`internet > 1337 > email > with legacy names 1`] = `"Jane.Doe@gmail.com"`; -exports[`internet > 1337 > email > with legacy names and provider 1`] = `"Jane_Doe@fakerjs.dev"`; +exports[`internet > 1337 > email > with legacy names and provider 1`] = `"Jane_Doe15@fakerjs.dev"`; -exports[`internet > 1337 > email > with legacy provider 1`] = `"Devyn27@fakerjs.dev"`; +exports[`internet > 1337 > email > with legacy provider 1`] = `"Devyn.Cronin54@fakerjs.dev"`; -exports[`internet > 1337 > email > with provider option 1`] = `"Devyn27@fakerjs.dev"`; +exports[`internet > 1337 > email > with provider option 1`] = `"Devyn.Cronin54@fakerjs.dev"`; exports[`internet > 1337 > emoji > noArgs 1`] = `"💇🏼‍♀️"`; exports[`internet > 1337 > emoji > with options 1`] = `"🐪"`; -exports[`internet > 1337 > exampleEmail > noArgs 1`] = `"Devyn54@example.com"`; +exports[`internet > 1337 > exampleEmail > noArgs 1`] = `"Devyn_Effertz45@example.com"`; -exports[`internet > 1337 > exampleEmail > with all options 1`] = `"Jane/Doe21@example.org"`; +exports[`internet > 1337 > exampleEmail > with all options 1`] = `"Jane&Doe@example.org"`; -exports[`internet > 1337 > exampleEmail > with allowSpecialCharacters option 1`] = `"Devyn54@example.com"`; +exports[`internet > 1337 > exampleEmail > with allowSpecialCharacters option 1`] = `"Devyn_Effertz45@example.com"`; -exports[`internet > 1337 > exampleEmail > with firstName option 1`] = `"Jane27@example.org"`; +exports[`internet > 1337 > exampleEmail > with firstName option 1`] = `"Jane.Cronin54@example.org"`; -exports[`internet > 1337 > exampleEmail > with lastName option 1`] = `"Devyn.Doe@example.com"`; +exports[`internet > 1337 > exampleEmail > with lastName option 1`] = `"Devyn.Doe27@example.com"`; -exports[`internet > 1337 > exampleEmail > with legacy names 1`] = `"Jane.Doe21@example.org"`; +exports[`internet > 1337 > exampleEmail > with legacy names 1`] = `"Jane.Doe@example.org"`; -exports[`internet > 1337 > exampleEmail > with legacy names and options 1`] = `"Jane/Doe21@example.org"`; +exports[`internet > 1337 > exampleEmail > with legacy names and options 1`] = `"Jane&Doe@example.org"`; exports[`internet > 1337 > httpMethod 1`] = `"POST"`; @@ -408,20 +408,20 @@ exports[`internet > 1337 > url > without slash appended and with http protocol 1 exports[`internet > 1337 > userAgent 1`] = `"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.7.0; rv:6.2) Gecko/20100101 Firefox/6.2.2"`; -exports[`internet > 1337 > userName > noArgs 1`] = `"Devyn27"`; +exports[`internet > 1337 > userName > noArgs 1`] = `"Devyn.Cronin54"`; -exports[`internet > 1337 > userName > with Chinese names 1`] = `"hlzp8d_tpv"`; +exports[`internet > 1337 > userName > with Chinese names 1`] = `"hlzp8d_tpv15"`; -exports[`internet > 1337 > userName > with Cyrillic names 1`] = `"Fedor_Dostoevskii"`; +exports[`internet > 1337 > userName > with Cyrillic names 1`] = `"Fedor_Dostoevskii15"`; -exports[`internet > 1337 > userName > with Latin names 1`] = `"Jane_Doe"`; +exports[`internet > 1337 > userName > with Latin names 1`] = `"Jane_Doe15"`; -exports[`internet > 1337 > userName > with accented names 1`] = `"Helene_Muller"`; +exports[`internet > 1337 > userName > with accented names 1`] = `"Helene_Muller15"`; -exports[`internet > 1337 > userName > with all option 1`] = `"Jane_Doe"`; +exports[`internet > 1337 > userName > with all option 1`] = `"Jane_Doe15"`; -exports[`internet > 1337 > userName > with firstName option 1`] = `"Jane21"`; +exports[`internet > 1337 > userName > with firstName option 1`] = `"Jane.MacGyver27"`; -exports[`internet > 1337 > userName > with lastName option 1`] = `"Devyn.Doe21"`; +exports[`internet > 1337 > userName > with lastName option 1`] = `"Devyn.Doe"`; -exports[`internet > 1337 > userName > with legacy names 1`] = `"Jane_Doe"`; +exports[`internet > 1337 > userName > with legacy names 1`] = `"Jane_Doe15"`; From 7735ef51de2653d50180922b367a35bcb739e550 Mon Sep 17 00:00:00 2001 From: Austin Millwood Date: Fri, 3 Nov 2023 15:34:00 -0400 Subject: [PATCH 3/5] internet: added separator parameter to username method --- src/modules/internet/index.ts | 17 ++++++++--------- .../modules/__snapshots__/internet.spec.ts.snap | 14 +++++++------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/modules/internet/index.ts b/src/modules/internet/index.ts index 48503b1a098..9ab6f42f53c 100644 --- a/src/modules/internet/index.ts +++ b/src/modules/internet/index.ts @@ -490,7 +490,7 @@ export class InternetModule { /** * Generates a username using the given person's name as base. - * The resulting username will use the names provided or choose a random name if one is not provided. + * 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. * @@ -528,7 +528,7 @@ export class InternetModule { }): string; /** * Generates a username using the given person's name as base. - * The resulting username will use the names provided or choose a random name if one is not provided. + * 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. * @@ -554,7 +554,7 @@ export class InternetModule { userName(firstName?: string, lastName?: string): string; /** * Generates a username using the given person's name as base. - * The resulting username will use the names provided or choose a random name if one is not provided. + * 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. * @@ -636,16 +636,15 @@ export class InternetModule { let result: string; const hasLastName = options.lastName || legacyLastName; const strategy = this.faker.number.int(hasLastName ? 1 : 2); + const separator = this.faker.helpers.arrayElement(['.', '_']); switch (strategy) { case 0: - result = `${firstName}${this.faker.helpers.arrayElement([ - '.', - '_', - ])}${lastName}${this.faker.number.int(99)}`; + result = `${firstName}${separator}${lastName}${this.faker.number.int( + 99 + )}`; break; case 1: - result = - firstName + this.faker.helpers.arrayElement(['.', '_']) + lastName; + result = `${firstName}${separator}${lastName}`; break; case 2: result = `${firstName}${this.faker.number.int(99)}`; diff --git a/test/modules/__snapshots__/internet.spec.ts.snap b/test/modules/__snapshots__/internet.spec.ts.snap index 54e63fe4679..fde6e445a45 100644 --- a/test/modules/__snapshots__/internet.spec.ts.snap +++ b/test/modules/__snapshots__/internet.spec.ts.snap @@ -136,7 +136,7 @@ exports[`internet > 42 > userName > with accented names 1`] = `"Helene_Muller95" exports[`internet > 42 > userName > with all option 1`] = `"Jane_Doe95"`; -exports[`internet > 42 > userName > with firstName option 1`] = `"Jane18"`; +exports[`internet > 42 > userName > with firstName option 1`] = `"Jane73"`; exports[`internet > 42 > userName > with lastName option 1`] = `"Garnet_Doe"`; @@ -186,7 +186,7 @@ exports[`internet > 1211 > email > with all options 1`] = `"Jane.Doe@fakerjs.dev exports[`internet > 1211 > email > with allowSpecialCharacters option 1`] = `"Tito^Satterfield99@yahoo.com"`; -exports[`internet > 1211 > email > with firstName option 1`] = `"Jane22@hotmail.com"`; +exports[`internet > 1211 > email > with firstName option 1`] = `"Jane12@hotmail.com"`; exports[`internet > 1211 > email > with lastName option 1`] = `"Tito_Doe@yahoo.com"`; @@ -194,9 +194,9 @@ exports[`internet > 1211 > email > with legacy names 1`] = `"Jane_Doe77@hotmail. exports[`internet > 1211 > email > with legacy names and provider 1`] = `"Jane.Doe@fakerjs.dev"`; -exports[`internet > 1211 > email > with legacy provider 1`] = `"Tito22@fakerjs.dev"`; +exports[`internet > 1211 > email > with legacy provider 1`] = `"Tito12@fakerjs.dev"`; -exports[`internet > 1211 > email > with provider option 1`] = `"Tito22@fakerjs.dev"`; +exports[`internet > 1211 > email > with provider option 1`] = `"Tito12@fakerjs.dev"`; exports[`internet > 1211 > emoji > noArgs 1`] = `"🇮🇸"`; @@ -208,7 +208,7 @@ exports[`internet > 1211 > exampleEmail > with all options 1`] = `"Jane_Doe77@ex exports[`internet > 1211 > exampleEmail > with allowSpecialCharacters option 1`] = `"Tito^Satterfield99@example.com"`; -exports[`internet > 1211 > exampleEmail > with firstName option 1`] = `"Jane22@example.net"`; +exports[`internet > 1211 > exampleEmail > with firstName option 1`] = `"Jane12@example.net"`; exports[`internet > 1211 > exampleEmail > with lastName option 1`] = `"Tito_Doe@example.com"`; @@ -266,7 +266,7 @@ exports[`internet > 1211 > url > without slash appended and with http protocol 1 exports[`internet > 1211 > userAgent 1`] = `"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.3; Trident/4.0)"`; -exports[`internet > 1211 > userName > noArgs 1`] = `"Tito22"`; +exports[`internet > 1211 > userName > noArgs 1`] = `"Tito12"`; exports[`internet > 1211 > userName > with Chinese names 1`] = `"hlzp8d.tpv"`; @@ -278,7 +278,7 @@ exports[`internet > 1211 > userName > with accented names 1`] = `"Helene.Muller" exports[`internet > 1211 > userName > with all option 1`] = `"Jane.Doe"`; -exports[`internet > 1211 > userName > with firstName option 1`] = `"Jane77"`; +exports[`internet > 1211 > userName > with firstName option 1`] = `"Jane22"`; exports[`internet > 1211 > userName > with lastName option 1`] = `"Tito_Doe77"`; From f0de1f1decb0a22adb8cd040f36502bce7161b1d Mon Sep 17 00:00:00 2001 From: Austin Millwood Date: Tue, 7 Nov 2023 12:21:48 -0500 Subject: [PATCH 4/5] internet: updated unit tests --- test/modules/internet.spec.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/test/modules/internet.spec.ts b/test/modules/internet.spec.ts index 875012ff225..2a277a82dfc 100644 --- a/test/modules/internet.spec.ts +++ b/test/modules/internet.spec.ts @@ -348,7 +348,7 @@ describe('internet', () => { expect(suffix).toMatch(/^example\.(com|net|org)$/); expect(faker.definitions.internet.example_email).toContain(suffix); - expect(prefix).toMatch(/^Aiden([._]Harann)?\d*/); + expect(prefix).toMatch(/^Aiden[._]Harann\d*/); }); it('should return an email with special characters', () => { @@ -366,7 +366,7 @@ describe('internet', () => { expect(suffix).toMatch(/^example\.(com|net|org)$/); expect(faker.definitions.internet.example_email).toContain(suffix); - expect(prefix).toMatch(/^Mike([.!#$%&'*+-/=?^_`{|}~]Smith)?\d*/); + expect(prefix).toMatch(/^Mike[.!#$%&'*+-/=?^_`{|}~]Smith\d*/); }); }); @@ -397,9 +397,7 @@ describe('internet', () => { expect(username).toBeTruthy(); expect(username).toBeTypeOf('string'); expect(username).includes('Aiden'); - expect(username).toMatch( - /^Aiden((\d{1,2})|([._]Harann\d{1,2})|([._](Harann)))/ - ); + expect(username).toMatch(/^Aiden[._]Harann\d*/); }); it('should strip accents', () => { From b19be75dcf96d849fbaf3ce571ecf8c8c2862ab7 Mon Sep 17 00:00:00 2001 From: Austin Millwood Date: Thu, 9 Nov 2023 13:25:48 -0500 Subject: [PATCH 5/5] internet: cleaned up logic, improved unit tests --- src/modules/internet/index.ts | 6 ++-- .../__snapshots__/internet.spec.ts.snap | 36 +++++++++---------- test/modules/internet.spec.ts | 14 ++++---- 3 files changed, 29 insertions(+), 27 deletions(-) diff --git a/src/modules/internet/index.ts b/src/modules/internet/index.ts index 4cbbd29ad6d..63fbf078bc0 100644 --- a/src/modules/internet/index.ts +++ b/src/modules/internet/index.ts @@ -254,7 +254,7 @@ export class InternetModule extends ModuleBase { } const { - firstName = this.faker.person.firstName(), + firstName, lastName = legacyLastName, provider = legacyProvider ?? this.faker.helpers.arrayElement( @@ -466,7 +466,7 @@ export class InternetModule extends ModuleBase { } const { - firstName = this.faker.person.firstName(), + firstName, lastName = legacyLastName, allowSpecialCharacters = legacyOptions?.allowSpecialCharacters ?? false, } = options; @@ -626,10 +626,10 @@ export class InternetModule extends ModuleBase { const { firstName = this.faker.person.firstName(), lastName = legacyLastName ?? this.faker.person.lastName(), + lastName: hasLastName = legacyLastName, } = options; let result: string; - const hasLastName = options.lastName || legacyLastName; const strategy = this.faker.number.int(hasLastName ? 1 : 2); const separator = this.faker.helpers.arrayElement(['.', '_']); switch (strategy) { diff --git a/test/modules/__snapshots__/internet.spec.ts.snap b/test/modules/__snapshots__/internet.spec.ts.snap index fde6e445a45..488dd6a873b 100644 --- a/test/modules/__snapshots__/internet.spec.ts.snap +++ b/test/modules/__snapshots__/internet.spec.ts.snap @@ -38,15 +38,15 @@ exports[`internet > 42 > domainSuffix 1`] = `"info"`; exports[`internet > 42 > domainWord 1`] = `"hasty-sherbet"`; -exports[`internet > 42 > email > noArgs 1`] = `"Garnet59@hotmail.com"`; +exports[`internet > 42 > email > noArgs 1`] = `"Peyton59@yahoo.com"`; exports[`internet > 42 > email > with all options 1`] = `"Jane_Doe95@fakerjs.dev"`; -exports[`internet > 42 > email > with allowSpecialCharacters option 1`] = `"Garnet59@hotmail.com"`; +exports[`internet > 42 > email > with allowSpecialCharacters option 1`] = `"Peyton59@yahoo.com"`; exports[`internet > 42 > email > with firstName option 1`] = `"Jane_Wiegand77@yahoo.com"`; -exports[`internet > 42 > email > with lastName option 1`] = `"Garnet.Doe@hotmail.com"`; +exports[`internet > 42 > email > with lastName option 1`] = `"Peyton.Doe@yahoo.com"`; exports[`internet > 42 > email > with legacy names 1`] = `"Jane_Doe@yahoo.com"`; @@ -60,15 +60,15 @@ exports[`internet > 42 > emoji > noArgs 1`] = `"🕸️"`; exports[`internet > 42 > emoji > with options 1`] = `"🦔"`; -exports[`internet > 42 > exampleEmail > noArgs 1`] = `"Garnet59@example.net"`; +exports[`internet > 42 > exampleEmail > noArgs 1`] = `"Peyton59@example.com"`; exports[`internet > 42 > exampleEmail > with all options 1`] = `"Jane_Doe@example.com"`; -exports[`internet > 42 > exampleEmail > with allowSpecialCharacters option 1`] = `"Garnet59@example.net"`; +exports[`internet > 42 > exampleEmail > with allowSpecialCharacters option 1`] = `"Peyton59@example.com"`; exports[`internet > 42 > exampleEmail > with firstName option 1`] = `"Jane_Wiegand77@example.com"`; -exports[`internet > 42 > exampleEmail > with lastName option 1`] = `"Garnet.Doe@example.net"`; +exports[`internet > 42 > exampleEmail > with lastName option 1`] = `"Peyton.Doe@example.com"`; exports[`internet > 42 > exampleEmail > with legacy names 1`] = `"Jane_Doe@example.com"`; @@ -180,15 +180,15 @@ exports[`internet > 1211 > domainSuffix 1`] = `"org"`; exports[`internet > 1211 > domainWord 1`] = `"vicious-infrastructure"`; -exports[`internet > 1211 > email > noArgs 1`] = `"Tito.Satterfield99@yahoo.com"`; +exports[`internet > 1211 > email > noArgs 1`] = `"Jadyn.Satterfield99@hotmail.com"`; exports[`internet > 1211 > email > with all options 1`] = `"Jane.Doe@fakerjs.dev"`; -exports[`internet > 1211 > email > with allowSpecialCharacters option 1`] = `"Tito^Satterfield99@yahoo.com"`; +exports[`internet > 1211 > email > with allowSpecialCharacters option 1`] = `"Jadyn^Satterfield99@hotmail.com"`; exports[`internet > 1211 > email > with firstName option 1`] = `"Jane12@hotmail.com"`; -exports[`internet > 1211 > email > with lastName option 1`] = `"Tito_Doe@yahoo.com"`; +exports[`internet > 1211 > email > with lastName option 1`] = `"Jadyn_Doe@hotmail.com"`; exports[`internet > 1211 > email > with legacy names 1`] = `"Jane_Doe77@hotmail.com"`; @@ -202,15 +202,15 @@ exports[`internet > 1211 > emoji > noArgs 1`] = `"🇮🇸"`; exports[`internet > 1211 > emoji > with options 1`] = `"🌲"`; -exports[`internet > 1211 > exampleEmail > noArgs 1`] = `"Tito.Satterfield99@example.com"`; +exports[`internet > 1211 > exampleEmail > noArgs 1`] = `"Jadyn.Satterfield99@example.net"`; exports[`internet > 1211 > exampleEmail > with all options 1`] = `"Jane_Doe77@example.net"`; -exports[`internet > 1211 > exampleEmail > with allowSpecialCharacters option 1`] = `"Tito^Satterfield99@example.com"`; +exports[`internet > 1211 > exampleEmail > with allowSpecialCharacters option 1`] = `"Jadyn^Satterfield99@example.net"`; exports[`internet > 1211 > exampleEmail > with firstName option 1`] = `"Jane12@example.net"`; -exports[`internet > 1211 > exampleEmail > with lastName option 1`] = `"Tito_Doe@example.com"`; +exports[`internet > 1211 > exampleEmail > with lastName option 1`] = `"Jadyn_Doe@example.net"`; exports[`internet > 1211 > exampleEmail > with legacy names 1`] = `"Jane_Doe77@example.net"`; @@ -322,15 +322,15 @@ exports[`internet > 1337 > domainSuffix 1`] = `"biz"`; exports[`internet > 1337 > domainWord 1`] = `"fair-mile"`; -exports[`internet > 1337 > email > noArgs 1`] = `"Devyn_Effertz45@yahoo.com"`; +exports[`internet > 1337 > email > noArgs 1`] = `"Kellen_Effertz45@gmail.com"`; exports[`internet > 1337 > email > with all options 1`] = `"Jane_Doe15@fakerjs.dev"`; -exports[`internet > 1337 > email > with allowSpecialCharacters option 1`] = `"Devyn_Effertz45@yahoo.com"`; +exports[`internet > 1337 > email > with allowSpecialCharacters option 1`] = `"Kellen_Effertz45@gmail.com"`; exports[`internet > 1337 > email > with firstName option 1`] = `"Jane.Cronin54@gmail.com"`; -exports[`internet > 1337 > email > with lastName option 1`] = `"Devyn.Doe27@yahoo.com"`; +exports[`internet > 1337 > email > with lastName option 1`] = `"Kellen.Doe27@gmail.com"`; exports[`internet > 1337 > email > with legacy names 1`] = `"Jane.Doe@gmail.com"`; @@ -344,15 +344,15 @@ exports[`internet > 1337 > emoji > noArgs 1`] = `"💇🏼‍♀️"`; exports[`internet > 1337 > emoji > with options 1`] = `"🐪"`; -exports[`internet > 1337 > exampleEmail > noArgs 1`] = `"Devyn_Effertz45@example.com"`; +exports[`internet > 1337 > exampleEmail > noArgs 1`] = `"Kellen_Effertz45@example.org"`; exports[`internet > 1337 > exampleEmail > with all options 1`] = `"Jane&Doe@example.org"`; -exports[`internet > 1337 > exampleEmail > with allowSpecialCharacters option 1`] = `"Devyn_Effertz45@example.com"`; +exports[`internet > 1337 > exampleEmail > with allowSpecialCharacters option 1`] = `"Kellen_Effertz45@example.org"`; exports[`internet > 1337 > exampleEmail > with firstName option 1`] = `"Jane.Cronin54@example.org"`; -exports[`internet > 1337 > exampleEmail > with lastName option 1`] = `"Devyn.Doe27@example.com"`; +exports[`internet > 1337 > exampleEmail > with lastName option 1`] = `"Kellen.Doe27@example.org"`; exports[`internet > 1337 > exampleEmail > with legacy names 1`] = `"Jane.Doe@example.org"`; diff --git a/test/modules/internet.spec.ts b/test/modules/internet.spec.ts index 2a277a82dfc..be9aa02588e 100644 --- a/test/modules/internet.spec.ts +++ b/test/modules/internet.spec.ts @@ -253,9 +253,7 @@ describe('internet', () => { expect(prefix).includes('Aiden'); expect(prefix).includes('Harann'); - expect(prefix).toMatch( - /^Aiden((\d{1,2})|([._]Harann\d{1,2})|([._](Harann)))/ - ); + expect(prefix).toMatch(/^Aiden[._]Harann\d*/); expect(faker.definitions.internet.free_email).toContain(suffix); }); @@ -297,9 +295,7 @@ describe('internet', () => { const [prefix, suffix] = email.split('@'); - expect(prefix).toMatch( - /^Mike((\d{1,2})|([.!#$%&'*+-/=?^_`{|}~]Smith\d{1,2})|([.!#$%&'*+-/=?^_`{|}~]Smith))/ - ); + expect(prefix).toMatch(/^Mike[.!#$%&'*+-/=?^_`{|}~]Smith\d*/); expect(faker.definitions.internet.free_email).toContain(suffix); }); }); @@ -345,6 +341,8 @@ describe('internet', () => { expect(email).toSatisfy(validator.isEmail); const [prefix, suffix] = email.split('@'); + expect(email).includes('Aiden'); + expect(email).includes('Harann'); expect(suffix).toMatch(/^example\.(com|net|org)$/); expect(faker.definitions.internet.example_email).toContain(suffix); @@ -366,6 +364,8 @@ describe('internet', () => { expect(suffix).toMatch(/^example\.(com|net|org)$/); expect(faker.definitions.internet.example_email).toContain(suffix); + expect(prefix).includes('Mike'); + expect(prefix).includes('Smith'); expect(prefix).toMatch(/^Mike[.!#$%&'*+-/=?^_`{|}~]Smith\d*/); }); }); @@ -397,6 +397,7 @@ describe('internet', () => { expect(username).toBeTruthy(); expect(username).toBeTypeOf('string'); expect(username).includes('Aiden'); + expect(username).includes('Harann'); expect(username).toMatch(/^Aiden[._]Harann\d*/); }); @@ -406,6 +407,7 @@ describe('internet', () => { lastName: 'Smith', }); expect(username).includes('Adele'); + expect(username).includes('Smith'); }); it('should transliterate Cyrillic', () => {