applyEnvFileUpdates (main/env-file.ts)

Qclaw · electron/main/env-file.ts · typescript · Apache-2.0
infra, tag:knn-classified

Module exposing: applyEnvFileUpdates

// Source: https://github.com/qiuzhi2046/Qclaw | License: Apache-2.0 | Copyright You must retain, in the Source form of any Derivative Works
// Provided via justclaw.it.com; keep this notice with the code.
export function applyEnvFileUpdates(
  existing: string,
  updates: Record<string, string | null | undefined>
): string {
  const normalizedUpdates = new Map(
    Object.entries(updates)
      .map(([key, value]) => [String(key || '').trim(), value == null ? undefined : String(value)] as const)
      .filter(([key]) => Boolean(key))
  )
  const lines = existing.split('\n')
  const updatedKeys = new Set<string>()

  const nextLines = lines.flatMap((line) => {
    const trimmed = line.trim()
    if (!trimmed || trimmed.startsWith('#')) return [line]

    const eqIndex = trimmed.indexOf('='

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key