UNPKG

@deploystack/docker-to-iac

Version:

Translate docker run and docker compose file to Infrastructure as Code

28 lines (27 loc) 900 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseEnvFile = parseEnvFile; function parseEnvFile(content) { const env = {}; const lines = content.split('\n'); for (let line of lines) { line = line.split('#')[0].trim(); // Skip empty lines if (!line) continue; // Split on first equals sign (to handle values containing =) const separatorIndex = line.indexOf('='); if (separatorIndex === -1) continue; const key = line.slice(0, separatorIndex).trim(); let value = line.slice(separatorIndex + 1).trim(); if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith('\'') && value.endsWith('\''))) { value = value.slice(1, -1); } if (key) { env[key] = value; } } return env; }