-
Notifications
You must be signed in to change notification settings - Fork 43
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 #1210 from Patternslib/scrum-2615--depends-basepat…
…tern Scrum 2615 depends
- Loading branch information
Showing
11 changed files
with
898 additions
and
422 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
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
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,21 @@ | ||
/** | ||
* Get a universally unique id (uuid). | ||
* | ||
* @returns {String} - The uuid. | ||
*/ | ||
const create_uuid = () => { | ||
let uuid; | ||
if (window.crypto.randomUUID) { | ||
// Create a real UUID | ||
// window.crypto.randomUUID does only exist in browsers with secure | ||
// context. | ||
// See: https://developer.mozilla.org/en-US/docs/Web/API/Crypto/randomUUID | ||
uuid = window.crypto.randomUUID(); | ||
} else { | ||
// Create a sufficiently unique ID | ||
const array = new Uint32Array(4); | ||
uuid = window.crypto.getRandomValues(array).join(""); | ||
} | ||
return uuid; | ||
}; | ||
export default create_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import create_uuid from "./uuid"; | ||
|
||
describe("uuid", function () { | ||
it("returns a UUIDv4", function () { | ||
const uuid = create_uuid(); | ||
expect(uuid).toMatch( | ||
/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/ | ||
); | ||
}); | ||
|
||
it("returns a sufficiently unique id", function () { | ||
// Mock window.crypto.randomUUID not existing, like in browser with | ||
// non-secure context. | ||
const orig_randomUUID = window.crypto.randomUUID; | ||
window.crypto.randomUUID = undefined; | ||
|
||
const uuid = create_uuid(); | ||
expect(uuid).toMatch(/^[0-9]*$/); | ||
|
||
window.crypto.randomUUID = orig_randomUUID; | ||
}); | ||
}); |
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
Oops, something went wrong.