@stackmemoryai/stackmemory
Version:
Lossless, project-scoped memory for AI coding tools. Durable context across sessions with 56 MCP tools, FTS5 search, conductor orchestrator, loop/watch monitoring, snapshot capture, pre-flight overlap checks, Claude/Codex/OpenCode wrappers, Linear sync, a
50 lines (49 loc) • 1.38 kB
JavaScript
import { fileURLToPath as __fileURLToPath } from 'url';
import { dirname as __pathDirname } from 'path';
const __filename = __fileURLToPath(import.meta.url);
const __dirname = __pathDirname(__filename);
function getEnv(key, defaultValue) {
const value = process.env[key];
if (!value && !defaultValue) {
throw new Error(`Environment variable ${key} is required but not set`);
}
return value || defaultValue || "";
}
function getOptionalEnv(key, defaultValue) {
return process.env[key] || defaultValue;
}
function getRequiredEnv(key) {
const value = process.env[key];
if (!value) {
throw new Error(`Environment variable ${key} is required but not set`);
}
return value;
}
function getBooleanEnv(key, defaultValue = false) {
const value = process.env[key];
if (!value) return defaultValue;
return value.toLowerCase() === "true" || value === "1";
}
function getNumberEnv(key, defaultValue) {
const value = process.env[key];
if (!value) {
if (defaultValue === void 0) {
throw new Error(`Environment variable ${key} is required but not set`);
}
return defaultValue;
}
const num = parseInt(value, 10);
if (isNaN(num)) {
throw new Error(
`Environment variable ${key} must be a number, got: ${value}`
);
}
return num;
}
export {
getBooleanEnv,
getEnv,
getNumberEnv,
getOptionalEnv,
getRequiredEnv
};