Files
yaak/apps/yaak-client/lib/jsonComments.ts
Gregory Schier 6600116b1a Merge branch 'main' into wip/yaak-proxy-foundation
# Conflicts:
#	apps/yaak-client/components/JsonBodyEditor.tsx
#	apps/yaak-client/lib/jsonComments.ts
#	package-lock.json
#	packages/theme/src/window.ts
#	packages/ui/src/components/HeaderSize.tsx
2026-03-11 15:36:57 -07:00

31 lines
792 B
TypeScript

/**
* Simple heuristic to detect if a string likely contains JSON/JSONC comments.
* Checks for // and /* patterns that are NOT inside double-quoted strings.
* Used for UI hints only — doesn't need to be perfect.
*/
export function textLikelyContainsJsonComments(text: string): boolean {
let inString = false;
for (let i = 0; i < text.length; i++) {
const ch = text[i];
if (inString) {
if (ch === '"') {
inString = false;
} else if (ch === '\\') {
i++; // skip escaped char
}
continue;
}
if (ch === '"') {
inString = true;
continue;
}
if (ch === '/' && i + 1 < text.length) {
const next = text[i + 1];
if (next === '/' || next === '*') {
return true;
}
}
}
return false;
}