-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·63 lines (43 loc) · 1.22 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
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env node
const fs = require('fs');
const program = require('commander');
program
.version('3.0.0')
.usage('-f <file>')
.option('-f, --file [file]', "the cookies file")
.version('3.0.0', '-v, --version')
program.on('--help', function(){
console.log('');
console.log('Examples:');
console.log(' $ cookie2json -f cookies.txt');
});
program.parse(process.argv);
if (!program.file) {
program.outputHelp();
process.exit(1);
}
const file = fs.readFileSync(program.file, {encoding: 'utf-8'});
function run(str) {
var arrayOfLines = str.split("\n");
var i = 0;
var arrObjects = [];
for (i=0; i<arrayOfLines.length; i++){
var kuka = arrayOfLines[i].split("\t");
var cook = new Object();
cook.domain = kuka[0];
cook.expirationDate = parseInt(kuka[4]);
if (kuka[1] == "FALSE") cook.httpOnly = false;
if (kuka[1] == "TRUE") cook.httpOnly = true;
cook.name = kuka[5];
cook.path = kuka[2];
if (kuka[3] == "FALSE") cook.secure = false;
if (kuka[3] == "TRUE") cook.secure = true;
cook.value = kuka[6];
if (cook.domain !== '') {
arrObjects[i] = cook;
}
}
return JSON.stringify(arrObjects, null, 2);
}
// run(file)
console.log(run(file));