Skip to content

Commit

Permalink
remove semicolon
Browse files Browse the repository at this point in the history
  • Loading branch information
sapics committed Aug 27, 2024
1 parent bf01c6d commit 768ae0d
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 52 deletions.
34 changes: 17 additions & 17 deletions lib/fsWatcher.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var fs = require('fs'),
path = require('path'),
FSWatcher = {};
FSWatcher = {}

/**
* Takes a directory/file and watch for change. Upon change, call the
Expand All @@ -14,44 +14,44 @@ var fs = require('fs'),
* @param {Function} callback: function () : called when changes are detected
**/
function makeFsWatchFilter(name, directory, filename, cooldownDelay, callback) {
var cooldownId = null;
var cooldownId = null

//Delete the cooldownId and callback the outer function
function timeoutCallback() {
cooldownId = null;
callback();
cooldownId = null
callback()
}

//This function is called when there is a change in the data directory
//It sets a timer to wait for the change to be completed
function onWatchEvent(event, changedFile) {
var filePath = path.join(directory, changedFile);
var filePath = path.join(directory, changedFile)

if (!filename || filename === changedFile) {
if(!fs.existsSync(filePath)) return;
if(!fs.existsSync(filePath)) return
//If a cooldownId already exists, we delete it
if (cooldownId !== null) {
clearTimeout(cooldownId);
cooldownId = null;
clearTimeout(cooldownId)
cooldownId = null
}

//Once the cooldownDelay has passed, the timeoutCallback function will be called
cooldownId = setTimeout(timeoutCallback, cooldownDelay);
cooldownId = setTimeout(timeoutCallback, cooldownDelay)
}
}

//Manage the case where filename is missing (because it's optionnal)
if (typeof cooldownDelay === 'function') {
callback = cooldownDelay;
cooldownDelay = filename;
filename = null;
callback = cooldownDelay
cooldownDelay = filename
filename = null
}

if (FSWatcher[name]) {
stopWatching(name);
stopWatching(name)
}

FSWatcher[name] = fs.watch(directory, onWatchEvent);
FSWatcher[name] = fs.watch(directory, onWatchEvent)
}

/**
Expand All @@ -61,8 +61,8 @@ function makeFsWatchFilter(name, directory, filename, cooldownDelay, callback) {
*
**/
function stopWatching(name) {
FSWatcher[name].close();
FSWatcher[name].close()
}

module.exports.makeFsWatchFilter = makeFsWatchFilter;
module.exports.stopWatching = stopWatching;
module.exports.makeFsWatchFilter = makeFsWatchFilter
module.exports.stopWatching = stopWatching
8 changes: 4 additions & 4 deletions lib/geoip.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ function lookup4(ip) {
}
}
fline = cline * start / fastLookupNum | 0
cline = cline * end / fastLookupNum | 0;
cline = cline * end / fastLookupNum | 0

for(;;) {
line = fline + cline >> 1
Expand Down Expand Up @@ -208,7 +208,7 @@ function lookup6(ip) {
}
}
fline = cline * start / fastLookupNum | 0
cline = cline * end / fastLookupNum | 0;
cline = cline * end / fastLookupNum | 0

