This repository has been archived by the owner on Jan 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Diana Thayer
committed
Mar 16, 2017
1 parent
2bfddea
commit 3983030
Showing
2 changed files
with
82 additions
and
19 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 |
---|---|---|
@@ -1,12 +1,47 @@ | ||
window.makeUuid = (function () { | ||
|
||
// From http://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript | ||
// From http://pastebin.com/JSgC7eej | ||
return function makeUuid() { // eslint-disable-line no-unused-vars | ||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { | ||
var r = Math.random()*16 | 0, | ||
v = c === 'x' ? r : (r & 0x3 | 0x8); | ||
return v.toString(16); | ||
}); | ||
// get sixteen unsigned 8 bit random values | ||
var u = window | ||
.crypto | ||
.getRandomValues(new Uint8Array(16)); | ||
|
||
// set the version bit to v4 | ||
u[6] = (u[6] & 0x0f) | 0x40 | ||
|
||
// set the variant bit to "don't care" (yes, the RFC | ||
// calls it that) | ||
u[8] = (u[8] & 0xbf) | 0x80 | ||
|
||
// hex encode them and add the dashes | ||
var uid = ""; | ||
uid += u[0].toString(16); | ||
uid += u[1].toString(16); | ||
uid += u[2].toString(16); | ||
uid += u[3].toString(16); | ||
uid += "-"; | ||
|
||
uid += u[4].toString(16); | ||
uid += u[5].toString(16); | ||
uid += "-"; | ||
|
||
uid += u[6].toString(16); | ||
uid += u[7].toString(16); | ||
uid += "-"; | ||
|
||
uid += u[8].toString(16); | ||
uid += u[9].toString(16); | ||
uid += "-"; | ||
|
||
uid += u[10].toString(16); | ||
uid += u[11].toString(16); | ||
uid += u[12].toString(16); | ||
uid += u[13].toString(16); | ||
uid += u[14].toString(16); | ||
uid += u[15].toString(16); | ||
|
||
return uid; | ||
}; | ||
})(); | ||
null; |
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