function stripJsoncComments(source) {
  let result = "";
  let inString = false;
  let stringQuote = '"';
  let escaped = false;
  for (let index = 0; index < source.length; index += 1) {
    const char = source[index];
    const next = source[index + 1];
    if (inString) {
      result += char;
      if (escaped) {
        escaped = false;
        continue;
      }
      if (char === "\\") {
        escaped = true;
        continue;
      }
      if (char === stringQuote) {
        inString = false;
      }
      continue;
    }
    if (char === '"' || char === "'") {
      inString = true;
      stringQuote = char;
      result += char;
      continue;
    }
    if (char === "/" && next === "/") {
      while (index < source.length && source[index] !== "\n") {
        index += 1;
      }
      if (index < source.length) {
        result += source[index];
      }
      continue;
    }
    if (char === "/" && next === "*") {
      index += 2;
      while (index < source.length && !(source[index] === "*" && source[index + 1] === "/")) {
        index += 1;
      }
      index += 1;
      continue;
    }
    result += char;
  }
  return result;
}
function stripTrailingCommas(source) {
  let result = "";
  let inString = false;
  let stringQuote = '"';
  let escaped = false;
  for (let index = 0; index < source.length; index += 1) {
    const char = source[index];
    if (inString) {
      result += char;
      if (escaped) {
        escaped = false;
        continue;
      }
      if (char === "\\") {
        escaped = true;
        continue;
      }
      if (char === stringQuote) {
        inString = false;
      }
      continue;
    }
    if (char === '"' || char === "'") {
      inString = true;
      stringQuote = char;
      result += char;
      continue;
    }
    if (char === ",") {
      let lookahead = index + 1;
      while (lookahead < source.length && /\s/.test(source[lookahead])) {
        lookahead += 1;
      }
      const next = source[lookahead];
      if (next === "}" || next === "]") {
        continue;
      }
    }
    result += char;
  }
  return result;
}
function parseJsoncObject(source) {
  if (!source) {
    return null;
  }
  try {
    return JSON.parse(stripTrailingCommas(stripJsoncComments(source)));
  } catch {
    return null;
  }
}
export {
  parseJsoncObject as p
};
//# sourceMappingURL=jsonc-COxDkWRr.js.map
