diff options
| author | DivisionByZero <[email protected]> | 2023-02-04 22:13:20 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-02-04 21:13:20 +0000 |
| commit | 1b9ca0192095b69022b0a4ddc0d73db1e2c3fe17 (patch) | |
| tree | db55989ecbb9ca85dd14eceb1402a4cd300c5e20 /src/modules | |
| parent | 667599d8fb59c31166b897799f30788edc5f54d7 (diff) | |
| download | faker-1b9ca0192095b69022b0a4ddc0d73db1e2c3fe17.tar.xz faker-1b9ca0192095b69022b0a4ddc0d73db1e2c3fe17.zip | |
refactor(datatype): standardize arguments (#1804)
Diffstat (limited to 'src/modules')
| -rw-r--r-- | src/modules/datatype/index.ts | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/src/modules/datatype/index.ts b/src/modules/datatype/index.ts index 9a89ba24..25235bb5 100644 --- a/src/modules/datatype/index.ts +++ b/src/modules/datatype/index.ts @@ -206,25 +206,44 @@ export class DatatypeModule { /** * Returns a string containing UTF-16 chars between 33 and 125 (`!` to `}`). * - * @param length Length of the generated string. Max length is `2^20`. Defaults to `10`. + * @param options Length of the generated string or an options object. Defaults to `{}`. + * @param options.length Length of the generated string. Max length is `2^20`. Defaults to `10`. * * @see faker.string.sample() * * @example * faker.datatype.string() // 'Zo!.:*e>wR' * faker.datatype.string(5) // '6Bye8' + * faker.datatype.string({ length: 7 }) // 'dzOT00e' * * @since 5.5.0 * * @deprecated Use faker.string.sample() instead. */ - string(length = 10): string { + string( + options: + | number + | { + /** + * Length of the generated string. Max length is `2^20`. + * + * @default 10 + */ + length?: number; + } = {} + ): string { deprecated({ deprecated: 'faker.datatype.string()', proposed: 'faker.string.sample()', since: '8.0', until: '9.0', }); + if (typeof options === 'number') { + options = { length: options }; + } + + const { length = 10 } = options; + return this.faker.string.sample(length); } |
