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

URIjs

Package Overview
Dependencies
Maintainers
2
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.7.4 to 1.8.0

src/jquery.URI.js

27

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

@@ -23,2 +23,3 @@ "author": {

"url",
"urn",
"uri mutation",

@@ -38,2 +39,6 @@ "url mutation",

],
"categories": [
"Parsers & Compilers",
"Utilities"
],
"main": "./src/URI",

@@ -49,4 +54,20 @@ "homepage": "http://medialize.github.com/URI.js/",

"src/punycode.js",
"src/URITemplate.js"
]
"src/URITemplate.js",
"src/jquery.URI.js"
],
"jam": {
"main": "src/URI.js",
"dependencies": {
"jquery": ">=1.7.0"
},
"include": [
"src/URI.js",
"src/IPv6.js",
"src/SecondLevelDomains.js",
"src/punycode.js",
"src/URITemplate.js",
"src/jquery.URI.js"
]
}
}

89

README.md

@@ -20,3 +20,3 @@ # URI.js #

I still can't believe javascript - the f**ing backbone-language of the web - doesn't offer an API for mutating URLs. Browsers (Firefox) don't expose the `Location` object (the structure behind window.location). Yes, one could think of [decomposed IDL attributes](http://www.whatwg.org/specs/web-apps/current-work/multipage/urls.html#url-decomposition-idl-attributes) as a native URL management library. But it relies on the DOM element <a>, it's slow and doesn't offer any convenienve at all.
I still can't believe javascript - the f**ing backbone-language of the web - doesn't offer an API for mutating URLs. Browsers (Firefox) don't expose the `Location` object (the structure behind window.location). Yes, one could think of [decomposed IDL attributes](http://www.whatwg.org/specs/web-apps/current-work/multipage/urls.html#url-decomposition-idl-attributes) as a native URL management library. But it relies on the DOM element <a>, it's slow and doesn't offer any convenience at all.

@@ -79,14 +79,17 @@ How about a nice, clean and simple API for mutating URIs:

