forked from coolaj86/tel-carrier-db
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-bulk.js
41 lines (33 loc) · 847 Bytes
/
test-bulk.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
'use strict';
var fs = require('fs')
, telDb = require('./tel-carrier-db')
, filepath = process.argv[2]
, tried = {}
;
if (!filepath) {
console.log('Usage: node test-bulk ./path/to/file.txt');
return;
}
fs.readFile(filepath, 'utf8', function (err, data) {
var lines
;
lines = data.trim().split(/[,\n]/g);
lines.forEach(function (line) {
var num = /(?=\D|\b)(?=\+?1[\-\.\s]?)?\s*[\-\.\s\(]?\s*(\d{3})\s*[\-\.\s\)]?\s*(\d{3})\s*[\-\.\s]?\s*(\d{4})(?=\D|\b)/.exec(line)
, info
;
if (!num) {
console.log(line, 'is bunk');
return;
}
if (tried[num[1].toString() + num[2] + num[3]]) {
return;
}
info = telDb.lookup('1', num[1], num[2], num[3]);
if (!info) {
return;
}
tried[num[1].toString() + num[2] + num[3]] = true;
console.log(info);
});
});