-
Notifications
You must be signed in to change notification settings - Fork 0
/
datich.js
65 lines (44 loc) · 1.41 KB
/
datich.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
60
61
62
63
64
65
/**
* Modules dependencies
*/
var url = require('url');
var http = require('http');
var https = require('https');
var util = require('util');
var lib = {
"datich": require('./lib/datich.js')
};
for (var i = 2, c = 2; i < process.argv.length; i++) {
(function (i) {
var arg = process.argv[i];
// if help
if (arg === '--help' || arg == '-h') {
console.log('node datich.js [URL]... [VALUE]...');
// if it's an URL
} else if (/^http/.test(process.argv[i])) {
var urlToInspect = process.argv[i];
(url.parse(urlToInspect).protocol === 'http:' ? http : https)
.get(urlToInspect, function (res) {
var htmlReceived = '';
res.setEncoding('utf8');
res.on('data', function (chunk) {
htmlReceived += chunk;
});
res.on('end', function () {
console.log(res.statusCode + ' - ' + urlToInspect);
var dates = lib.datich(htmlReceived);
console.log(util.inspect(dates, {colors: true, depth: null}));
if (++c !== process.argv.length) console.log('\n');
});
}).on('error', function (err) {
console.error(err);
});
// if it's for testing a date
} else {
var str = process.argv[i];
var dates = lib.datich(str);
console.log(util.inspect(dates, {colors: true, depth: null}));
if (++c !== process.argv.length) console.log('\n');
}
})(i);
}