UNPKG

@anyme/anymejs

Version:
48 lines (45 loc) 1.84 kB
'use strict'; var require$$0$1 = require('node:fs'); var require$$0 = require('node:path'); (function env(path) { const parse = (path) => { const envContent = require$$0$1.readFileSync(path, "utf8").replace(/^\uFEFF/, ""); const lines = envContent.split(/\r?\n/); for (const line of lines) { const trimmedLine = line.trim(); if (!trimmedLine || trimmedLine.startsWith("#")) continue; const sepIndex = trimmedLine.indexOf("="); if (sepIndex === -1) continue; const key = line.slice(0, sepIndex).trim(); if (!key) continue; let value = trimmedLine.slice(sepIndex + 1).trim(); const commentIndex = value.indexOf("#"); if (commentIndex !== -1) value = value.slice(0, commentIndex).trim(); if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'"))) { const quoteChar = value[0]; value = value.slice(1, -1); if (quoteChar === '"') { value = value.replace(/\\"/g, '"').replace(/\\\\/g, "\\"); } else { value = value.replace(/\\'/g, "'").replace(/\\\\/g, "\\"); } } if (typeof process !== "undefined" && !(key in process.env)) process.env[key] = value; } }; const absolutePath = require$$0.isAbsolute(path) ? path : require$$0.resolve(path); if (!require$$0$1.existsSync(absolutePath)) return; if (typeof process?.loadEnvFile === "function") process.loadEnvFile(absolutePath); else parse(absolutePath); })(".env"); //# sourceMappingURL=env.js.map