Merge pull request #76 from a631807682/master

[nodejs] publish package on npm
This commit is contained in:
lionsoul 2018-10-02 10:19:43 +08:00 committed by GitHub
commit d82447c1b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 31 additions and 3 deletions

View File

@ -1 +1,2 @@
node_modules/
data/

View File

@ -1,5 +1,18 @@
# 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`。

11
binding/nodejs/deploy.sh Normal file
View File

@ -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

View File

@ -8,6 +8,8 @@
* @author dongwei<maledong_github@outlook.com>
*/
const fs = require('fs');
const path = require('path');
const DEFAULT_DB_PATH = path.join(__dirname,'./data/ip2region.db') ;
//#region Private Functions
/**
@ -134,7 +136,7 @@ class IP2Region {
//#region Static Functions
// Single Instance
static create(dbPath) {
static create(dbPath = DEFAULT_DB_PATH) {
let existInstance = _globalInstances.get(dbPath);
if (existInstance == null) {
existInstance = new IP2Region({ dbPath: dbPath });

View File

@ -1,5 +1,5 @@
{
"name": "ip2region",
"name": "lionsoul-ip2region",
"version": "0.0.1",
"description": "ip database ",
"main": "ip2region.js",
@ -7,6 +7,7 @@
"test": "jest",
"coverage": "npm run test && jest --coverage"
},
"files": ["data/"],
"repository": {
"type": "git",
"url": "https://github.com/lionsoul2016/ip2region"
@ -26,4 +27,4 @@
"jest": "^19.0.2",
"benchmark": "^2.1.4"
}
}
}