MCPcopy
hub / github.com/upstash/context7 / stripJsonComments

Function stripJsonComments

packages/cli/src/setup/mcp-writer.ts:5–28  ·  view source on GitHub ↗
(text: string)

Source from the content-addressed store, hash-verified

3import { STDIO_PACKAGE } from "./agents.js";
4
5function stripJsonComments(text: string): string {
6 let result = "";
7 let i = 0;
8 while (i < text.length) {
9 if (text[i] === '"') {
10 const start = i++;
11 while (i < text.length && text[i] !== '"') {
12 if (text[i] === "\\") i++;
13 i++;
14 }
15 result += text.slice(start, ++i);
16 } else if (text[i] === "/" && text[i + 1] === "/") {
17 i += 2;
18 while (i < text.length && text[i] !== "\n") i++;
19 } else if (text[i] === "/" && text[i + 1] === "*") {
20 i += 2;
21 while (i < text.length && !(text[i] === "*" && text[i + 1] === "/")) i++;
22 i += 2;
23 } else {
24 result += text[i++];
25 }
26 }
27 return result;
28}
29
30export async function readJsonConfig(filePath: string): Promise<Record<string, unknown>> {
31 let raw: string;

Callers 1

readJsonConfigFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected