Skip to content

Commit

Permalink
Merge 7e2b2d3 into ad86907
Browse files Browse the repository at this point in the history
  • Loading branch information
florisvink committed Mar 26, 2018
2 parents ad86907 + 7e2b2d3 commit be34231
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ The parsing engine currently supports the following rules:
- `BASIC=basic` becomes `{BASIC: 'basic'}`
- empty lines are skipped
- lines beginning with `#` are treated as comments
- export statements `export KEY=value` will be processed as it was `KEY=value`
- empty values become empty strings (`EMPTY=` becomes `{EMPTY: ''}`)
- single and double quoted values are escaped (`SINGLE_QUOTE='quoted'` becomes `{SINGLE_QUOTE: "quoted"}`)
- new lines are expanded if in double quotes (`MULTILINE="new\nline"` becomes
Expand Down
5 changes: 5 additions & 0 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ function parse (src) {

// convert Buffers before splitting into lines and processing
src.toString().split('\n').forEach(function (line) {
// remove export statemet "export " from beginning of line
if (line.substring(0, 7).toLowerCase() === 'export ') {
line = line.substring(7)
}

// matching "KEY' and 'VAL' in 'KEY=VAL'
const keyValueArr = line.match(/^\s*([\w\.\-]+)\s*=\s*(.*)?\s*$/)
// matched?
Expand Down
1 change: 1 addition & 0 deletions test/.env
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ RETAIN_INNER_QUOTES={"foo": "bar"}
RETAIN_INNER_QUOTES_AS_STRING='{"foo": "bar"}'
INCLUDE_SPACE=some spaced out string
USERNAME="therealnerdybeast@example.tld"
export EXPORT_STATEMENT="should be stripped"
5 changes: 5 additions & 0 deletions test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,5 +193,10 @@ describe('dotenv', function () {
parsed.should.have.property('USERNAME', 'therealnerdybeast@example.tld')
done()
})

it('remove export statement from beginning', function (done) {
parsed.should.have.property('EXPORT_STATEMENT', 'should be stripped')
done()
})
})
})

0 comments on commit be34231

Please sign in to comment.