Comparing version 0.0.5 to 0.1.0
@@ -296,4 +296,20 @@ var ip = exports, | ||
ip.toLong = function toInt(ip){ | ||
var ipl=0; | ||
ip.split('.').forEach(function( octet ) { | ||
ipl<<=8; | ||
ipl+=parseInt(octet); | ||
}); | ||
return(ipl >>>0); | ||
}; | ||
ip.fromLong = function fromInt(ipl){ | ||
return ( (ipl>>>24) +'.' + | ||
(ipl>>16 & 255) +'.' + | ||
(ipl>>8 & 255) +'.' + | ||
(ipl & 255) ); | ||
}; | ||
function _normalizeFamily(family) { | ||
return family ? family.toLowerCase() : 'ipv4'; | ||
} |
{ | ||
"name": "ip", | ||
"version": "0.0.5", | ||
"version": "0.1.0", | ||
"author": "Fedor Indutny <fedor@indutny.com>", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/indutny/node-ip", |
@@ -24,2 +24,7 @@ # IP | ||
ip.toString(buf, offset, 4); // '127.0.0.1' | ||
// ipv4 long conversion | ||
ip.toLong('127.0.0.1'); // 2130706433 | ||
ip.fromLong(2130706433); // '127.0.0.1' | ||
``` | ||
@@ -26,0 +31,0 @@ |
@@ -211,2 +211,18 @@ var ip = require('..'), | ||
}); | ||
describe('toLong() method', function(){ | ||
it('should respond with a int', function(){ | ||
assert.equal(ip.toLong('127.0.0.1'), 2130706433); | ||
assert.equal(ip.toLong('255.255.255.255'), 4294967295); | ||
}); | ||
}); | ||
describe('fromLong() method', function(){ | ||
it('should repond with ipv4 address', function(){ | ||
assert.equal(ip.fromLong(2130706433), '127.0.0.1'); | ||
assert.equal(ip.fromLong(4294967295), '255.255.255.255'); | ||
}); | ||
}) | ||
}); |
17469
460
55