This repository has been archived by the owner on Oct 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from carlosdaniiel07/feature/uuid
Add UUID checks
- Loading branch information
Showing
3 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { makeFunction } from "checks/helpers"; | ||
|
||
const IS_UUID = /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i | ||
export const isUUID = makeFunction({ | ||
regex: IS_UUID, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { isUUID } from "checks/uuid"; | ||
|
||
/** | ||
* | ||
* True | ||
* | ||
*/ | ||
|
||
describe("is UUID (return True)", () => { | ||
it("with valid UUID", () => { | ||
const result = isUUID("24bd85a1-4eb7-4f63-829e-75c08ac2b6c0"); | ||
expect(result).toBeTruthy(); | ||
}); | ||
}); | ||
|
||
/** | ||
* | ||
* False | ||
* | ||
*/ | ||
|
||
describe("is UUID (return False)", () => { | ||
it("with invalid UUID (1)", () => { | ||
const result = isUUID("24bd85a1-4eb7-4f63-829e-75c08ac2b6t1"); | ||
expect(result).toBe(false); | ||
}); | ||
|
||
it("with invalid UUID (2)", () => { | ||
const result = isUUID("e7f019ea-4d52-11eb-ae93"); | ||
expect(result).toBe(false); | ||
}); | ||
}); |