Created
August 22, 2015 14:52
-
-
Save matthewbednarski/58f638ca9721d33e3ac8 to your computer and use it in GitHub Desktop.
a service for producing v4 uuids
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() { | |
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