UNPKG

@newrelic/gatsby-theme-newrelic

Version:

[![Community Project header](https://github.com/newrelic/opensource-website/raw/master/src/images/categories/Community_Project.png)](https://opensource.newrelic.com/oss-category/#community-project)

21 lines (19 loc) 569 B
const generateUUID = () => { if ( typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function' ) { return crypto.randomUUID(); } if ( typeof crypto !== 'undefined' && typeof crypto.getRandomValues === 'function' ) { return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, (c) => { const v = crypto.getRandomValues(new Uint8Array(1))[0]; return (c ^ (v & (15 >> (c / 4)))).toString(16); }); } throw new Error('Web Crypto API is not available in this environment'); }; export default generateUUID;