Skip to content

Commit

Permalink
fix: generate-sequential-string was allowing non-unique string
Browse files Browse the repository at this point in the history
  • Loading branch information
uzenith360 committed Sep 16, 2023
1 parent 1492866 commit dd0092f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/generate-sequential-string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ export default (
outputLength: number = 32,
charset: string = '2346789ABCDEFHKLMNPQRTVWXY',
): string => {
if (new Set([...charset]).size !== charset.length) {
throw new Error('Character set must be unique');
}

const charsetLength: number = charset.length;
const output: string[] = [];

Expand Down
4 changes: 4 additions & 0 deletions tests/generate-sequential-string.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ describe('Generate sequential string', () => {
assert.equal(next(), 'AAAABC');
assert.equal(next(), 'AAAAB1');
});

it('should throw error if character set is not unique', () => {
assert.throws(() => generateSequentialString(0, 0, '01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ'))
});
});

describe('Generate all combinations', () => {
Expand Down

0 comments on commit dd0092f

Please sign in to comment.