Skip to content

fix(#113): Adds regex to random.word to trim unwanted characters #218

New issue

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

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

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/random.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,15 @@ export class Random {
'name.jobArea',
'name.jobType',
];
// regex statement used to remove unwanted characters from beginning/end of words
const wordSanitizerRegex = /^[\s()\[\]{}.,\-'"]+|[\s()\[\]{}.,\-'"]+$/g;

// randomly pick from the many faker methods that can generate words
const randomWordMethod = this.faker.random.arrayElement(wordMethods);
const result = this.faker.fake('{{' + randomWordMethod + '}}');
return this.faker.random.arrayElement(result.split(' '));

// sanitize and return word
return this.faker.random.arrayElement(result.split(' ')).replace(wordSanitizerRegex, "");
}

readonly randomWord: Random['word'] = this.word.bind(this);
Expand Down