Skip to content

Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors

803 B
Raw Blame
/**
 * Parse a `.env` value with dotenv-compatible comment handling.
 *
 * Without this, `KEY=value  # note` stored the comment text as part of the
 * value. The shipped .env ships exactly such a line for QUOTA_STORE_DRIVER, and
 * consumers compare it with `===`, so annotating a variable inline silently
 * disabled it (#10100).
 *
 * Quoted values are returned verbatim — a `#` inside quotes is data. For
 * unquoted values a `#` *preceded by whitespace* starts a comment, so
 * `pass#word` is preserved.
 */
export function parseEnvValue(raw) {
  const value = String(raw).trim();

  const quoted = value.match(/^(['"])([\s\S]*)\1\s*(?:#.*)?$/);
  if (quoted) return quoted[2];

  const commentIdx = value.search(/\s#/);
  return (commentIdx === -1 ? value : value.slice(0, commentIdx)).trim();
}