haraka-net-utils
Advanced tools
Comparing version 1.3.2 to 1.3.3
#### 1.N.N - YYYY-MM-DD | ||
#### 1.3.3 - 2021-12-20 | ||
- refactored is_local_host function to return a promise instead of using a callback #65 | ||
#### 1.3.2 - 2021-12-20 | ||
@@ -6,0 +9,0 @@ |
24
index.js
@@ -143,16 +143,16 @@ 'use strict'; | ||
exports.is_local_host = function (host, done) { | ||
exports.is_local_host = async function (host) { | ||
if (net.isIP(host)) { | ||
done([], this.is_local_ip(host)); | ||
return; | ||
return this.is_local_ip(host); | ||
} | ||
return new Promise((resolve, reject) => { | ||
const self = this; | ||
const self = this; | ||
this.get_ips_by_host(host, function (errors, ips) { | ||
if (errors.length) { | ||
done(errors, undefined); | ||
} | ||
else { | ||
done([], ips.length ? self.is_local_ip(ips[0]) : false); | ||
} | ||
this.get_ips_by_host(host, function (errors, ips) { | ||
// don't reject if some IPs have been found (get_ips_by_host can return errors say for IPv6 but work for IPv4) | ||
if (errors && errors.length && (!ips || !ips.length)) { | ||
return reject(errors); | ||
} | ||
resolve(ips.length ? self.is_local_ip(ips[0]) : false); | ||
}); | ||
}); | ||
@@ -168,3 +168,3 @@ } | ||
console.error(`invalid IP address: ${ip}`); | ||
// console.error(`invalid IP address: ${ip}`); | ||
return false; | ||
@@ -171,0 +171,0 @@ } |
{ | ||
"name": "haraka-net-utils", | ||
"version": "1.3.2", | ||
"version": "1.3.3", | ||
"description": "haraka network utilities", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -85,7 +85,6 @@ | ||
function _is_local_host (done, host, expected) { | ||
net_utils.is_local_host(host, function (errors, is_local_host) { | ||
assert.strictEqual(expected, is_local_host); | ||
done(); | ||
}); | ||
async function _is_local_host (done, host, expected) { | ||
const is_local_host = await net_utils.is_local_host(host); | ||
assert.strictEqual(expected, is_local_host); | ||
done(); | ||
} | ||
@@ -124,4 +123,4 @@ | ||
it('invalid host string', function (done) { | ||
_is_local_host(done, 'invalid host string', undefined); | ||
it('invalid host string', async function () { | ||
await assert.rejects(net_utils.is_local_host('invalid host string')); | ||
}) | ||
@@ -128,0 +127,0 @@ }) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
80970
1448