Comparing version 0.1.2 to 0.1.4
@@ -1,5 +0,4 @@ | ||
var fs = require('fs'), | ||
Buffer = require('buffer').Buffer; | ||
var fs = require('fs'); | ||
// http://docs.oracle.com/javase/6/docs/api/java/io/RandomAccessFile.html | ||
// http://docs.oracle.com/javase/6/docs/api/java/io/RandomAccessFile.html | ||
@@ -9,3 +8,3 @@ function Buff(path) { | ||
this.ba = fs.openSync(path, 'r'); | ||
}; | ||
} | ||
Buff.prototype.ba = null; | ||
@@ -40,3 +39,2 @@ Buff.prototype.meta = null; | ||
module.exports = Buff; | ||
module.exports = Buff; |
@@ -1,2 +0,1 @@ | ||
/** | ||
@@ -8,3 +7,3 @@ * Creates a new Country. | ||
*/ | ||
function Country(code, name) { | ||
module.exports = function(code, name) { | ||
@@ -21,3 +20,3 @@ this.code = code; | ||
return this.code; | ||
} | ||
}; | ||
@@ -31,5 +30,3 @@ /** | ||
return this.name; | ||
} | ||
} | ||
module.exports = Country; | ||
}; | ||
}; |
@@ -1,6 +0,5 @@ | ||
function DatabaseInfo(info) { | ||
module.exports = function(info) { | ||
var _info = info.toString(); | ||
this.getType = function() { | ||
if (_info == null || _info == "") { | ||
if (!_info) { | ||
return module.exports.COUNTRY_EDITION; | ||
@@ -11,3 +10,3 @@ } else { | ||
// databases from April 2003 and earlier. | ||
return parseInt(_info.substring(4, 7)) - 105; | ||
return parseInt(_info.substring(4, 7), 10) - 105; | ||
} | ||
@@ -20,3 +19,3 @@ }; | ||
for (var i = 0; i < _info.length - 9; i++) { | ||
if (_info.charCodeAt(i) == 0x20) | ||
if (_info.charCodeAt(i) === 0x20) | ||
return new Date( | ||
@@ -33,4 +32,2 @@ _info.substring(i+1, i+9) | ||
module.exports = DatabaseInfo; | ||
module.exports.COUNTRY_EDITION = 1; | ||
@@ -37,0 +34,0 @@ module.exports.REGION_EDITION_REV0 = 7; |
@@ -22,2 +22,2 @@ function DynBuffer(source, offset, length) { | ||
module.exports = DynBuffer; | ||
module.exports = DynBuffer; |
@@ -1,2 +0,1 @@ | ||
const EARTH_DIAMETER = 2 * 6378.2; | ||
@@ -6,16 +5,16 @@ const PI = 3.14159265; | ||
function Location() { | ||
this.countryCode; | ||
this.countryName; | ||
this.region; | ||
this.city; | ||
this.postalCode; | ||
this.latitude; | ||
this.longitude; | ||
this.dma_code; | ||
this.area_code; | ||
this.metro_code; | ||
module.exports = function() { | ||
this.countryCode = null; | ||
this.countryName = null; | ||
this.region = null; | ||
this.city = null; | ||
this.postalCode = null; | ||
this.latitude = null; | ||
this.longitude = null; | ||
this.dmaCode = null; | ||
this.areaCode = null; | ||
this.metroCode = null; | ||
this.distance = function(loc) { | ||
var delta_lat, delta_lon; | ||
var temp; | ||
@@ -33,13 +32,9 @@ | ||
// find the deltas | ||
delta_lat = lat2 - lat1; | ||
delta_lon = (lon2 - lon1) * RAD_CONVERT; | ||
var deltaLat = lat2 - lat1; | ||
var deltaLon = (lon2 - lon1) * RAD_CONVERT; | ||
// Find the great circle distance | ||
temp = Math.pow(Math.sin(delta_lat/2),2) + Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(delta_lon/2),2); | ||
return Math.round(EARTH_DIAMETER * Math.atan2(Math.sqrt(temp),Math.sqrt(1-temp)) * 1e6) / 1e6; | ||
temp = Math.pow(Math.sin(deltaLat/2),2) + Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(deltaLon/2), 2); | ||
return Math.round(EARTH_DIAMETER * Math.atan2(Math.sqrt(temp), Math.sqrt(1-temp)) * 1e6) / 1e6; | ||
}; | ||
}; | ||
module.exports = Location; | ||
@@ -1,2 +0,1 @@ | ||
var Buff = require('./buff'), | ||
@@ -101,5 +100,4 @@ DatabaseInfo = require('./database_info'), | ||
var recordLength = 0; | ||
var index_cache = new Buffer(0); | ||
var databaseInfo = null; | ||
var last_netmask; | ||
var indexCache = new Buffer(0); | ||
var lastNetmask; | ||
var file; | ||
@@ -117,3 +115,3 @@ var dbbuffer; | ||
var read = file.readFully(delim); | ||
if (read == 3 && (delim[0]&0xFF) == 255 && (delim[1]&0xFF) == 255 && (delim[2]&0xFF) == 255) { | ||
if (read === 3 && (delim[0]&0xFF) === 255 && (delim[1]&0xFF) === 255 && (delim[2]&0xFF) === 255) { | ||
hasStructureInfo = true; | ||
@@ -133,5 +131,5 @@ break; | ||
// Find the database info string. | ||
for (var i = 0; i < DATABASE_INFO_MAX_SIZE; i++) { | ||
for (i = 0; i < DATABASE_INFO_MAX_SIZE; i++) { | ||
file.readFully(delim); | ||
if (delim[0] == 0 && delim[1] == 0 && delim[2] == 0) { | ||
if (delim[0] + delim[1] + delim[2] === 0) { | ||
var dbInfo = new Buffer(i); | ||
@@ -144,3 +142,3 @@ file.readFully(dbInfo); | ||
return null; | ||
}; | ||
} | ||
@@ -152,11 +150,11 @@ module.exports.ip2Long = function(ip) { | ||
ip[0] = parseInt(ip[0]) >> 0; | ||
ip[1] = parseInt(ip[1]) >> 0; | ||
ip[2] = parseInt(ip[2]) >> 0; | ||
ip[3] = parseInt(ip[3]) >> 0; | ||
ip[0] = parseInt(ip[0], 10) >> 0; | ||
ip[1] = parseInt(ip[1], 10) >> 0; | ||
ip[2] = parseInt(ip[2], 10) >> 0; | ||
ip[3] = parseInt(ip[3], 10) >> 0; | ||
return ip[0] * (c === 1 || 16777216) | ||
+ ip[1] * (c <= 2 || 65536) | ||
+ ip[2] * (c <= 3 || 256) | ||
+ ip[3] * 1; | ||
return ip[0] * (c === 1 || 16777216) + | ||
ip[1] * (c <= 2 || 65536) + | ||
ip[2] * (c <= 3 || 256) + | ||
ip[3] * 1; | ||
}; | ||
@@ -170,3 +168,3 @@ | ||
// already initialized | ||
if (path == this.path && this.inited) | ||
if (path === this.path && this.inited) | ||
return true; | ||
@@ -186,7 +184,7 @@ | ||
var i, j; | ||
var i, j, l; | ||
var delim = new Buffer(3); | ||
var buf = new Buffer(SEGMENT_RECORD_LENGTH); | ||
if (file == null) | ||
if (!file) | ||
throw new Error('Invalid file'); | ||
@@ -199,3 +197,3 @@ | ||
if (delim.readInt8(0) == -1 && delim.readInt8(1) == -1 && delim.readInt8(2) == -1) { | ||
if (delim.readInt8(0) === -1 && delim.readInt8(1) === -1 && delim.readInt8(2) === -1) { | ||
databaseType = file.readByte(); | ||
@@ -209,35 +207,35 @@ | ||
// Determine the database type. | ||
if (databaseType == DatabaseInfo.REGION_EDITION_REV0) { | ||
if (databaseType === DatabaseInfo.REGION_EDITION_REV0) { | ||
databaseSegment = STATE_BEGIN_REV0; | ||
recordLength = STANDARD_RECORD_LENGTH; | ||
} else if (databaseType == DatabaseInfo.REGION_EDITION_REV1){ | ||
} else if (databaseType === DatabaseInfo.REGION_EDITION_REV1){ | ||
databaseSegment = STATE_BEGIN_REV1; | ||
recordLength = STANDARD_RECORD_LENGTH; | ||
} else if (databaseType == DatabaseInfo.CITY_EDITION_REV0 || | ||
databaseType == DatabaseInfo.CITY_EDITION_REV1 || | ||
databaseType == DatabaseInfo.ORG_EDITION || | ||
databaseType == DatabaseInfo.ORG_EDITION_V6 || | ||
databaseType == DatabaseInfo.ISP_EDITION || | ||
databaseType == DatabaseInfo.ISP_EDITION_V6 || | ||
databaseType == DatabaseInfo.DOMAIN_EDITION || | ||
databaseType == DatabaseInfo.DOMAIN_EDITION_V6 || | ||
databaseType == DatabaseInfo.ASNUM_EDITION || | ||
databaseType == DatabaseInfo.ASNUM_EDITION_V6 || | ||
databaseType == DatabaseInfo.NETSPEED_EDITION_REV1 || | ||
databaseType == DatabaseInfo.NETSPEED_EDITION_REV1_V6 || | ||
databaseType == DatabaseInfo.CITY_EDITION_REV0_V6 || | ||
databaseType == DatabaseInfo.CITY_EDITION_REV1_V6 | ||
} else if (databaseType === DatabaseInfo.CITY_EDITION_REV0 || | ||
databaseType === DatabaseInfo.CITY_EDITION_REV1 || | ||
databaseType === DatabaseInfo.ORG_EDITION || | ||
databaseType === DatabaseInfo.ORG_EDITION_V6 || | ||
databaseType === DatabaseInfo.ISP_EDITION || | ||
databaseType === DatabaseInfo.ISP_EDITION_V6 || | ||
databaseType === DatabaseInfo.DOMAIN_EDITION || | ||
databaseType === DatabaseInfo.DOMAIN_EDITION_V6 || | ||
databaseType === DatabaseInfo.ASNUM_EDITION || | ||
databaseType === DatabaseInfo.ASNUM_EDITION_V6 || | ||
databaseType === DatabaseInfo.NETSPEED_EDITION_REV1 || | ||
databaseType === DatabaseInfo.NETSPEED_EDITION_REV1_V6 || | ||
databaseType === DatabaseInfo.CITY_EDITION_REV0_V6 || | ||
databaseType === DatabaseInfo.CITY_EDITION_REV1_V6 | ||
) { | ||
databaseSegment = 0; | ||
if (databaseType == DatabaseInfo.CITY_EDITION_REV0 || | ||
databaseType == DatabaseInfo.CITY_EDITION_REV1 || | ||
databaseType == DatabaseInfo.ASNUM_EDITION_V6 || | ||
databaseType == DatabaseInfo.NETSPEED_EDITION_REV1 || | ||
databaseType == DatabaseInfo.NETSPEED_EDITION_REV1_V6 || | ||
databaseType == DatabaseInfo.CITY_EDITION_REV0_V6 || | ||
databaseType == DatabaseInfo.CITY_EDITION_REV1_V6 || | ||
databaseType == DatabaseInfo.ASNUM_EDITION | ||
if (databaseType === DatabaseInfo.CITY_EDITION_REV0 || | ||
databaseType === DatabaseInfo.CITY_EDITION_REV1 || | ||
databaseType === DatabaseInfo.ASNUM_EDITION_V6 || | ||
databaseType === DatabaseInfo.NETSPEED_EDITION_REV1 || | ||
databaseType === DatabaseInfo.NETSPEED_EDITION_REV1_V6 || | ||
databaseType === DatabaseInfo.CITY_EDITION_REV0_V6 || | ||
databaseType === DatabaseInfo.CITY_EDITION_REV1_V6 || | ||
databaseType === DatabaseInfo.ASNUM_EDITION | ||
) { | ||
@@ -260,6 +258,6 @@ recordLength = STANDARD_RECORD_LENGTH; | ||
if (databaseType == DatabaseInfo.COUNTRY_EDITION || | ||
databaseType == DatabaseInfo.COUNTRY_EDITION_V6 || | ||
databaseType == DatabaseInfo.PROXY_EDITION || | ||
databaseType == DatabaseInfo.NETSPEED_EDITION | ||
if (databaseType === DatabaseInfo.COUNTRY_EDITION || | ||
databaseType === DatabaseInfo.COUNTRY_EDITION_V6 || | ||
databaseType === DatabaseInfo.PROXY_EDITION || | ||
databaseType === DatabaseInfo.NETSPEED_EDITION | ||
) { | ||
@@ -272,4 +270,4 @@ databaseSegment = COUNTRY_BEGIN; | ||
if ((dboptions & GEOIP_MEMORY_CACHE) != 0) { | ||
var l = file.length(); | ||
if ((dboptions & GEOIP_MEMORY_CACHE) !== 0) { | ||
l = file.length(); | ||
dbbuffer = new Buffer(l); | ||
@@ -281,11 +279,11 @@ file.seek(0); | ||
if ((dboptions & GEOIP_INDEX_CACHE) != 0) { | ||
var l = databaseSegment * recordLength * 2; | ||
index_cache = new Buffer(l); | ||
if (index_cache != null) { | ||
if ((dboptions & GEOIP_INDEX_CACHE) !== 0) { | ||
l = databaseSegment * recordLength * 2; | ||
indexCache = new Buffer(l); | ||
if (indexCache !== null) { | ||
file.seek(0); | ||
file.readFully(index_cache,0,l); | ||
file.readFully(indexCache,0,l); | ||
} | ||
} else { | ||
index_cache = null; | ||
indexCache = null; | ||
} | ||
@@ -297,3 +295,3 @@ | ||
return true; | ||
} | ||
}; | ||
@@ -326,3 +324,3 @@ var _cache = null; | ||
// cache 10 levels only | ||
if (depth == 31 - 10) | ||
if (depth === 31 - 10) | ||
return null; | ||
@@ -339,3 +337,3 @@ | ||
_buildIndex(31, 0); | ||
}; | ||
} | ||
@@ -346,4 +344,4 @@ module.exports.seekCountry = function(ipAddress) { | ||
if (_cache == null) { | ||
if ((dboptions & GEOIP_MEMORY_CACHE) != 0) | ||
if (_cache === null) { | ||
if ((dboptions & GEOIP_MEMORY_CACHE) !== 0) | ||
_makeCache(); | ||
@@ -363,3 +361,3 @@ else | ||
if (cache != undefined) { | ||
if (cache !== undefined) { | ||
x0 = cache[0]; | ||
@@ -370,8 +368,8 @@ x1 = cache[1]; | ||
// read from memory | ||
if ((dboptions & GEOIP_MEMORY_CACHE) != 0) { | ||
if ((dboptions & GEOIP_MEMORY_CACHE) !== 0) { | ||
buf = new DynBuffer(dbbuffer, 2 * recordLength * offset, 2 * MAX_RECORD_LENGTH); | ||
// read from index cache | ||
} else if ((dboptions & GEOIP_INDEX_CACHE) != 0) { | ||
buf = new DynBuffer(index_cache, 2 * recordLength * offset, 2 * MAX_RECORD_LENGTH); | ||
} else if ((dboptions & GEOIP_INDEX_CACHE) !== 0) { | ||
buf = new DynBuffer(indexCache, 2 * recordLength * offset, 2 * MAX_RECORD_LENGTH); | ||
@@ -385,3 +383,4 @@ // read from disk | ||
x0 = 0, x1 = 0; | ||
x0 = 0; | ||
x1 = 0; | ||
@@ -401,3 +400,3 @@ for (var j = 0; j<recordLength; j++) { | ||
if (x1 >= databaseSegment) { | ||
last_netmask = 32 - depth; | ||
lastNetmask = 32 - depth; | ||
return x1; | ||
@@ -408,3 +407,3 @@ } | ||
if (x0 >= databaseSegment) { | ||
last_netmask = 32 - depth; | ||
lastNetmask = 32 - depth; | ||
return x0; | ||
@@ -422,3 +421,3 @@ } | ||
module.exports.getCountry = function(ipAddress) { | ||
if (typeof ipAddress == "string") | ||
if (typeof ipAddress === "string") | ||
ipAddress = this.ip2Long(ipAddress); | ||
@@ -428,3 +427,3 @@ | ||
if (ret == 0) | ||
if (ret === 0) | ||
return UNKNOWN_COUNTRY; | ||
@@ -437,5 +436,3 @@ | ||
var ip = ipnum; | ||
if (typeof ipnum == "string") | ||
if (typeof ipnum === "string") | ||
ipnum = this.ip2Long(ipnum); | ||
@@ -449,3 +446,3 @@ | ||
var str_length = 0; | ||
var pointer = 0; | ||
var j, seekCountry; | ||
@@ -455,6 +452,5 @@ var latitude = 0, longitude = 0; | ||
try { | ||
seekCountry = this.seekCountry(ipnum); | ||
if (seekCountry == databaseSegment) | ||
if (seekCountry === databaseSegment) | ||
return null; | ||
@@ -464,3 +460,3 @@ | ||
if ((dboptions & GEOIP_MEMORY_CACHE) != 0) { | ||
if ((dboptions & GEOIP_MEMORY_CACHE) !== 0) { | ||
recordBuf = new DynBuffer(dbbuffer, recordPointer, Math.min(dbbuffer.length - recordPointer, FULL_RECORD_LENGTH)); | ||
@@ -482,36 +478,36 @@ } else { | ||
// get region | ||
while (recordBuf.at(recordBufOffset + str_length) != 0x00) | ||
str_length++; | ||
while (recordBuf.at(recordBufOffset + pointer) !== 0x00) | ||
pointer++; | ||
if (str_length > 0) | ||
record.region = recordBuf.toString('utf8', recordBufOffset, recordBufOffset + str_length); | ||
if (pointer > 0) | ||
record.region = recordBuf.toString('utf8', recordBufOffset, recordBufOffset + pointer); | ||
recordBufOffset += str_length + 1; | ||
str_length = 0; | ||
recordBufOffset += pointer + 1; | ||
pointer = 0; | ||
// get city | ||
while (recordBuf.at(recordBufOffset + str_length) != 0x00) | ||
str_length++; | ||
while (recordBuf.at(recordBufOffset + pointer) !== 0x00) | ||
pointer++; | ||
if (str_length > 0) | ||
record.city = recordBuf.toString('utf8', recordBufOffset, recordBufOffset + str_length); | ||
if (pointer > 0) | ||
record.city = recordBuf.toString('utf8', recordBufOffset, recordBufOffset + pointer); | ||
recordBufOffset += str_length + 1; | ||
str_length = 0; | ||
recordBufOffset += pointer + 1; | ||
pointer = 0; | ||
// get postal code | ||
while (recordBuf.at(recordBufOffset + str_length) != 0x00) | ||
str_length++; | ||
while (recordBuf.at(recordBufOffset + pointer) !== 0x00) | ||
pointer++; | ||
if (str_length > 0) | ||
record.postalCode = recordBuf.toString('utf8', recordBufOffset, recordBufOffset + str_length); | ||
if (pointer > 0) | ||
record.postalCode = recordBuf.toString('utf8', recordBufOffset, recordBufOffset + pointer); | ||
recordBufOffset += str_length + 1; | ||
recordBufOffset += pointer + 1; | ||
// get latitude | ||
latitude = (recordBuf.readUInt8(recordBufOffset + 0) << (0 * 8)) | ||
+ (recordBuf.readUInt8(recordBufOffset + 1) << (1 * 8)) | ||
+ (recordBuf.readUInt8(recordBufOffset + 2) << (2 * 8)); | ||
latitude = (recordBuf.readUInt8(recordBufOffset + 0) << (0 * 8)) + | ||
(recordBuf.readUInt8(recordBufOffset + 1) << (1 * 8)) + | ||
(recordBuf.readUInt8(recordBufOffset + 2) << (2 * 8)); | ||
@@ -522,22 +518,22 @@ record.latitude = latitude/10000 - 180; | ||
// get longitude | ||
longitude = (recordBuf.readUInt8(recordBufOffset + 0) << (0 * 8)) | ||
+ (recordBuf.readUInt8(recordBufOffset + 1) << (1 * 8)) | ||
+ (recordBuf.readUInt8(recordBufOffset + 2) << (2 * 8)); | ||
longitude = (recordBuf.readUInt8(recordBufOffset + 0) << (0 * 8)) + | ||
(recordBuf.readUInt8(recordBufOffset + 1) << (1 * 8)) + | ||
(recordBuf.readUInt8(recordBufOffset + 2) << (2 * 8)); | ||
record.longitude = longitude/10000 - 180; | ||
record.dma_code = record.metro_code = 0; | ||
record.area_code = 0; | ||
record.dmaCode = record.metroCode = 0; | ||
record.areaCode = 0; | ||
if (databaseType == DatabaseInfo.CITY_EDITION_REV1) { | ||
if (databaseType === DatabaseInfo.CITY_EDITION_REV1) { | ||
// get DMA code | ||
var metroarea_combo = 0; | ||
if (record.countryCode == "US") { | ||
var metroareaCombo = 0; | ||
if (record.countryCode === "US") { | ||
recordBufOffset += 3; | ||
for (j = 0; j < 3; j++) | ||
metroarea_combo += recordBuf.readUInt8(recordBufOffset + j) << (j * 8); | ||
metroareaCombo += recordBuf.readUInt8(recordBufOffset + j) << (j * 8); | ||
record.metro_code = record.dma_code = metroarea_combo/1000; | ||
record.area_code = metroarea_combo % 1000; | ||
record.metroCode = record.dmaCode = metroareaCombo/1000; | ||
record.areaCode = metroareaCombo % 1000; | ||
} | ||
@@ -555,29 +551,29 @@ } | ||
if (typeof ipnum == "string") | ||
if (typeof ipnum === "string") | ||
ipnum = this.ip2Long(ipnum); | ||
var record = new Region(); | ||
var seek_region = 0; | ||
var seekRegion = 0; | ||
if (databaseType == DatabaseInfo.REGION_EDITION_REV0) { | ||
seek_region = this.seekCountry(ipnum) - STATE_BEGIN_REV0; | ||
if (databaseType === DatabaseInfo.REGION_EDITION_REV0) { | ||
seekRegion = this.seekCountry(ipnum) - STATE_BEGIN_REV0; | ||
if (seek_region >= 1000) { | ||
if (seekRegion >= 1000) { | ||
record.countryCode = "US"; | ||
record.countryName = "United States"; | ||
record.region = String.fromCharCode( | ||
((seek_region - 1000) / 26) + 65, | ||
((seek_region - 1000) % 26) + 65 | ||
((seekRegion - 1000) / 26) + 65, | ||
((seekRegion - 1000) % 26) + 65 | ||
); | ||
} else { | ||
record.countryCode = countryCode[seek_region]; | ||
record.countryName = countryName[seek_region]; | ||
record.countryCode = countryCode[seekRegion]; | ||
record.countryName = countryName[seekRegion]; | ||
record.region = ""; | ||
} | ||
} else if (databaseType == DatabaseInfo.REGION_EDITION_REV1) { | ||
seek_region = seekCountry(ipnum) - STATE_BEGIN_REV1; | ||
} else if (databaseType === DatabaseInfo.REGION_EDITION_REV1) { | ||
seekRegion = this.seekCountry(ipnum) - STATE_BEGIN_REV1; | ||
if (seek_region < US_OFFSET) { | ||
if (seekRegion < US_OFFSET) { | ||
record.countryCode = ""; | ||
@@ -587,21 +583,21 @@ record.countryName = ""; | ||
} else if (seek_region < CANADA_OFFSET) { | ||
} else if (seekRegion < CANADA_OFFSET) { | ||
record.countryCode = "US"; | ||
record.countryName = "United States"; | ||
record.region = String.fromCharCode( | ||
((seek_region - US_OFFSET)/26) + 65, | ||
((seek_region - US_OFFSET)%26) + 65 | ||
((seekRegion - US_OFFSET)/26) + 65, | ||
((seekRegion - US_OFFSET)%26) + 65 | ||
); | ||
} else if (seek_region < WORLD_OFFSET) { | ||
} else if (seekRegion < WORLD_OFFSET) { | ||
record.countryCode = "CA"; | ||
record.countryName = "Canada"; | ||
record.region = String.fromCharCode( | ||
((seek_region - CANADA_OFFSET)/26) + 65, | ||
((seek_region - CANADA_OFFSET)%26) + 65 | ||
((seekRegion - CANADA_OFFSET)/26) + 65, | ||
((seekRegion - CANADA_OFFSET)%26) + 65 | ||
); | ||
} else { | ||
record.countryCode = countryCode[(seek_region - WORLD_OFFSET) / FIPS_RANGE]; | ||
record.countryName = countryName[(seek_region - WORLD_OFFSET) / FIPS_RANGE]; | ||
record.countryCode = countryCode[(seekRegion - WORLD_OFFSET) / FIPS_RANGE]; | ||
record.countryName = countryName[(seekRegion - WORLD_OFFSET) / FIPS_RANGE]; | ||
record.region = ""; | ||
@@ -622,11 +618,11 @@ } | ||
recordBuf, | ||
position = 0; | ||
pointer = 0; | ||
seekCountry = this.seekCountry(ipnum); | ||
if (seekCountry == databaseSegment) | ||
if (seekCountry === databaseSegment) | ||
return null; | ||
recordPointer = seekCountry + (2 * recordLength - 1) * databaseSegment; | ||
if ((dboptions & GEOIP_MEMORY_CACHE) != 0) { | ||
if ((dboptions & GEOIP_MEMORY_CACHE) !== 0) { | ||
recordBuf = new DynBuffer(dbbuffer, recordPointer, Math.min(dbbuffer.length - recordPointer, MAX_ORG_RECORD_LENGTH)); | ||
@@ -640,5 +636,5 @@ } else { | ||
while (recordBuf.at(++position) != 0x00); | ||
while (recordBuf.at(++pointer) !== 0x00); | ||
return recordBuf.toString('utf8', 0, position); | ||
return recordBuf.toString('utf8', 0, pointer); | ||
}; | ||
@@ -645,0 +641,0 @@ |
@@ -1,2 +0,1 @@ | ||
var _data = require('./region_name_data'); | ||
@@ -8,6 +7,6 @@ | ||
if (regionCode == null) | ||
if (!regionCode) | ||
return null; | ||
if (regionCode == "") | ||
if (regionCode === "") | ||
return null; | ||
@@ -33,6 +32,6 @@ | ||
if (regionCode2 == -1) | ||
if (regionCode2 === -1) | ||
return null; | ||
return _data[countryCode][regionCode2]; | ||
}; | ||
}; |
function Region() { | ||
this.countryCode; | ||
this.countryName; | ||
this.region; | ||
module.exports = function() { | ||
this.countryCode = null; | ||
this.countryName = null; | ||
this.region = null; | ||
}; | ||
module.exports = Region; |
/* jshint indent: 2 */ | ||
// Do not modify this file, it was generated by | ||
@@ -67,3 +68,3 @@ // ./tools/gen_time_zone.rb | ||
"NU": "America/Rankin_Inlet", | ||
"ON": "America/Rainy_River", | ||
"ON": "America/Toronto", | ||
"PE": "America/Halifax", | ||
@@ -70,0 +71,0 @@ "QC": "America/Montreal", |
@@ -1,6 +0,5 @@ | ||
var _data = require('./time_zone_data'); | ||
module.exports = function(country, region) { | ||
if (country == null) | ||
if (!country) | ||
return null; | ||
@@ -11,2 +10,2 @@ | ||
return _data[country][region]; | ||
}; | ||
}; |
{ | ||
"name": "maxmind", | ||
"version": "0.1.2", | ||
"version": "0.1.4", | ||
"homepage": "https://github.com/runk/node-maxmind", | ||
@@ -10,3 +10,4 @@ "description": "IP lookup using Maxmind databases", | ||
"devDependencies": { | ||
"mocha": ">= 1.10.0" | ||
"mocha": ">= 1.10.0", | ||
"jshint": ">= 2.1.3" | ||
}, | ||
@@ -26,3 +27,6 @@ "repository": { | ||
"url": "http://www.gnu.org/licenses/lgpl-2.1.txt" | ||
}] | ||
}], | ||
"scripts": { | ||
"lint": "jshint ./lib/*.js" | ||
} | ||
} |
@@ -117,5 +117,5 @@ | ||
assert.equal(l.longitude, 40.97139999999999); | ||
assert.equal(l.metro_code, 0); | ||
assert.equal(l.dma_code, 0); | ||
assert.equal(l.area_code, 0); | ||
assert.equal(l.metroCode, 0); | ||
assert.equal(l.dmaCode, 0); | ||
assert.equal(l.areaCode, 0); | ||
}); | ||
@@ -131,5 +131,5 @@ | ||
assert.equal(l.longitude, 37.38319999999999); | ||
assert.equal(l.metro_code, 0); | ||
assert.equal(l.dma_code, 0); | ||
assert.equal(l.area_code, 0); | ||
assert.equal(l.metroCode, 0); | ||
assert.equal(l.dmaCode, 0); | ||
assert.equal(l.areaCode, 0); | ||
}); | ||
@@ -145,5 +145,5 @@ | ||
assert.equal(l.longitude, -1.6742999999999881); | ||
assert.equal(l.metro_code, 0); | ||
assert.equal(l.dma_code, 0); | ||
assert.equal(l.area_code, 0); | ||
assert.equal(l.metroCode, 0); | ||
assert.equal(l.dmaCode, 0); | ||
assert.equal(l.areaCode, 0); | ||
}); | ||
@@ -150,0 +150,0 @@ }); |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
173748
29
2
6634