// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.

/**
 * Converts the byte array to a UUID string
 * @param bytes Used to convert Byte to Hex
 */
export function bytesToUuid(bytes: number[] | Uint8Array): string {
  const bits = [...bytes].map((bit) => {
    const s = bit.toString(16);
    return bit < 0x10 ? "0" + s : s;
  });
  return [
    ...bits.slice(0, 4),
    "-",
    ...bits.slice(4, 6),
    "-",
    ...bits.slice(6, 8),
    "-",
    ...bits.slice(8, 10),
    "-",
    ...bits.slice(10, 16),
  ].join("");
}

/**
 * Converts a string to a byte array by converting the hex value to a number.
 * @param uuid Value that gets converted.
 */
export function uuidToBytes(uuid: string): number[] {
  const bytes: number[] = [];

  uuid.replace(/[a-fA-F0-9]{2}/g, (hex: string): string => {
    bytes.push(parseInt(hex, 16));
    return "";
  });

  return bytes;
}

// denoCacheMetadata={"headers":{"etag":"\"f47d8d5671627d4a4934a15eab112d9c\"","access-control-expose-headers":"*","content-type":"text/typescript","server":"cloudflare","alt-svc":"h3=\":443\"; ma=86400","report-to":"{\"group\":\"cf-nel\",\"max_age\":604800,\"endpoints\":[{\"url\":\"https://a.nel.cloudflare.com/report/v4?s=7zj0xjv%2FG1ht8M2iXxghME54Bp6iz2uEWfkr7DO8lS6mjHYXoSPtJ1xklP52h0Nx5%2FVej51cmYDDvyZkG%2BNpGqS9Rz1T3xLmNyI78sGP%2BVOMimly0iDbYJk%3D\"}]}","date":"Tue, 28 Jul 2026 12:31:15 GMT","content-security-policy":"default-src 'none'; script-src 'none'; style-src 'none'; img-src 'none'; font-src 'none'; connect-src 'none'; frame-src 'none'; object-src 'none'; frame-ancestors 'none'; sandbox; form-action 'none';","x-jsr-backend":"modules","cf-ray":"a223e6586c5b7db6-LAX","cache-control":"public, max-age=31536000, immutable","vary":"Origin","access-control-allow-origin":"*","x-robots-tag":"noindex","content-length":"935","nel":"{\"report_to\":\"cf-nel\",\"success_fraction\":0.0,\"max_age\":604800}","set-cookie":"__cf_bm=EDRodvBFcrScOV6k1tiIb3fhwZDrxtmg1UvtPE_lKN4-1785241875.2704759-1.0.1.1-Bquqq2s1Ni8Mc4ErMVrsA.PdzTk1wYb41QlfT7quIdNWrvz211yCWRJyrYv5y7fpUKFnpKOdvvzdTeFZOs7xrgM861dCwptXHO7M15wQHme5zcqqcpAzJLhaA8XJvpiO; HttpOnly; SameSite=None; Secure; Path=/; Domain=jsr.io; Expires=Tue, 28 Jul 2026 13:01:15 GMT","x-content-type-options":"nosniff","cross-origin-resource-policy":"cross-origin"},"url":"https://jsr.io/@std/uuid/0.224.3/_common.ts","time":1785241875}