mirror of
https://github.com/netfun2000/ip2region.git
synced 2026-02-27 09:44:31 +08:00
Refactor of codes in node.js
1) Add async method: `binarySearch` and `btreeSearch`. 2) Refactor of tests by putting them into `tests` folder. 3) Create several new tests in details. 4) Remove useless and reformat codes to be clear. 5) Remove useless snapshots, because they can be recreated when you run `npm run test`.
This commit is contained in:
23
binding/nodejs/tests/utils/asyncFor.js
Normal file
23
binding/nodejs/tests/utils/asyncFor.js
Normal file
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* Async For
|
||||
* @param {Array} groupArray
|
||||
* @param {Function} exeCallBack
|
||||
* @param {Function} finalCallBack
|
||||
*/
|
||||
function asyncFor(groupArray, exeCallBack, finalCallBack) {
|
||||
|
||||
let i = 0;
|
||||
|
||||
function _innerAsyncLoop() {
|
||||
if (i < groupArray.length) {
|
||||
exeCallBack(groupArray[i++], _innerAsyncLoop);
|
||||
}
|
||||
else {
|
||||
finalCallBack();
|
||||
}
|
||||
}
|
||||
|
||||
_innerAsyncLoop();
|
||||
}
|
||||
|
||||
module.exports = asyncFor;
|
||||
9
binding/nodejs/tests/utils/fetchMainVersion.js
Normal file
9
binding/nodejs/tests/utils/fetchMainVersion.js
Normal file
@@ -0,0 +1,9 @@
|
||||
let node_ver = process.version
|
||||
// Because nodejs's version is something like `v8.11.3`. So we should ignore `v` first
|
||||
node_ver = node_ver.substr(1);
|
||||
// Splitted by `.`
|
||||
node_ver = node_ver.split('.');
|
||||
// Take the main version number
|
||||
node_ver = parseInt(node_ver[0]);
|
||||
|
||||
module.exports = node_ver;
|
||||
16
binding/nodejs/tests/utils/testData.js
Normal file
16
binding/nodejs/tests/utils/testData.js
Normal file
@@ -0,0 +1,16 @@
|
||||
module.exports = [
|
||||
'0.0.0.0',
|
||||
'10.10.10.10',
|
||||
'210.109.255.230',
|
||||
'192.168.0.1',
|
||||
'255.255.255.255',
|
||||
'77.49.66.88',
|
||||
'210.248.255.231',
|
||||
'35.193.251.120',
|
||||
'197.84.60.202',
|
||||
'183.196.233.159',
|
||||
'20.108.91.101',
|
||||
'120.196.148.137',
|
||||
'249.255.250.200',
|
||||
'112.65.1.130'
|
||||
]
|
||||
Reference in New Issue
Block a user