TypeScript node client library for IP2Region
Install the package with NPM
npm install ts-ip2region
# or
yarn add ts-ip2region
import { Searcher, CachePolicy, ISearcher } from 'ts-ip2region';
const dbPath = './ip2region.xdb';
const searcher: ISearcher = new Searcher(CachePolicy.Content, dbPath);
const ip = '8.8.8.8';
const regionInfo = await searcher.search(ip);
console.log(`IP: ${ip}, Region: ${regionInfo}`);
await searcher.close();
Cache Policy | Description | Thread Safe |
---|---|---|
CachePolicy.Content | Cache the entire xdb data. |
Yes |
CachePolicy.VectorIndex | Cache vecotorIndex to speed up queries and reduce system io pressure by reducing one fixed IO operation. |
Yes |
CachePolicy.File | Completely file-based queries | Yes |
Generate using maker, or download pre-generated xdb files
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.