UNPKG

parse-dotenv

Version:

Zero dependency .env to object parser

3 lines (2 loc) 558 B
import{resolve as t}from"path";import{readFileSync as r}from"fs";var n=t(process.cwd(),".env");export default function(t,e){void 0===e&&(e={emptyLines:!1});try{var o=r(t||n,{encoding:"UTF-8"}),i={},c=0,f=0;return o.split("\n").map(function(t){return e.comments&&t.startsWith("#")?["__COMMENT_"+(f+=1)+"__",t]:t?t.split("=").map(function(t){return t.trim()}):e.emptyLines?["__EMPTYLINE_"+(c+=1)+"__",""]:[""]}).filter(function(t){return t.length>1}).forEach(function(t){i[t[0]]=t[1]}),i}catch(t){throw new Error(t)}} //# sourceMappingURL=parse-dotenv.mjs.map