forked from digitalsadhu/env-reader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
47 lines (31 loc) · 867 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
'use strict';
var through = require('through')
var write = function write(chunk) {
var self = this
//read each line
var data = chunk.toString('utf8')
var lines = data.split('\n')
lines.forEach(function (line) {
//generic catch all
if (!line) return
//skip empty lines
if (line.match(/^\s*$/)) return
//skip lines starting with comments
if (line.match(/^\s*#.*$/)) return
//skip lines that start with =
if (line.match(/^\s*=.*$/)) return
//skip lines that dont have an =
if (!line.match(/^.*=.*$/)) return
//trim spaces
line = line.replace(/\s*=\s*/, '=')
line = line.replace(/^\s*(.*)\s*=\s*(.*)$/, '$1=$2')
line = line.replace(/\s$/, '')
self.emit('data', line)
})
}
var end = function end () {
this.emit('end')
}
module.exports = function () {
return through(write, end)
}