aboutsummaryrefslogtreecommitdiff
path: root/src/modules/system
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/system
parent50fb72ce3d7a911564ad5ff9f929ca5567a83757 (diff)
downloadfaker-f06126a1ba8515d6e0b7733999d5cd2f8849be7a.tar.xz
faker-f06126a1ba8515d6e0b7733999d5cd2f8849be7a.zip
feat(helpers): introduce `multiple` method (#1545)
Diffstat (limited to 'src/modules/system')
-rw-r--r--src/modules/system/index.ts14
1 files changed, 6 insertions, 8 deletions
diff --git a/src/modules/system/index.ts b/src/modules/system/index.ts
index 4bf28aff..ca78929e 100644
--- a/src/modules/system/index.ts
+++ b/src/modules/system/index.ts
@@ -67,20 +67,18 @@ export class SystemModule {
extensionCount?: number | { min: number; max: number };
} = {}
): string {
- const extensionCount = this.faker.helpers.rangeToNumber(
- options.extensionCount ?? 1
- );
+ const { extensionCount = 1 } = options;
const baseName = this.faker.word.words().toLowerCase().replace(/\W/g, '_');
- if (extensionCount <= 0) {
+ const extensionsStr = this.faker.helpers
+ .multiple(() => this.fileExt(), { count: extensionCount })
+ .join('.');
+
+ if (extensionsStr.length === 0) {
return baseName;
}
- const extensionsStr = Array.from({ length: extensionCount })
- .map(() => this.fileExt())
- .join('.');
-
return `${baseName}.${extensionsStr}`;
}