diff options
| author | Leyla Jähnig <[email protected]> | 2022-03-21 14:09:40 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-03-21 13:09:40 +0000 |
| commit | c51fb1570669284e14915916636de97b7f644e17 (patch) | |
| tree | eca1459573da807c31dcdf3e2e6c4613064c8696 /src | |
| parent | 5a15c40ec98fc1d39309d875899b88a0b7684bcf (diff) | |
| download | faker-c51fb1570669284e14915916636de97b7f644e17.tar.xz faker-c51fb1570669284e14915916636de97b7f644e17.zip | |
fix: alphaNumeric all chars banned (#550)
Diffstat (limited to 'src')
| -rw-r--r-- | src/random.ts | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/random.ts b/src/random.ts index c2d8ecb2..dd58c3ce 100644 --- a/src/random.ts +++ b/src/random.ts @@ -479,11 +479,17 @@ export class Random { 'y', 'z', ]; - if (options) { - if (options.bannedChars) { - charsArray = arrayRemove(charsArray, options.bannedChars); - } + + if (options.bannedChars) { + charsArray = arrayRemove(charsArray, options.bannedChars); } + + if (charsArray.length === 0) { + throw new Error( + 'Unable to generate string, because all possible characters are banned.' + ); + } + for (let i = 0; i < count; i++) { wholeString += this.faker.random.arrayElement(charsArray); } |
