Skip to content

Commit

Permalink
fix: alphaNumeric all chars banned (#550)
Browse files Browse the repository at this point in the history
  • Loading branch information
xDivisionByZerox committed Mar 21, 2022
1 parent 5a15c40 commit c51fb15
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
14 changes: 10 additions & 4 deletions src/random.ts
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion test/random.spec.ts
Expand Up @@ -210,7 +210,7 @@ describe('random', () => {
expect(alphaText).match(/[b-oq-z]/);
});

it.todo('should throw if all possible characters being banned', () => {
it('should throw if all possible characters being banned', () => {
const bannedChars = 'abcdefghijklmnopqrstuvwxyz0123456789'.split('');
expect(() =>
faker.random.alphaNumeric(5, {
Expand Down

0 comments on commit c51fb15

Please sign in to comment.