UNPKG

1.11 kBJavaScriptView Raw
1'use strict';
2var fs = require('fs');
3// Read bot list from user-agents.org
4var botlist = require('./botlist.json');
5// Read custom bot list
6var custombotlist = require('./customBotlist.json');
7
8var ua_list = {};
9var exports = module.exports = {};
10
11var printList = function() {
12 console.log(ua_list);
13}
14exports.printList = printList;
15
16var uaCount = function(callback) {
17 callback(Object.keys(ua_list).length);
18}
19exports.uaCount = uaCount;
20
21var isBot = function(ua_string) {
22 if (ua_list[ua_string]) {
23 return true;
24 }
25 return false;
26}
27exports.isBot = isBot;
28
29var loadBotList = function(callback) {
30 ua_list = botlist;
31 for (var attrname in custombotlist) {
32 ua_list[attrname] = custombotlist[attrname];
33 }
34 callback(null);
35}
36// Added so that tests would wait until the bot list is loaded before executing
37exports.loadBotList = loadBotList;
38
39loadBotList(function() {
40 uaCount(function(count) {
41 if (count === 0) {
42 console.log("WARNING: No bot list loaded. Bot list count is 0");
43 } else {
44 console.log("Bot detector loaded. Bot list count: " + count);
45 }
46 });
47});