## Using URI.js ##
## npm ##
### Browser ###
```
npm install URIjs
```
I guess you'll manage to use the [build tool](http://medialize.github.com/URI.js/build.html) or follow the [instructions below](#minify) to combine and minify the various files into URI.min.js - and I'm fairly certain you know how to `<script src=".../URI.min.js"></script>` that sucker, too.
### Node.js and NPM ###
## Server-side JS ##
Install with `npm install URIjs` or add `"URIjs"` to the dependencies in your `package.json`.
```javascript
// load URI.js
var URI = require('URIjs');
// load an optional module (e.g. URITemplate)
var URITemplate = require('URIjs/src/URITemplate');

@@ -98,2 +101,21 @@ URI("/foo/bar/baz.html")

### RequireJS ###
Clone the URI.js repository or use a package manager to get URI.js into your project.
```javascript
require.config({
paths: {
URIjs: 'where-you-put-uri.js/src'
}
});
require(['URIjs/URI'], function(URI) {
console.log("URI.js and dependencies: ", URI("//amazon.co.uk").is('sld') ? 'loaded' : 'failed');
});
require(['URIjs/URITemplate'], function(URITemplate) {
console.log("URITemplate.js and dependencies: ", URITemplate._cache ? 'loaded' : 'failed');
});
```
## Minify ##

@@ -118,12 +140,17 @@

Docs where you get more info on parsing and working with URLs
Documents specifying how URLs work:
* [Uniform Resource Identifiers (URI): Generic Syntax](http://www.ietf.org/rfc/rfc2396.txt) ([superseded by 3986](http://tools.ietf.org/html/rfc3986))
* [Internationalized Resource Identifiers (IRI)](http://tools.ietf.org/html/rfc3987)
* [IPv6 Literal Addresses in URL's](http://www.ietf.org/rfc/rfc2732.txt) ([superseded by 3986](http://tools.ietf.org/html/rfc3986))
* [Punycode - Internationalized Domain Name (IDN)](http://www.ietf.org/rfc/rfc3492.txt) ([html version](http://tools.ietf.org/html/rfc3492))
* [URI - Reference Resolution](http://tools.ietf.org/html/rfc3986#section-5)
* [URL - Living Standard](http://url.spec.whatwg.org/)
* [RFC 3986 - Uniform Resource Identifier (URI): Generic Syntax](http://tools.ietf.org/html/rfc3986)
* [RFC 3987 - Internationalized Resource Identifiers (IRI)](http://tools.ietf.org/html/rfc3987)
* [Punycode: A Bootstring encoding of Unicode for Internationalized Domain Names in Applications (IDNA)](http://tools.ietf.org/html/rfc3492)
* [application/x-www-form-urlencoded](http://www.w3.org/TR/REC-html40/interact/forms.html#form-content-type) (Query String Parameters) and [application/x-www-form-urlencoded encoding algorithm](http://www.whatwg.org/specs/web-apps/current-work/multipage/association-of-controls-and-forms.html#application/x-www-form-urlencoded-encoding-algorithm)
Informal stuff
* [Parsing URLs for Fun and Profit](http://tools.ietf.org/html/draft-abarth-url-01)
* [application/x-www-form-urlencoded](http://www.w3.org/TR/REC-html40/interact/forms.html#form-content-type) (Query String Parameters) and [application/x-www-form-urlencoded encoding algorithm](http://www.whatwg.org/specs/web-apps/current-work/multipage/association-of-controls-and-forms.html#application/x-www-form-urlencoded-encoding-algorithm)
* [Naming URL components](http://tantek.com/2011/238/b1/many-ways-slice-url-name-pieces)
How other environments do things
* [Java URI Class](http://docs.oracle.com/javase/7/docs/api/java/net/URI.html)

@@ -135,13 +162,3 @@ * [Java Inet6Address Class](http://docs.oracle.com/javase/1.5.0/docs/api/java/net/Inet6Address.html)

### HTML5 URL Draft ###
* [W3C URL Draft](http://dvcs.w3.org/hg/url/raw-file/tip/Overview.html)
* [Webkit #71968 - Implement URL API](https://bugs.webkit.org/show_bug.cgi?id=71968)
### MozURLProperty ###
* https://www.w3.org/Bugs/Public/show_bug.cgi?id=14148
* http://www.whatwg.org/specs/web-apps/current-work/multipage/workers.html#workerlocation
* MozURLProperty (not documented yet?!) https://developer.mozilla.org/User:trevorh/Interface_documentation_status
### Alternatives ###

@@ -172,4 +189,10 @@

* [URI Template JS](https://github.com/fxa/uritemplate-js) by Franz Antesberger
* [Temple](https://github.com/brettstimmerman/temple) by Brett Stimmerman
* ([jsperf comparison](http://jsperf.com/uri-templates/2))
#### Various ####
* [TLD.js](https://github.com/oncletom/tld.js) - second level domain names
* [Public Suffic](http://mxr.mozilla.org/mozilla-central/source/netwerk/dns/effective_tld_names.dat?raw=1) - second level domain names
## Authors ##

@@ -193,2 +216,22 @@

### 1.8.0 (November 13th 2012) ###
* adding [`.resource()`](http://medialize.github.com/URI.js/docs.html#accessors-resource) as compound of [path, query, fragment]
* adding jQuery 1.8.x compatibility for jQuery.URI.js (remaining backwards compatibility!)
* adding default ports for gopher, ws, wss
* adding [`.duplicateQueryParameters()`](http://medialize.github.com/URI.js/docs.html#setting-duplicateQueryParameters) to control if `key=value` duplicates have to be preserved or reduced ([Issue #51](https://github.com/medialize/URI.js/issues/51)
* updating [Punycode.js](https://github.com/bestiejs/punycode.js/) to version 1.1.1
* improving AMD/Node using [UMD returnExports](https://github.com/umdjs/umd/blob/master/returnExports.js) - ([Issue #44](https://github.com/medialize/URI.js/issues/44), [Issue #47](https://github.com/medialize/URI.js/issues/47))
* fixing `.addQuery("empty")` to properly add `?empty` - ([Issue #46](https://github.com/medialize/URI.js/issues/46))
* fixing parsing of badly formatted userinfo `http://username:pass:word@hostname`
* fixing parsing of Windows-Drive-Letter paths `file://C:/WINDOWS/foo.txt`
* fixing `URI(location)` to properly parse the URL - ([Issue #50](https://github.com/medialize/URI.js/issues/50))
* fixing type error for fragment abuse demos - ([Issue #50](https://github.com/medialize/URI.js/issues/50))
* adding documentation for various [encode/decode functions](http://medialize.github.com/URI.js/docs.html#encoding-decoding)
* adding some pointers on possible problems with URLs to [About URIs](http://medialize.github.com/URI.js/about-uris.html)
* adding tests for fragment abuse and splitting tests into separate scopes
* adding meta-data for [Jam](http://jamjs.org/) and [Bower](http://twitter.github.com/bower/)
Note: QUnit seems to be having some difficulties on IE8. While the jQuery-plugin tests fail, the plugin itself works. We're still trying to figure out what's making QUnit "lose its config state".
### 1.7.4 (October 21st 2012) ###

@@ -195,0 +238,0 @@

@@ -5,3 +5,3 @@ /*!

*
* Version: 1.7.4
* Version: 1.8.0
*

@@ -16,10 +16,26 @@ * Author: Rodney Rehm

*/
(function (root, factory) {
// https://github.com/umdjs/umd/blob/master/returnExports.js
if (typeof exports === 'object') {
// Node
module.exports = factory();
} else if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(factory);
} else {
// Browser globals (root is window)
root.IPv6 = factory();
}
}(this, function () {
"use strict";
(function(undefined){
/*
var _in = "fe80:0000:0000:0000:0204:61ff:fe9d:f156";
var _out = IPv6.best(_in);
var _expected = "fe80::204:61ff:fe9d:f156";
var global = typeof module !== 'undefined' && module.exports
? module.exports
: window;
console.log(_in, _out, _expected, _out === _expected);
*/
var best = function(address) {
function best(address) {
// based on:

@@ -35,6 +51,6 @@ // Javascript to test an IPv6 address for proper format, and to

var _address = address.toLowerCase(),
segments = _address.split(':'),
length = segments.length,
total = 8;
var _address = address.toLowerCase();
var segments = _address.split(':');
var length = segments.length;
var total = 8;

@@ -97,8 +113,8 @@ // trim colons (:: or ::a:b:c… or …a:b:c::)

// find longest sequence of zeroes and coalesce them into one segment
var best = -1,
_best = 0,
_current = 0,
current = -1,
inzeroes = false;
// i; already declared
var best = -1;
var _best = 0;
var _current = 0;
var current = -1;
var inzeroes = false;
// i; already declared

@@ -158,13 +174,5 @@ for (i = 0; i < total; i++) {

global.IPv6 = {
return {
best: best
};
})();
/*
var _in = "fe80:0000:0000:0000:0204:61ff:fe9d:f156",
_out = IPv6.best(_in),
_expected = "fe80::204:61ff:fe9d:f156";
console.log(_in, _out, _expected, _out === _expected);
*/
}));

@@ -1,7 +0,2 @@

/*!
* Punycode.js <http://mths.be/punycode>
* Copyright 2011 Mathias Bynens <http://mathiasbynens.be/>
* Available under MIT license <http://mths.be/mit>
*/
/*! http://mths.be/punycode by @mathias */
;(function(root) {

@@ -37,3 +32,3 @@

/** Regular expressions */
regexNonASCII = /[^ -~]/, // matches unprintable ASCII chars + non-ASCII chars
regexNonASCII = /[^ -~]/, // unprintable ASCII chars + non-ASCII chars
regexPunycode = /^xn--/,

@@ -44,4 +39,2 @@

'overflow': 'Overflow: input needs wider integers to process.',
'ucs2decode': 'UCS-2(decode): illegal sequence',
'ucs2encode': 'UCS-2(encode): illegal value',
'not-basic': 'Illegal input >= 0x80 (not a basic code point)',

@@ -102,9 +95,13 @@ 'invalid-input': 'Invalid input'

/**
* Creates an array containing the decimal code points of each character in
* the string.
* Creates an array containing the decimal code points of each Unicode
* character in the string. While JavaScript uses UCS-2 internally,
* this function will convert a pair of surrogate halves (each of which
* UCS-2 exposes as separate characters) into a single code point,
* matching UTF-16.
* @see `punycode.ucs2.encode`
* @see <http://mathiasbynens.be/notes/javascript-encoding>
* @memberOf punycode.ucs2
* @name decode
* @param {String} string The Unicode input string.
* @returns {Array} The new array.
* @param {String} string The Unicode input string (UCS-2).
* @returns {Array} The new array of code points.
*/

@@ -119,10 +116,13 @@ function ucs2decode(string) {

value = string.charCodeAt(counter++);
if ((value & 0xF800) == 0xD800) {
if ((value & 0xF800) == 0xD800 && counter < length) {
// high surrogate, and there is a next character
extra = string.charCodeAt(counter++);
if ((value & 0xFC00) != 0xD800 || (extra & 0xFC00) != 0xDC00) {
error('ucs2decode');
if ((extra & 0xFC00) == 0xDC00) { // low surrogate
output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000);
} else {
output.push(value, extra);
}
value = ((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000;
} else {
output.push(value);
}
output.push(value);
}

@@ -138,3 +138,3 @@ return output;

* @param {Array} codePoints The array of decimal code points.
* @returns {String} The new string.
* @returns {String} The new Unicode string (UCS-2).
*/

@@ -144,5 +144,2 @@ function ucs2encode(array) {

var output = '';
if ((value & 0xF800) == 0xD800) {
error('ucs2encode');
}
if (value > 0xFFFF) {

@@ -290,3 +287,3 @@ value -= 0x10000;

i += digit * w;
t = k <= bias ? tMin : k >= bias + tMax ? tMax : k - bias;
t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);

@@ -414,3 +411,3 @@ if (digit < t) {

for (q = delta, k = base; /* no condition */; k += base) {
t = k <= bias ? tMin : k >= bias + tMax ? tMax : k - bias;
t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
if (q < t) {

@@ -484,6 +481,7 @@ break;

*/
'version': '0.3.0',
'version': '1.1.1',
/**
* An object of methods to convert from JavaScript's internal character
* representation (UCS-2) to Unicode and back.
* representation (UCS-2) to decimal Unicode code points, and back.
* @see <http://mathiasbynens.be/notes/javascript-encoding>
* @memberOf punycode

@@ -521,2 +519,2 @@ * @type Object

}(this));
}(this));

@@ -5,3 +5,3 @@ /*!

*
* Version: 1.7.4
* Version: 1.8.0
*

@@ -17,7 +17,26 @@ * Author: Rodney Rehm

(function(undefined){
(function (root, factory) {
// https://github.com/umdjs/umd/blob/master/returnExports.js
if (typeof exports === 'object') {
// Node
module.exports = factory();
} else if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(factory);
} else {
// Browser globals (root is window)
root.SecondLevelDomains = factory();
}
}(this, function () {
"use strict";
var hasOwn = Object.prototype.hasOwnProperty;
var SLD = {
// list of known Second Level Domains
// converted list of SLDs from https://github.com/gavingmiller/second-level-domains
// ----
// publicsuffix.org is more current and actually used by a couple of browsers internally.
// downside is it also contains domains like "dyndns.org" - which is fine for the security
// issues browser have to deal with (SOP for cookies, etc) - but is way overboard for URI.js
// ----
list: {

@@ -177,3 +196,3 @@ "ac":"com|gov|mil|net|org",

for (var tld in SLD.list) {
if (!Object.prototype.hasOwnProperty.call(SLD.list, tld)) {
if (!hasOwn.call(SLD.list, tld)) {
continue;

@@ -194,7 +213,3 @@ }

(typeof module !== 'undefined' && module.exports
? module.exports = SLD
: window.SecondLevelDomains = SLD
);
})();
return SLD;
}));
/*!
* URI.js - Mutating URLs
*
* Version: 1.7.4
* Version: 1.8.0
*

@@ -14,36 +14,43 @@ * Author: Rodney Rehm

*/
(function (root, factory) {
// https://github.com/umdjs/umd/blob/master/returnExports.js
if (typeof exports === 'object') {
// Node
module.exports = factory(require('./punycode'), require('./IPv6'), require('./SecondLevelDomains'));
} else if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['./punycode', './IPv6', './SecondLevelDomains'], factory);
} else {
// Browser globals (root is window)
root.URI = factory(root.punycode, root.IPv6, root.SecondLevelDomains);
}
}(this, function (punycode, IPv6, SLD) {
"use strict";
(function(undefined) {
function URI(url, base) {
// Allow instantiation without the 'new' keyword
if (!(this instanceof URI)) {
return new URI(url, base);
}
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, base);
if (url === undefined) {
if (typeof location !== 'undefined') {
url = location.href + "";
} else {
url = "";
}
}
if (url === undefined) {
if (typeof location !== 'undefined') {
url = location.href + "";
} else {
url = "";
}
}
this.href(url);
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);
}
// 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;
};
return this;
},
p = URI.prototype;
var p = URI.prototype;
var hasOwn = Object.prototype.hasOwnProperty;

@@ -60,4 +67,4 @@ function escapeRegEx(string) {

function filterArrayValues(data, value) {
var lookup = {},
i, length;
var lookup = {};
var i, length;

@@ -83,2 +90,4 @@ if (isArray(value)) {

// state: allow duplicate query parameters (a=1&a=1)
URI.duplicateQueryParameters = false;
// static properties

@@ -101,3 +110,6 @@ URI.protocol_expression = /^[a-z][a-z0-9-+-]*$/i;

https: "443",
ftp: "21"
ftp: "21",
gopher: "70",
ws: "80",
wss: "443"
};

@@ -205,11 +217,11 @@ // allowed hostname characters according to RFC 3986

// generate encode/decode path functions
var _parts = {'encode':'encode', 'decode':'decode'},
_part,
generateAccessor = function(_group, _part){
return function(string) {
return URI[_part](string + "").replace(URI.characters[_group][_part].expression, function(c) {
return URI.characters[_group][_part].map[c];
});
};
var _parts = {'encode':'encode', 'decode':'decode'};
var _part;
var generateAccessor = function(_group, _part) {
return function(string) {
return URI[_part](string + "").replace(URI.characters[_group][_part].expression, function(c) {
return URI.characters[_group][_part].map[c];
});
};
};

@@ -222,4 +234,7 @@ for (_part in _parts) {

URI.parse = function(string) {
var pos, t, parts = {};
URI.parse = function(string, parts) {
var pos, t;
if (!parts) {
parts = {};
}
// [protocol"://"[username[":"password]"@"]hostname[":"port]"/"?][path]["?"querystring]["#"fragment]

@@ -257,2 +272,5 @@

parts.protocol = undefined;
} else if (parts.protocol === 'file') {
// the file scheme: does not contain an authority
string = string.substring(pos + 3);
} else if (string.substring(pos + 1, pos + 3) === '//') {

@@ -278,4 +296,5 @@ string = string.substring(pos + 3);

// extract host:port
var pos = string.indexOf('/'),
t;
var pos = string.indexOf('/');
var bracketPos;
var t;

@@ -290,3 +309,3 @@ if (pos === -1) {

// IPv6+port in the format [2001:db8::1]:80 (for the time being)
var bracketPos = string.indexOf(']');
bracketPos = string.indexOf(']');
parts.hostname = string.substring(1, bracketPos) || null;

@@ -318,5 +337,5 @@ parts.port = string.substring(bracketPos+2, pos) || null;

// extract username:password
var pos = string.indexOf('@'),
firstSlash = string.indexOf('/'),
t;
var pos = string.indexOf('@');
var firstSlash = string.indexOf('/');
var t;

@@ -327,3 +346,4 @@ // authority@ must come before /path

parts.username = t[0] ? URI.decode(t[0]) : null;
parts.password = t[1] ? URI.decode(t[1]) : null;
t.shift();
parts.password = t[0] ? URI.decode(t.join(':')) : null;
string = string.substring(pos + 1);

@@ -349,11 +369,12 @@ } else {

var items = {},
splits = string.split('&'),
length = splits.length;
var items = {};
var splits = string.split('&');
var length = splits.length;
var v, name, value;
for (var i = 0; i < length; i++) {
var v = splits[i].split('='),
name = URI.decodeQuery(v.shift()),
// no "=" is null according to http://dvcs.w3.org/hg/url/raw-file/tip/Overview.html#collect-url-parameters
value = v.length ? URI.decodeQuery(v.join('=')) : null;
v = splits[i].split('=');
name = URI.decodeQuery(v.shift());
// no "=" is null according to http://dvcs.w3.org/hg/url/raw-file/tip/Overview.html#collect-url-parameters
value = v.length ? URI.decodeQuery(v.join('=')) : null;

@@ -375,3 +396,3 @@ if (items[name]) {

URI.build = function(parts) {
var t = '';
var t = "";

@@ -406,6 +427,6 @@ if (parts.protocol) {

URI.buildHost = function(parts) {
var t = '';
var t = "";
if (!parts.hostname) {
return '';
return "";
} else if (URI.ip6_expression.test(parts.hostname)) {

@@ -432,3 +453,3 @@ if (parts.port) {

URI.buildUserinfo = function(parts) {
var t = '';
var t = "";

@@ -455,7 +476,8 @@ if (parts.username) {

var t = "";
for (var key in data) {
if (Object.hasOwnProperty.call(data, key) && key) {
var unique, key, i, length;
for (key in data) {
if (hasOwn.call(data, key) && key) {
if (isArray(data[key])) {
var unique = {};
for (var i = 0, length = data[key].length; i < length; i++) {
unique = {};
for (i = 0, length = data[key].length; i < length; i++) {
if (data[key][i] !== undefined && unique[data[key][i] + ""] === undefined) {

@@ -485,3 +507,3 @@ t += "&" + URI.buildQueryParameter(key, data[key][i]);

for (var key in name) {
if (Object.prototype.hasOwnProperty.call(name, key)) {
if (hasOwn.call(name, key)) {
URI.addQuery(data, key, name[key]);

@@ -508,9 +530,11 @@ }

URI.removeQuery = function(data, name, value) {
var i, length, key;
if (isArray(name)) {
for (var i = 0, length = name.length; i < length; i++) {
for (i = 0, length = name.length; i < length; i++) {
data[name[i]] = undefined;
}
} else if (typeof name === "object") {
for (var key in name) {
if (Object.prototype.hasOwnProperty.call(name, key)) {
for (key in name) {
if (hasOwn.call(name, key)) {
URI.removeQuery(data, key, name[key]);

@@ -535,4 +559,4 @@ }

URI.commonPath = function(one, two) {
var length = Math.min(one.length, two.length),
pos;
var length = Math.min(one.length, two.length);
var pos;

@@ -676,36 +700,49 @@ // find first non-matching character

return this.toString();
} else {
this._string = "";
this._parts = {
protocol: null,
username: null,
password: null,
hostname: null,
urn: null,
port: null,
path: null,
query: null,
fragment: null
};
}
var _URI = href instanceof URI,
_object = typeof href === "object" && (href.hostname || href.path),
key;
this._string = "";
this._parts = {
protocol: null,
username: null,
password: null,
hostname: null,
urn: null,
port: null,
path: null,
query: null,
fragment: null,
// state
duplicateQueryParameters: URI.duplicateQueryParameters
};
if (typeof href === "string") {
this._parts = URI.parse(href);
} else if (_URI || _object) {
var src = _URI ? href._parts : href;
for (key in src) {
if (Object.hasOwnProperty.call(this._parts, key)) {
this._parts[key] = src[key];
}
var _URI = href instanceof URI;
var _object = typeof href === "object" && (href.hostname || href.path);
var key;
// window.location is reported to be an object, but it's not the sort
// of object we're looking for:
// * location.protocol ends with a colon
// * location.query != object.search
// * location.hash != object.fragment
// simply serializing the unknown object should do the trick
// (for location, not for everything...)
if (!_URI && _object && Object.prototype.toString.call(href) !== "[object Object]") {
href = href.toString();
}
if (typeof href === "string") {
this._parts = URI.parse(href, this._parts);
} else if (_URI || _object) {
var src = _URI ? href._parts : href;
for (key in src) {
if (hasOwn.call(this._parts, key)) {
this._parts[key] = src[key];
}
} else {
throw new TypeError("invalid input");
}
} else {
throw new TypeError("invalid input");
}
this.build(!build);
return this;
}
this.build(!build);
return this;
};

@@ -715,10 +752,10 @@

p.is = function(what) {
var ip = false,
ip4 = false,
ip6 = false,
name = false,
sld = false,
idn = false,
punycode = false,
relative = !this._parts.urn;
var ip = false;
var ip4 = false;
var ip6 = false;
var name = false;
var sld = false;
var idn = false;
var punycode = false;
var relative = !this._parts.urn;

@@ -781,5 +818,5 @@ if (this._parts.hostname) {

// component specific input validation
var _protocol = p.protocol,
_port = p.port,
_hostname = p.hostname;
var _protocol = p.protocol;
var _port = p.port;
var _hostname = p.hostname;

@@ -836,3 +873,3 @@ p.protocol = function(v, build) {

// combination accessors
// compound accessors
p.host = function(v, build) {

@@ -886,2 +923,16 @@ if (this._parts.urn) {

};
p.resource = function(v, build) {
var parts;
if (v === undefined) {
return this.path() + this.search() + this.hash();
}
parts = URI.parse(v);
this._parts.path = parts.path;
this._parts.query = parts.query;
this._parts.fragment = parts.fragment;
this.build(!build);
return this;
};

@@ -904,5 +955,5 @@ // fraction accessors

} else {
var e = this._parts.hostname.length - this.domain().length,
sub = this._parts.hostname.substring(0, e),
replace = new RegExp('^' + escapeRegEx(sub));
var e = this._parts.hostname.length - this.domain().length;
var sub = this._parts.hostname.substring(0, e);
var replace = new RegExp('^' + escapeRegEx(sub));

@@ -982,4 +1033,4 @@ if (v && v[v.length - 1] !== '.') {

var pos = this._parts.hostname.lastIndexOf('.'),
tld = this._parts.hostname.substring(pos + 1);
var pos = this._parts.hostname.lastIndexOf('.');
var tld = this._parts.hostname.substring(pos + 1);

@@ -993,2 +1044,3 @@ if (build !== true && SLD && SLD.list[tld.toLowerCase()]) {

var replace;
if (!v) {

@@ -1028,4 +1080,4 @@ throw new TypeError("cannot set TLD empty");

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

@@ -1035,5 +1087,5 @@ return v ? URI.decodePath(res) : res;

} else {
var e = this._parts.path.length - this.filename().length,
directory = this._parts.path.substring(0, e),
replace = new RegExp('^' + escapeRegEx(directory));
var e = this._parts.path.length - this.filename().length;
var directory = this._parts.path.substring(0, e);
var replace = new RegExp('^' + escapeRegEx(directory));

@@ -1072,4 +1124,4 @@ // fully qualifier directories begin with a slash

var pos = this._parts.path.lastIndexOf('/'),
res = this._parts.path.substring(pos+1);
var pos = this._parts.path.lastIndexOf('/');
var res = this._parts.path.substring(pos+1);

@@ -1079,2 +1131,3 @@ return v ? URI.decodePathSegment(res) : res;

var mutatedDirectory = false;
if (v[0] === '/') {

@@ -1111,5 +1164,5 @@ v = v.substring(1);

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

@@ -1129,4 +1182,4 @@ if (pos === -1) {

var suffix = this.suffix(),
replace;
var suffix = this.suffix();
var replace;

@@ -1155,6 +1208,6 @@ if (!suffix) {

p.segment = function(segment, v, build) {
var separator = this._parts.urn ? ':' : '/',
path = this.path(),
absolute = path.substring(0, 1) === '/',
segments = path.split(separator);
var separator = this._parts.urn ? ':' : '/';
var path = this.path();
var absolute = path.substring(0, 1) === '/';
var segments = path.split(separator);

@@ -1217,3 +1270,3 @@ if (typeof segment !== 'number') {

} else if (v !== undefined && typeof v !== "string") {
this._parts.query = URI.buildQuery(v);
this._parts.query = URI.buildQuery(v, this._parts.duplicateQueryParameters);
this.build(!build);

@@ -1227,4 +1280,4 @@ return this;

var data = URI.parseQuery(this._parts.query);
URI.addQuery(data, name, value);
this._parts.query = URI.buildQuery(data);
URI.addQuery(data, name, value === undefined ? null : value);
this._parts.query = URI.buildQuery(data, this._parts.duplicateQueryParameters);
if (typeof name !== "string") {

@@ -1240,3 +1293,3 @@ build = value;

URI.removeQuery(data, name, value);
this._parts.query = URI.buildQuery(data);
this._parts.query = URI.buildQuery(data, this._parts.duplicateQueryParameters);
if (typeof name !== "string") {

@@ -1311,6 +1364,6 @@ build = value;

var _was_relative,
_was_relative_prefix,
_path = this._parts.path,
_parent, _pos;
var _was_relative;
var _was_relative_prefix;
var _path = this._parts.path;
var _parent, _pos;

@@ -1386,4 +1439,4 @@ // handle relative paths

// expect unicode input, iso8859 output
var e = URI.encode,
d = URI.decode;
var e = URI.encode;
var d = URI.decode;

@@ -1400,4 +1453,4 @@ URI.encode = escape;

// expect iso8859 input, unicode output
var e = URI.encode,
d = URI.decode;
var e = URI.encode;
var d = URI.decode;

@@ -1458,5 +1511,5 @@ URI.encode = strictEncodeURIComponent;

p.absoluteTo = function(base) {
var resolved = this.clone(),
properties = ['protocol', 'username', 'password', 'hostname', 'port'],
basedir, i, p;
var resolved = this.clone();
var properties = ['protocol', 'username', 'password', 'hostname', 'port'];
var basedir, i, p;

@@ -1496,6 +1549,5 @@ if (this._parts.urn) {

p.relativeTo = function(base) {
var relative = this.clone(),
properties = ['protocol', 'username', 'password', 'hostname', 'port'],
common,
_base;
var relative = this.clone();
var properties = ['protocol', 'username', 'password', 'hostname', 'port'];
var common, _base;

@@ -1528,5 +1580,5 @@ if (this._parts.urn) {

} else {
var parents = '../',
_common = new RegExp('^' + escapeRegEx(common)),
_parents = _base.replace(_common, '/').match(/\//g).length -1;
var parents = '../';
var _common = new RegExp('^' + escapeRegEx(common));
var _parents = _base.replace(_common, '/').match(/\//g).length -1;

@@ -1546,10 +1598,8 @@ while (_parents--) {

p.equals = function(uri) {
var one = this.clone(),
two = new URI(uri),
one_map = {},
two_map = {},
checked = {},
one_query,
two_query,
key;
var one = this.clone();
var two = new URI(uri);
var one_map = {};
var two_map = {};
var checked = {};
var one_query, two_query, key;

@@ -1584,3 +1634,3 @@ one.normalize();

for (key in one_map) {
if (Object.prototype.hasOwnProperty.call(one_map, key)) {
if (hasOwn.call(one_map, key)) {
if (!isArray(one_map[key])) {

@@ -1615,3 +1665,3 @@ if (one_map[key] !== two_map[key]) {

for (key in two_map) {
if (Object.prototype.hasOwnProperty.call(two_map, key)) {
if (hasOwn.call(two_map, key)) {
if (!checked[key]) {

@@ -1627,7 +1677,9 @@ // two contains a parameter not present in one

(typeof module !== 'undefined' && module.exports
? module.exports = URI
: window.URI = URI
);
// state
p.duplicateQueryParameters = function(v) {
this._parts.duplicateQueryParameters = !!v;
return this;
};
})();
return URI;
}));

@@ -5,3 +5,3 @@ /*!

*
* Version: 1.7.4
* Version: 1.8.0
*

@@ -16,103 +16,113 @@ * Author: Rodney Rehm

*/
(function(undefined) {
(function (root, factory) {
// https://github.com/umdjs/umd/blob/master/returnExports.js
if (typeof exports === 'object') {
// Node
module.exports = factory(require('./URI'));
} else if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['./URI'], factory);
} else {
// Browser globals (root is window)
root.URITemplate = factory(root.URI);
}
}(this, function (URI) {
"use strict";
var hasOwn = Object.prototype.hasOwnProperty;
function URITemplate(expression) {
// serve from cache where possible
if (URITemplate._cache[expression]) {
return URITemplate._cache[expression];
}
var hasOwn = Object.prototype.hasOwnProperty,
_use_module = typeof module !== "undefined" && module.exports,
_load_module = function(module) {
return _use_module ? require('./' + module) : window[module];
// Allow instantiation without the 'new' keyword
if (!(this instanceof URITemplate)) {
return new URITemplate(expression);
}
this.expression = expression;
URITemplate._cache[expression] = this;
return this;
}
function Data(data) {
this.data = data;
this.cache = {};
}
var p = URITemplate.prototype;
// list of operators and their defined options
var operators = {
// Simple string expansion
'' : {
prefix: "",
separator: ",",
named: false,
empty_name_separator: false,
encode : "encode"
},
URI = _load_module('URI'),
URITemplate = function(expression) {
// serve from cache where possible
if (URITemplate._cache[expression]) {
return URITemplate._cache[expression];
}
// Allow instantiation without the 'new' keyword
if (!(this instanceof URITemplate)) {
return new URITemplate(expression);
}
this.expression = expression;
URITemplate._cache[expression] = this;
return this;
// Reserved character strings
'+' : {
prefix: "",
separator: ",",
named: false,
empty_name_separator: false,
encode : "encodeReserved"
},
Data = function(data) {
this.data = data;
this.cache = {};
// Fragment identifiers prefixed by "#"
'#' : {
prefix: "#",
separator: ",",
named: false,
empty_name_separator: false,
encode : "encodeReserved"
},
p = URITemplate.prototype,
// list of operators and their defined options
operators = {
// Simple string expansion
'' : {
prefix: "",
separator: ",",
named: false,
empty_name_separator: false,
encode : "encode"
},
// Reserved character strings
'+' : {
prefix: "",
separator: ",",
named: false,
empty_name_separator: false,
encode : "encodeReserved"
},
// Fragment identifiers prefixed by "#"
'#' : {
prefix: "#",
separator: ",",
named: false,
empty_name_separator: false,
encode : "encodeReserved"
},
// Name labels or extensions prefixed by "."
'.' : {
prefix: ".",
separator: ".",
named: false,
empty_name_separator: false,
encode : "encode"
},
// Path segments prefixed by "/"
'/' : {
prefix: "/",
separator: "/",
named: false,
empty_name_separator: false,
encode : "encode"
},
// Path parameter name or name=value pairs prefixed by ";"
';' : {
prefix: ";",
separator: ";",
named: true,
empty_name_separator: false,
encode : "encode"
},
// Query component beginning with "?" and consisting
// of name=value pairs separated by "&"; an
'?' : {
prefix: "?",
separator: "&",
named: true,
empty_name_separator: true,
encode : "encode"
},
// Continuation of query-style &name=value pairs
// within a literal query component.
'&' : {
prefix: "&",
separator: "&",
named: true,
empty_name_separator: true,
encode : "encode"
}
// Name labels or extensions prefixed by "."
'.' : {
prefix: ".",
separator: ".",
named: false,
empty_name_separator: false,
encode : "encode"
},
// Path segments prefixed by "/"
'/' : {
prefix: "/",
separator: "/",
named: false,
empty_name_separator: false,
encode : "encode"
},
// Path parameter name or name=value pairs prefixed by ";"
';' : {
prefix: ";",
separator: ";",
named: true,
empty_name_separator: false,
encode : "encode"
},
// Query component beginning with "?" and consisting
// of name=value pairs separated by "&"; an
'?' : {
prefix: "?",
separator: "&",
named: true,
empty_name_separator: true,
encode : "encode"
},
// Continuation of query-style &name=value pairs
// within a literal query component.
'&' : {
prefix: "&",
separator: "&",
named: true,
empty_name_separator: true,
encode : "encode"
}
// The operator characters equals ("="), comma (","), exclamation ("!"),
// at sign ("@"), and pipe ("|") are reserved for future extensions.
};
// The operator characters equals ("="), comma (","), exclamation ("!"),
// at sign ("@"), and pipe ("|") are reserved for future extensions.
};
// storage for already parsed templates

@@ -130,10 +140,10 @@ URITemplate._cache = {};

// container for defined options for the given operator
var options = operators[expression.operator],
// expansion type (include keys or not)
type = options.named ? "Named" : "Unnamed",
// list of variables within the expression
variables = expression.variables,
// result buffer for evaluating the expression
buffer = [],
d, variable, i, l, value;
var options = operators[expression.operator];
// expansion type (include keys or not)
var type = options.named ? "Named" : "Unnamed";
// list of variables within the expression
var variables = expression.variables;
// result buffer for evaluating the expression
var buffer = [];
var d, variable, i, l, value;

@@ -174,11 +184,11 @@ for (i = 0; variable = variables[i]; i++) {

// variable result buffer
var result = "",
// peformance crap
encode = options.encode,
empty_name_separator = options.empty_name_separator,
// flag noting if values are already encoded
_encode = !d[encode].length,
// key for named expansion
_name = d.type === 2 ? '': URI[encode](name),
_value, i, l;
var result = "";
// peformance crap
var encode = options.encode;
var empty_name_separator = options.empty_name_separator;
// flag noting if values are already encoded
var _encode = !d[encode].length;
// key for named expansion
var _name = d.type === 2 ? '': URI[encode](name);
var _value, i, l;

@@ -241,9 +251,9 @@ // for each found value

// variable result buffer
var result = "",
// performance crap
encode = options.encode,
empty_name_separator = options.empty_name_separator,
// flag noting if values are already encoded
_encode = !d[encode].length,
_name, _value, i, l;
var result = "";
// performance crap
var encode = options.encode;
var empty_name_separator = options.empty_name_separator;
// flag noting if values are already encoded
var _encode = !d[encode].length;
var _name, _value, i, l;

@@ -325,11 +335,11 @@ // for each found value

// performance crap
var expression = this.expression,
ePattern = URITemplate.EXPRESSION_PATTERN,
vPattern = URITemplate.VARIABLE_PATTERN,
nPattern = URITemplate.VARIABLE_NAME_PATTERN,
// token result buffer
parts = [],
var expression = this.expression;
var ePattern = URITemplate.EXPRESSION_PATTERN;
var vPattern = URITemplate.VARIABLE_PATTERN;
var nPattern = URITemplate.VARIABLE_NAME_PATTERN;
// token result buffer
var parts = [];
// position within source template
pos = 0,
variables, eMatch, vMatch;
var pos = 0;
var variables, eMatch, vMatch;

@@ -401,14 +411,14 @@ // RegExp is shared accross all templates,

// performance crap
var data = this.data,
// cache for processed data-point
d = {
// type of data 0: undefined/null, 1: string, 2: object, 3: array
type: 0,
// original values (except undefined/null)
val: [],
// cache for encoded values (only for non-maxlength expansion)
encode: [],
encodeReserved: []
},
i, l, value;
var data = this.data;
// cache for processed data-point
var d = {
// type of data 0: undefined/null, 1: string, 2: object, 3: array
type: 0,
// original values (except undefined/null)
val: [],
// cache for encoded values (only for non-maxlength expansion)
encode: [],
encodeReserved: []
};
var i, l, value;

@@ -473,4 +483,4 @@ if (this.cache[key] !== undefined) {

URI.expand = function(expression, data) {
var template = new URITemplate(expression),
expansion = template.expand(data);
var template = new URITemplate(expression);
var expansion = template.expand(data);

@@ -480,7 +490,3 @@ return new URI(expansion);

(typeof module !== 'undefined' && module.exports
? module.exports = URITemplate
: window.URITemplate = URITemplate
);
})();
return URITemplate;
}));
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