MCPcopy Create free account
hub / github.com/freeCodeCamp/freeCodeCamp / genUUID

Function genUUID

client/src/utils/growthbook-cookie.ts:6–19  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

4
5 // use the browsers crypto.randomUUID if set
6 const genUUID = () => {
7 if (window?.crypto?.randomUUID) return window.crypto.randomUUID();
8
9 // return a random UUID style string`
10 return ((1e7).toString() + -1e3 + -4e3 + -8e3 + -1e11).replace(
11 /[018]/g,
12 c =>
13 (
14 Number(c) ^
15 (crypto.getRandomValues(new Uint8Array(1))[0] &
16 (15 >> (Number(c) / 4)))
17 ).toString(16)
18 );
19 };
20
21 const getCookie = (name: string) => {
22 const value = `; ${document.cookie}`;

Callers 1

getUUIDFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected