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

URIjs

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

URIjs - npm Package Compare versions

Comparing version 1.4.2 to 1.6.3

src/SecondLevelDomains.js

3

package.json
{
"name": "URIjs",
"version": "1.4.2",
"version": "1.6.3",
"title": "URI.js - Mutating URLs",

@@ -37,4 +37,5 @@ "author": {

"src/IPv6.js",
"src/SecondLevelDomains.js",
"src/punycode.js"
]
}

@@ -0,1 +1,16 @@

/*!
* URI.js - Mutating URLs
* IPv6 Support
*
* Version: 1.6.3
*
* Author: Rodney Rehm
* Web: http://medialize.github.com/URI.js/
*
* Licensed under
* MIT License http://www.opensource.org/licenses/mit-license
* GPL v3 http://opensource.org/licenses/GPL-3.0
*
*/
(function(undefined){

@@ -7,3 +22,2 @@

var best = function(address) {

@@ -141,3 +155,2 @@ // based on:

global.IPv6 = {

@@ -144,0 +157,0 @@ best: best

@@ -1,5 +0,5 @@

/*
* URL.js - Mutating URLs
/*!
* URI.js - Mutating URLs
*
* Version: 1.4.2
* Version: 1.6.3
*

@@ -17,11 +17,30 @@ * Author: Rodney Rehm

var punycode = typeof module !== "undefined" && module.exports
? require('./punycode')
: window.punycode;
var _use_module = typeof module !== "undefined" && module.exports,
_load_module = function(module) {
return _use_module ? require('./' + module) : window[module];
},
punycode = _load_module('punycode'),
IPv6 = _load_module('IPv6'),
SLD = _load_module('SecondLevelDomains'),
URI = function(url, base) {
// Allow instantiation without the 'new' keyword
if (!(this instanceof URI)) {
return new URI(url);
}
var IPv6 = typeof module !== "undefined" && module.exports
? require('./IPv6')
: window.IPv6;
if (url === undefined) {
url = location.href + "";
}
this.href(url);
// resolve to base according to http://dvcs.w3.org/hg/url/raw-file/tip/Overview.html#constructor
if (base !== undefined) {
return this.absoluteTo(base);
}
return this;
},
p = URI.prototype;
function escapeRegEx(string) {

@@ -59,24 +78,2 @@ // https://github.com/medialize/URI.js/commit/85ac21783c11f8ccab06106dba9735a31a86924d#commitcomment-821963

// constructor
var URI = function(url, base) {
// Allow instantiation without the 'new' keyword
if (!(this instanceof URI)) {
return new URI(url);
}
if (url === undefined) {
url = location.href + "";
}
this.href(url);
// resolve to base according to http://dvcs.w3.org/hg/url/raw-file/tip/Overview.html#constructor
if (base !== undefined) {
return this.absoluteTo(base);
}
return this;
};
var p = URI.prototype;
// static properties

@@ -167,6 +164,4 @@ URI.idn_expression = /[^a-z0-9\.-]/i;

var _parts = {'encode':'encode', 'decode':'decode'},
_part;
for (_part in _parts) {
URI[_part + "PathSegment"] = (function(_part){
_part,
generateAccessor = function(_part){
return function(string) {

@@ -177,3 +172,6 @@ return URI[_part](string + "").replace(URI.characters.pathname[_part].expression, function(c) {

};
})(_parts[_part]);
};
for (_part in _parts) {
URI[_part + "PathSegment"] = generateAccessor(_parts[_part]);
}

@@ -202,9 +200,22 @@

// extract protocol
pos = string.indexOf('://');
if (pos > -1) {
parts.protocol = string.substring(0, pos);
string = string.substring(pos + 3);
if (string.substring(0, 2) === '//') {
// relative-scheme
parts.protocol = '';
string = string.substring(2);
// extract "user:pass@host:port"
string = URI.parseAuthority(string, parts);
} else {
pos = string.indexOf(':');
if (pos > -1) {
parts.protocol = string.substring(0, pos);
if (string.substring(pos + 1, pos + 3) === '//') {
string = string.substring(pos + 3);
// extract "user:pass@host:port"
string = URI.parseAuthority(string, parts);
} else {
string = string.substring(pos + 1);
parts.urn = true;
}
}
}

@@ -220,3 +231,5 @@

// extract host:port
var pos = string.indexOf('/');
var pos = string.indexOf('/'),
t;
if (pos === -1) {

@@ -252,5 +265,10 @@ pos = string.length;

URI.parseAuthority = function(string, parts) {
string = URI.parseUserinfo(string, parts);
return URI.parseHost(string, parts);
};
URI.parseUserinfo = function(string, parts) {
// extract username:password
var pos = string.indexOf('@'),
firstSlash = string.indexOf('/');
firstSlash = string.indexOf('/'),
t;

@@ -267,4 +285,4 @@ // authority@ must come before /path

}
return URI.parseHost(string, parts);
return string;
};

@@ -310,5 +328,9 @@ URI.parseQuery = function(string) {

if (typeof parts.protocol === "string" && parts.protocol.length) {
t += parts.protocol + "://";
if (parts.protocol) {
t += parts.protocol + ":";
}
if (!parts.urn && (t || parts.hostname)) {
t += '//';
}

@@ -357,2 +379,5 @@ t += (URI.buildAuthority(parts) || '');

URI.buildAuthority = function(parts) {
return URI.buildUserinfo(parts) + URI.buildHost(parts);
};
URI.buildUserinfo = function(parts) {
var t = '';

@@ -369,5 +394,3 @@

}
t += URI.buildHost(parts);
return t;

@@ -519,2 +542,6 @@ };

p.clone = function() {
return new URI(this);
};
p.toString = function() {

@@ -529,15 +556,16 @@ return this.build(false)._string;

_parts = {protocol: 'protocol', username: 'username', password: 'password', hostname: 'hostname', port: 'port'};
generateAccessor = function(_part){
return function(v, build) {
if (v === undefined) {
return this._parts[_part] || "";
} else {
this._parts[_part] = v;
this.build(!build);
return this;
}
};
};
for (_part in _parts) {
p[_part] = (function(_part){
return function(v, build) {
if (v === undefined) {
return this._parts[_part] || "";
} else {
this._parts[_part] = v;
this.build(!build);
return this;
}
};
})(_parts[_part]);
p[_part] = generateAccessor(_parts[_part]);
}

@@ -547,21 +575,23 @@

_parts = {query: '?', fragment: '#'};
for (_part in _parts) {
p[_part] = (function(_part, _key){
return function(v, build) {
if (v === undefined) {
return this._parts[_part] || "";
} else {
if (v !== null) {
v = v + "";
if (v[0] === _key) {
v = v.substring(1);
}
generateAccessor = function(_part, _key){
return function(v, build) {
if (v === undefined) {
return this._parts[_part] || "";
} else {
if (v !== null) {
v = v + "";
if (v[0] === _key) {
v = v.substring(1);
}
}
this._parts[_part] = v;
this.build(!build);
return this;
}
};
})(_part, _parts[_part]);
this._parts[_part] = v;
this.build(!build);
return this;
}
};
};
for (_part in _parts) {
p[_part] = generateAccessor(_part, _parts[_part]);
}

@@ -571,9 +601,11 @@

_parts = {search: ['?', 'query'], hash: ['#', 'fragment']};
generateAccessor = function(_part, _key){
return function(v, build) {
var t = this[_part](v, build);
return typeof t === "string" && t.length ? (_key + t) : t;
};
};
for (_part in _parts) {
p[_part] = (function(_part, _key){
return function(v, build) {
var t = this[_part](v, build);
return typeof t === "string" && t.length ? (_key + t) : t;
};
})(_parts[_part][1], _parts[_part][0]);
p[_part] = generateAccessor(_parts[_part][1], _parts[_part][0]);
}

@@ -583,3 +615,3 @@

if (v === undefined || v === true) {
var res = this._parts.path || "/";
var res = this._parts.path || (this._parts.urn ? '' : '/');
return v ? URI.decodePath(res) : res;

@@ -603,2 +635,3 @@ } else {

hostname: null,
urn: null,
port: null,

@@ -638,5 +671,6 @@ path: null,

name = false,
sld = false,
idn = false,
punycode = false,
relative = true;
relative = !this._parts.urn;

@@ -649,2 +683,3 @@ if (this._parts.hostname) {

name = !ip;
sld = name && SLD && SLD.has(this._parts.hostname);
idn = name && URI.idn_expression.test(this._parts.hostname);

@@ -657,2 +692,5 @@ punycode = name && URI.punycode_expression.test(this._parts.hostname);

return relative;
case 'absolute':
return !relative;

@@ -664,2 +702,5 @@ // hostname identification

case 'sld':
return sld;
case 'ip':

@@ -680,3 +721,9 @@ return ip;

return idn;
case 'url':
return !this._parts.urn;
case 'urn':
return !!this._parts.urn;
case 'punycode':

@@ -696,7 +743,7 @@ return punycode;

if (v !== undefined) {
// accept trailing :
if (v) {
if (v[v.length - 1] === ":") {
v = v.substring(0, v.length - 1);
} else if (v.match(/[^a-zA-z0-9\.+-]/)) {
// accept trailing ://
v = v.replace(/:(\/\/)?$/, '');
if (v.match(/[^a-zA-z0-9\.+-]/)) {
throw new TypeError("Protocol '" + v + "' contains characters other than [A-Z0-9.+-]");

@@ -708,3 +755,8 @@ }

};
p.scheme = p.protocol;
p.port = function(v, build) {
if (this._parts.urn) {
return v === undefined ? '' : this;
}
if (v !== undefined) {

@@ -729,2 +781,6 @@ if (v === 0) {

p.hostname = function(v, build) {
if (this._parts.urn) {
return v === undefined ? '' : this;
}
if (v !== undefined) {

@@ -740,2 +796,6 @@ var x = {};

p.host = function(v, build) {
if (this._parts.urn) {
return v === undefined ? '' : this;
}
if (v === undefined) {

@@ -750,2 +810,6 @@ return this._parts.hostname ? URI.buildHost(this._parts) : "";

p.authority = function(v, build) {
if (this._parts.urn) {
return v === undefined ? '' : this;
}
if (v === undefined) {

@@ -759,6 +823,32 @@ return this._parts.hostname ? URI.buildAuthority(this._parts) : "";

};
p.userinfo = function(v, build) {
if (this._parts.urn) {
return v === undefined ? '' : this;
}
if (v === undefined) {
if (!this._parts.username) {
return "";
}
var t = URI.buildUserinfo(this._parts);
return t.substring(0, t.length -1);
} else {
if (v[v.length-1] !== '@') {
v += '@';
}
URI.parseUserinfo(v, this._parts);
this.build(!build);
return this;
}
};
// fraction accessors
p.subdomain = function(v, build) {
// convenience, return "example.org" from "www.example.org"
if (this._parts.urn) {
return v === undefined ? '' : this;
}
// convenience, return "www" from "www.example.org"
if (v === undefined) {

@@ -769,2 +859,3 @@ if (!this._parts.hostname || this.is('IP')) {

// grab domain and add another segment
var end = this._parts.hostname.length - this.domain().length - 1;

@@ -791,2 +882,11 @@ return this._parts.hostname.substring(0, end) || "";

p.domain = function(v, build) {
if (this._parts.urn) {
return v === undefined ? '' : this;
}
if (typeof v == 'boolean') {
build = v;
v = undefined;
}
// convenience, return "example.org" from "www.example.org"

@@ -798,4 +898,12 @@ if (v === undefined) {

// "localhost" is a domain, too
return this._parts.hostname.match(/\.?([^\.]+\.[^\.]+)$/)[1] || this._parts.hostname;
// if hostname consists of 1 or 2 segments, it must be the domain
var t = this._parts.hostname.match(/\./g);
if (t && t.length < 2) {
return this._parts.hostname;
}
// grab tld and add another segment
var end = this._parts.hostname.length - this.tld(build).length - 1;
end = this._parts.hostname.lastIndexOf('.', end -1) + 1;
return this._parts.hostname.substring(end) || "";
} else {

@@ -820,2 +928,11 @@ if (!v) {

p.tld = function(v, build) {
if (this._parts.urn) {
return v === undefined ? '' : this;
}
if (typeof v == 'boolean') {
build = v;
v = undefined;
}
// return "org" from "www.example.org"

@@ -827,13 +944,25 @@ if (v === undefined) {

var pos = this._parts.hostname.lastIndexOf('.');
return this._parts.hostname.substring(pos + 1);
var pos = this._parts.hostname.lastIndexOf('.'),
tld = this._parts.hostname.substring(pos + 1);
if (build !== true && SLD && SLD.list[tld.toLowerCase()]) {
return SLD.get(this._parts.hostname) || tld;
}
return tld;
} else {
var replace;
if (!v) {
throw new TypeError("cannot set TLD empty");
} else if (v.match(/[^a-zA-Z0-9-]/)) {
throw new TypeError("TLD '" + v + "' contains characters other than [A-Z0-9]");
if (SLD && SLD.is(v)) {
replace = new RegExp(escapeRegEx(this.tld()) + "$");
this._parts.hostname = this._parts.hostname.replace(replace, v);
} else {
throw new TypeError("TLD '" + v + "' contains characters other than [A-Z0-9]");
}
} else if (!this._parts.hostname || this.is('IP')) {
throw new ReferenceError("cannot set TLD on non-domain host");
} else {
var replace = new RegExp(escapeRegEx(this.tld()) + "$");
replace = new RegExp(escapeRegEx(this.tld()) + "$");
this._parts.hostname = this._parts.hostname.replace(replace, v);

@@ -847,4 +976,12 @@ }

p.directory = function(v, build) {
if (this._parts.urn) {
return v === undefined ? '' : this;
}
if (v === undefined || v === true) {
if (!this._parts.path || this._parts.path === '/') {
if (!this._parts.path && !this._parts.hostname) {
return '';
}
if (this._parts.path === '/') {
return '/';

@@ -854,3 +991,3 @@ }

var end = this._parts.path.length - this.filename().length - 1,
res = this._parts.path.substring(0, end) || "/";
res = this._parts.path.substring(0, end) || (this._parts.hostname ? "/" : "");

@@ -887,2 +1024,6 @@ return v ? URI.decodePath(res) : res;

p.filename = function(v, build) {
if (this._parts.urn) {
return v === undefined ? '' : this;
}
if (v === undefined || v === true) {

@@ -921,2 +1062,6 @@ if (!this._parts.path || this._parts.path === '/') {

p.suffix = function(v, build) {
if (this._parts.urn) {
return v === undefined ? '' : this;
}
if (v === undefined || v === true) {

@@ -929,3 +1074,3 @@ if (!this._parts.path || this._parts.path === '/') {

pos = filename.lastIndexOf('.'),
s;
s, res;

@@ -1010,2 +1155,10 @@ if (pos === -1) {

p.normalize = function() {
if (this._parts.urn) {
return this
.normalizeProtocol(false)
.normalizeQuery(false)
.normalizeFragment(false)
.build();
}
return this

@@ -1052,2 +1205,6 @@ .normalizeProtocol(false)

p.normalizePath = function(build) {
if (this._parts.urn) {
return this;
}
if (!this._parts.path || this._parts.path === '/') {

@@ -1156,3 +1313,3 @@ return this;

p.readable = function() {
var uri = new URI(this);
var uri = this.clone();
// removing username, password, because they shouldn't be displayed according to RFC 3986

@@ -1202,5 +1359,13 @@ uri.username("").password("").normalize();

p.absoluteTo = function(base) {
if (!this.is('relative')) {
throw new Error('Cannot resolve non-relative URL');
var resolved = this.clone(),
properties = ['protocol', 'username', 'password', 'hostname', 'port'],
basedir;
if (this._parts.urn) {
throw new Error('URNs do not have any generally defined hierachical components');
}
if (this._parts.hostname) {
return resolved;
}

@@ -1211,5 +1376,2 @@ if (!(base instanceof URI)) {

var resolved = new URI(this),
properties = ['protocol', 'username', 'password', 'hostname', 'port'];
for (var i = 0, p; p = properties[i]; i++) {

@@ -1220,3 +1382,4 @@ resolved._parts[p] = base._parts[p];

if (resolved.path()[0] !== '/') {
resolved._parts.path = base.directory() + '/' + resolved._parts.path;
basedir = base.directory();
resolved._parts.path = (basedir ? (basedir + '/') : '') + resolved._parts.path;
resolved.normalizePath();

@@ -1229,2 +1392,11 @@ }

p.relativeTo = function(base) {
var relative = this.clone(),
properties = ['protocol', 'username', 'password', 'hostname', 'port'],
common,
_base;
if (this._parts.urn) {
throw new Error('URNs do not have any generally defined hierachical components');
}
if (!(base instanceof URI)) {

@@ -1238,7 +1410,5 @@ base = new URI(base);

var relative = new URI(this),
properties = ['protocol', 'username', 'password', 'hostname', 'port'],
common = URI.commonPath(relative.path(), base.path()),
_base = base.directory();
common = URI.commonPath(relative.path(), base.path());
_base = base.directory();
for (var i = 0, p; p = properties[i]; i++) {

@@ -1272,3 +1442,3 @@ relative._parts[p] = null;

p.equals = function(uri) {
var one = new URI(this),
var one = this.clone(),
two = new URI(uri),

@@ -1275,0 +1445,0 @@ one_map = {},

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