for(;;) {
line = fline + cline >> 1
Expand All @@ -219,7 +219,7 @@ function lookup6(ip) {
cline = line
continue
}

if(buffer.readBigUInt64BE(offset + 8) < ip){
if(fline === line) {
return null
Expand Down Expand Up @@ -473,7 +473,7 @@ module.exports = {
})
},

// Start watching for data updates. The watcher waits one minute for file transfer to
// Start watching for data updates. The watcher waits one minute for file transfer to
// completete before triggering the callback.
startWatchingDataUpdate: function (callback) {
fsWatcher.makeFsWatchFilter(watcherName, geodatadir, 60*1000, function () {
Expand Down
54 changes: 27 additions & 27 deletions lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,63 +1,63 @@
var utils = module.exports = {};
var utils = module.exports = {}

utils.fieldsSize = function(types){
var size = 0;
var size = 0
for(var type of types){
switch(type){
case 'postcode':
size += 5
break;
break
case 'area':
size += 2;
break;
size += 2
break
default:
size += 4;
break;
size += 4
break
}
}
return size
}

utils.aton4 = function(a) {
a = a.split(/\./);
return ((parseInt(a[0], 10)<<24)>>>0) + ((parseInt(a[1], 10)<<16)>>>0) + ((parseInt(a[2], 10)<<8)>>>0) + (parseInt(a[3], 10)>>>0);
};
a = a.split(/\./)
return ((parseInt(a[0], 10)<<24)>>>0) + ((parseInt(a[1], 10)<<16)>>>0) + ((parseInt(a[2], 10)<<8)>>>0) + (parseInt(a[3], 10)>>>0)
}

utils.aton6 = function(a) {
a = a.replace(/"/g, '').split(/:/);
a = a.replace(/"/g, '').split(/:/)

var l = a.length - 1;
var i;
var l = a.length - 1
var i

if (a[l] === '') a[l] = 0;
if (a[l] === '') a[l] = 0

if (l < 7) {
var omitted = 8 - a.length, omitStart = a.indexOf(''), omitEnd = omitStart + omitted;
var omitted = 8 - a.length, omitStart = a.indexOf(''), omitEnd = omitStart + omitted
for(i = 7; i >= omitStart; i--){
a[i] = i > omitEnd ? a[i - omitted] : 0;
a[i] = i > omitEnd ? a[i - omitted] : 0
}
}

var r = 0n;
var r = 0n
for (i = 0; i < 4; i++) {
if(a[i]) {
r += BigInt(parseInt(a[i], 16)) << BigInt(16 * (3 - i));
r += BigInt(parseInt(a[i], 16)) << BigInt(16 * (3 - i))
}
}
return r;
};
return r
}
utils.isPrivateIP = function(addr) {
addr = addr.toString();
addr = addr.toString()
return addr.match(/^10\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/) != null ||
addr.match(/^192\.168\.([0-9]{1,3})\.([0-9]{1,3})/) != null ||
addr.match(/^172\.16\.([0-9]{1,3})\.([0-9]{1,3})/) != null ||
addr.match(/^127\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/) != null ||
addr.match(/^169\.254\.([0-9]{1,3})\.([0-9]{1,3})/) != null ||
addr.match(/^fc00:/) != null || addr.match(/^fe80:/) != null;
};
addr.match(/^fc00:/) != null || addr.match(/^fe80:/) != null
}

utils.ntoa4 = function(n) {
n = n.toString();
n = '' + (n>>>24&0xff) + '.' + (n>>>16&0xff) + '.' + (n>>>8&0xff) + '.' + (n&0xff);
return n;
};
n = n.toString()
n = '' + (n>>>24&0xff) + '.' + (n>>>16&0xff) + '.' + (n>>>8&0xff) + '.' + (n&0xff)
return n
}
7 changes: 3 additions & 4 deletions scripts/updatedb.js
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,6 @@ function processCountryDataIpLocationDb(src, fileName, srcUrl, cb) {
if(!datFile.write(b)){
rl.pause()
}
preCC = cc
}
}

Expand Down Expand Up @@ -749,7 +748,7 @@ function processCityDataNamesEn(src, dest, cb) {
}
}
var rl = readline.createInterface({
input: fs.createReadStream(tmpDataFile),
input: fs.createReadStream(tmpDataFile),
crlfDelay: Infinity
})
rl.on('line', processLine)
Expand Down Expand Up @@ -830,7 +829,7 @@ function processCityDataNames(src, dest, cb) {

var datFile = fs.createWriteStream(dataFile, {highWaterMark: 1024 * 1024})
var rl = readline.createInterface({
input: fs.createReadStream(tmpDataFile, {highWaterMark: 1024 * 1024}),
input: fs.createReadStream(tmpDataFile, {highWaterMark: 1024 * 1024}),
crlfDelay: Infinity
})
rl.on('line', processLine)
Expand Down Expand Up @@ -942,7 +941,7 @@ if(ip_location_db){

console.log('Fetching new databases from MaxMind...')
console.log('Storing files at ' + dataPath)

async.eachSeries(databases, function(database, nextDatabase) {
if(isDebug){
async.seq(processData)(database, nextDatabase)
Expand Down

0 comments on commit 768ae0d

Please sign in to comment.