File size: 404 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
export default () => {
if (typeof crypto !== 'undefined' && crypto.randomUUID) {
return crypto.randomUUID();
}
const d =
typeof performance === 'undefined' ? Date.now() : performance.now() * 1000;
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
const r = (Math.random() * 16 + d) % 16 | 0;
return (c == 'x' ? r : (r & 0x3) | 0x8).toString(16);
});
};
|