hosts-lookup 1.1.3 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +11 -17
- package/package.json +3 -3
- package/readme.md +3 -4
package/index.js
CHANGED
|
@@ -1,22 +1,16 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
|
|
3
|
-
module.exports = function (hname
|
|
2
|
+
const getHosts = require('get-hosts');
|
|
3
|
+
module.exports = function (hname) {
|
|
4
4
|
if (typeof hname !== 'string') {
|
|
5
5
|
throw new TypeError('Expected a string');
|
|
6
6
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
)
|
|
15
|
-
|
|
16
|
-
if (host) {
|
|
17
|
-
cb(null, host[Object.keys(host)[0]])
|
|
18
|
-
} else {
|
|
19
|
-
cb(new Error('No such host!'),false);
|
|
20
|
-
}
|
|
21
|
-
|
|
7
|
+
return new Promise((resolve, reject) => {
|
|
8
|
+
const host = getHosts()
|
|
9
|
+
.filter(info => (
|
|
10
|
+
Object.keys(info)[0]).includes(hname)
|
|
11
|
+
)[0];
|
|
12
|
+
host ?
|
|
13
|
+
resolve(host[Object.keys(host)[0]]) :
|
|
14
|
+
reject('No such host!');
|
|
15
|
+
});
|
|
22
16
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hosts-lookup",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "Lookup your `/etc/hosts`",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "hemanth/hosts-lookup",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"node": ">= 4"
|
|
14
14
|
},
|
|
15
15
|
"scripts": {
|
|
16
|
-
"test": "mocha"
|
|
16
|
+
"test": "mocha test.js"
|
|
17
17
|
},
|
|
18
18
|
"files": [
|
|
19
19
|
"index.js"
|
|
@@ -29,6 +29,6 @@
|
|
|
29
29
|
"get-hosts": "^2.0.1"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"mocha": "
|
|
32
|
+
"mocha": "^11.7.0"
|
|
33
33
|
}
|
|
34
34
|
}
|
package/readme.md
CHANGED
|
@@ -14,10 +14,9 @@ $ npm install --save hosts-lookup
|
|
|
14
14
|
|
|
15
15
|
```js
|
|
16
16
|
var hostsLookup = require('hosts-lookup');
|
|
17
|
-
hostsLookup('crazy-cat'
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
});
|
|
17
|
+
hostsLookup('crazy-cat')
|
|
18
|
+
.then(console.log) // => ip is value from `hosts` if found.
|
|
19
|
+
.catch(console.error)
|
|
21
20
|
```
|
|
22
21
|
P.S: This module was created as a result of this [issue](https://github.com/sindresorhus/module-requests/issues/13).
|
|
23
22
|
|