Skip to content

Commit

Permalink
fix: loosen uuid validation and support uuid v8 (custom)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffreiffers committed Oct 11, 2023
1 parent 5ac89d6 commit 86151b4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions libs/utils/src/lib/validation/uuid.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { validUUID } from './uuid';

describe('validUUID', () => {
test('validate valid uuid', () => {
expect(validUUID('6ec0bd7f-11c0-43da-975e-2a8ad9ebae0b')).toStrictEqual(true);
expect(validUUID('596547fb-f496-804e-933c-1fc948dd6ada')).toStrictEqual(true);
});
test('validate invalid uuid', () => {
expect(validUUID('invalid-uuid')).toStrictEqual(false);
});
});
2 changes: 1 addition & 1 deletion libs/utils/src/lib/validation/uuid.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export const validUUID = (uuid?: string) => {
return uuid?.match(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}$/i) !== null;
return uuid?.match(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{3,4}-[0-9a-f]{3,4}-[0-9a-f]{12}$/i) !== null;
};

0 comments on commit 86151b4

Please sign in to comment.