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

ip-address

Package Overview
Dependencies
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ip-address - npm Package Compare versions

Comparing version 3.2.1 to 4.0.0

coverage.sh

12

lib/ipv6.js

@@ -5,8 +5,12 @@ 'use strict';

var common = require('./common.js');
var merge = reqiore('lodash.merge');
var find = require('lodash.find');
var merge = require('lodash.merge');
var sprintf = require('sprintf').sprintf;
var v4 = require('./ipv4.js').v4;
var v6 = exports.v6 = {};
var v6 = exports.v6 = {
helpers: require('./v6/helpers.js')
};
merge(v6, require('./v6/constants.js'));

@@ -274,7 +278,7 @@

function isType(type) {
function isType(name, type) {
return self.isInSubnet(new v6.Address(type));
}
return _.find(v6.TYPES, isType) || 'Global unicast';
return find(v6.TYPES, isType) || 'Global unicast';
};

@@ -281,0 +285,0 @@

@@ -47,3 +47,3 @@ exports.BITS = 128;

exports.RE_URL = new RegExp(/\[{0,1}([0-9a-f:]+)\]{0,1}/);
exports.RE_URL = new RegExp(/^\[{0,1}([0-9a-f:]+)\]{0,1}/);
exports.RE_URL_WITH_PORT = new RegExp(/\[([0-9a-f:]+)\]:([0-9]{1,5})/);
'use strict';
var constants4 = require('../v4/constants.js');
var helpers = require('./helpers.js');
var sprintf = require('sprintf').sprintf;
var constants4 = require('../v4/constants.js');
function spanLeadingZeroesSimple(group) {
return group.replace(/^(0+)/, '<span class="zero">$1</span>');
}
/*

@@ -58,67 +55,7 @@ * Returns the address in link form with a default port of 80

// TODO: Put these helpers somewhere else
var v6 = {Address: {}};
/*
* Returns the string with each character contained in a <span>
*/
v6.Address.spanAll = function (s, optionalOffset) {
if (optionalOffset === undefined) {
optionalOffset = 0;
}
var letters = s.split('');
return letters.map(function (n, i) {
return sprintf('<span class="digit value-%s position-%d">%s</span>', n,
i + optionalOffset,
v6.Address.spanAllZeroes(n)); // XXX Use #base-2 .value-0 instead?
}).join('');
};
/*
* Returns the string with all zeroes contained in a <span>
*/
v6.Address.spanAllZeroes = function (s) {
return s.replace(/(0+)/g, '<span class="zero">$1</span>');
};
/*
* Returns the string with leading zeroes contained in a <span>
*/
v6.Address.spanLeadingZeroes = function (address) {
var groups = address.split(':');
return groups.map(function (g) {
return spanLeadingZeroesSimple(g);
}).join(':');
};
/*
* Groups an address
*/
v6.Address.simpleGroup = function (addressString, offset) {
var groups = addressString.split(':');
if (!offset) {
offset = 0;
}
return groups.map(function (g, i) {
if (/group-v4/.test(g)) {
return g;
}
return sprintf('<span class="hover-group group-%d">%s</span>',
i + offset,
spanLeadingZeroesSimple(g));
}).join(':');
};
/*
* Groups an address
*/
v6.Address.group = function (addressString) {
var address6 = new v6.Address(addressString);
var address4 = address6.address.match(constants4.RE_ADDRESS);
exports.group = function () {
var address4 = this.address.match(constants4.RE_ADDRESS);
var i;

@@ -130,3 +67,3 @@

address6.address = address6.address.replace(constants4.RE_ADDRESS,
this.address = this.address.replace(constants4.RE_ADDRESS,
sprintf('<span class="hover-group group-v4 group-6">%s</span>' +

@@ -139,5 +76,5 @@ '.' +

if (address6.elidedGroups === 0) {
if (this.elidedGroups === 0) {
// The simple case
return v6.Address.simpleGroup(address6.address);
return helpers.simpleGroup(this.address);
}

@@ -148,6 +85,6 @@

var halves = address6.address.split('::');
var halves = this.address.split('::');
if (halves[0].length) {
output.push(v6.Address.simpleGroup(halves[0]));
output.push(helpers.simpleGroup(halves[0]));
} else {

@@ -159,4 +96,4 @@ output.push('');

for (i = address6.elisionBegin;
i < address6.elisionBegin + address6.elidedGroups; i++) {
for (i = this.elisionBegin;
i < this.elisionBegin + this.elidedGroups; i++) {
classes.push(sprintf('group-%d', i));

@@ -168,3 +105,3 @@ }

if (halves[1].length) {
output.push(v6.Address.simpleGroup(halves[1], address6.elisionEnd));
output.push(helpers.simpleGroup(halves[1], this.elisionEnd));
} else {

@@ -171,0 +108,0 @@ output.push('');

@@ -103,10 +103,2 @@ 'use strict';

function add(piece) {
if (Array.isArray(piece)) {
output = output.concat(piece);
} else {
output.push(piece);
}
}
// TODO: revisit why this is necessary

@@ -117,6 +109,6 @@ var address6 = new this.constructor(this.correctForm());

// The simple case
add(simpleRegularExpression(address6.parsedAddress));
output.push(simpleRegularExpression(address6.parsedAddress));
} else if (address6.elidedGroups === v6.GROUPS) {
// A completely elided address
add(possibleElisions(v6.GROUPS));
output.push(possibleElisions(v6.GROUPS));
} else {

@@ -127,6 +119,6 @@ // A partially elided address

if (halves[0].length) {
add(simpleRegularExpression(halves[0].split(':')));
output.push(simpleRegularExpression(halves[0].split(':')));
}
add(possibleElisions(address6.elidedGroups,
output.push(possibleElisions(address6.elidedGroups,
halves[0].length !== 0,

@@ -136,3 +128,3 @@ halves[1].length !== 0));

if (halves[1].length) {
add(simpleRegularExpression(halves[1].split(':')));
output.push(simpleRegularExpression(halves[1].split(':')));
}

@@ -154,4 +146,4 @@

*/
exports.regularExpression = function () {
return new RegExp(this.regularExpressionString(), 'i');
exports.regularExpression = function (optionalSubstring) {
return new RegExp(this.regularExpressionString(optionalSubstring), 'i');
};

@@ -10,3 +10,3 @@ {

],
"version": "3.2.1",
"version": "4.0.0",
"author": "Beau Gunderson <beau@beaugunderson.com> (https://beaugunderson.com/)",

@@ -16,4 +16,3 @@ "license": "MIT",

"scripts": {
"test": "./node_modules/.bin/mocha -R spec",
"posttest": "./coverage.js"
"test": "mocha -R spec"
},

@@ -34,27 +33,13 @@ "bin": {

"cliff": "0.1.x",
"coveralls": "^2.11.2",
"jsbn": "0.0.0",
"lodash.find": "^3.2.0",
"lodash.merge": "^3.2.1",
"mocha-lcov-reporter": "0.0.2",
"sprintf": "0.1.x"
},
"devDependencies": {
"blanket": "^1.1.6",
"chai": "^2.3.0",
"coveralls": "^2.11.2",
"istanbul": "^0.3.13",
"mocha": "^2.2.4"
},
"config": {
"blanket": {
"pattern": [
"ipv4.js",
"ipv6.js",
"common.js",
"attributes.js",
"constants.js",
"html.js",
"regular-expressions.js"
]
}
}
}

@@ -7,12 +7,2 @@ [![Build Status](https://secure.travis-ci.org/beaugunderson/ip-address.png?branch=master)](http://travis-ci.org/beaugunderson/ip-address) [![Coverage Status](https://img.shields.io/coveralls/beaugunderson/ip-address.svg)](https://coveralls.io/r/beaugunderson/ip-address?branch=master)

### Pardon our dust
I'm currently working on tearing out the browser-specific stuff because I don't
want to duplicate the work of browserify. You should be able to use it just
fine with browserify right now but I'd like to do more cleanup before pushing
4.0 to npm.
I'll also be doing some renaming but will keep around the old names with
deprecation warnings.
### Examples

@@ -51,4 +41,4 @@

- IPv4-compatible (i.e. `::ffff:192.168.0.1`)
- Works in [node.js](http://nodejs.org/) and the browser
- Unit tests with [node.js](http://nodejs.org/) and
- Works in [node.js](http://nodejs.org/) and the browser (with browserify)
- 1,500+ unit tests with [node.js](http://nodejs.org/) and
[Mocha](http://visionmedia.github.com/mocha/)

@@ -64,11 +54,4 @@

### Future functionality
- Investigate `procstreams` for the CLI tool
- Base 64/85 encoding?
- Reverse lookups? (Whether a domain name has IPv6 glue)
### TODO
- Documentation
- npm deprecate, rename to ip-address
- [Better documentation](https://github.com/documentationjs/documentation)

@@ -57,12 +57,15 @@ 'use strict';

var re = address6.regularExpression();
var reSubstring = address6.regularExpression(true);
it('matches the correct form via regex', function () {
var re = address6.regularExpression();
re.test(address6.correctForm()).should.equal(true);
reSubstring.test('abc ' + address6.correctForm() + ' def')
.should.equal(true);
});
it('matches the canonical form via regex', function () {
var re = address6.regularExpression();
re.test(address6.canonicalForm()).should.equal(true);
reSubstring.test('abc ' + address6.canonicalForm() + ' def')
.should.equal(true);
});

@@ -76,5 +79,5 @@

var re = address6.regularExpression();
re.test(addressString).should.equal(true);
reSubstring.test('abc ' + addressString + ' def')
.should.equal(true);
});

@@ -96,2 +99,3 @@ }

address6.isValid().should.equal(false);
should.not.exist(address6.correctForm());
});

@@ -98,0 +102,0 @@ }

@@ -116,2 +116,10 @@ 'use strict';

it('has a correct start address', function () {
should.equal(topic.startAddress().correctForm(), '127.0.0.0');
});
it('has a correct end address', function () {
should.equal(topic.endAddress().correctForm(), '127.0.255.255');
});
it('is in its own subnet', function () {

@@ -118,0 +126,0 @@ topic.isInSubnet(new v4.Address('127.0.0.1/16')).should.equal(true);

@@ -16,9 +16,5 @@ 'use strict';

function notationsToAddresseses(notations) {
var addresses = [];
notations.forEach(function (notation) {
addresses.push(new v6.Address(notation));
return notations.map(function (notation) {
return new v6.Address(notation);
});
return addresses;
}

@@ -46,2 +42,23 @@

describe('a fully ellided /0 address', function () {
var topic = new v6.Address('::/0');
it('gets the correct reverse from', function () {
topic.reverseForm().should.equal('ip6.arpa.');
});
});
describe('A link local address', function () {
var topic = new v6.Address('fe80::baf6:b1ff:fe15:4885');
it('gets the correct type', function () {
topic.getType().should.equal('Link-local unicast');
topic.isTeredo().should.equal(false);
topic.isLoopback().should.equal(false);
topic.isMulticast().should.equal(false);
topic.isLinkLocal().should.equal(true);
});
});
describe('A correct address', function () {

@@ -69,2 +86,7 @@ var topic = new v6.Address('a:b:c:d:e:f:0:1/64');

it('gets the correct reverse from', function () {
topic.reverseForm()
.should.equal('d.0.0.0.c.0.0.0.b.0.0.0.a.0.0.0.ip6.arpa.');
});
it('gets the correct scope', function () {

@@ -78,2 +100,7 @@ topic.getScope().should.equal('Global');

it('gets the correct microsoft transcription', function () {
topic.microsoftTranscription()
.should.equal('a-b-c-d-e-f-0-1.ipv6-literal.net');
});
it('has correct bit information', function () {

@@ -106,2 +133,11 @@ topic.getBitsPastSubnet().should.equal(

it('has a correct start address', function () {
should.equal(topic.startAddress().correctForm(), 'ffff::');
});
it('has a correct end address', function () {
should.equal(topic.endAddress().correctForm(),
'ffff::ffff:ffff:ffff:ffff');
});
it('calculates and formats the subnet size', function () {

@@ -264,2 +300,16 @@ topic.possibleSubnets().should.equal('18,446,744,073,709,551,616');

describe('Address from an IPv4 address', function () {
var obj = v6.Address.fromAddress4('192.168.0.1');
it('should parse correctly', function () {
expect(obj.valid).to.equal(true);
expect(obj.correctForm()).to.equal('::ffff:c0a8:1');
expect(obj.v4inv6()).to.equal('::ffff:192.168.0.1');
});
it('should generate a 6to4 address', function () {
expect(obj.get6to4().correctForm()).to.equal('2002:c0a8:1::');
});
});
describe('Address inside a URL or inside a URL with a port', function () {

@@ -274,2 +324,10 @@ it('should work with a host address', function () {

it('should fail with an invalid URL', function () {
var obj = v6.Address.fromURL('http://zombo/foo');
expect(obj.error).to.equal('failed to parse address from URL');
expect(obj.address).to.equal(null);
expect(obj.port).to.equal(null);
});
it('should work with a basic URL', function () {

@@ -315,3 +373,3 @@ var obj = v6.Address.fromURL('http://2001:db8::5/foo');

it('should work with a address with a long port', function () {
it('should work with an address with a long port', function () {
var obj = v6.Address.fromURL('[2001:db8::5]:65536');

@@ -354,2 +412,111 @@

});
describe('HTML helpers', function () {
describe('href', function () {
var topic = new v6.Address('2001:4860:4001:803::1011');
it('should generate a URL correctly', function () {
topic.href().should.equal('http://[2001:4860:4001:803::1011]/');
topic.href(8080).should.equal('http://[2001:4860:4001:803::1011]:8080/');
});
});
describe('link', function () {
var topic = new v6.Address('2001:4860:4001:803::1011');
it('should generate an anchor correctly', function () {
topic.link()
.should.equal('<a href="/#address=2001:4860:4001:803::1011">' +
'2001:4860:4001:803::1011</a>');
topic.link({className: 'highlight', prefix: '/?address='})
.should.equal('<a href="/?address=2001:4860:4001:803::1011" ' +
'class="highlight">2001:4860:4001:803::1011</a>');
});
it('should generate a v4inv6 anchor correctly', function () {
var topic4 = new v6.Address('::ffff:c0a8:1');
topic4.link({v4: true})
.should.equal('<a href="/#address=::ffff:192.168.0.1">' +
'::ffff:192.168.0.1</a>');
});
});
describe('group', function () {
it('should group a fully ellided address', function () {
var topic = new v6.Address('::');
topic.group()
.should.equal(':<span class="hover-group group-0 group-1 group-2 ' +
'group-3 group-4 group-5 group-6 group-7"></span>:');
});
it('should group an address with no ellision', function () {
var topic = new v6.Address('a:b:c:d:1:2:3:4');
topic.group()
.should.equal('<span class="hover-group group-0">a</span>:' +
'<span class="hover-group group-1">b</span>:' +
'<span class="hover-group group-2">c</span>:' +
'<span class="hover-group group-3">d</span>:' +
'<span class="hover-group group-4">1</span>:' +
'<span class="hover-group group-5">2</span>:' +
'<span class="hover-group group-6">3</span>:' +
'<span class="hover-group group-7">4</span>');
});
it('should group an ellided address', function () {
var topic = new v6.Address('2001:4860:4001:803::1011');
topic.group()
.should.equal('<span class="hover-group group-0">2001</span>:' +
'<span class="hover-group group-1">4860</span>:' +
'<span class="hover-group group-2">4001</span>:' +
'<span class="hover-group group-3">803</span>:' +
'<span class="hover-group group-4 group-5 ' +
'group-6"></span>:' +
'<span class="hover-group group-7">1011</span>');
});
it('should group an IPv4 address', function () {
var topic = new v6.Address('192.168.0.1');
topic.group().should.equal(
'<span class="hover-group group-v4 group-6">192.168</span>.' +
'<span class="hover-group group-v4 group-7">0.1</span>');
});
});
});
describe('String helpers', function () {
describe('spanLeadingZeroes', function () {
it('should span leading zeroes', function () {
var topic = v6.helpers.spanLeadingZeroes('0000:0000:4444:0001');
topic
.should.equal('<span class="zero">0000</span>:' +
'<span class="zero">0000</span>:4444:' +
'<span class="zero">000</span>1');
});
});
describe('spanAll', function () {
it('should span leading zeroes', function () {
var topic = v6.helpers.spanAll('001100');
topic
.should.equal('<span class="digit value-0 position-0">' +
'<span class="zero">0</span></span>' +
'<span class="digit value-0 position-1">' +
'<span class="zero">0</span></span>' +
'<span class="digit value-1 position-2">1</span>' +
'<span class="digit value-1 position-3">1</span>' +
'<span class="digit value-0 position-4">' +
'<span class="zero">0</span></span>' +
'<span class="digit value-0 position-5">' +
'<span class="zero">0</span></span>');
});
});
});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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