aboutsummaryrefslogtreecommitdiff
path: root/src/modules/random
diff options
context:
space:
mode:
authorST-DDT <[email protected]>2022-12-07 20:18:08 +0100
committerGitHub <[email protected]>2022-12-07 20:18:08 +0100
commitf06126a1ba8515d6e0b7733999d5cd2f8849be7a (patch)
tree56dadba70a0c2d78bd7ef6a6e255796cce38ea8b /src/modules/random
parent50fb72ce3d7a911564ad5ff9f929ca5567a83757 (diff)
downloadfaker-f06126a1ba8515d6e0b7733999d5cd2f8849be7a.tar.xz
faker-f06126a1ba8515d6e0b7733999d5cd2f8849be7a.zip
feat(helpers): introduce `multiple` method (#1545)
Diffstat (limited to 'src/modules/random')
-rw-r--r--src/modules/random/index.ts23
1 files changed, 9 insertions, 14 deletions
diff --git a/src/modules/random/index.ts b/src/modules/random/index.ts
index f8691198..1f4b499b 100644
--- a/src/modules/random/index.ts
+++ b/src/modules/random/index.ts
@@ -137,28 +137,23 @@ export class RandomModule {
}
/**
- * Returns string with set of random words.
+ * Returns a string with a given number of random words.
*
- * @param count Number of words. Defaults to a random value between `1` and `3`.
+ * @param count The number or range of words. Defaults to a random value between `1` and `3`.
+ * @param count.min The minimum number of words. Defaults to `1`.
+ * @param count.max The maximum number of words. Defaults to `3`.
*
* @example
* faker.random.words() // 'neural'
* faker.random.words(5) // 'copy Handcrafted bus client-server Point'
+ * faker.random.words({ min: 3, max: 5 }) // 'cool sticky Borders'
*
* @since 3.1.0
*/
- words(count?: number): string {
- const words: string[] = [];
-
- if (count == null) {
- count = this.faker.number.int({ min: 1, max: 3 });
- }
-
- for (let i = 0; i < count; i++) {
- words.push(this.word());
- }
-
- return words.join(' ');
+ words(
+ count: number | { min: number; max: number } = { min: 1, max: 3 }
+ ): string {
+ return this.faker.helpers.multiple(this.word, { count }).join(' ');
}
/**