Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ipv6

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ipv6 - npm Package Compare versions

Comparing version 3.0.0 to 3.1.0

81

ipv6.js

@@ -35,2 +35,5 @@ if (typeof exports !== 'undefined') {

v6.RE_URL = new RegExp(/([0-9a-f:]+)/);
v6.RE_URL_WITH_PORT = new RegExp(/\[([0-9a-f:]+)\]:([0-9]{1,5})/);
// Convenience functions

@@ -223,2 +226,15 @@ function map(array, fn) {

/*
* Converts an IPv4 address object to an array of bytes
*/
v4.Address.prototype.toArray = function () {
var array = new Array(4);
this.parsedAddress.map(function (part, index) {
array[index] = parseInt(part, 10);
});
return array;
};
/*
* Converts an IPv4 address object to an IPv6 address group

@@ -280,3 +296,3 @@ */

v4.Address.fromBigInteger = function (bigInteger) {
return v4.Address.fromInteger(parseInt(bigInteger.toString()));
return v4.Address.fromInteger(parseInt(bigInteger.toString(), 10));
};

@@ -387,2 +403,65 @@

/*
* Converts a URL (optional port number) to an address object
*/
v6.Address.fromURL = function (url) {
var host;
var port;
var result;
// If we have brackets parse them and find a port
if (url.indexOf('[') !== -1 && url.indexOf(']') !== -1) {
result = v6.RE_URL_WITH_PORT.exec(url);
if (result === null) {
return {
error: 'failed to parse address with port',
address: null,
port: null
};
}
host = result[1];
port = result[2];
// If there's a URL extract the address
} else if (url.indexOf('/') !== -1) {
// Remove the protocol prefix
url = url.replace(/^[a-z0-9]+:\/\//, '');
// Parse the address
result = v6.RE_URL.exec(url);
if (result === null) {
return {
error: 'failed to parse address from URL',
address: null,
port: null
};
}
host = result[1];
// Otherwise just assign the URL to the host and let the library parse it
} else {
host = url;
}
// If there's a port convert it to an integer
if (port) {
port = parseInt(port, 10);
//squelch out of range ports
if (port < 0 || port > 65536) {
port = null;
}
} else {
// Standardize `undefined` to `null`
port = null;
}
return {
address: new v6.Address(host),
port: port
};
};
/*
* A helper function to compact an array

@@ -389,0 +468,0 @@ */

11

package.json

@@ -9,3 +9,3 @@ {

],
"version": "3.0.0",
"version": "3.1.0",
"author": "Beau Gunderson <beau@beaugunderson.com>",

@@ -30,9 +30,8 @@ "license": "MIT",

"sprintf": "0.1.x",
"cli": "0.3.x",
"cliff": "0.1.x",
"eyes": "0.1.x"
"cli": "0.4.x",
"cliff": "0.1.x"
},
"devDependencies": {
"mocha": "1.8.x",
"chai": "1.5.x"
"mocha": "1.15.x",
"chai": "1.8.x"
},

@@ -39,0 +38,0 @@ "engines": {

@@ -59,2 +59,3 @@ javascript-ipv6 [![Build Status](https://secure.travis-ci.org/beaugunderson/javascript-ipv6.png?branch=master)](http://travis-ci.org/beaugunderson/javascript-ipv6)

- Parsing of most IPv6 notations
- Parsing of IPv6 Addresses and Ports from URLs with `v6.Address.fromURL(url)`
- Validity checking

@@ -61,0 +62,0 @@ - Decoding of the [Teredo information](http://en.wikipedia.org/wiki/Teredo_tunneling#IPv6_addressing) in an address

@@ -142,2 +142,17 @@ var sprintf = require('sprintf').sprintf;

describe('Converting an address to an array', function () {
var topic = new v4.Address('127.0.0.1');
it('should convert correctly', function () {
var a = topic.toArray();
a.should.be.an.instanceOf(Array).and.have.lengthOf(4);
a[0].should.equal(127);
a[1].should.equal(0);
a[2].should.equal(0);
a[3].should.equal(1);
});
});
describe('A different notation of the same address', function () {

@@ -144,0 +159,0 @@ var addresses = notationsToAddresseses([

var sprintf = require('sprintf').sprintf;
var should = require('chai').should();
var chai = require('chai');
var should = chai.should();
var expect = chai.expect;
var v4 = require('../ipv6').v4;
var v6 = require('../ipv6').v6;

@@ -37,3 +38,4 @@

it('is contained by an identical address with an identical subnet', function () {
it('is contained by an identical address with an identical subnet',
function () {
var same = new v6.Address('ffff::/64');

@@ -79,3 +81,4 @@

should.equal(topic.canonicalForm(), '000a:0000:0000:0000:0000:0000:0000:000b');
should.equal(topic.canonicalForm(),
'000a:0000:0000:0000:0000:0000:0000:000b');
});

@@ -97,3 +100,3 @@ });

describe('An address with a subnet', function () {
var topic = new v6.Address('a::b/48');
var topic = new v6.Address('a:b::/48');

@@ -109,8 +112,7 @@ it('validates', function () {

it('is in its own subnet', function () {
topic.isInSubnet(new v6.Address('a::b/48')).should.equal(true);
topic.isInSubnet(new v6.Address('a:b::/48')).should.equal(true);
});
// XXX? .should.equal(false) right?
it('is not in another subnet', function () {
topic.isInSubnet(new v6.Address('a::c/48')).should.equal(true);
topic.isInSubnet(new v6.Address('a:c::/48')).should.equal(false);
});

@@ -193,2 +195,68 @@ });

});
describe('Address inside a URL or inside a URL with a port', function () {
it('should work with a host address', function () {
var obj = v6.Address.fromURL('2001:db8::5');
expect(obj.address.valid).to.equal(true);
expect(obj.address.address).to.equal('2001:db8::5');
expect(obj.port).to.equal(null);
});
it('should work with a basic URL', function () {
var obj = v6.Address.fromURL('http://2001:db8::5/foo');
expect(obj.address.isValid()).to.equal(true);
expect(obj.address.address).equal('2001:db8::5');
expect(obj.port).to.equal(null);
});
it('should work with a URL with a port', function () {
var obj = v6.Address.fromURL('http://[2001:db8::5]:80/foo');
expect(obj.address.isValid()).to.equal(true);
expect(obj.address.address).to.equal('2001:db8::5');
expect(obj.port).to.equal(80);
});
it('should work with a URL with a long port number', function () {
var obj = v6.Address.fromURL('http://[2001:db8::5]:65536/foo');
expect(obj.address.isValid()).to.equal(true);
expect(obj.address.address).to.equal('2001:db8::5');
expect(obj.port).to.equal(65536);
});
it('should work with a address with a port', function () {
var obj = v6.Address.fromURL('[2001:db8::5]:80');
expect(obj.address.isValid()).to.equal(true);
expect(obj.address.address).to.equal('2001:db8::5');
expect(obj.port).to.equal(80);
});
it('should work with a address with a long port', function () {
var obj = v6.Address.fromURL('[2001:db8::5]:65536');
expect(obj.address.isValid()).to.equal(true);
expect(obj.address.address).to.equal('2001:db8::5');
expect(obj.port).to.equal(65536);
});
it('should parse the address but fail with an invalid port', function () {
var obj = v6.Address.fromURL('[2001:db8::5]:65537');
expect(obj.address.isValid()).to.equal(true);
expect(obj.address.address).to.equal('2001:db8::5');
expect(obj.port).to.equal(null);
});
it('should fail with an invalid address and not return a port',
function () {
var obj = v6.Address.fromURL('[2001:db8:z:5]:65536');
expect(obj.error).to.equal('failed to parse address with port');
expect(obj.port).to.equal(null);
});
});
});

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc