Comparing version 1.0.3 to 1.0.4
@@ -11,66 +11,54 @@ | ||
exports.init = function(path) { | ||
_defaultDB = new mmdb.MMDB(path || _defaultPath); | ||
return _defaultDB; | ||
_defaultDB = new mmdb.MMDB(path || _defaultPath); | ||
return _defaultDB; | ||
} | ||
exports.cleanup = function() { | ||
_defaultDB = null; | ||
_defaultDB = null; | ||
} | ||
exports.lookup = function(address, callback) { | ||
if (!_defaultDB) { | ||
console.log("WARNING: ipgeo2 database not initialized, initializing default now."); | ||
exports.init(); | ||
} | ||
_defaultDB.lookup(address, callback); | ||
if (!_defaultDB) { | ||
console.log("WARNING: ipgeo2 database not initialized, initializing default now."); | ||
exports.init(); | ||
} | ||
_defaultDB.lookup(address, callback); | ||
} | ||
exports.lookupSync = function(address) { | ||
if (!_defaultDB) { | ||
console.log("WARNING: ipgeo2 database not initialized, initializing default now."); | ||
exports.init(); | ||
} | ||
return _defaultDB.lookupSync(address); | ||
if (!_defaultDB) { | ||
console.log("WARNING: ipgeo2 database not initialized, initializing default now."); | ||
exports.init(); | ||
} | ||
return _defaultDB.lookupSync(address); | ||
} | ||
function parseResult(result) { | ||
return { | ||
country: result.country ? result.country.iso_code : undefined, | ||
continent: result.continent ? result.continent.code : undefined, | ||
postal: result.postal ? result.postal.code : undefined, | ||
city: result.city && result.city.names ? result.city.names.en : undefined, | ||
location: result.location, | ||
subdivision: result.subdivisions ? result.subdivisions[0].iso_code : undefined | ||
}; | ||
return { | ||
country: result.country ? result.country.iso_code : undefined, | ||
continent: result.continent ? result.continent.code : undefined, | ||
postal: result.postal ? result.postal.code : undefined, | ||
city: result.city && result.city.names ? result.city.names.en : undefined, | ||
location: result.location, | ||
subdivision: result.subdivisions ? result.subdivisions[0].iso_code : undefined | ||
}; | ||
} | ||
exports.lookupSimple = function(address, callback) { | ||
exports.lookup(address, function(error, result) { | ||
if (result) { | ||
callback(null, parseResult(result)); | ||
} | ||
else { | ||
callback(error, null); | ||
} | ||
}); | ||
exports.lookup(address, function(error, result) { | ||
if (result) { | ||
callback(null, parseResult(result)); | ||
} | ||
else { | ||
callback(error, null); | ||
} | ||
}); | ||
} | ||
exports.lookupSimpleSync = function(address) { | ||
var result = exports.lookupSync(address); | ||
if (result) { | ||
return parseResult(result); | ||
} | ||
return null; | ||
var result = exports.lookupSync(address); | ||
if (result) { | ||
return parseResult(result); | ||
} | ||
return null; | ||
} |
{ | ||
"name": "geoip2", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "Maxmind GeoIP2 database reader for geolocating ip addresses. Fast native implementation by wrapping libmaxminddb.", | ||
@@ -9,11 +9,13 @@ "main": "./node-geoip2.js", | ||
"keywords": [ | ||
"geoip", | ||
"geoip2", | ||
"geolocation", | ||
"maxmind", | ||
"mmdb", | ||
"maxminddb", | ||
"geoip", | ||
"geoip2", | ||
"geo", | ||
"geolocation", | ||
"ip" | ||
], | ||
"scripts": { | ||
"test": "./node_modules/.bin/mocha" | ||
}, | ||
"repository": { | ||
@@ -25,3 +27,7 @@ "type": "git", | ||
"nan": "2.3.3" | ||
}, | ||
"devDependencies": { | ||
"mocha": "^2.5.1", | ||
"chai": "^3.5.0" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
65694823
96
96
2