-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
45 lines (34 loc) · 993 Bytes
/
utils.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
const readline = require('readline');
const fs = require('fs');
module.exports = {readInputFromFile: readInputFromFile, extractDependenciesList:extractDependenciesList };
function readInputFromFile(source, callback) {
fs.readFile(source, 'utf8', function (err, data) {
if (err) {
throw err;
}
callback(data);
});
}
function extractDependenciesList(filePath, callback){
var dependenciesArray = [];
var parsedDependenciesList = [];
var re = /.*@[0-9.]+/i;
const rl = readline.createInterface({
input: fs.createReadStream(filePath),
crlfDelay: Infinity
});
rl.on('line', (line) => {
if(line.match(re)){
dependenciesArray.push(line);
}
});
rl.on('close', () => {
dependenciesArray.forEach((dep) => {
var re = /(.*)@(.*)/i;
dep.replace(re, function(match, name, version) {
parsedDependenciesList.push({name:name, version:version});
});
});
callback(parsedDependenciesList);
})
}