Skip to content

Commit

Permalink
Add custom UUID function
Browse files Browse the repository at this point in the history
  • Loading branch information
gjong authored Aug 16, 2024
1 parent 4e802f1 commit de6d219
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions src/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,20 +86,15 @@ const Resolver = {
}
},
uuid: () => {
return window.crypto !== undefined ? window.crypto.randomUUID() : '' + Date.now()
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'
.replace(/[xy]/g, function (c) {
const r = Math.random() * 16 | 0,
v = c == 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
}
}

// add the randomUUID option to crypto
window.crypto.randomUUID = function () {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'
.replace(/[xy]/g, function (c) {
const r = Math.random() * 16 | 0,
v = c == 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
}

export {
Attachment,
When,
Expand Down

0 comments on commit de6d219

Please sign in to comment.