Skip to content

Commit

Permalink
feat(isUUID): support uuid v7 (#2345)
Browse files Browse the repository at this point in the history
closes #2344
  • Loading branch information
ruscon committed Apr 25, 2024
1 parent 31c88cf commit 6d5c52a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/lib/isUUID.js
Expand Up @@ -6,6 +6,7 @@ const uuid = {
3: /^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,
4: /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
5: /^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
7: /^[0-9A-F]{8}-[0-9A-F]{4}-7[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
all: /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i,
};

Expand Down
28 changes: 28 additions & 0 deletions test/validators.test.js
Expand Up @@ -5021,6 +5021,7 @@ describe('Validators', () => {
'A987FBC9-4BED-3078-CF07-9141BA07C9F3',
'A987FBC9-4BED-4078-8F07-9141BA07C9F3',
'A987FBC9-4BED-5078-AF07-9141BA07C9F3',
'018C544A-D384-7000-BB74-3B1738ABE43C',
],
invalid: [
'',
Expand All @@ -5038,6 +5039,7 @@ describe('Validators', () => {
valid: [
'A117FBC9-4BED-3078-CF07-9141BA07C9F3',
'A117FBC9-4BED-5078-AF07-9141BA07C9F3',
'018C544A-D384-7000-BB74-3B1738ABE43C',
],
invalid: [
'',
Expand All @@ -5051,6 +5053,7 @@ describe('Validators', () => {
args: [null],
valid: [
'A127FBC9-4BED-3078-CF07-9141BA07C9F3',
'018C544A-D384-7000-BB74-3B1738ABE43C',
],
invalid: [
'',
Expand All @@ -5072,6 +5075,7 @@ describe('Validators', () => {
'AAAAAAAA-1111-2222-AAAG-111111111111',
'A987FBC9-4BED-4078-8F07-9141BA07C9F3',
'A987FBC9-4BED-5078-AF07-9141BA07C9F3',
'018C544A-D384-7000-BB74-3B1738ABE43C',
],
});
test({
Expand All @@ -5087,6 +5091,7 @@ describe('Validators', () => {
'AAAAAAAA-1111-1111-AAAG-111111111111',
'A987FBC9-4BED-4078-8F07-9141BA07C9F3',
'A987FBC9-4BED-5078-AF07-9141BA07C9F3',
'018C544A-D384-7000-BB74-3B1738ABE43C',
],
});
test({
Expand All @@ -5102,6 +5107,7 @@ describe('Validators', () => {
'AAAAAAAA-1111-1111-AAAG-111111111111',
'A987FBC9-4BED-4078-8F07-9141BA07C9F3',
'A987FBC9-4BED-5078-AF07-9141BA07C9F3',
'018C544A-D384-7000-BB74-3B1738ABE43C',
],
});
test({
Expand All @@ -5120,6 +5126,7 @@ describe('Validators', () => {
'AAAAAAAA-1111-1111-AAAG-111111111111',
'A987FBC9-4BED-5078-AF07-9141BA07C9F3',
'A987FBC9-4BED-3078-CF07-9141BA07C9F3',
'018C544A-D384-7000-BB74-3B1738ABE43C',
],
});
test({
Expand All @@ -5138,6 +5145,7 @@ describe('Validators', () => {
'AAAAAAAA-1111-1111-AAAG-111111111111',
'9c858901-8a57-4791-81fe-4c455b099bc9',
'A987FBC9-4BED-3078-CF07-9141BA07C9F3',
'018C544A-D384-7000-BB74-3B1738ABE43C',
],
});
test({
Expand All @@ -5150,6 +5158,26 @@ describe('Validators', () => {
'987FBC97-4BED-3078-AF07-9141BA07C9F3',
'987FBC97-4BED-4078-AF07-9141BA07C9F3',
'987FBC97-4BED-5078-AF07-9141BA07C9F3',
'018C544A-D384-7000-BB74-3B1738ABE43C',
],
});
test({
validator: 'isUUID',
args: [7],
valid: [
'018C544A-D384-7000-BB74-3B1738ABE43C',
],
invalid: [
'',
'xxxA987FBC9-4BED-3078-CF07-9141BA07C9F3',
'934859',
'AAAAAAAA-1111-1111-AAAG-111111111111',
'A987FBC9-4BED-5078-AF07-9141BA07C9F3',
'A987FBC9-4BED-3078-CF07-9141BA07C9F3',
'713ae7e3-cb32-45f9-adcb-7c4fa86b90c1',
'625e63f3-58f5-40b7-83a1-a72ad31acffb',
'57b73598-8764-4ad0-a76a-679bb6640eb1',
'9c858901-8a57-4791-81fe-4c455b099bc9',
],
});
});
Expand Down

0 comments on commit 6d5c52a

Please sign in to comment.