[nodejs] publish package on npm
This commit is contained in:
parent
c95bed6f58
commit
ad219e3e07
|
|
@ -1 +1,2 @@
|
||||||
node_modules/
|
node_modules/
|
||||||
|
data/
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,18 @@
|
||||||
# nodejs 客户端
|
# nodejs 客户端
|
||||||
|
|
||||||
|
## Install
|
||||||
|
```
|
||||||
|
npm install lionsoul-ip2region --save
|
||||||
|
```
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
```
|
||||||
|
const searcher = require('lionsoul-ip2region').create();
|
||||||
|
searcher.btreeSearchSync('xxx.xxx.xxx.xxx')
|
||||||
|
// => { city: 2163, region: '中国|0|广东省|深圳市|联通' }
|
||||||
|
```
|
||||||
|
|
||||||
## 实现情况:
|
## 实现情况:
|
||||||
|
|
||||||
现已实现同步和异步查询,具体使用方法可以参考 `nodejs\tests\constructorTest.spec.js` 和`nodejs\tests\createTest.spec.js`。
|
现已实现同步和异步查询,具体使用方法可以参考 `nodejs\tests\constructorTest.spec.js` 和`nodejs\tests\createTest.spec.js`。
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
#!/bin/sh
|
||||||
|
echo 'create dir'
|
||||||
|
if [ ! -d "data" ]; then
|
||||||
|
mkdir data
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "copy db"
|
||||||
|
cp '../../data/ip2region.db' './data/'
|
||||||
|
|
||||||
|
echo "npm publish"
|
||||||
|
npm publish
|
||||||
|
|
@ -8,6 +8,8 @@
|
||||||
* @author dongwei<maledong_github@outlook.com>
|
* @author dongwei<maledong_github@outlook.com>
|
||||||
*/
|
*/
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
const DEFAULT_DB_PATH = path.join(__dirname,'./data/ip2region.db') ;
|
||||||
|
|
||||||
//#region Private Functions
|
//#region Private Functions
|
||||||
/**
|
/**
|
||||||
|
|
@ -134,7 +136,7 @@ class IP2Region {
|
||||||
//#region Static Functions
|
//#region Static Functions
|
||||||
|
|
||||||
// Single Instance
|
// Single Instance
|
||||||
static create(dbPath) {
|
static create(dbPath = DEFAULT_DB_PATH) {
|
||||||
let existInstance = _globalInstances.get(dbPath);
|
let existInstance = _globalInstances.get(dbPath);
|
||||||
if (existInstance == null) {
|
if (existInstance == null) {
|
||||||
existInstance = new IP2Region({ dbPath: dbPath });
|
existInstance = new IP2Region({ dbPath: dbPath });
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"name": "ip2region",
|
"name": "lionsoul-ip2region",
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"description": "ip database ",
|
"description": "ip database ",
|
||||||
"main": "ip2region.js",
|
"main": "ip2region.js",
|
||||||
|
|
@ -7,6 +7,7 @@
|
||||||
"test": "jest",
|
"test": "jest",
|
||||||
"coverage": "npm run test && jest --coverage"
|
"coverage": "npm run test && jest --coverage"
|
||||||
},
|
},
|
||||||
|
"files": ["data/"],
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/lionsoul2016/ip2region"
|
"url": "https://github.com/lionsoul2016/ip2region"
|
||||||
|
|
@ -26,4 +27,4 @@
|
||||||
"jest": "^19.0.2",
|
"jest": "^19.0.2",
|
||||||
"benchmark": "^2.1.4"
|
"benchmark": "^2.1.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue