Comparing version 0.0.2 to 0.0.3
@@ -104,2 +104,31 @@ var ip = exports, | ||
ip.or = function or(a, b) { | ||
a = ip.toBuffer(a); | ||
b = ip.toBuffer(b); | ||
// same protocol | ||
if (a.length == b.length) { | ||
for (var i = 0; i < a.length; ++i) { | ||
a[i] |= b[i]; | ||
} | ||
return ip.toString(a); | ||
// mixed protocols | ||
} else { | ||
var buff = a; | ||
var other = b; | ||
if (b.length > a.length) { | ||
buff = b; | ||
other = a; | ||
} | ||
var offset = buff.length - other.length; | ||
for (var i = offset; i < buff.length; ++i) { | ||
buff[i] |= other[i - offset]; | ||
} | ||
return ip.toString(buff); | ||
} | ||
}; | ||
ip.isEqual = function isEqual(a, b) { | ||
@@ -106,0 +135,0 @@ a = ip.toBuffer(a); |
{ | ||
"name": "ip", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"author": "Fedor Indutny <fedor@indutny.com>", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/indutny/node-ip", |
@@ -15,2 +15,3 @@ # IP | ||
ip.not('255.255.255.0') // 0.0.0.255 | ||
ip.or('192.168.1.134', '0.0.0.255') // 192.168.1.255 | ||
ip.isPrivate('127.0.0.1') // true | ||
@@ -17,0 +18,0 @@ ``` |
@@ -29,2 +29,14 @@ var ip = require('..'), | ||
describe('or() method', function() { | ||
it('should or bits in ipv4 addresses', function() { | ||
assert.equal(ip.or('0.0.0.255', '192.168.1.10'), '192.168.1.255'); | ||
}); | ||
it('should or bits in ipv6 addresses', function() { | ||
assert.equal(ip.or('::ff', '::abcd:dcba:abcd:dcba'), '::abcd:dcba:abcd:dcff'); | ||
}); | ||
it('should or bits in mixed addresses', function() { | ||
assert.equal(ip.or('0.0.0.255', '::abcd:dcba:abcd:dcba'), '::abcd:dcba:abcd:dcff'); | ||
}); | ||
}); | ||
describe('mask() method', function() { | ||
@@ -31,0 +43,0 @@ it('should mask bits in address', function() { |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
14398
381
43
1