aboutsummaryrefslogtreecommitdiff
path: root/src/modules/word
diff options
context:
space:
mode:
authorST-DDT <[email protected]>2022-11-21 17:55:32 +0100
committerGitHub <[email protected]>2022-11-21 17:55:32 +0100
commit9cd716e891d3bb8d9a8f9d43899d0dcd161e1832 (patch)
treeb8e24d4d9d9c6372e3b687e64600de0f825a33bc /src/modules/word
parent7cbeda6eeab94eef6e8f56f9e31cc57c4072f3b2 (diff)
downloadfaker-9cd716e891d3bb8d9a8f9d43899d0dcd161e1832.tar.xz
faker-9cd716e891d3bb8d9a8f9d43899d0dcd161e1832.zip
feat(helpers): add rangeToNumber method and add range parameters (#1486)
Diffstat (limited to 'src/modules/word')
-rw-r--r--src/modules/word/index.ts16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/modules/word/index.ts b/src/modules/word/index.ts
index 89795919..d326cd70 100644
--- a/src/modules/word/index.ts
+++ b/src/modules/word/index.ts
@@ -375,18 +375,26 @@ export class WordModule {
/**
* Returns a string containing a number of space separated random words.
*
- * @param count Number of words. Defaults to a random value between `1` and `3`.
+ * @param options The optional options object or the number of words to return.
+ * @param options.count The number of words to return. Defaults to a random value between `1` and `3`.
*
* @example
* faker.word.words() // 'almost'
* faker.word.words(5) // 'before hourly patiently dribble equal'
+ * faker.word.words({ count: 5 }) // 'whoever edible um kissingly faraway'
+ * faker.word.words({ count: { min: 5, max: 10 } }) // 'vice buoyant through apropos poised total wary boohoo'
*
* @since 8.0.0
*/
- words(count?: number): string {
- if (count == null) {
- count = this.faker.datatype.number({ min: 1, max: 3 });
+ words(
+ options: number | { count?: number | { min: number; max: number } } = {}
+ ): string {
+ if (typeof options === 'number') {
+ options = { count: options };
}
+ const count = this.faker.helpers.rangeToNumber(
+ options.count ?? { min: 1, max: 3 }
+ );
return Array.from({ length: count }, () => this.sample()).join(' ');
}