mmdb-lib
TypeScript icon, indicating that this package has built-in type declarations

2.1.0 • Public • Published

mmdb-lib

Javascript library for working with Maxmind binary databases (aka mmdb or geoip2).

Library is designed to be agnostic to environment and works equally well in node.js and browser. Module is fully compatible with IPv6. There are no differences in API between IPv4 and IPv6.

Installation

npm i mmdb-lib

Usage

import fs from 'fs';
import * as mmdb from 'mmdb-lib';

// Get a buffer with mmdb database, from file system or whereever.
const db = fs.readFileSync('/path/to/GeoLite2-City.mmdb');

const reader = new mmdb.Reader<CityResponse>(db);
console.log(reader.get('66.6.44.4')); // inferred type `CityResponse`
console.log(reader.getWithPrefixLength('66.6.44.4')); // tuple with inferred type `[CityResponse|null, number]`

Supported response types:

- CountryResponse
- CityResponse
- AnonymousIPResponse
- AsnResponse
- ConnectionTypeResponse
- DomainResponse
- IspResponse

Usage in browser-like environments

Library expects to receive an instance of Buffer during instantiation of Reader. Since there is no direct alternative of node's Buffer in browser, you can use https://github.com/feross/buffer that mimics native Buffer interface. Neither ArrayBuffer nor Uint8Array is supported right now. Another requirement is BigInt object available.

Options

Reader(db:Buffer, [options])

  • options: <Object>
    • cache: <Object> Cache helper. tiny-lru is great basic option. Only two methods expected: get(key: string | number): any and set(key: string | number, val: any): void.

References

License

MIT

Contributing

add a link

Package Sidebar

Install

npm i mmdb-lib

Weekly Downloads

107,959

Version

2.1.0

License

MIT

Unpacked Size

34.3 kB

Total Files

19

Last publish

Collaborators

  • runk