* Generates a given length string of digits. * * @param options Either the length of the string to generate or the optional options object. * @param options.length The length of the string to generate either as a fixed length or as a length range. Defaults to `1`. * @param options.allowL
(
options:
| number
| {
/**
* The length of the string to generate either as a fixed length or as a length range.
*
* @default 1
*/
length?:
| number
| {
/**
* The minimum length of the string to generate.
*/
min: number;
/**
* The maximum length of the string to generate.
*/
max: number;
};
/**
* Whether leading zeros are allowed or not.
*
* @default true
*/
allowLeadingZeros?: boolean;
/**
* An array of digits which should be excluded in the generated string.
*
* @default []
*/
exclude?: ReadonlyArray<LiteralUnion<NumericChar>> | string;
} = {}
)
| 566 | * @since 8.0.0 |
| 567 | */ |
| 568 | numeric( |
| 569 | options: |
| 570 | | number |
| 571 | | { |
| 572 | /** |
| 573 | * The length of the string to generate either as a fixed length or as a length range. |
| 574 | * |
| 575 | * @default 1 |
| 576 | */ |
| 577 | length?: |
| 578 | | number |
| 579 | | { |
| 580 | /** |
| 581 | * The minimum length of the string to generate. |
| 582 | */ |
| 583 | min: number; |
| 584 | /** |
| 585 | * The maximum length of the string to generate. |
| 586 | */ |
| 587 | max: number; |
| 588 | }; |
| 589 | /** |
| 590 | * Whether leading zeros are allowed or not. |
| 591 | * |
| 592 | * @default true |
| 593 | */ |
| 594 | allowLeadingZeros?: boolean; |
| 595 | /** |
| 596 | * An array of digits which should be excluded in the generated string. |
| 597 | * |
| 598 | * @default [] |
| 599 | */ |
| 600 | exclude?: ReadonlyArray<LiteralUnion<NumericChar>> | string; |
| 601 | } = {} |
| 602 | ): string { |
| 603 | if (typeof options === 'number') { |
| 604 | options = { |
| 605 | length: options, |
| 606 | }; |
| 607 | } |
| 608 | |
| 609 | const length = this.faker.helpers.rangeToNumber(options.length ?? 1); |
| 610 | if (length <= 0) { |
| 611 | return ''; |
| 612 | } |
| 613 | |
| 614 | const { allowLeadingZeros = true } = options; |
| 615 | let { exclude = [] } = options; |
| 616 | |
| 617 | if (typeof exclude === 'string') { |
| 618 | exclude = [...exclude]; |
| 619 | } |
| 620 | |
| 621 | const allowedDigits = DIGIT_CHARS.filter( |
| 622 | (digit) => !exclude.includes(digit) |
| 623 | ); |
| 624 | |
| 625 | if ( |
no test coverage detected