aboutsummaryrefslogtreecommitdiff
path: root/src/modules/system
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/system
parent7cbeda6eeab94eef6e8f56f9e31cc57c4072f3b2 (diff)
downloadfaker-9cd716e891d3bb8d9a8f9d43899d0dcd161e1832.tar.xz
faker-9cd716e891d3bb8d9a8f9d43899d0dcd161e1832.zip
feat(helpers): add rangeToNumber method and add range parameters (#1486)
Diffstat (limited to 'src/modules/system')
-rw-r--r--src/modules/system/index.ts11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/modules/system/index.ts b/src/modules/system/index.ts
index 8c935c88..12bb25ba 100644
--- a/src/modules/system/index.ts
+++ b/src/modules/system/index.ts
@@ -50,23 +50,26 @@ export class SystemModule {
* Returns a random file name with extension.
*
* @param options An options object.
- * @param options.extensionCount Define how many extensions the file name should have. A negative number will be treated as `0`. Defaults to `1`.
+ * @param options.extensionCount Define how many extensions the file name should have. Defaults to `1`.
*
* @example
* faker.system.fileName() // 'faithfully_calculating.u8mdn'
* faker.system.fileName({ extensionCount: 2 }) // 'times_after.swf.ntf'
+ * faker.system.fileName({ extensionCount: { min: 1, max: 2 } }) // 'jaywalk_like_ill.osfpvg'
*
* @since 3.1.0
*/
fileName(
options: {
/**
- * Define how many extensions the file name should have. A negative number will be treated as `0`. Defaults to `1`.
+ * Define how many extensions the file name should have. Defaults to `1`.
*/
- extensionCount?: number;
+ extensionCount?: number | { min: number; max: number };
} = {}
): string {
- const { extensionCount = 1 } = options;
+ const extensionCount = this.faker.helpers.rangeToNumber(
+ options.extensionCount ?? 1
+ );
const baseName = this.faker.word.words().toLowerCase().replace(/\W/g, '_');