npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mmdb-lib

v2.1.0

Published

Maxmind DB (MMDB) Library

Downloads

490,481

Readme

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

  • 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/

License

MIT

Contributing

add a link