INNER CODE UNIT · TypeScript
requote
f5/unovis · packages/mcp/src/codegen/index.ts:49
function requote (jsonText: string): string {
let out = ''
let i = 0
while (i < jsonText.length) {
if (jsonText[i] !== '"') {
out += jsonText[i]
i += 1
continue
}
let end = i + 1
while (end < jsonText.length && jsonText[end] !== '"') end += jsonText[end] === '\\' ? 2 : 1
const body = jsonText.slice(i + 1, end)
out += body.includes("'") ? `"${body}"` : `'${body.replace(/\\"/g, '"')}'`
i = end + 1
}
return out.replace(/'([A-Za-z_$][\w$]*)':/g, '$1:') // unquote plain object keys
}