diff options
| author | Eric Cheng <[email protected]> | 2022-04-06 03:56:39 -0400 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-04-06 07:56:39 +0000 |
| commit | 20f33e6640551b1d95059207ae2a54ba9115690c (patch) | |
| tree | f6baed3989c51f387baad0c1bb5d842e56e66a2f /src | |
| parent | 40c9d5a8d0a03d8cb9275e40640b6d193ce1780c (diff) | |
| download | faker-20f33e6640551b1d95059207ae2a54ba9115690c.tar.xz faker-20f33e6640551b1d95059207ae2a54ba9115690c.zip | |
feat: faker.finance.pin() (#695)
Diffstat (limited to 'src')
| -rw-r--r-- | src/finance.ts | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/finance.ts b/src/finance.ts index 5581ad4e..32f8454e 100644 --- a/src/finance.ts +++ b/src/finance.ts @@ -292,6 +292,23 @@ export class Finance { } /** + * Generates a random PIN number. + * + * @param length The length of the PIN to generate. Defaults to `4`. + * @throws Will throw an error if length is less than 1. + * + * @example + * faker.finance.pin() // '5067' + * faker.finance.pin(6) // '213789' + */ + pin(length: number = 4): string { + if (length < 1) { + throw new FakerError('minimum length is 1'); + } + return Array.from({ length }, () => this.faker.datatype.number(9)).join(''); + } + + /** * Generates a random ethereum Address. * * @example |
