Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/lib/isUUID.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ const uuid = {
all: /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i,
};

export default function isUUID(str, version = 'all') {
export default function isUUID(str, version) {
assertString(str);
const pattern = uuid[version];
const pattern = uuid[![undefined, null].includes(version) ? version : 'all'];
return pattern && pattern.test(str);
}
28 changes: 28 additions & 0 deletions test/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -4413,6 +4413,34 @@ describe('Validators', () => {
'AAAAAAAA-1111-1111-AAAG-111111111111',
],
});
test({
validator: 'isUUID',
args: [undefined],
valid: [
'A117FBC9-4BED-3078-CF07-9141BA07C9F3',
'A117FBC9-4BED-5078-AF07-9141BA07C9F3',
],
invalid: [
'',
'xxxA987FBC9-4BED-3078-CF07-9141BA07C9F3',
'A987FBC94BED3078CF079141BA07C9F3',
'A11AAAAA-1111-1111-AAAG-111111111111',
],
});
test({
validator: 'isUUID',
args: [null],
valid: [
'A127FBC9-4BED-3078-CF07-9141BA07C9F3',
],
invalid: [
'',
'xxxA987FBC9-4BED-3078-CF07-9141BA07C9F3',
'A127FBC9-4BED-3078-CF07-9141BA07C9F3xxx',
'912859',
'A12AAAAA-1111-1111-AAAG-111111111111',
],
});
test({
validator: 'isUUID',
args: [3],
Expand Down