lib/util.js
function parse(str) {

    let res = {};

    str.split(constants.REGEX.newline).map(line => {

        line = line.trim();

        // ignore empty lines and comments
        if (!line || line[0] === '#') {
            return;
        }

        // replace variables that are not escaped
        line = line.replace(constants.REGEX.args, (match, $1, $2) => {

            let key = $1 !== undefined ? $1 : $2;

            if (match.slice(0, 2) === '\\\\') {
                return match.slice(2);
            }

            return process.env[key] !== undefined ? process.env[key] : res[key];

        });

        // find the line split index based on the first occurence of = sign
        let index = line.indexOf('=') > -1 ? line.indexOf('=') : line.length;

        // get key/val and trim whitespace
        let key = line.slice(0, index).trim();
        let val = line.slice(index +1).trim();

        val = parseComment(val).replace(constants.REGEX.quotes, '');

        res[key] = unescape(val);

    });

    return res;

}
function parse(str) {

    let res = {};

    str.split(constants.REGEX.newline).map(line => {

        line = line.trim();

        // ignore empty lines and comments
        if (!line || line[0] === '#') {
            return;
        }

        // replace variables that are not escaped
        line = line.replace(constants.REGEX.args, (match, $1, $2) => {

            let key = $1 !== undefined ? $1 : $2;

            if (match.slice(0, 2) === '\\\\') {
                return match.slice(2);
            }

            return process.env[key] !== undefined ? process.env[key] : res[key];

        });

        // find the line split index based on the first occurence of = sign
        let index = line.indexOf('=') > -1 ? line.indexOf('=') : line.length;

        // get key/val and trim whitespace
        let key = line.slice(0, index).trim();
        let val = line.slice(index +1).trim();

        val = parseComment(val).replace(constants.REGEX.quotes, '');

        res[key] = unescape(val);

    });

    return res;

}
function parse ( str ) { let res = { } ; str . split ( constants . REGEX . newline ) . map ( line => { line = line . trim ( ) ; // ignore empty lines and comments if ( ! line || line [ 0 ] === '#' ) { return ; } // replace variables that are not escaped line = line . replace ( constants . REGEX . args , ( match , $1 , $2 ) => { let key = $1 !== undefined ? $1 : $2 ; if ( match . slice ( 0 , 2 ) === '\\\\' ) { return match . slice ( 2 ) ; } return process . env [ key ] !== undefined ? process . env [ key ] : res [ key ] ; } ) ; // find the line split index based on the first occurence of = sign let index = line . indexOf ( '=' ) > - 1 ? line . indexOf ( '=' ) : line . length ; // get key/val and trim whitespace let key = line . slice ( 0 , index ) . trim ( ) ; let val = line . slice ( index + 1 ) . trim ( ) ; val = parseComment ( val ) . replace ( constants . REGEX . quotes , '' ) ; res [ key ] = unescape ( val ) ; } ) ; return res ; }
parse a string and return an env object
parse a string and return an env object