mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
Add types for node-ip2region (#47224)
This commit is contained in:
parent
33b4f8d690
commit
b498ec1033
80
types/node-ip2region/index.d.ts
vendored
Normal file
80
types/node-ip2region/index.d.ts
vendored
Normal file
@ -0,0 +1,80 @@
|
||||
// Type definitions for node-ip2region 1.0
|
||||
// Project: https://github.com/lionsoul2014/ip2region
|
||||
// Definitions by: DCsunset <https://github.com/DefinitelyTyped>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// Minimum TypeScript Version: 3.7
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
type SearchResult = {
|
||||
city: number;
|
||||
region: string;
|
||||
} | null;
|
||||
|
||||
type SearchCallback = (err: NodeJS.ErrnoException, result: SearchResult) => void;
|
||||
|
||||
declare class IP2Region {
|
||||
//#region Static Functions
|
||||
|
||||
// Single Instance
|
||||
static create(dbPath?: string): IP2Region;
|
||||
|
||||
/**
|
||||
* For backward compatibility
|
||||
*/
|
||||
static destroy(): void;
|
||||
|
||||
//#endregion
|
||||
|
||||
constructor(options?: { dbPath: string });
|
||||
|
||||
//#region Public Functions
|
||||
/**
|
||||
* Destroy the current file by closing it.
|
||||
*/
|
||||
destroy(): void;
|
||||
|
||||
/**
|
||||
* Sync of binarySearch.
|
||||
* @param ip The IP address to search for.
|
||||
* @return A result something like `{ city: 2163, region: '中国|0|广东省|深圳市|阿里云' }`
|
||||
*/
|
||||
binarySearchSync(ip: string): SearchResult;
|
||||
|
||||
/**
|
||||
* Async of binarySearch.
|
||||
* @param ip The IP address to search for.
|
||||
* @param callBack The callBack function with two parameters, if successful,
|
||||
* err is null and result is `{ city: 2163, region: '中国|0|广东省|深圳市|阿里云' }`
|
||||
*/
|
||||
binarySearch(ip: string, callBack: SearchCallback): void;
|
||||
|
||||
/**
|
||||
* Sync of btreeSearch.
|
||||
* @param ip The IP address to search for.
|
||||
* @return A result something like `{ city: 2163, region: '中国|0|广东省|深圳市|阿里云' }`
|
||||
*/
|
||||
btreeSearchSync(ip: string): SearchResult;
|
||||
|
||||
/**
|
||||
* Async of btreeSearch.
|
||||
* @param ip The IP address to search for.
|
||||
* @param callBack The callBack function with two parameters, if successful,
|
||||
* err is null and result is `{ city: 2163, region: '中国|0|广东省|深圳市|阿里云' }`
|
||||
*/
|
||||
btreeSearch(ip: string, callBack: SearchCallback): void;
|
||||
|
||||
/**
|
||||
* Sync of MemorySearch.
|
||||
* @param ip
|
||||
*/
|
||||
memorySearchSync(ip: string): SearchResult;
|
||||
|
||||
/**
|
||||
* Async of MemorySearch.
|
||||
* @param ip
|
||||
*/
|
||||
memorySearch(ip: string, callBack: SearchCallback): void;
|
||||
}
|
||||
|
||||
export = IP2Region;
|
||||
28
types/node-ip2region/node-ip2region-tests.ts
Normal file
28
types/node-ip2region/node-ip2region-tests.ts
Normal file
@ -0,0 +1,28 @@
|
||||
import IP2Region = require('node-ip2region');
|
||||
|
||||
const searcher = new IP2Region({
|
||||
dbPath: './db',
|
||||
});
|
||||
searcher.binarySearch('1.1.1.1', (_err, result) => {
|
||||
result?.city;
|
||||
result?.region;
|
||||
});
|
||||
let result = searcher.binarySearchSync('1.1.1.1');
|
||||
result?.city;
|
||||
result?.region;
|
||||
searcher.btreeSearch('1.1.1.1', (_err, result) => {
|
||||
result?.city;
|
||||
result?.region;
|
||||
});
|
||||
result = searcher.btreeSearchSync('1.1.1.1');
|
||||
result?.city;
|
||||
result?.region;
|
||||
searcher.memorySearch('1.1.1.1', (_err, result) => {
|
||||
result?.city;
|
||||
result?.region;
|
||||
});
|
||||
result = searcher.memorySearchSync('1.1.1.1');
|
||||
result?.city;
|
||||
result?.region;
|
||||
|
||||
searcher.destroy();
|
||||
23
types/node-ip2region/tsconfig.json
Normal file
23
types/node-ip2region/tsconfig.json
Normal file
@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictFunctionTypes": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"node-ip2region-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/node-ip2region/tslint.json
Normal file
1
types/node-ip2region/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user