diff options
| author | ST-DDT <[email protected]> | 2022-11-21 17:55:32 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-11-21 17:55:32 +0100 |
| commit | 9cd716e891d3bb8d9a8f9d43899d0dcd161e1832 (patch) | |
| tree | b8e24d4d9d9c6372e3b687e64600de0f825a33bc /src/modules/system | |
| parent | 7cbeda6eeab94eef6e8f56f9e31cc57c4072f3b2 (diff) | |
| download | faker-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.ts | 11 |
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, '_'); |
