aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/random.ts14
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);
}