ip2region_private/binding/typescript
Alan e49a076dee update: add ts-ip2region client 2024-12-17 16:36:29 +08:00
..
src update: add ts-ip2region client 2024-12-17 16:36:29 +08:00
test update: add ts-ip2region client 2024-12-17 16:36:29 +08:00
.gitattributes update: add ts-ip2region client 2024-12-17 16:36:29 +08:00
.gitignore update: add ts-ip2region client 2024-12-17 16:36:29 +08:00
README.md update: add ts-ip2region client 2024-12-17 16:36:29 +08:00
package.json v0.1.1 2024-12-17 16:34:30 +08:00
tsconfig.json update: add ts-ip2region client 2024-12-17 16:36:29 +08:00
yarn.lock update: add ts-ip2region client 2024-12-17 16:36:29 +08:00

README.md

ts-ip2region

TypeScript node client library for IP2Region

Installation

Install the package with NPM

npm install ts-ip2region
# or
yarn add ts-ip2region

Usage

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

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

XDB File Description

Generate using maker, or download pre-generated xdb files

Contributing

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.

License

Apache License 2.0