diff --git a/README.md b/README.md index 339e275..66fdc63 100644 --- a/README.md +++ b/README.md @@ -55,9 +55,9 @@ example result: node: ``` -> const IP2Region = require('./ip2region.js'); -> const dbService = new IP2Region({dbPath: './ip2region.db'}); -> dbService.binarySearchSync('101.105.35.57') +> let ip2region = require('./ip2region.js'); +> let dbService = ip2region.create('./ip2region.db'); +> dbService.binarySearchSync(' 101.105.35.57') { city: 0, region: '中国|0|广东|深圳|鹏博士' } ``` diff --git a/binding/nodejs/ip2region.js b/binding/nodejs/ip2region.js index 686fcff..c6396cb 100644 --- a/binding/nodejs/ip2region.js +++ b/binding/nodejs/ip2region.js @@ -54,6 +54,10 @@ function getLong(buffer, offset) { */ class IP2Region { + static create(dbPath) { + return new IP2Region({dbPath}); + } + constructor(options = {}) { const { dbPath } = options; if (!dbPath || !fs.existsSync(dbPath)) { diff --git a/binding/nodejs/ip2region.spec.js b/binding/nodejs/ip2region.spec.js index a7650ee..0982fd7 100644 --- a/binding/nodejs/ip2region.spec.js +++ b/binding/nodejs/ip2region.spec.js @@ -5,7 +5,7 @@ describe('ip2region', () => { let instance; beforeAll(() => { - instance = new IP2Region({dbPath: path.join(__dirname, '../../data/ip2region.db')}); + instance = IP2Region.create(path.join(__dirname, '../../data/ip2region.db')); }); afterAll(() => {