diff options
| author | Matt Mayer <[email protected]> | 2023-02-02 19:56:31 +0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-02-02 13:56:31 +0100 |
| commit | 1ae2f6f489bcf7b317202877af3419ecc01bc1d0 (patch) | |
| tree | c6060b154328834ded18c3adf47d988a60e00755 /src/modules | |
| parent | 9c3618d66550b7a72cade402b035ecdbcb485625 (diff) | |
| download | faker-1ae2f6f489bcf7b317202877af3419ecc01bc1d0.tar.xz faker-1ae2f6f489bcf7b317202877af3419ecc01bc1d0.zip | |
fix(person): change fullName to use name patterns (#1637)
Diffstat (limited to 'src/modules')
| -rw-r--r-- | src/modules/person/index.ts | 29 |
1 files changed, 10 insertions, 19 deletions
diff --git a/src/modules/person/index.ts b/src/modules/person/index.ts index 03609cbc..da30fee7 100644 --- a/src/modules/person/index.ts +++ b/src/modules/person/index.ts @@ -187,27 +187,18 @@ export class PersonModule { lastName = this.lastName(sex), } = options; - const nameParts: string[] = []; - const prefix = this.faker.helpers.maybe(() => this.prefix(sex), { - probability: 0.125, - }); - - if (prefix) { - nameParts.push(prefix); - } - - nameParts.push(firstName); - nameParts.push(lastName); + const fullNamePattern: string = this.faker.helpers.weightedArrayElement( + this.faker.definitions.person.name + ); - const suffix = this.faker.helpers.maybe(() => this.suffix(), { - probability: 0.125, + const fullName = this.faker.helpers.mustache(fullNamePattern, { + 'person.prefix': () => this.prefix(sex), + 'person.firstName': () => firstName, + 'person.middleName': () => this.middleName(sex), + 'person.lastName': () => lastName, + 'person.suffix': () => this.suffix(), }); - - if (suffix) { - nameParts.push(suffix); - } - - return nameParts.join(' '); + return fullName; } /** |
