Merge branch 'master' of https://github.com/lionsoul2014/ip2region
This commit is contained in:
commit
af9c8794ff
|
|
@ -0,0 +1 @@
|
|||
node_modules/
|
||||
|
|
@ -1,3 +1,3 @@
|
|||
# nodejs 客户端
|
||||
|
||||
现已实现同步查询,异步查询未实现,用法参考 test.js
|
||||
现已实现同步查询,异步查询未实现,用法参考 ip2region.spec.js
|
||||
|
|
|
|||
|
|
@ -0,0 +1,29 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`binarySearch 1`] = `
|
||||
Object {
|
||||
"city": 2163,
|
||||
"region": "中国|华南|广东省|深圳市|阿里云",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`binarySearch 2`] = `
|
||||
Object {
|
||||
"city": 0,
|
||||
"region": "未分配或者内网IP|0|0|0|0",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`should query 1`] = `
|
||||
Object {
|
||||
"city": 2163,
|
||||
"region": "中国|华南|广东省|深圳市|阿里云",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`should query 2`] = `
|
||||
Object {
|
||||
"city": 0,
|
||||
"region": "未分配或者内网IP|0|0|0|0",
|
||||
}
|
||||
`;
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
'use strict';
|
||||
|
||||
const ip = require('./ip2region');
|
||||
|
||||
const query = ip.create('../../data/ip2region.db');
|
||||
|
||||
it('should query', () => {
|
||||
expect(query.btreeSearchSync('120.24.78.68')).toMatchSnapshot();
|
||||
expect(query.btreeSearchSync('10.10.10.10')).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('binarySearch', () => {
|
||||
expect(query.binarySearchSync('120.24.78.68')).toMatchSnapshot();
|
||||
expect(query.binarySearchSync('10.10.10.10')).toMatchSnapshot();
|
||||
});
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
"description": "ip database ",
|
||||
"main": "ip2region.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
"test": "jest"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
|
@ -20,5 +20,8 @@
|
|||
"bugs": {
|
||||
"url": "https://github.com/lionsoul2016/ip2region/issues"
|
||||
},
|
||||
"homepage": "https://github.com/lionsoul2016/ip2region"
|
||||
"homepage": "https://github.com/lionsoul2016/ip2region",
|
||||
"devDependencies": {
|
||||
"jest": "^19.0.2"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,15 +0,0 @@
|
|||
/**
|
||||
* test program
|
||||
* */
|
||||
|
||||
var Ip2region = require('./ip2region');
|
||||
|
||||
// 1. create a ip2region object
|
||||
var ipObj = Ip2region.create('../../data/ip2region.db');
|
||||
|
||||
// 2. use
|
||||
//console.log(ipObj.binarySearchSync("120.24.78.68"));
|
||||
console.log(ipObj.btreeSearchSync("120.24.78.68"));
|
||||
|
||||
// 3. destroy
|
||||
Ip2region.destroy(ipObj);
|
||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue