{"version":3,"file":"stringUtils.mjs","names":[],"sources":["../../../src/tools/utils/stringUtils.ts"],"sourcesContent":["/**\n * UUID v4\n * from https://gist.github.com/jed/982883\n */\nexport function generateUUID(placeholder?: string): string {\n  return placeholder\n    ? // eslint-disable-next-line  no-bitwise\n      (parseInt(placeholder, 10) ^ ((Math.random() * 16) >> (parseInt(placeholder, 10) / 4))).toString(16)\n    : `${1e7}-${1e3}-${4e3}-${8e3}-${1e11}`.replace(/[018]/g, generateUUID)\n}\n\n// Assuming input string is following the HTTP Cookie format defined in\n// https://www.ietf.org/rfc/rfc2616.txt and https://www.ietf.org/rfc/rfc6265.txt, we don't need to\n// be too strict with this regex.\nconst COMMA_SEPARATED_KEY_VALUE = /(\\S+?)\\s*=\\s*(.*?)(?:;|$)/g\n\n/**\n * Returns the value of the key with the given name\n * If there are multiple values with the same key, returns the first one\n */\nexport function findCommaSeparatedValue(rawString: string, name: string): string | undefined {\n  COMMA_SEPARATED_KEY_VALUE.lastIndex = 0\n  while (true) {\n    const match = COMMA_SEPARATED_KEY_VALUE.exec(rawString)\n    if (match) {\n      if (match[1] === name) {\n        return match[2]\n      }\n    } else {\n      break\n    }\n  }\n}\n\n/**\n * Returns a map of all the values with the given key\n * If there are multiple values with the same key, returns all the values\n */\nexport function findAllCommaSeparatedValues(rawString: string): Map<string, string[]> {\n  const result = new Map<string, string[]>()\n  COMMA_SEPARATED_KEY_VALUE.lastIndex = 0\n  while (true) {\n    const match = COMMA_SEPARATED_KEY_VALUE.exec(rawString)\n    if (match) {\n      const key = match[1]\n      const value = match[2]\n      if (result.has(key)) {\n        result.get(key)!.push(value)\n      } else {\n        result.set(key, [value])\n      }\n    } else {\n      break\n    }\n  }\n  return result\n}\n\n/**\n * Returns a map of the values with the given key\n * ⚠️ If there are multiple values with the same key, returns the LAST one\n *\n * @deprecated use `findAllCommaSeparatedValues()` instead\n */\nexport function findCommaSeparatedValues(rawString: string): Map<string, string> {\n  const result = new Map<string, string>()\n  COMMA_SEPARATED_KEY_VALUE.lastIndex = 0\n  while (true) {\n    const match = COMMA_SEPARATED_KEY_VALUE.exec(rawString)\n    if (match) {\n      result.set(match[1], match[2])\n    } else {\n      break\n    }\n  }\n  return result\n}\n\nexport function safeTruncate(candidate: string, length: number, suffix = '') {\n  const lastChar = candidate.charCodeAt(length - 1)\n  const isLastCharSurrogatePair = lastChar >= 0xd800 && lastChar <= 0xdbff\n  const correctedLength = isLastCharSurrogatePair ? length + 1 : length\n\n  if (candidate.length <= correctedLength) {\n    return candidate\n  }\n\n  return `${candidate.slice(0, correctedLength)}${suffix}`\n}\n"],"mappings":";;;;;AAIA,SAAgB,aAAa,aAA8B;CACzD,OAAO,eAEF,SAAS,aAAa,EAAE,IAAM,KAAK,OAAO,IAAI,MAAQ,SAAS,aAAa,EAAE,IAAI,EAAA,CAAK,SAAS,EAAE,IACnG,uCAAsC,QAAQ,UAAU,YAAY;AAC1E;AAKA,MAAM,4BAA4B;;;;;AAMlC,SAAgB,wBAAwB,WAAmB,MAAkC;CAC3F,0BAA0B,YAAY;CACtC,OAAO,MAAM;EACX,MAAM,QAAQ,0BAA0B,KAAK,SAAS;EACtD,IAAI;OACE,MAAM,OAAO,MACf,OAAO,MAAM;EAAA,OAGf;CAEJ;AACF;;;;;AAMA,SAAgB,4BAA4B,WAA0C;CACpF,MAAM,yBAAS,IAAI,IAAsB;CACzC,0BAA0B,YAAY;CACtC,OAAO,MAAM;EACX,MAAM,QAAQ,0BAA0B,KAAK,SAAS;EACtD,IAAI,OAAO;GACT,MAAM,MAAM,MAAM;GAClB,MAAM,QAAQ,MAAM;GACpB,IAAI,OAAO,IAAI,GAAG,GAChB,OAAO,IAAI,GAAG,CAAC,CAAE,KAAK,KAAK;QAE3B,OAAO,IAAI,KAAK,CAAC,KAAK,CAAC;EAE3B,OACE;CAEJ;CACA,OAAO;AACT;;;;;;;AAQA,SAAgB,yBAAyB,WAAwC;CAC/E,MAAM,yBAAS,IAAI,IAAoB;CACvC,0BAA0B,YAAY;C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