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 🙏

© 2026 – Pkg Stats / Ryan Hefner

ts-ip2region2

v1.2.1

Published

TypeScript-first ip2region implementation with native Node.js addon. Ultra-fast IPv4/IPv6 geolocation queries.

Readme

ts-ip2region2

High-performance Node.js native addon for ip2region xdb query with IPv4/IPv6 support. Written in TypeScript with full type definitions.

Features

  • 🚀 High Performance - Native C++ implementation with microsecond-level response
  • 🌐 IPv4 & IPv6 - Full support for both IPv4 and IPv6 address queries
  • 💾 Multiple Cache Strategies - file/vectorIndex/content caching options
  • 🔒 Memory Safe - Automatic resource management prevents memory leaks
  • 📝 TypeScript - Complete TypeScript type definitions included
  • 🔧 Cross Platform - Works on Windows, Linux, and macOS
  • 📦 Bundled Data - Includes compressed database files

Installation

npm install ts-ip2region2

The database files are automatically included and extracted during installation.

Quick Start

import { Ip2Region } from 'ts-ip2region2';

// Create searcher instance (uses bundled data)
const searcher = new Ip2Region();

// Or with options
const searcher2 = new Ip2Region({ cachePolicy: 'content', ipVersion: 'v6' });

// Or specify custom database path
const searcher3 = new Ip2Region('./custom.xdb', {
  cachePolicy: 'vectorIndex',
  ipVersion: 'v4'
});

// Query IP address
const result = searcher.search('120.229.45.2');
console.log(result);
// Output: { region: '中国|广东省|深圳市|移动', ioCount: 3, took: 1000 }

// Clean up
searcher.close();

API Reference

Constructor

// Using default bundled data
new Ip2Region()
new Ip2Region(options: Ip2RegionOptions)

// Using custom database
new Ip2Region(dbPath: string, options?: Ip2RegionOptions)

Methods

  • search(ip: string): SearchResult - Query IP address location
  • close(): void - Release resources

Static Methods

  • Ip2Region.verify(dbPath: string): boolean - Verify xdb file
  • Ip2Region.verifyDetailed(dbPath: string): VerifyResult - Verify with detailed info

Performance Benchmark

Benchmark results on Windows x64 with Node.js v22.14.0 (10,000 iterations):

| Cache Strategy | Avg Time (μs/op) | QPS | |---------------|------------------|-----| | file | ~31 | ~32,000 | | vectorIndex | ~22 | ~45,000 | | content | ~1.3 | ~750,000 |

Performance Improvements:

  • vectorIndex is ~40% faster than file mode
  • content is ~95% faster than vectorIndex mode
  • content is ~96% faster than file mode

Comparison with Native C:

  • Native C (vectorIndex): ~5 μs/op
  • Node.js Addon (vectorIndex): ~22 μs/op
  • Overhead: ~4.4x (mainly from N-API call overhead)

Despite the N-API overhead, the performance is still excellent for most use cases, achieving 45,000+ QPS with vectorIndex mode.

Recommendation: Use vectorIndex for most scenarios as it provides excellent performance with moderate memory usage.

Run benchmark yourself:

npm run benchmark

License

Apache-2.0