Created
April 3, 2012 21:57
-
-
Save atheken/2295777 to your computer and use it in GitHub Desktop.
Guid generator in Javascript.
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
(function(){ | |
if(!window.String.UUID){ | |
var matcher = /[xy]/g; | |
var replacer = function(c) { | |
var r = Math.random()*16|0; | |
var v = c == 'x' ? r : (r&0x3|0x8); | |
return v.toString(16); | |
}; | |
//maybe shouldn't be modifying the global variable, but seems like the best place to put this. | |
window.String.UUID = function(){ | |
//see http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript for more details. | |
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(matcher, replacer); | |
}; | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment