mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-12-03 19:51:53 +00:00
Typing for maxmind
This commit is contained in:
Vendored
+73
@@ -0,0 +1,73 @@
|
||||
// Type definitions for maxmind
|
||||
// Project: https://github.com/runk/node-maxmind
|
||||
// Definitions by: Joshua DeVinney <https://github.com/geoffreak>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
export declare function open(database: string, opts?: IOptions): IReader;
|
||||
export declare function validate(ip: string): boolean;
|
||||
|
||||
export declare interface IReader {
|
||||
get(ip: string): IResponse | null;
|
||||
readonly metadata: IMetadata;
|
||||
}
|
||||
|
||||
export declare interface IOptions {
|
||||
cache?: {
|
||||
max?: number;
|
||||
maxAge?: number;
|
||||
}
|
||||
}
|
||||
|
||||
export declare interface IMetadata {
|
||||
readonly binaryFormatMajorVersion: number;
|
||||
readonly binaryFormatMinorVersion: number;
|
||||
readonly buildEpoch: Date;
|
||||
readonly databaseType: string;
|
||||
readonly languages: string[];
|
||||
readonly description: ITranslations;
|
||||
readonly ipVersion: number;
|
||||
readonly nodeCount: number;
|
||||
readonly recordSize: number;
|
||||
readonly nodeByteSize: number;
|
||||
readonly searchTreeSize: number;
|
||||
readonly treeDepth: number;
|
||||
}
|
||||
|
||||
export declare interface IResponse {
|
||||
readonly continent?: {
|
||||
readonly geoname_id: number;
|
||||
readonly names: ITranslations;
|
||||
readonly code: string;
|
||||
};
|
||||
readonly country?: {
|
||||
readonly geoname_id: number;
|
||||
readonly names: ITranslations;
|
||||
readonly iso_code: string;
|
||||
};
|
||||
readonly registered_country?: {
|
||||
readonly geoname_id: number;
|
||||
readonly names: ITranslations;
|
||||
readonly iso_code: string;
|
||||
};
|
||||
readonly location?: {
|
||||
readonly accuracy_radius: number;
|
||||
readonly latitude: number;
|
||||
readonly longitude: number;
|
||||
readonly metro_code?: number;
|
||||
readonly time_zone?: string;
|
||||
};
|
||||
readonly subdivisions?: {
|
||||
readonly geoname_id: number;
|
||||
readonly names: ITranslations;
|
||||
readonly iso_code: string;
|
||||
}[];
|
||||
readonly city?: {
|
||||
readonly geoname_id: number;
|
||||
readonly names: ITranslations;
|
||||
};
|
||||
readonly postal?: { code: string };
|
||||
}
|
||||
|
||||
export declare interface ITranslations {
|
||||
readonly [index: string]: string;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import * as maxmind from 'maxmind';
|
||||
|
||||
// Examples from https://github.com/runk/node-maxmind/blob/master/README.md
|
||||
|
||||
// Example 1
|
||||
var cityLookup = maxmind.open('/path/to/GeoLite2-City.mmdb');
|
||||
var city = cityLookup.get('66.6.44.4');
|
||||
|
||||
var orgLookup = maxmind.open('/path/to/GeoOrg.mmdb');
|
||||
var organization = orgLookup.get('66.6.44.4');
|
||||
|
||||
// Example 2
|
||||
var lookup = maxmind.open('/path/to/GeoLite2.mmdb');
|
||||
var location = lookup.get('2001:4860:0:1001::3004:ef68');
|
||||
|
||||
// Example 3
|
||||
var lookup = maxmind.open('/path/to/GeoLite2.mmdb', {
|
||||
cache: {
|
||||
max: 1000, // max items in cache
|
||||
maxAge: 1000 * 60 * 60 // life time in milliseconds
|
||||
}
|
||||
})
|
||||
lookup.get('1.1.1.1');
|
||||
|
||||
// Example 4
|
||||
maxmind.validate('66.6.44.4'); // returns true
|
||||
maxmind.validate('66.6.44.boom!'); // returns false
|
||||
|
||||
maxmind.validate('2001:4860:0:1001::3004:ef68'); // returns true
|
||||
maxmind.validate('2001:4860:0:1001::3004:boom!'); // returns false
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es6",
|
||||
"noImplicitAny": true,
|
||||
"strictNullChecks": false,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"maxmind-tests.ts"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user