INNER CODE UNIT · TypeScript

removeJson

austin-starks/Promptimizer · src/utils/index.ts:1

export function removeJson(text: string) {
  if (!text) {
    return text;
  }
  let firstBrace = text.indexOf("```");
  if (firstBrace === -1) {
    firstBrace = text.indexOf("{");
  }
  let lastBrace = text.lastIndexOf("```");
  let lastIndex = 3;
  if (lastBrace === -1) {
    lastBrace = text.lastIndexOf("}");
    lastIndex = 1;
  }
  if (firstBrace === -1 || lastBrace === -1 || lastBrace < firstBrace) {
    return text;
  }
  let result =

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…