PageSourceSearch

https://www.agent-zero.ai/src/lib/guid.js

js agent-zero.ai collected 2026-10-04 15:31:25 UTC 1,363 bytes, 48 lines download raw bytes

1export function generateUUIDv4(hyphens = true) {
2  const cryptoObj = globalThis.crypto || globalThis.msCrypto;
3  const bytes = new Uint8Array(16);
4  cryptoObj.getRandomValues(bytes);
5
6  // Set version to 4
7  bytes[6] = (bytes[6] & 0x0f) | 0x40;
8  // Set variant to 10xx
9  bytes[8] = (bytes[8] & 0x3f) | 0x80;
10
11  const hex = [...bytes].map((b) => b.toString(16).padStart(2, "0")).join("");
12
13  if (hyphens) {
14    return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(
15      12,
16      16
17    )}-${hex.slice(16, 20)}-${hex.slice(20)}`;
18  } else {
19    return hex;
20  }
21}
22
23export function generateID(length = 8, caseSensitive = true, symbols = false) {
24  // define characters to use for ID generation
25  const lowerChars = "abcdefghijklmnopqrstuvwxyz";
26  const upperChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
27  const numbers = "0123456789";
28  const _symbols = "!@#$%^&*()_+";
29
30  // combine character sets based on caseSensitive flag
31  const chars =
32    numbers + (caseSensitive ? lowerChars + upperChars : lowerChars) +
33    (_symbols && symbols);
34
35  // get crypto object
36  const cryptoObj = globalThis.crypto || globalThis.msCrypto;
37
38  // generate random ID
39  let result = "";
40  const array = new Uint32Array(length);
41  cryptoObj.getRandomValues(array);
42  
43  for (let i = 0; i < length; i++) {
44    result += chars.charAt(array[i] % chars.length);
45  }
46
47  return result;
48}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.