Skip to content

Instantly share code, notes, and snippets.

@matthewbednarski
Created August 22, 2015 14:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewbednarski/58f638ca9721d33e3ac8 to your computer and use it in GitHub Desktop.
Save matthewbednarski/58f638ca9721d33e3ac8 to your computer and use it in GitHub Desktop.
a service for producing v4 uuids
(function() {
var app = angular.module('mcbUuid', [])
.service('uuid', [Uuid]);
// http://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript
//
function Uuid() {
this.newUuid = function() {
var d = new Date().getTime();
var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = (d + Math.random() * 16) % 16 | 0;
d = Math.floor(d / 16);
return (c == 'x' ? r : (r & 0x3 | 0x8)).toString(16);
});
return uuid;
};
}
return app;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment