UNPKG

591 BJavaScriptView Raw
1/**
2 *
3 * This function was taken from a stackoverflow answer:
4 *
5 * http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript
6 *
7 * Many thanks to:
8 *
9 * Briguy37 (http://stackoverflow.com/users/508537/briguy37)
10 * broofa (http://stackoverflow.com/users/109538/broofa)
11 *
12 */
13
14module.exports = function() {
15 var d = new Date().getTime();
16 return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
17 var r = (d + Math.random()*16)%16 | 0;
18 d = Math.floor(d/16);
19 return (c=='x' ? r : (r&0x3|0x8)).toString(16);
20 });
21};