Comparing version 2.12.0 to 3.0.0
{ | ||
"name": "maxmind", | ||
"version": "2.12.0", | ||
"version": "3.0.0", | ||
"homepage": "https://github.com/runk/node-maxmind", | ||
@@ -26,16 +26,16 @@ "description": "IP lookup using Maxmind databases", | ||
"dependencies": { | ||
"big-integer": "^1.6.31", | ||
"@types/sinon": "^7.0.11", | ||
"tiny-lru": "^6.0.0" | ||
}, | ||
"devDependencies": { | ||
"@types/ip-address": "^5.8.2", | ||
"@types/jest": "^24.0.11", | ||
"@types/node": "10.12.20", | ||
"eslint": "2.13.1", | ||
"github-publish-release": "5.0.1", | ||
"ip-address": "5.8.9", | ||
"istanbul": "0.4.5", | ||
"mocha": "5.2.0", | ||
"nyc": "13.1.0", | ||
"jest": "^24.7.1", | ||
"sinon": "7.2.3", | ||
"ts-jest": "^24.0.2", | ||
"tslint": "5.12.1", | ||
"typescript": "3.3.1" | ||
"typescript": "^3.3.1" | ||
}, | ||
@@ -50,14 +50,19 @@ "repository": { | ||
}, | ||
"main": "index.js", | ||
"typings": "./index.d.ts", | ||
"files": [ | ||
"lib" | ||
], | ||
"main": "lib/index.js", | ||
"typings": "lib/index.d.ts", | ||
"engines": { | ||
"node": ">=4.8", | ||
"npm": ">=1" | ||
"node": ">=10", | ||
"npm": ">=6" | ||
}, | ||
"license": "MIT", | ||
"scripts": { | ||
"lint": "scripts/lint", | ||
"build": "rm -rf lib/* && tsc", | ||
"lint": "tslint -p tsconfig.json -c tslint.json", | ||
"lint:types": "tsc --noEmit", | ||
"release": "scripts/release", | ||
"test": "scripts/test" | ||
"test": "jest" | ||
} | ||
} |
124
README.md
@@ -1,9 +0,6 @@ | ||
node-maxmind [![Build Status](https://api.travis-ci.org/runk/node-maxmind.svg?branch=master)](https://travis-ci.org/runk/node-maxmind) | ||
======== | ||
# node-maxmind [![Build Status](https://api.travis-ci.org/runk/node-maxmind.svg?branch=master)](https://travis-ci.org/runk/node-maxmind) | ||
Vanilla Javascript module for Geo IP lookup using Maxmind binary databases (aka mmdb or geoip2). | ||
Fastest Maxmind lookup library available - up to [17,000% faster](https://github.com/runk/node-maxmind-benchmark) than other libraries. Module has 100% test coverage with comprehensive test suite. It natively works with binary Maxmind database format and doesn't require any "CSV - {specific lib format}" conversions as some other modules do. Maxmind binary databases are highly optimized for size and performance so there's no point using other formats. | ||
## GEO databases | ||
@@ -13,3 +10,2 @@ | ||
## Installation | ||
@@ -21,3 +17,2 @@ | ||
## Usage | ||
@@ -28,22 +23,11 @@ | ||
```javascript | ||
var maxmind = require('maxmind'); | ||
const maxmind = require('maxmind'); | ||
maxmind.open('/path/to/GeoLite2-City.mmdb', (err, cityLookup) => { | ||
var city = cityLookup.get('66.6.44.4'); | ||
maxmind.open('/path/to/GeoLite2-City.mmdb').then((lookup) => { | ||
console.log(lookup.get('66.6.44.4')); | ||
}); | ||
maxmind.open('/path/to/GeoOrg.mmdb', (err, orgLookup) => { | ||
var city = orgLookup.get('66.6.44.4'); | ||
maxmind.open('/path/to/GeoOrg.mmdb').then((lookup) => { | ||
console.log(lookup.get('66.6.44.4')); | ||
}); | ||
// Be careful with sync version! Since mmdb files | ||
// are quite large (city database is about 100Mb) | ||
// `fs.readFileSync` blocks whole process while it | ||
// reads file into buffer. | ||
var cityLookup = maxmind.openSync('/path/to/GeoLite2-City.mmdb'); | ||
var city = cityLookup.get('66.6.44.4'); | ||
var orgLookup = maxmind.openSync('/path/to/GeoOrg.mmdb'); | ||
var organization = orgLookup.get('66.6.44.4'); | ||
``` | ||
@@ -54,27 +38,12 @@ | ||
```typescript | ||
import * as maxmind from 'maxmind'; | ||
import maxmind, { CityResponse } from 'maxmind'; | ||
maxmind.open<maxmind.CityResponse>('/path/to/GeoLite2-City.mmdb', (err, cityLookup) => { | ||
let city = cityLookup.get('8.8.8.8'); // inferred type maxmind.CityResponse | ||
}); | ||
const lookup = await maxmind.open<CityResponse>('/path/to/GeoLite2-City.mmdb'); | ||
console.log(lookup.get('66.6.44.4')); // inferred type maxmind.CityResponse | ||
// sync version | ||
let cityLookup = maxmind.openSync<maxmind.CityResponse>('/path/to/GeoLite2-City.mmdb'); | ||
let city = cityLookup.get('8.8.8.8'); // inferred type maxmind.CityResponse | ||
// use Reader class directly | ||
let cityLookup: maxmind.Reader<maxmind.CityResponse> = null; | ||
myLib.downloadFromCloudToStream(someCloudMaxmindDbUrl, (err, buffer) => { | ||
if (!err) { | ||
cityLookup = new maxmind.Reader(buffer); | ||
} | ||
}); | ||
if (cityLookup) { | ||
let city = cityLookup.get('8.8.8.8'); // inferred type maxmind.CityResponse | ||
} | ||
// Use Reader class directly | ||
import Reader from 'maxmind/lib/reader'; | ||
const buffer = await downloadFromCloudToStream(); | ||
const lookup = new Reader<CityResponse>(buffer); | ||
let city = lookup.get('8.8.8.8'); // inferred type maxmind.CityResponse | ||
``` | ||
@@ -99,47 +68,18 @@ | ||
```javascript | ||
var lookup = maxmind.openSync('/path/to/GeoLite2.mmdb'); | ||
var location = lookup.get('2001:4860:0:1001::3004:ef68'); | ||
const lookup = await maxmind.open('/path/to/GeoLite2.mmdb'); | ||
const location = lookup.get('2001:4860:0:1001::3004:ef68'); | ||
``` | ||
## Options | ||
### cache | ||
Module uses [tiny-lru](https://github.com/avoidwork/tiny-lru). You can configure its settings by doing following: | ||
```javascript | ||
var lookup = maxmind.openSync('/path/to/GeoLite2.mmdb', { | ||
cache: { | ||
max: 500, // Max items in cache, by default it's 6000 | ||
} | ||
}); | ||
lookup.get('1.1.1.1'); | ||
``` | ||
### watchForUpdates | ||
Supports reloading the reader when changes occur to the database that is loaded. (default `false`). Only supported by Node v0.5.10+. | ||
```javascript | ||
var lookup = maxmind.openSync('/path/to/GeoLite2.mmdb', { watchForUpdates: true }); | ||
lookup.get('1.1.1.1'); | ||
``` | ||
_maxmind.open(filepath, [options])_ | ||
You also can specify wether the watcher should be persistent or not. If it is persistent, a node process will be blocked in watching state if the watcher is the only thing still running in the program. You can use `watchForUpdatesNonPersistent` option (default `false`) to prevent this behavior. | ||
```javascript | ||
var lookup = maxmind.openSync('/path/to/GeoLite2.mmdb', { | ||
watchForUpdates: true, | ||
watchForUpdatesNonPersistent: true, | ||
}); | ||
lookup.get('1.1.1.1'); | ||
``` | ||
- `filepath`: `<string>` Path to the binary mmdb database file. | ||
- `options`: `<Object>` | ||
- `cache`: `<Object>` Cache options. Under the bonnet module uses [tiny-lru](https://github.com/avoidwork/tiny-lru) cache. | ||
- `max`: `<number>` Max cache items to keep in memory. _Default_: `6000`. | ||
- `watchForUpdates`: `<boolean>` Supports reloading the reader when changes occur to the database that is loaded. _Default_: `false`. | ||
- `watchForUpdatesNonPersistent`: `<boolean>` Controlls wether the watcher should be persistent or not. If it is persistent, a node process will be blocked in watching state if the watcher is the only thing still running in the program. _Default_: `false`. | ||
- `watchForUpdatesHook`: `<Function>` Hook function that is fired on database update. _Default_: `null`. | ||
Also, you can specify custom hook function on database update. | ||
```javascript | ||
var opts = { | ||
watchForUpdates: true, | ||
watchForUpdatesHook: () => { console.log('database updated!'); }, | ||
}; | ||
var lookup = maxmind.openSync('/path/to/GeoLite2.mmdb', opts); | ||
lookup.get('1.1.1.1'); | ||
``` | ||
## IP addresses validation | ||
@@ -157,3 +97,2 @@ | ||
## GeoIP Legacy binary format | ||
@@ -163,12 +102,11 @@ | ||
## References | ||
- Loosely based on https://github.com/PaddeK/node-maxmind-db | ||
- MaxMind DB file format specification http://maxmind.github.io/MaxMind-DB/ | ||
- MaxMind test/sample DB files https://github.com/maxmind/MaxMind-DB | ||
- GeoLite2 Free Downloadable Databases http://dev.maxmind.com/geoip/geoip2/geolite2/ | ||
- Great talk about V8 performance https://www.youtube.com/watch?v=UJPdhx5zTaw | ||
- V8 Optimization killers https://github.com/petkaantonov/bluebird/wiki/Optimization-killers | ||
- More V8 performance tips http://www.html5rocks.com/en/tutorials/speed/v8/ | ||
- Loosely based on https://github.com/PaddeK/node-maxmind-db | ||
- MaxMind DB file format specification http://maxmind.github.io/MaxMind-DB/ | ||
- MaxMind test/sample DB files https://github.com/maxmind/MaxMind-DB | ||
- GeoLite2 Free Downloadable Databases http://dev.maxmind.com/geoip/geoip2/geolite2/ | ||
- Great talk about V8 performance https://www.youtube.com/watch?v=UJPdhx5zTaw | ||
- V8 Optimization killers https://github.com/petkaantonov/bluebird/wiki/Optimization-killers | ||
- More V8 performance tips http://www.html5rocks.com/en/tutorials/speed/v8/ | ||
@@ -175,0 +113,0 @@ ## License |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
37306
26
0
296
109
+ Added@types/sinon@^7.0.11
+ Added@types/sinon@7.5.2(transitive)
- Removedbig-integer@^1.6.31
- Removedbig-integer@1.6.52(transitive)