From 1ae2f6f489bcf7b317202877af3419ecc01bc1d0 Mon Sep 17 00:00:00 2001 From: Matt Mayer Date: Thu, 2 Feb 2023 19:56:31 +0700 Subject: fix(person): change fullName to use name patterns (#1637) --- src/modules/person/index.ts | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) (limited to 'src/modules') 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; } /** -- cgit v1.2.3