MCPcopy Create free account
hub / github.com/QodeXcli/QodeX / upsertLine

Method upsertLine

src/tools/network/network-optimize.ts:194–200  ·  view source on GitHub ↗

Insert or replace a single line in a config file (creating it if needed).

(file: string, matcher: RegExp, line: string)

Source from the content-addressed store, hash-verified

192
193 /** Insert or replace a single line in a config file (creating it if needed). */
194 private async upsertLine(file: string, matcher: RegExp, line: string): Promise<void> {
195 let body = '';
196 try { body = await fs.readFile(file, 'utf8'); } catch { /* new file */ }
197 if (matcher.test(body)) body = body.replace(matcher, line);
198 else body = (body && !body.endsWith('\n') ? body + '\n' : body) + line + '\n';
199 await fs.writeFile(file, body);
200 }
201}

Callers 1

applyOneMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected