-
-
Save lcaballero/be998c27207f68d74834 to your computer and use it in GitHub Desktop.
A uuid mixin for Lodash.
This file contains hidden or 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
_.mixin | |
# Better than random number, this should not allow for collisions. | |
# Code was minimally modified from | |
# [stackoverflow](http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript), | |
# demonstrated at [jsfiddle](http://jsfiddle.net/briguy37/2MVFd/) | |
uuid : -> | |
now = Date.now() | |
'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace /[xy]/g, (c) -> | |
r = (now + Math.random() * 16) % 16 | 0 | |
now = Math.floor now / 16 | |
((if c is "x" then r else (r & 0x7 | 0x8))).toString 16 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment