diff options
| author | ST-DDT <[email protected]> | 2022-12-07 20:18:08 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-12-07 20:18:08 +0100 |
| commit | f06126a1ba8515d6e0b7733999d5cd2f8849be7a (patch) | |
| tree | 56dadba70a0c2d78bd7ef6a6e255796cce38ea8b /src/modules/lorem | |
| parent | 50fb72ce3d7a911564ad5ff9f929ca5567a83757 (diff) | |
| download | faker-f06126a1ba8515d6e0b7733999d5cd2f8849be7a.tar.xz faker-f06126a1ba8515d6e0b7733999d5cd2f8849be7a.zip | |
feat(helpers): introduce `multiple` method (#1545)
Diffstat (limited to 'src/modules/lorem')
| -rw-r--r-- | src/modules/lorem/index.ts | 20 |
1 files changed, 6 insertions, 14 deletions
diff --git a/src/modules/lorem/index.ts b/src/modules/lorem/index.ts index c73a92c8..8e989ab6 100644 --- a/src/modules/lorem/index.ts +++ b/src/modules/lorem/index.ts @@ -72,10 +72,8 @@ export class LoremModule { * @since 2.0.1 */ words(wordCount: number | { min: number; max: number } = 3): string { - wordCount = this.faker.helpers.rangeToNumber(wordCount); - - return Array.from({ length: wordCount }) - .map(() => this.word()) + return this.faker.helpers + .multiple(() => this.word(), { count: wordCount }) .join(' '); } @@ -141,10 +139,8 @@ export class LoremModule { sentenceCount: number | { min: number; max: number } = { min: 2, max: 6 }, separator: string = ' ' ): string { - sentenceCount = this.faker.helpers.rangeToNumber(sentenceCount); - - return Array.from({ length: sentenceCount }) - .map(() => this.sentence()) + return this.faker.helpers + .multiple(() => this.sentence(), { count: sentenceCount }) .join(separator); } @@ -202,10 +198,8 @@ export class LoremModule { paragraphCount: number | { min: number; max: number } = 3, separator: string = '\n' ): string { - paragraphCount = this.faker.helpers.rangeToNumber(paragraphCount); - - return Array.from({ length: paragraphCount }) - .map(() => this.paragraph()) + return this.faker.helpers + .multiple(() => this.paragraph(), { count: paragraphCount }) .join(separator); } @@ -267,8 +261,6 @@ export class LoremModule { lines( lineCount: number | { min: number; max: number } = { min: 1, max: 5 } ): string { - lineCount = this.faker.helpers.rangeToNumber(lineCount); - return this.sentences(lineCount, '\n'); } } |
