Skip to content

Instantly share code, notes, and snippets.

@justinobney
Created September 19, 2013 13:55
Show Gist options
  • Save justinobney/6623855 to your computer and use it in GitHub Desktop.
Save justinobney/6623855 to your computer and use it in GitHub Desktop.
UUID in JS
var svc = {
new: function() {
function _p8(s) {
var p = (Math.random().toString(16)+"000000000").substr(2,8);
return s ? "-" + p.substr(0,4) + "-" + p.substr(4,4) : p ;
}
return _p8() + _p8(true) + _p8(true) + _p8();
},
empty: function() {
return '00000000-0000-0000-0000-000000000000';
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment