From e918cf3ca647be91e38413f148f31b360b596ac6 Mon Sep 17 00:00:00 2001 From: Willem Date: Tue, 18 Jun 2019 09:51:14 -0500 Subject: [PATCH] Support empty lines and comments. In debug mode, show errors like: ``` [dotenv][DEBUG] did not match key and value when parsing line : [dotenv][DEBUG] did not match key and value when parsing line : # ``` Sometimes we need to add empty lines to separate groups of variables, or comment some of them. We don't want the debugger or the parser catch them. --- lib/main.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/main.js b/lib/main.js index 38f36f31..1b50270e 100644 --- a/lib/main.js +++ b/lib/main.js @@ -39,6 +39,11 @@ function parse (src /*: string | Buffer */, options /*: ?DotenvParseOptions */) // convert Buffers before splitting into lines and processing src.toString().split(NEWLINE).forEach(function (line, idx) { + line = line.trim() + // ignore empty and commented lines + if (line === '' || line[0] === '#') { + return + } // matching "KEY' and 'VAL' in 'KEY=VAL' const keyValueArr = line.match(RE_INI_KEY_VAL) // matched?