diff options
| author | Eric Cheng <[email protected]> | 2022-12-06 18:13:51 -0500 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-12-07 00:13:51 +0100 |
| commit | c4b7ce8648cbd5ac2b224942908bccf9914e08f9 (patch) | |
| tree | 82c0d99fe5c45cedb542ac05aaad3f2e8921df83 /src | |
| parent | 6bac476695c146a794b5337785979a7395d7dc89 (diff) | |
| download | faker-c4b7ce8648cbd5ac2b224942908bccf9914e08f9.tar.xz faker-c4b7ce8648cbd5ac2b224942908bccf9914e08f9.zip | |
refactor(string)!: swap `allowLeadingZeros` default to `true` (#1602)
Diffstat (limited to 'src')
| -rw-r--r-- | src/modules/helpers/index.ts | 2 | ||||
| -rw-r--r-- | src/modules/number/index.ts | 2 | ||||
| -rw-r--r-- | src/modules/random/index.ts | 4 | ||||
| -rw-r--r-- | src/modules/string/index.ts | 10 |
4 files changed, 11 insertions, 7 deletions
diff --git a/src/modules/helpers/index.ts b/src/modules/helpers/index.ts index 7f2c5898..af6ae4b8 100644 --- a/src/modules/helpers/index.ts +++ b/src/modules/helpers/index.ts @@ -539,7 +539,7 @@ export class HelpersModule { * faker.helpers.fake('Good Morning {{person.firstName}}!') // 'Good Morning Estelle!' * faker.helpers.fake('You can call me at {{phone.number(!## ### #####!)}}.') // 'You can call me at 202 555 973722.' * faker.helpers.fake('I flipped the coin and got: {{helpers.arrayElement(["heads", "tails"])}}') // 'I flipped the coin and got: tails' - * faker.helpers.fake('I rolled the dice and got: {{string.numeric(1, {"allowLeadingZeros": true})}}') // 'I rolled the dice and got: 6' + * faker.helpers.fake('Your PIN number is: {{string.numeric(4, {"exclude": ["0"]})}}') // 'Your PIN number is: 4834' * * @since 7.4.0 */ diff --git a/src/modules/number/index.ts b/src/modules/number/index.ts index c30d5015..1f46cb64 100644 --- a/src/modules/number/index.ts +++ b/src/modules/number/index.ts @@ -26,6 +26,8 @@ export class NumberModule { * * @throws When options define `max < min`. * + * @see faker.string.numeric() If you would like to generate a `string` of digits with a given length (range). + * * @example * faker.number.int() // 55422 * faker.number.int(100) // 52 diff --git a/src/modules/random/index.ts b/src/modules/random/index.ts index 21e46509..f8691198 100644 --- a/src/modules/random/index.ts +++ b/src/modules/random/index.ts @@ -262,7 +262,7 @@ export class RandomModule { * * @param length The number of digits to generate. Defaults to `1`. * @param options The options to use. Defaults to `{}`. - * @param options.allowLeadingZeros If true, leading zeros will be allowed. Defaults to `false`. + * @param options.allowLeadingZeros Whether leading zeros are allowed or not. Defaults to `true`. * @param options.bannedDigits An array of digits which should be banned in the generated string. Defaults to `[]`. * * @see faker.string.numeric() @@ -270,7 +270,7 @@ export class RandomModule { * @example * faker.random.numeric() // '2' * faker.random.numeric(5) // '31507' - * faker.random.numeric(42) // '56434563150765416546479875435481513188548' + * faker.random.numeric(42) // '00434563150765416546479875435481513188548' * faker.random.numeric(42, { allowLeadingZeros: true }) // '00564846278453876543517840713421451546115' * faker.random.numeric(6, { bannedDigits: ['0'] }) // '943228' * diff --git a/src/modules/string/index.ts b/src/modules/string/index.ts index de1ec446..827c1f45 100644 --- a/src/modules/string/index.ts +++ b/src/modules/string/index.ts @@ -317,15 +317,17 @@ export class StringModule { * * @param options Either the number of characters or the options to use. * @param options.length The number or range of digits to generate. Defaults to `1`. - * @param options.allowLeadingZeros If true, leading zeros will be allowed. Defaults to `false`. + * @param options.allowLeadingZeros Whether leading zeros are allowed or not. Defaults to `true`. * @param options.exclude An array of digits which should be excluded in the generated string. Defaults to `[]`. * + * @see faker.number.int() If you would like to generate a `number` (within a range). + * * @example * faker.string.numeric() // '2' * faker.string.numeric(5) // '31507' - * faker.string.numeric(42) // '56434563150765416546479875435481513188548' + * faker.string.numeric(42) // '06434563150765416546479875435481513188548' * faker.string.numeric({ length: { min: 5, max: 10 } }) // '197089478' - * faker.string.numeric({ length: 42, allowLeadingZeros: true }) // '00564846278453876543517840713421451546115' + * faker.string.numeric({ length: 42, allowLeadingZeros: false }) // '72564846278453876543517840713421451546115' * faker.string.numeric({ length: 6, exclude: ['0'] }) // '943228' * * @since 8.0.0 @@ -350,7 +352,7 @@ export class StringModule { return ''; } - const { allowLeadingZeros = false } = options; + const { allowLeadingZeros = true } = options; let { exclude = [] } = options; if (typeof exclude === 'string') { |
