Skip to content

Commit

Permalink
minLengthLimit cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
4kimov committed Sep 6, 2023
1 parent 701f016 commit ab98ff7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ export default class Sqids {
}

// test min length (type [might be lang-specific] + min length + max length)
if (typeof minLength != 'number' || minLength < 0 || minLength > 1_000) {
throw new Error(`Minimum length has to be between 0 and ${1_000}`);
const minLengthLimit = 1_000;
if (typeof minLength != 'number' || minLength < 0 || minLength > minLengthLimit) {
throw new Error(`Minimum length has to be between 0 and ${minLengthLimit}`);
}

// clean up blocklist:
Expand Down
5 changes: 3 additions & 2 deletions tests/minlength.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ test('min lengths', () => {
});

test('out-of-range invalid min length', async () => {
const minLengthError = 'Minimum length has to be between 0 and 1000';
const minLengthLimit = 1_000;
const minLengthError = `Minimum length has to be between 0 and ${minLengthLimit}`;

await expect(
async () =>
Expand All @@ -105,7 +106,7 @@ test('out-of-range invalid min length', async () => {
await expect(
async () =>
new Sqids({
minLength: 1_000 + 1
minLength: minLengthLimit + 1
})
).rejects.toThrow(minLengthError);
});

0 comments on commit ab98ff7

Please sign in to comment.