Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mmdb-lib

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mmdb-lib

Maxmind DB (MMDB) Library

  • 2.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
139K
decreased by-6.61%
Maintainers
1
Weekly downloads
 
Created
Source

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

Keywords

FAQs

Package last updated on 03 Feb 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc