aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/random.ts34
1 files changed, 30 insertions, 4 deletions
diff --git a/src/random.ts b/src/random.ts
index b84a2ece..0658cdd5 100644
--- a/src/random.ts
+++ b/src/random.ts
@@ -242,7 +242,6 @@ export class Random {
* @example
* faker.random.word() // 'Seamless'
*/
- // TODO: have ability to return specific type of word? As in: noun, adjective, verb, etc
word(): string {
const wordMethods = [
'commerce.department',
@@ -278,9 +277,36 @@ export class Random {
'name.jobType',
];
- // randomly pick from the many faker methods that can generate words
- const randomWordMethod = this.faker.random.arrayElement(wordMethods);
- const result = this.faker.fake('{{' + randomWordMethod + '}}');
+ const bannedChars = [
+ '!',
+ '#',
+ '%',
+ '&',
+ '*',
+ ')',
+ '(',
+ '+',
+ '=',
+ '.',
+ '<',
+ '>',
+ '{',
+ '}',
+ '[',
+ ']',
+ ':',
+ ';',
+ "'",
+ '"',
+ '_',
+ '-',
+ ];
+ let result: string;
+ do {
+ // randomly pick from the many faker methods that can generate words
+ const randomWordMethod = this.faker.random.arrayElement(wordMethods);
+ result = this.faker.fake('{{' + randomWordMethod + '}}');
+ } while (bannedChars.some((char) => result.includes(char)));
return this.faker.random.arrayElement(result.split(' '));
}