Skip to content

Commit

Permalink
Destructure and improve regex
Browse files Browse the repository at this point in the history
  • Loading branch information
rottabonus committed Oct 10, 2024
1 parent fb29811 commit 035ecf3
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/api/minimumVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ export type AppClient = {
};

export const toAppClient = (value: Client): AppClient => {
const splitted = value.version.split('.').map(Number);
const [major, minor, patch] = value.version.split('.').map(Number);

return {
client: value.client,
major: splitted[0],
minor: splitted[1],
patch: splitted[2],
major,
minor,
patch,
};
};

Expand Down
4 changes: 1 addition & 3 deletions src/lib/__tests__/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ describe('Validate The invalid password', () => {
});

describe('Validate correct versions', () => {
['1.23.3', '10.20.0', '3.99.99', '2.11.1'].forEach(version => {
['1.23.3', '10.20.0', '3.99.99', '2.11.1', '3.110.5'].forEach(version => {
it(`decodes valid version ${version}`, () => {
expect(isRight(validators.ValidVersion.decode(version))).toEqual(true);
});
Expand All @@ -133,8 +133,6 @@ describe('Validate invalid versions', () => {
[
'1.2',
'1.2.3.4',
'123.45.6',
'1.234.5',
'01.2.3',
'1.2.03',
'a.b.c',
Expand Down
2 changes: 1 addition & 1 deletion src/lib/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const isValidDescription = (value: string): boolean => {
};

const isValidVersion = (value: string): boolean => {
return /^\d{1,2}\.\d{1,2}\.\d{1,2}$/.test(value);
return /^\d+\.\d+\.\d+$/.test(value);
};

export const ValidEmail = new t.Type<string, string, unknown>(
Expand Down

0 comments on commit 035ecf3

Please sign in to comment.