-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
49 lines (33 loc) · 1.02 KB
/
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
47
48
'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
//extract variable name, trimming whitespace
line = line.replace(/^\s*(.*?)\s*=/, '$1=')
//remove the optional export keyword before variable name
line = line.replace(/^(?:export\s)?\s*(.*?)=/, '$1=')
//extract variable value, trimming whitespace
line = line.replace(/^(.*?)=\s*(.*?)\s*$/, '$1=$2')
self.emit('data', line)
})
}
var end = function end () {
this.emit('end')
}
module.exports = function () {
return through(write, end)
}