Skip to content

fix: change random.word to be based on definitions.word.* #276

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
wants to merge 12 commits into from
54 changes: 11 additions & 43 deletions src/random.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,53 +159,21 @@ export class Random {
return this.faker.datatype.boolean();
}

// TODO: have ability to return specific type of word? As in: noun, adjective, verb, etc
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The question is if we want to have this feature too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have. Users can use faker.word.xyz to do it... That's why I removed this comment.

/**
* word
*
* @method faker.random.word
* @param type
* Returns random word.
*/
// TODO @Shinigami92 2022-01-11: `type` is not in use
word(type?: unknown): string {
const wordMethods = [
'commerce.department',
'commerce.productName',
'commerce.productAdjective',
'commerce.productMaterial',
'commerce.product',
'commerce.color',

'company.catchPhraseAdjective',
'company.catchPhraseDescriptor',
'company.catchPhraseNoun',
'company.bsAdjective',
'company.bsBuzz',
'company.bsNoun',
'address.streetSuffix',
'address.county',
'address.country',
'address.state',

'finance.accountName',
'finance.transactionType',
'finance.currencyName',

'hacker.noun',
'hacker.verb',
'hacker.adjective',
'hacker.ingverb',
'hacker.abbreviation',

'name.jobDescriptor',
'name.jobArea',
'name.jobType',
word(): string {
const generators = [
this.faker.word.adjective,
this.faker.word.adverb,
this.faker.word.conjunction,
this.faker.word.interjection,
this.faker.word.noun,
this.faker.word.preposition,
this.faker.word.verb,
];

// 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(' '));
return this.faker.random.arrayElement(generators)();
}

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