Code Monkey home page Code Monkey logo

mmdb-lib's Introduction

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

mmdb-lib's People

Contributors

horgh avatar kevcenteno avatar oschwald avatar renovate[bot] avatar runk avatar umanshahzad avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

mmdb-lib's Issues

Request for supporting older version of node

Hey, I have a project which runs on the older version of the node (8.4.0). after including this library it fails due to node version required is 10.4 or above.

After digging a little more I got to know that it requires BigInt.

assert_1.default(typeof BigInt !== 'undefined', 'Apparently you are using old version of node. Please upgrade to node 10.4.x or above.');

Is it possible to add https://www.npmjs.com/package/big-integer as a dependency that polyfills BigInt?

Feature Request: Consider integrating WASM option

I'm not sure how the performance would compare, but I have a project you could use as an example masxminddb-deno, where I used the maxminddb Rust library to build a webassembly module and a wrapper around it in Deno.

Another possible benefit aside from any potential performance is that it would give a way to to consume Uint8Arrays

ESM version

Currently, this module (js version) has this piece of code:

exports.default = Reader;

This code if it is used in ESM module is exported as named export default, which is hard to import and it is inconsistent with types.

For example:

import Reader from 'mmdb-lib'; // Reader is equal to {default: ActuallyReader}
import {default as Reader} from 'mmdb-lib'; // Reader is equal to {default: ActuallyReader} because default is a special keyword here

The only way to import Reader correctly from typescript + native ESM without esModuleInterop is:

import * as MMDB from 'mmdb-lib';
const Reader = (MMDB.default as unknown as typeof MMDB).default;

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

This repository currently has no open or pending branches.

Detected dependencies

github-actions
.github/workflows/build.yml
  • actions/checkout v4
  • actions/setup-node v4
.github/workflows/release.yml
  • actions/checkout v4
  • actions/setup-node v4
npm
package.json
  • @types/ip-address 6.0.0
  • @types/mocha ^10.0.1
  • @types/node 20.11.16
  • @types/sinon 17.0.3
  • ip-address 9.0.5
  • mocha ^10.2.0
  • prettier ^3.0.0
  • semantic-release ^23.0.0
  • sinon 17.0.1
  • ts-node ^10.4.0
  • typescript 5.3.3
  • node >=10
  • npm >=6

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.