-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRHPCO-JStrings.js
40 lines (38 loc) · 981 Bytes
/
RHPCO-JStrings.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
/**
* RHPCO-JStrings - Extracts all Literal from an input javascript file
* rakkapriccio@gmail.com
*
* Usage:
* $ node RHPCO-JStrings.js input_file.js
*/
var fs = require('fs');
var async = require('async');
var esprima = require('esprima');
var estraverse = require('estraverse');
function listStrings(code){
var strings=[];
var ast = esprima.parse(code);
estraverse.traverse(ast, {
enter: function(node){
if (node.type === 'Literal' ){
strings.push(node.value);
}
}
});
return strings;
}
try{
if( typeof process.argv[2] != null ){
fs.readFile(process.argv[2], 'utf8', function (err,data) {
if (err) {
return console.log(err.message);
}
results = listStrings(data);
results.forEach(function(s){
console.log(s);
})
});
}
}catch(err){
console.log("Sorry :( \n"+err.message);
}