From 7b2c1954db4fcd0e6180eba12d8a8d28dc1a5329 Mon Sep 17 00:00:00 2001 From: Rickyc81 Date: Tue, 26 Aug 2025 17:34:39 +0200 Subject: [PATCH] feat(parser): add support for env inline comments --- src/index.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 7a68e27..f7ab657 100644 --- a/src/index.js +++ b/src/index.js @@ -190,7 +190,11 @@ class Dotenv { */ loadFile ({ file, silent }) { try { - return fs.readFileSync(file, 'utf8') + const content = fs.readFileSync(file, 'utf8') + return content + .split('\n') + .map(this.removeInlineComment) + .join('\n') } catch (err) { this.warn(`Failed to load ${file}.`, silent) return {} @@ -205,6 +209,12 @@ class Dotenv { warn (msg, silent) { !silent && console.warn(msg) } + + removeInlineComment (str) { + const hashIndex = str.indexOf('#') + if (hashIndex === -1) return str.trim() + return str.substring(0, hashIndex).trim() + } } export default Dotenv