Socket
Socket
Sign inDemoInstall

uri-js

Package Overview
Dependencies
1
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.1.1 to 3.0.0

.babelrc

40

package.json
{
"name": "uri-js",
"version": "2.1.1",
"version": "3.0.0",
"description": "An RFC 3986/3987 compliant, scheme extendable URI/IRI parsing/validating/resolving library for JavaScript.",
"main": "build/uri.js",
"main": "dist/es5/uri.all.js",
"types": "dist/es5/uri.all.d.ts",
"module": "dist/esnext/index.js",
"directories": {

@@ -10,5 +12,8 @@ "test": "tests"

"scripts": {
"setup": "grunt setup",
"build": "grunt",
"test": "node_modules/.bin/mocha -u mocha-qunit-ui build/uri.js tests/tests.js"
"build:esnext": "node_modules/.bin/tsc",
"build:es5": "node_modules/.bin/rollup -c && cp dist/esnext/uri.d.ts dist/es5/uri.all.d.ts && npm run build:es5:fix-sourcemap",
"build:es5:fix-sourcemap": "node_modules/.bin/sorcery -i dist/es5/uri.all.js",
"build:es5:min": "node_modules/.bin/uglifyjs dist/es5/uri.all.js --support-ie8 --output dist/es5/uri.all.min.js --in-source-map dist/es5/uri.all.js.map --source-map uri.all.min.js.map --comments --compress --mangle --pure-funcs merge subexp && mv uri.all.min.js.map dist/es5/ && cp dist/es5/uri.all.d.ts dist/es5/uri.all.min.d.ts",
"build": "npm run build:esnext && npm run build:es5 && npm run build:es5:min",
"test": "node_modules/.bin/mocha -u mocha-qunit-ui dist/es5/uri.all.js tests/tests.js"
},

@@ -34,6 +39,7 @@ "repository": {

"RFC4122",
"RFC4291",
"RFC6068"
],
"author": "Gary Court <gary.court@gmail.com>",
"license": "BSD",
"license": "BSD-2-Clause",
"bugs": {

@@ -44,11 +50,17 @@ "url": "https://github.com/garycourt/uri-js/issues"

"devDependencies": {
"api-closure-compiler": "^1.0.5",
"grunt": "^0.4.5",
"grunt-closure-compiler-build": "^1.0.1",
"grunt-contrib-copy": "^0.8.0",
"grunt-contrib-rename": "0.0.3",
"grunt-typescript": "^0.6.2",
"mocha": "^2.2.5",
"mocha-qunit-ui": "^0.1.2"
"babel-cli": "^6.24.0",
"babel-plugin-external-helpers": "^6.22.0",
"babel-preset-latest": "^6.24.0",
"mocha": "^3.2.0",
"mocha-qunit-ui": "^0.1.3",
"rollup": "^0.41.6",
"rollup-plugin-babel": "^2.7.1",
"rollup-plugin-node-resolve": "^2.0.0",
"sorcery": "^0.10.0",
"typescript": "^2.2.1",
"uglify-js": "^2.8.14"
},
"dependencies": {
"punycode": "^2.1.0"
}
}

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

URI.js weighs in at only 2.3kb (gzipped, 7kb deflated). Need IRI support? It's only an extra 1.3kb (3.6kb gzipped, 9.8kb deflated).
URI.js has an extensive test suite, and works in all (Node.js, web) environments. It weighs in at 5.6kb (gzipped, 15kb deflated).

@@ -44,5 +44,5 @@ ## API

//convert IRI to URI
URI.serialize(URI.parse("http://exampl�.org/ros�")) === "http://xn--exampl-gva.org/ros%C3%A9"
URI.serialize(URI.parse("http://examplé.org/rosé")) === "http://xn--exampl-gva.org/ros%C3%A9"
//convert URI to IRI
URI.serialize(URI.parse("http://xn--exampl-gva.org/ros%C3%A9"), {iri:true}) === "http://exampl�.org/ros�"
URI.serialize(URI.parse("http://xn--exampl-gva.org/ros%C3%A9"), {iri:true}) === "http://examplé.org/rosé"

@@ -54,15 +54,15 @@ ### Options

* `scheme` (string)
Indicates the scheme that the URI should be treated as, overriding the URI's normal scheme parsing behavior.
* `reference` (string)
If set to `"suffix"`, it indicates that the URI is in the suffix format, and the validator will use the option's `scheme` property to determine the URI's scheme.
* `tolerant` (boolean, false)
If set to `true`, the parser will not report invalid URIs. It will also relax URI resolving rules.
If set to `true`, the parser will relax URI resolving rules.
* `absolutePath` (boolean, false)
If set to `true`, the serializer will not resolve a relative `path` component.

@@ -73,9 +73,9 @@

If set to `true`, the serializer will unescape non-ASCII characters as per [RFC 3987](http://www.ietf.org/rfc/rfc3987.txt).
* `unicodeSupport` (boolean, false)
If set to `true`, the parser will unescape non-ASCII characters in the parsed output as per [RFC 3987](http://www.ietf.org/rfc/rfc3987.txt).
* `domainHost` (boolean, false)
If set to `true`, the library will treat the `host` component as a domain name, and convert IDNs (International Domain Names) as per [RFC 5891](http://www.ietf.org/rfc/rfc5891.txt).

@@ -89,8 +89,6 @@

* https \[[RFC 2818](http://www.ietf.org/rfc/rfc2818.txt)\]
* mailto \[[RFC 6068](http://www.ietf.org/rfc/rfc6068.txt)\]
* urn \[[RFC 2141](http://www.ietf.org/rfc/rfc2141.txt)\]
* urn:uuid \[[RFC 4122](http://www.ietf.org/rfc/rfc4122.txt)\]
* mailto \[[RFC 6068](http://www.ietf.org/rfc/rfc6068.txt)\]
Note: The minified version of URI.js only comes with http/https support compiled in.
### HTTP Support

@@ -105,3 +103,3 @@

//{
// scheme : "mailto",
// scheme : "mailto",
// to : ["alpha@example.com", "bravo@example.com"],

@@ -113,5 +111,5 @@ // subject : "SUBSCRIBE",

URI.serialize({
scheme : "mailto",
to : ["alpha@example.com"],
subject : "REMOVE",
scheme : "mailto",
to : ["alpha@example.com"],
subject : "REMOVE",
body : "Please remove me",

@@ -127,10 +125,6 @@ headers : {

<script type="text/javascript" src="uri-js/dist/uri.min.js"></script>
<script type="text/javascript" src="uri-js/dist/es5/uri.all.min.js"></script>
If you need IRI support, use the following tag instead:
To load in a CommonJS (Node.js) environment, first install with npm by running on the command line:
<script type="text/javascript" src="uri-js/dist/uri-iri.min.js"></script>
To load in a CommonJS (Node.js/io.js) environment, first install with npm by running on the command line:
npm install uri-js

@@ -142,7 +136,19 @@

If you are writing your code in ES6+ (ESNEXT) or TypeScript, you would load it using:
import * as URI from "uri-js";
Or you can load just what you need using named exports:
import { parse, serialize, resolve, resolveComponents, normalize, equal, removeDotSegments, pctEncChar, pctDecChars, escapeComponent, unescapeComponent } from "uri-js";
## Breaking changes from 2.x
URI validation has been removed as it was slow, exposed a vulnerabilty, and was generally not useful.
## Breaking changes from 1.x
The `errors` array on parsed components as now been changed to an `error` string.
The `errors` array on parsed components is now an `error` string.
## License
## License ([Simplified BSD](http://en.wikipedia.org/wiki/BSD_licenses#2-clause))

@@ -159,2 +165,2 @@ Copyright 2011 Gary Court. All rights reserved.

The views and conclusions contained in the software and documentation are those of the authors and should not be interpreted as representing official policies, either expressed or implied, of Gary Court.
The views and conclusions contained in the software and documentation are those of the authors and should not be interpreted as representing official policies, either expressed or implied, of Gary Court.

@@ -1,11 +0,20 @@

declare var punycode: {
decode(string: string): string;
encode(string: string): string;
toUnicode(domain: string): string;
toASCII(domain: string): string;
ucs2: {
decode(string: string): string;
encode(codePoints: number[]): string;
}
version: string;
}
declare module 'punycode' {
function ucs2decode(string:string):Array<number>;
function ucs2encode(array:Array<number>):string;
function decode(string:string):string;
function encode(string:string):string;
function toASCII(string:string):string;
function toUnicode(string:string):string;
export default {
'version': '2.2.0',
'ucs2': {
'decode': ucs2decode,
'encode': ucs2encode
},
'decode': decode,
'encode': encode,
'toASCII': toASCII,
'toUnicode': toUnicode
};
}

@@ -1,7 +0,8 @@

///<reference path="../uri.ts"/>
if (typeof COMPILED === "undefined" && typeof URI === "undefined" && typeof require === "function") var URI = <typeof URI>require("../uri");
import { URIComponents, URIOptions } from "../uri";
URI.SCHEMES["http"] = URI.SCHEMES["https"] = {
export default {
scheme : "http",
domainHost : true,
parse : function (components:URIComponents, options:URIOptions):URIComponents {

@@ -12,5 +13,6 @@ //report missing host

}
return components;
},
serialize : function (components:URIComponents, options:URIOptions):URIComponents {

@@ -21,2 +23,3 @@ //normalize the default port

}
//normalize the empty path

@@ -26,9 +29,9 @@ if (!components.path) {

}
//NOTE: We do not parse query strings for HTTP URIs
//as WWW Form Url Encoded query strings are part of the HTML4+ spec,
//and not the HTTP spec.
//and not the HTTP spec.
return components;
}
};
};

@@ -1,11 +0,11 @@

///<reference path="../uri.ts"/>
if (typeof COMPILED === "undefined" && typeof URI === "undefined" && typeof require === "function") {
var URI = <typeof URI>require("../uri"), punycode = <typeof punycode>require("../punycode");
}
import { URIComponents, URIOptions } from "../uri";
import { pctEncChar, pctDecChars, unescapeComponent } from "../uri";
import punycode from "punycode";
import { merge, subexp, toUpperCase, toArray } from "../util";
interface MailtoHeaders {
export interface MailtoHeaders {
[hfname:string]:string
}
interface MailtoComponents extends URIComponents {
export interface MailtoComponents extends URIComponents {
to:Array<string>,

@@ -17,203 +17,163 @@ headers?:MailtoHeaders,

(function () {
function merge(...sets:Array<string>):string {
if (sets.length > 1) {
sets[0] = sets[0].slice(0, -1);
let xl = sets.length - 1;
for (let x = 1; x < xl; ++x) {
sets[x] = sets[x].slice(1, -1);
}
sets[xl] = sets[xl].slice(1);
return sets.join('');
} else {
return sets[0];
}
}
const O:MailtoHeaders = {};
const isIRI = true;
function subexp(str:string):string {
return "(?:" + str + ")";
}
//RFC 3986
const UNRESERVED$$ = "[A-Za-z0-9\\-\\.\\_\\~" + (isIRI ? "\\xA0-\\u200D\\u2010-\\u2029\\u202F-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF" : "") + "]";
const HEXDIG$$ = "[0-9A-Fa-f]"; //case-insensitive
const PCT_ENCODED$ = subexp(subexp("%[EFef]" + HEXDIG$$ + "%" + HEXDIG$$ + HEXDIG$$ + "%" + HEXDIG$$ + HEXDIG$$) + "|" + subexp("%[89A-Fa-f]" + HEXDIG$$ + "%" + HEXDIG$$ + HEXDIG$$) + "|" + subexp("%" + HEXDIG$$ + HEXDIG$$)); //expanded
var
O = {},
isIRI = URI.IRI_SUPPORT,
//RFC 5322, except these symbols as per RFC 6068: @ : / ? # [ ] & ; =
//const ATEXT$$ = "[A-Za-z0-9\\!\\#\\$\\%\\&\\'\\*\\+\\-\\/\\=\\?\\^\\_\\`\\{\\|\\}\\~]";
//const WSP$$ = "[\\x20\\x09]";
//const OBS_QTEXT$$ = "[\\x01-\\x08\\x0B\\x0C\\x0E-\\x1F\\x7F]"; //(%d1-8 / %d11-12 / %d14-31 / %d127)
//const QTEXT$$ = merge("[\\x21\\x23-\\x5B\\x5D-\\x7E]", OBS_QTEXT$$); //%d33 / %d35-91 / %d93-126 / obs-qtext
//const VCHAR$$ = "[\\x21-\\x7E]";
//const WSP$$ = "[\\x20\\x09]";
//const OBS_QP$ = subexp("\\\\" + merge("[\\x00\\x0D\\x0A]", OBS_QTEXT$$)); //%d0 / CR / LF / obs-qtext
//const FWS$ = subexp(subexp(WSP$$ + "*" + "\\x0D\\x0A") + "?" + WSP$$ + "+");
//const QUOTED_PAIR$ = subexp(subexp("\\\\" + subexp(VCHAR$$ + "|" + WSP$$)) + "|" + OBS_QP$);
//const QUOTED_STRING$ = subexp('\\"' + subexp(FWS$ + "?" + QCONTENT$) + "*" + FWS$ + "?" + '\\"');
const ATEXT$$ = "[A-Za-z0-9\\!\\$\\%\\'\\*\\+\\-\\^\\_\\`\\{\\|\\}\\~]";
const QTEXT$$ = "[\\!\\$\\%\\'\\(\\)\\*\\+\\,\\-\\.0-9\\<\\>A-Z\\x5E-\\x7E]";
const VCHAR$$ = merge(QTEXT$$, "[\\\"\\\\]");
const DOT_ATOM_TEXT$ = subexp(ATEXT$$ + "+" + subexp("\\." + ATEXT$$ + "+") + "*");
const QUOTED_PAIR$ = subexp("\\\\" + VCHAR$$);
const QCONTENT$ = subexp(QTEXT$$ + "|" + QUOTED_PAIR$);
const QUOTED_STRING$ = subexp('\\"' + QCONTENT$ + "*" + '\\"');
//RFC 3986
UNRESERVED$$ = "[A-Za-z0-9\\-\\.\\_\\~" + (isIRI ? "\\xA0-\\u200D\\u2010-\\u2029\\u202F-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF" : "") + "]",
HEXDIG$$ = "[0-9A-Fa-f]", //case-insensitive
PCT_ENCODED$ = subexp(subexp("%[EFef]" + HEXDIG$$ + "%" + HEXDIG$$ + HEXDIG$$ + "%" + HEXDIG$$ + HEXDIG$$) + "|" + subexp("%[89A-Fa-f]" + HEXDIG$$ + "%" + HEXDIG$$ + HEXDIG$$) + "|" + subexp("%" + HEXDIG$$ + HEXDIG$$)), //expanded
//RFC 6068
const DTEXT_NO_OBS$$ = "[\\x21-\\x5A\\x5E-\\x7E]"; //%d33-90 / %d94-126
const SOME_DELIMS$$ = "[\\!\\$\\'\\(\\)\\*\\+\\,\\;\\:\\@]";
const QCHAR$ = subexp(UNRESERVED$$ + "|" + PCT_ENCODED$ + "|" + SOME_DELIMS$$);
const DOMAIN$ = subexp(DOT_ATOM_TEXT$ + "|" + "\\[" + DTEXT_NO_OBS$$ + "*" + "\\]");
const LOCAL_PART$ = subexp(DOT_ATOM_TEXT$ + "|" + QUOTED_STRING$);
const ADDR_SPEC$ = subexp(LOCAL_PART$ + "\\@" + DOMAIN$);
const TO$ = subexp(ADDR_SPEC$ + subexp("\\," + ADDR_SPEC$) + "*");
const HFNAME$ = subexp(QCHAR$ + "*");
const HFVALUE$ = HFNAME$;
const HFIELD$ = subexp(HFNAME$ + "\\=" + HFVALUE$);
const HFIELDS2$ = subexp(HFIELD$ + subexp("\\&" + HFIELD$) + "*");
const HFIELDS$ = subexp("\\?" + HFIELDS2$);
const MAILTO_URI = new RegExp("^mailto\\:" + TO$ + "?" + HFIELDS$ + "?$");
//RFC 5322, except these symbols as per RFC 6068: @ : / ? # [ ] & ; =
//ATEXT$$ = "[A-Za-z0-9\\!\\#\\$\\%\\&\\'\\*\\+\\-\\/\\=\\?\\^\\_\\`\\{\\|\\}\\~]",
//WSP$$ = "[\\x20\\x09]",
//OBS_QTEXT$$ = "[\\x01-\\x08\\x0B\\x0C\\x0E-\\x1F\\x7F]", //(%d1-8 / %d11-12 / %d14-31 / %d127)
//QTEXT$$ = merge("[\\x21\\x23-\\x5B\\x5D-\\x7E]", OBS_QTEXT$$), //%d33 / %d35-91 / %d93-126 / obs-qtext
//VCHAR$$ = "[\\x21-\\x7E]",
//WSP$$ = "[\\x20\\x09]",
//OBS_QP$ = subexp("\\\\" + merge("[\\x00\\x0D\\x0A]", OBS_QTEXT$$)), //%d0 / CR / LF / obs-qtext
//FWS$ = subexp(subexp(WSP$$ + "*" + "\\x0D\\x0A") + "?" + WSP$$ + "+"),
//QUOTED_PAIR$ = subexp(subexp("\\\\" + subexp(VCHAR$$ + "|" + WSP$$)) + "|" + OBS_QP$),
//QUOTED_STRING$ = subexp('\\"' + subexp(FWS$ + "?" + QCONTENT$) + "*" + FWS$ + "?" + '\\"'),
ATEXT$$ = "[A-Za-z0-9\\!\\$\\%\\'\\*\\+\\-\\^\\_\\`\\{\\|\\}\\~]",
QTEXT$$ = "[\\!\\$\\%\\'\\(\\)\\*\\+\\,\\-\\.0-9\\<\\>A-Z\\x5E-\\x7E]",
VCHAR$$ = merge(QTEXT$$, "[\\\"\\\\]"),
DOT_ATOM_TEXT$ = subexp(ATEXT$$ + "+" + subexp("\\." + ATEXT$$ + "+") + "*"),
QUOTED_PAIR$ = subexp("\\\\" + VCHAR$$),
QCONTENT$ = subexp(QTEXT$$ + "|" + QUOTED_PAIR$),
QUOTED_STRING$ = subexp('\\"' + QCONTENT$ + "*" + '\\"'),
const UNRESERVED = new RegExp(UNRESERVED$$, "g");
const PCT_ENCODED = new RegExp(PCT_ENCODED$, "g");
const NOT_LOCAL_PART = new RegExp(merge("[^]", ATEXT$$, "[\\.]", '[\\"]', VCHAR$$), "g");
const NOT_DOMAIN = new RegExp(merge("[^]", ATEXT$$, "[\\.]", "[\\[]", DTEXT_NO_OBS$$, "[\\]]"), "g");
const NOT_HFNAME = new RegExp(merge("[^]", UNRESERVED$$, SOME_DELIMS$$), "g");
const NOT_HFVALUE = NOT_HFNAME;
const TO = new RegExp("^" + TO$ + "$");
const HFIELDS = new RegExp("^" + HFIELDS2$ + "$");
//RFC 6068
DTEXT_NO_OBS$$ = "[\\x21-\\x5A\\x5E-\\x7E]", //%d33-90 / %d94-126
SOME_DELIMS$$ = "[\\!\\$\\'\\(\\)\\*\\+\\,\\;\\:\\@]",
QCHAR$ = subexp(UNRESERVED$$ + "|" + PCT_ENCODED$ + "|" + SOME_DELIMS$$),
DOMAIN$ = subexp(DOT_ATOM_TEXT$ + "|" + "\\[" + DTEXT_NO_OBS$$ + "*" + "\\]"),
LOCAL_PART$ = subexp(DOT_ATOM_TEXT$ + "|" + QUOTED_STRING$),
ADDR_SPEC$ = subexp(LOCAL_PART$ + "\\@" + DOMAIN$),
TO$ = subexp(ADDR_SPEC$ + subexp("\\," + ADDR_SPEC$) + "*"),
HFNAME$ = subexp(QCHAR$ + "*"),
HFVALUE$ = HFNAME$,
HFIELD$ = subexp(HFNAME$ + "\\=" + HFVALUE$),
HFIELDS2$ = subexp(HFIELD$ + subexp("\\&" + HFIELD$) + "*"),
HFIELDS$ = subexp("\\?" + HFIELDS2$),
MAILTO_URI = URI.VALIDATE_SUPPORT && new RegExp("^mailto\\:" + TO$ + "?" + HFIELDS$ + "?$"),
function decodeUnreserved(str:string):string {
const decStr = pctDecChars(str);
return (!decStr.match(UNRESERVED) ? str : decStr);
}
UNRESERVED = new RegExp(UNRESERVED$$, "g"),
PCT_ENCODED = new RegExp(PCT_ENCODED$, "g"),
NOT_LOCAL_PART = new RegExp(merge("[^]", ATEXT$$, "[\\.]", '[\\"]', VCHAR$$), "g"),
NOT_DOMAIN = new RegExp(merge("[^]", ATEXT$$, "[\\.]", "[\\[]", DTEXT_NO_OBS$$, "[\\]]"), "g"),
NOT_HFNAME = new RegExp(merge("[^]", UNRESERVED$$, SOME_DELIMS$$), "g"),
NOT_HFVALUE = NOT_HFNAME,
TO = URI.VALIDATE_SUPPORT && new RegExp("^" + TO$ + "$"),
HFIELDS = URI.VALIDATE_SUPPORT && new RegExp("^" + HFIELDS2$ + "$")
;
export default {
scheme : "mailto",
function toUpperCase(str:string):string {
return str.toUpperCase();
}
parse : function (components:MailtoComponents, options:URIOptions):MailtoComponents {
const to = components.to = (components.path ? components.path.split(",") : []);
components.path = undefined;
function decodeUnreserved(str:string):string {
var decStr = URI.pctDecChars(str);
return (!decStr.match(UNRESERVED) ? str : decStr);
}
if (components.query) {
let unknownHeaders = false
const headers:MailtoHeaders = {};
const hfields = components.query.split("&");
function toArray(obj:any):Array<any> {
return obj !== undefined && obj !== null ? (obj instanceof Array && !obj.callee ? obj : (typeof obj.length !== "number" || obj.split || obj.setInterval || obj.call ? [obj] : Array.prototype.slice.call(obj))) : [];
}
for (let x = 0, xl = hfields.length; x < xl; ++x) {
const hfield = hfields[x].split("=");
URI.SCHEMES["mailto"] = {
parse : function (components:MailtoComponents, options:URIOptions):MailtoComponents {
if (URI.VALIDATE_SUPPORT && !components.error) {
if (components.path && !TO.test(components.path)) {
components.error = "Email address is not valid";
} else if (components.query && !HFIELDS.test(components.query)) {
components.error = "Header fields are invalid";
switch (hfield[0]) {
case "to":
const toAddrs = hfield[1].split(",");
for (let x = 0, xl = toAddrs.length; x < xl; ++x) {
to.push(toAddrs[x]);
}
break;
case "subject":
components.subject = unescapeComponent(hfield[1], options);
break;
case "body":
components.body = unescapeComponent(hfield[1], options);
break;
default:
unknownHeaders = true;
headers[unescapeComponent(hfield[0], options)] = unescapeComponent(hfield[1], options);
break;
}
}
let to = components.to = (components.path ? components.path.split(",") : []);
components.path = undefined;
if (unknownHeaders) components.headers = headers;
}
if (components.query) {
let unknownHeaders = false, headers:MailtoHeaders = {};
components.query = undefined;
let hfields = components.query.split("&");
for (let x = 0, xl = hfields.length; x < xl; ++x) {
let hfield = hfields[x].split("=");
for (let x = 0, xl = to.length; x < xl; ++x) {
const addr = to[x].split("@");
switch (hfield[0]) {
case "to":
let toAddrs = hfield[1].split(",");
for (let x = 0, xl = toAddrs.length; x < xl; ++x) {
to.push(toAddrs[x]);
}
break;
case "subject":
components.subject = URI.unescapeComponent(hfield[1], options);
break;
case "body":
components.body = URI.unescapeComponent(hfield[1], options);
break;
default:
unknownHeaders = true;
headers[URI.unescapeComponent(hfield[0], options)] = URI.unescapeComponent(hfield[1], options);
break;
}
addr[0] = unescapeComponent(addr[0]);
if (!options.unicodeSupport) {
//convert Unicode IDN -> ASCII IDN
try {
addr[1] = punycode.toASCII(unescapeComponent(addr[1], options).toLowerCase());
} catch (e) {
components.error = components.error || "Email address's domain name can not be converted to ASCII via punycode: " + e;
}
if (unknownHeaders) components.headers = headers;
} else {
addr[1] = unescapeComponent(addr[1], options).toLowerCase();
}
components.query = undefined;
to[x] = addr.join("@");
}
return components;
},
serialize : function (components:MailtoComponents, options:URIOptions):URIComponents {
const to = toArray(components.to);
if (to) {
for (let x = 0, xl = to.length; x < xl; ++x) {
let addr = to[x].split("@");
const toAddr = String(to[x]);
const atIdx = toAddr.lastIndexOf("@");
const localPart = (toAddr.slice(0, atIdx)).replace(PCT_ENCODED, decodeUnreserved).replace(PCT_ENCODED, toUpperCase).replace(NOT_LOCAL_PART, pctEncChar);
let domain = toAddr.slice(atIdx + 1);
addr[0] = URI.unescapeComponent(addr[0]);
if (typeof punycode !== "undefined" && !options.unicodeSupport) {
//convert Unicode IDN -> ASCII IDN
try {
addr[1] = punycode.toASCII(URI.unescapeComponent(addr[1], options).toLowerCase());
} catch (e) {
components.error = components.error || "Email address's domain name can not be converted to ASCII via punycode: " + e;
}
} else {
addr[1] = URI.unescapeComponent(addr[1], options).toLowerCase();
//convert IDN via punycode
try {
domain = (!options.iri ? punycode.toASCII(unescapeComponent(domain, options).toLowerCase()) : punycode.toUnicode(domain));
} catch (e) {
components.error = components.error || "Email address's domain name can not be converted to " + (!options.iri ? "ASCII" : "Unicode") + " via punycode: " + e;
}
to[x] = addr.join("@");
to[x] = localPart + "@" + domain;
}
return components;
},
serialize : function (components:MailtoComponents, options:URIOptions):URIComponents {
let to = toArray(components.to);
if (to) {
for (let x = 0, xl = to.length; x < xl; ++x) {
let toAddr = String(to[x]);
let atIdx = toAddr.lastIndexOf("@");
let localPart = toAddr.slice(0, atIdx);
let domain = toAddr.slice(atIdx + 1);
localPart = localPart.replace(PCT_ENCODED, decodeUnreserved).replace(PCT_ENCODED, toUpperCase).replace(NOT_LOCAL_PART, URI.pctEncChar);
components.path = to.join(",");
}
if (typeof punycode !== "undefined") {
//convert IDN via punycode
try {
domain = (!options.iri ? punycode.toASCII(URI.unescapeComponent(domain, options).toLowerCase()) : punycode.toUnicode(domain));
} catch (e) {
components.error = components.error || "Email address's domain name can not be converted to " + (!options.iri ? "ASCII" : "Unicode") + " via punycode: " + e;
}
} else {
domain = domain.replace(PCT_ENCODED, decodeUnreserved).toLowerCase().replace(PCT_ENCODED, toUpperCase).replace(NOT_DOMAIN, URI.pctEncChar);
}
const headers = components.headers = components.headers || {};
to[x] = localPart + "@" + domain;
}
if (components.subject) headers["subject"] = components.subject;
if (components.body) headers["body"] = components.body;
components.path = to.join(",");
const fields = [];
for (const name in headers) {
if (headers[name] !== O[name]) {
fields.push(
name.replace(PCT_ENCODED, decodeUnreserved).replace(PCT_ENCODED, toUpperCase).replace(NOT_HFNAME, pctEncChar) +
"=" +
headers[name].replace(PCT_ENCODED, decodeUnreserved).replace(PCT_ENCODED, toUpperCase).replace(NOT_HFVALUE, pctEncChar)
);
}
}
if (fields.length) {
components.query = fields.join("&");
}
let headers = components.headers = components.headers || {};
if (components.subject) headers["subject"] = components.subject;
if (components.body) headers["body"] = components.body;
let fields = [];
for (let name in headers) {
if (headers[name] !== O[name]) {
fields.push(
name.replace(PCT_ENCODED, decodeUnreserved).replace(PCT_ENCODED, toUpperCase).replace(NOT_HFNAME, URI.pctEncChar) +
"=" +
headers[name].replace(PCT_ENCODED, decodeUnreserved).replace(PCT_ENCODED, toUpperCase).replace(NOT_HFVALUE, URI.pctEncChar)
);
}
}
if (fields.length) {
components.query = fields.join("&");
}
return components;
}
return components;
}
})();
}

@@ -1,99 +0,59 @@

///<reference path="../uri.ts"/>
if (typeof COMPILED === "undefined" && typeof URI === "undefined" && typeof require === "function") var URI = <typeof URI>require("../uri");
import { URIComponents, URIOptions } from "../uri";
import { pctEncChar, SCHEMES } from "../uri";
(function () {
var pctEncChar = URI.pctEncChar,
NID$ = "(?:[0-9A-Za-z][0-9A-Za-z\\-]{1,31})",
PCT_ENCODED$ = "(?:\\%[0-9A-Fa-f]{2})",
TRANS$$ = "[0-9A-Za-z\\(\\)\\+\\,\\-\\.\\:\\=\\@\\;\\$\\_\\!\\*\\'\\/\\?\\#]",
NSS$ = "(?:(?:" + PCT_ENCODED$ + "|" + TRANS$$ + ")+)",
URN_SCHEME = new RegExp("^urn\\:(" + NID$ + ")$"),
URN_PATH = new RegExp("^(" + NID$ + ")\\:(" + NSS$ + ")$"),
URN_PARSE = /^([^\:]+)\:(.*)/,
URN_EXCLUDED = /[\x00-\x20\\\"\&\<\>\[\]\^\`\{\|\}\~\x7F-\xFF]/g,
UUID = /^[0-9A-Fa-f]{8}(?:\-[0-9A-Fa-f]{4}){3}\-[0-9A-Fa-f]{12}$/;
//RFC 2141
URI.SCHEMES["urn"] = {
parse : function (components:URIComponents, options:URIOptions):URIComponents {
var matches = components.path.match(URN_PATH),
scheme:string,
schemeHandler:URISchemeHandler;
if (!matches) {
if (!options.tolerant) {
components.error = components.error || "URN is not strictly valid.";
}
matches = components.path.match(URN_PARSE);
const NID$ = "(?:[0-9A-Za-z][0-9A-Za-z\\-]{1,31})";
const PCT_ENCODED$ = "(?:\\%[0-9A-Fa-f]{2})";
const TRANS$$ = "[0-9A-Za-z\\(\\)\\+\\,\\-\\.\\:\\=\\@\\;\\$\\_\\!\\*\\'\\/\\?\\#]";
const NSS$ = "(?:(?:" + PCT_ENCODED$ + "|" + TRANS$$ + ")+)";
const URN_SCHEME = new RegExp("^urn\\:(" + NID$ + ")$");
const URN_PATH = new RegExp("^(" + NID$ + ")\\:(" + NSS$ + ")$");
const URN_PARSE = /^([^\:]+)\:(.*)/;
const URN_EXCLUDED = /[\x00-\x20\\\"\&\<\>\[\]\^\`\{\|\}\~\x7F-\xFF]/g;
//RFC 2141
export default {
scheme : "urn",
parse : function (components:URIComponents, options:URIOptions):URIComponents {
const matches = components.path && components.path.match(URN_PARSE);
if (matches) {
const scheme = "urn:" + matches[1].toLowerCase();
let schemeHandler = SCHEMES[scheme];
//in order to serialize properly,
//every URN must have a serializer that calls the URN serializer
if (!schemeHandler) {
//create fake scheme handler
schemeHandler = SCHEMES[scheme] = {
scheme : scheme,
parse : function (components:URIComponents, options:URIOptions):URIComponents {
return components;
},
serialize : SCHEMES["urn"].serialize
};
}
if (matches) {
scheme = "urn:" + matches[1].toLowerCase();
schemeHandler = URI.SCHEMES[scheme];
//in order to serialize properly,
//every URN must have a serializer that calls the URN serializer
if (!schemeHandler) {
//create fake scheme handler
schemeHandler = URI.SCHEMES[scheme] = {
parse : function (components:URIComponents, options:URIOptions):URIComponents {
return components;
},
serialize : URI.SCHEMES["urn"].serialize
};
}
components.scheme = scheme;
components.path = matches[2];
components = schemeHandler.parse(components, options);
} else {
components.error = components.error || "URN can not be parsed.";
}
return components;
},
serialize : function (components:URIComponents, options:URIOptions):URIComponents {
var scheme = components.scheme || options.scheme,
matches:RegExpMatchArray;
if (scheme && scheme !== "urn") {
var matches = scheme.match(URN_SCHEME);
if (!matches) {
matches = ["urn:" + scheme, scheme];
}
components.scheme = "urn";
components.path = matches[1] + ":" + (components.path ? components.path.replace(URN_EXCLUDED, pctEncChar) : "");
}
return components;
components.scheme = scheme;
components.path = matches[2];
components = schemeHandler.parse(components, options);
} else {
components.error = components.error || "URN can not be parsed.";
}
};
//RFC 4122
URI.SCHEMES["urn:uuid"] = {
parse : function (components:URIComponents, options:URIOptions):URIComponents {
if (!options.tolerant && (!components.path || !components.path.match(UUID))) {
components.error = components.error || "UUID is not valid.";
}
return components;
},
serialize : function (components:URIComponents, options:URIOptions):URIComponents {
//ensure UUID is valid
if (!options.tolerant && (!components.path || !components.path.match(UUID))) {
//invalid UUIDs can not have this scheme
components.scheme = undefined;
} else {
//normalize UUID
components.path = (components.path || "").toLowerCase();
}
return URI.SCHEMES["urn"].serialize(components, options);
return components;
},
serialize : function (components:URIComponents, options:URIOptions):URIComponents {
const scheme = components.scheme || options.scheme;
if (scheme && scheme !== "urn") {
const matches = scheme.match(URN_SCHEME) || ["urn:" + scheme, scheme];
components.scheme = "urn";
components.path = matches[1] + ":" + (components.path ? components.path.replace(URN_EXCLUDED, pctEncChar) : "");
}
};
}());
return components;
}
};
/**
* URI.js
*
*
* @fileoverview An RFC 3986 compliant, scheme extendable URI parsing/validating/resolving library for JavaScript.
* @author <a href="mailto:gary.court@gmail.com">Gary Court</a>
* @version 2.0.0
* @see http://github.com/garycourt/uri-js
* @license URI.js v2.0.0 (c) 2011 Gary Court. License: http://github.com/garycourt/uri-js
*/

@@ -13,13 +11,13 @@

* Copyright 2011 Gary Court. All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
*
* THIS SOFTWARE IS PROVIDED BY GARY COURT ``AS IS'' AND ANY EXPRESS OR IMPLIED

@@ -34,3 +32,3 @@ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND

* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
* The views and conclusions contained in the software and documentation are those of the

@@ -41,24 +39,8 @@ * authors and should not be interpreted as representing official policies, either expressed

///<reference path="punycode.d.ts"/>
///<reference path="commonjs.d.ts"/>
import URI_PROTOCOL from "./regexps-uri";
import IRI_PROTOCOL from "./regexps-iri";
import punycode from "punycode";
import { toUpperCase, typeOf } from "./util";
/**
* Compiler switch for indicating code is compiled
* @define {boolean}
*/
const COMPILED = false;
/**
* Compiler switch for supporting IRI URIs
* @define {boolean}
*/
const URI__IRI_SUPPORT = true;
/**
* Compiler switch for supporting URI validation
* @define {boolean}
*/
const URI__VALIDATE_SUPPORT = true;
interface URIComponents {
export interface URIComponents {
scheme?:string,

@@ -75,3 +57,3 @@ userinfo?:string,

interface URIOptions {
export interface URIOptions {
scheme?:string,

@@ -86,3 +68,4 @@ reference?:string,

interface URISchemeHandler {
export interface URISchemeHandler {
scheme:string,
parse(components:URIComponents, options:URIOptions):URIComponents,

@@ -95,4 +78,3 @@ serialize(components:URIComponents, options:URIOptions):URIComponents,

interface URIRegExps {
URI_REF : RegExp,
export interface URIRegExps {
NOT_SCHEME : RegExp,

@@ -108,363 +90,245 @@ NOT_USERINFO : RegExp,

OTHER_CHARS : RegExp,
PCT_ENCODED : RegExp
PCT_ENCODED : RegExp,
IPV6ADDRESS : RegExp
}
var URI = (function () {
function merge(...sets:Array<string>):string {
if (sets.length > 1) {
sets[0] = sets[0].slice(0, -1);
let xl = sets.length - 1;
for (let x = 1; x < xl; ++x) {
sets[x] = sets[x].slice(1, -1);
}
sets[xl] = sets[xl].slice(1);
return sets.join('');
} else {
return sets[0];
}
}
export const SCHEMES:{[scheme:string]:URISchemeHandler} = {};
function subexp(str:string):string {
return "(?:" + str + ")";
}
export function pctEncChar(chr:string):string {
const c = chr.charCodeAt(0);
let e:string;
function buildExps(isIRI:boolean):URIRegExps {
const
ALPHA$$ = "[A-Za-z]",
CR$ = "[\\x0D]",
DIGIT$$ = "[0-9]",
DQUOTE$$ = "[\\x22]",
HEXDIG$$ = merge(DIGIT$$, "[A-Fa-f]"), //case-insensitive
LF$$ = "[\\x0A]",
SP$$ = "[\\x20]",
PCT_ENCODED$ = subexp(subexp("%[EFef]" + HEXDIG$$ + "%" + HEXDIG$$ + HEXDIG$$ + "%" + HEXDIG$$ + HEXDIG$$) + "|" + subexp("%[89A-Fa-f]" + HEXDIG$$ + "%" + HEXDIG$$ + HEXDIG$$) + "|" + subexp("%" + HEXDIG$$ + HEXDIG$$)), //expanded
GEN_DELIMS$$ = "[\\:\\/\\?\\#\\[\\]\\@]",
SUB_DELIMS$$ = "[\\!\\$\\&\\'\\(\\)\\*\\+\\,\\;\\=]",
RESERVED$$ = merge(GEN_DELIMS$$, SUB_DELIMS$$),
UCSCHAR$$ = isIRI ? "[\\xA0-\\u200D\\u2010-\\u2029\\u202F-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF]" : "[]", //subset, excludes bidi control characters
IPRIVATE$$ = isIRI ? "[\\uE000-\\uF8FF]" : "[]", //subset
UNRESERVED$$ = merge(ALPHA$$, DIGIT$$, "[\\-\\.\\_\\~]", UCSCHAR$$),
SCHEME$ = subexp(ALPHA$$ + merge(ALPHA$$, DIGIT$$, "[\\+\\-\\.]") + "*"),
USERINFO$ = subexp(subexp(PCT_ENCODED$ + "|" + merge(UNRESERVED$$, SUB_DELIMS$$, "[\\:]")) + "*"),
DEC_OCTET$ = subexp(subexp("25[0-5]") + "|" + subexp("2[0-4]" + DIGIT$$) + "|" + subexp("1" + DIGIT$$ + DIGIT$$) + "|" + subexp("[1-9]" + DIGIT$$) + "|" + DIGIT$$),
IPV4ADDRESS$ = subexp(DEC_OCTET$ + "\\." + DEC_OCTET$ + "\\." + DEC_OCTET$ + "\\." + DEC_OCTET$),
H16$ = subexp(HEXDIG$$ + "{1,4}"),
LS32$ = subexp(subexp(H16$ + "\\:" + H16$) + "|" + IPV4ADDRESS$),
IPV6ADDRESS$ = subexp(merge(UNRESERVED$$, SUB_DELIMS$$, "[\\:]") + "+"), //FIXME
IPVFUTURE$ = subexp("v" + HEXDIG$$ + "+\\." + merge(UNRESERVED$$, SUB_DELIMS$$, "[\\:]") + "+"),
IP_LITERAL$ = subexp("\\[" + subexp(IPV6ADDRESS$ + "|" + IPVFUTURE$) + "\\]"),
REG_NAME$ = subexp(subexp(PCT_ENCODED$ + "|" + merge(UNRESERVED$$, SUB_DELIMS$$)) + "*"),
HOST$ = subexp(IP_LITERAL$ + "|" + IPV4ADDRESS$ + "(?!" + REG_NAME$ + ")" + "|" + REG_NAME$),
PORT$ = subexp(DIGIT$$ + "*"),
AUTHORITY$ = subexp(subexp(USERINFO$ + "@") + "?" + HOST$ + subexp("\\:" + PORT$) + "?"),
PCHAR$ = subexp(PCT_ENCODED$ + "|" + merge(UNRESERVED$$, SUB_DELIMS$$, "[\\:\\@]")),
SEGMENT$ = subexp(PCHAR$ + "*"),
SEGMENT_NZ$ = subexp(PCHAR$ + "+"),
SEGMENT_NZ_NC$ = subexp(subexp(PCT_ENCODED$ + "|" + merge(UNRESERVED$$, SUB_DELIMS$$, "[\\@]")) + "+"),
PATH_ABEMPTY$ = subexp(subexp("\\/" + SEGMENT$) + "*"),
PATH_ABSOLUTE$ = subexp("\\/" + subexp(SEGMENT_NZ$ + PATH_ABEMPTY$) + "?"), //simplified
PATH_NOSCHEME$ = subexp(SEGMENT_NZ_NC$ + PATH_ABEMPTY$), //simplified
PATH_ROOTLESS$ = subexp(SEGMENT_NZ$ + PATH_ABEMPTY$), //simplified
PATH_EMPTY$ = "(?!" + PCHAR$ + ")",
PATH$ = subexp(PATH_ABEMPTY$ + "|" + PATH_ABSOLUTE$ + "|" + PATH_NOSCHEME$ + "|" + PATH_ROOTLESS$ + "|" + PATH_EMPTY$),
QUERY$ = subexp(subexp(PCHAR$ + "|" + merge("[\\/\\?]", IPRIVATE$$)) + "*"),
FRAGMENT$ = subexp(subexp(PCHAR$ + "|[\\/\\?]") + "*"),
HIER_PART$ = subexp(subexp("\\/\\/" + AUTHORITY$ + PATH_ABEMPTY$) + "|" + PATH_ABSOLUTE$ + "|" + PATH_ROOTLESS$ + "|" + PATH_EMPTY$),
URI$ = subexp(SCHEME$ + "\\:" + HIER_PART$ + subexp("\\?" + QUERY$) + "?" + subexp("\\#" + FRAGMENT$) + "?"),
RELATIVE_PART$ = subexp(subexp("\\/\\/" + AUTHORITY$ + PATH_ABEMPTY$) + "|" + PATH_ABSOLUTE$ + "|" + PATH_NOSCHEME$ + "|" + PATH_EMPTY$),
RELATIVE$ = subexp(RELATIVE_PART$ + subexp("\\?" + QUERY$) + "?" + subexp("\\#" + FRAGMENT$) + "?"),
URI_REFERENCE$ = subexp(URI$ + "|" + RELATIVE$),
ABSOLUTE_URI$ = subexp(SCHEME$ + "\\:" + HIER_PART$ + subexp("\\?" + QUERY$) + "?"),
GENERIC_REF$ = "^(" + SCHEME$ + ")\\:" + subexp(subexp("\\/\\/(" + subexp("(" + USERINFO$ + ")@") + "?(" + HOST$ + ")" + subexp("\\:(" + PORT$ + ")") + "?)") + "?(" + PATH_ABEMPTY$ + "|" + PATH_ABSOLUTE$ + "|" + PATH_ROOTLESS$ + "|" + PATH_EMPTY$ + ")") + subexp("\\?(" + QUERY$ + ")") + "?" + subexp("\\#(" + FRAGMENT$ + ")") + "?$",
RELATIVE_REF$ = "^(){0}" + subexp(subexp("\\/\\/(" + subexp("(" + USERINFO$ + ")@") + "?(" + HOST$ + ")" + subexp("\\:(" + PORT$ + ")") + "?)") + "?(" + PATH_ABEMPTY$ + "|" + PATH_ABSOLUTE$ + "|" + PATH_NOSCHEME$ + "|" + PATH_EMPTY$ + ")") + subexp("\\?(" + QUERY$ + ")") + "?" + subexp("\\#(" + FRAGMENT$ + ")") + "?$",
ABSOLUTE_REF$ = "^(" + SCHEME$ + ")\\:" + subexp(subexp("\\/\\/(" + subexp("(" + USERINFO$ + ")@") + "?(" + HOST$ + ")" + subexp("\\:(" + PORT$ + ")") + "?)") + "?(" + PATH_ABEMPTY$ + "|" + PATH_ABSOLUTE$ + "|" + PATH_ROOTLESS$ + "|" + PATH_EMPTY$ + ")") + subexp("\\?(" + QUERY$ + ")") + "?$",
SAMEDOC_REF$ = "^" + subexp("\\#(" + FRAGMENT$ + ")") + "?$",
AUTHORITY_REF$ = "^" + subexp("(" + USERINFO$ + ")@") + "?(" + HOST$ + ")" + subexp("\\:(" + PORT$ + ")") + "?$"
;
return {
URI_REF : URI__VALIDATE_SUPPORT && new RegExp("(" + GENERIC_REF$ + ")|(" + RELATIVE_REF$ + ")"),
NOT_SCHEME : new RegExp(merge("[^]", ALPHA$$, DIGIT$$, "[\\+\\-\\.]"), "g"),
NOT_USERINFO : new RegExp(merge("[^\\%\\:]", UNRESERVED$$, SUB_DELIMS$$), "g"),
NOT_HOST : new RegExp(merge("[^\\%]", UNRESERVED$$, SUB_DELIMS$$), "g"),
NOT_PATH : new RegExp(merge("[^\\%\\/\\:\\@]", UNRESERVED$$, SUB_DELIMS$$), "g"),
NOT_PATH_NOSCHEME : new RegExp(merge("[^\\%\\/\\@]", UNRESERVED$$, SUB_DELIMS$$), "g"),
NOT_QUERY : new RegExp(merge("[^\\%]", UNRESERVED$$, SUB_DELIMS$$, "[\\:\\@\\/\\?]", IPRIVATE$$), "g"),
NOT_FRAGMENT : new RegExp(merge("[^\\%]", UNRESERVED$$, SUB_DELIMS$$, "[\\:\\@\\/\\?]"), "g"),
ESCAPE : new RegExp(merge("[^]", UNRESERVED$$, SUB_DELIMS$$), "g"),
UNRESERVED : new RegExp(UNRESERVED$$, "g"),
OTHER_CHARS : new RegExp(merge("[^\\%]", UNRESERVED$$, RESERVED$$), "g"),
PCT_ENCODED : new RegExp(PCT_ENCODED$, "g")
};
}
if (c < 16) e = "%0" + c.toString(16).toUpperCase();
else if (c < 128) e = "%" + c.toString(16).toUpperCase();
else if (c < 2048) e = "%" + ((c >> 6) | 192).toString(16).toUpperCase() + "%" + ((c & 63) | 128).toString(16).toUpperCase();
else e = "%" + ((c >> 12) | 224).toString(16).toUpperCase() + "%" + (((c >> 6) & 63) | 128).toString(16).toUpperCase() + "%" + ((c & 63) | 128).toString(16).toUpperCase();
const
URI_PROTOCOL = buildExps(false),
IRI_PROTOCOL = URI__IRI_SUPPORT ? buildExps(true) : undefined,
URI_PARSE = /^(?:([^:\/?#]+):)?(?:\/\/((?:([^\/?#@]*)@)?([^\/?#:]*)(?:\:(\d*))?))?([^?#]*)(?:\?([^#]*))?(?:#((?:.|\n)*))?/i,
RDS1 = /^\.\.?\//,
RDS2 = /^\/\.(\/|$)/,
RDS3 = /^\/\.\.(\/|$)/,
RDS4 = /^\.\.?$/,
RDS5 = /^\/?(?:.|\n)*?(?=\/|$)/,
NO_MATCH_IS_UNDEFINED = ("").match(/(){0}/)[1] === undefined
;
return e;
}
function pctEncChar(chr:string):string {
let c = chr.charCodeAt(0), e:string;
if (c < 16) e = "%0" + c.toString(16).toUpperCase();
else if (c < 128) e = "%" + c.toString(16).toUpperCase();
else if (c < 2048) e = "%" + ((c >> 6) | 192).toString(16).toUpperCase() + "%" + ((c & 63) | 128).toString(16).toUpperCase();
else e = "%" + ((c >> 12) | 224).toString(16).toUpperCase() + "%" + (((c >> 6) & 63) | 128).toString(16).toUpperCase() + "%" + ((c & 63) | 128).toString(16).toUpperCase();
return e;
}
export function pctDecChars(str:string):string {
let newStr = "";
let i = 0;
const il = str.length;
function pctDecChars(str:string):string {
var
newStr = "",
i = 0,
il = str.length,
c:number,
c2:number,
c3:number
;
while (i < il) {
c = parseInt(str.substr(i + 1, 2), 16);
if (c < 128) {
newStr += String.fromCharCode(c);
i += 3;
while (i < il) {
const c = parseInt(str.substr(i + 1, 2), 16);
if (c < 128) {
newStr += String.fromCharCode(c);
i += 3;
}
else if (c >= 194 && c < 224) {
if ((il - i) >= 6) {
const c2 = parseInt(str.substr(i + 4, 2), 16);
newStr += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
} else {
newStr += str.substr(i, 6);
}
else if (c >= 194 && c < 224) {
if ((il - i) >= 6) {
c2 = parseInt(str.substr(i + 4, 2), 16);
newStr += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
} else {
newStr += str.substr(i, 6);
}
i += 6;
i += 6;
}
else if (c >= 224) {
if ((il - i) >= 9) {
const c2 = parseInt(str.substr(i + 4, 2), 16);
const c3 = parseInt(str.substr(i + 7, 2), 16);
newStr += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
} else {
newStr += str.substr(i, 9);
}
else if (c >= 224) {
if ((il - i) >= 9) {
c2 = parseInt(str.substr(i + 4, 2), 16);
c3 = parseInt(str.substr(i + 7, 2), 16);
newStr += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
} else {
newStr += str.substr(i, 9);
}
i += 9;
}
else {
newStr += str.substr(i, 3);
i += 3;
}
i += 9;
}
return newStr;
else {
newStr += str.substr(i, 3);
i += 3;
}
}
function typeOf(o:any):string {
return o === undefined ? "undefined" : (o === null ? "null" : Object.prototype.toString.call(o).split(" ").pop().split("]").shift().toLowerCase());
}
return newStr;
}
function toUpperCase(str:string):string {
return str.toUpperCase();
function _normalizeComponentEncoding(components:URIComponents, protocol:URIRegExps) {
function decodeUnreserved(str:string):string {
const decStr = pctDecChars(str);
return (!decStr.match(protocol.UNRESERVED) ? str : decStr);
}
var SCHEMES:{[scheme:string]:URISchemeHandler} = {};
function _normalizeComponentEncoding(components:URIComponents, protocol:URIRegExps) {
function decodeUnreserved(str:string):string {
var decStr = pctDecChars(str);
return (!decStr.match(protocol.UNRESERVED) ? str : decStr);
}
if (components.scheme) components.scheme = String(components.scheme).replace(protocol.PCT_ENCODED, decodeUnreserved).toLowerCase().replace(protocol.NOT_SCHEME, "");
if (components.userinfo !== undefined) components.userinfo = String(components.userinfo).replace(protocol.PCT_ENCODED, decodeUnreserved).replace(protocol.NOT_USERINFO, pctEncChar).replace(protocol.PCT_ENCODED, toUpperCase);
if (components.host !== undefined) components.host = String(components.host).replace(protocol.PCT_ENCODED, decodeUnreserved).toLowerCase().replace(protocol.NOT_HOST, pctEncChar).replace(protocol.PCT_ENCODED, toUpperCase);
if (components.path !== undefined) components.path = String(components.path).replace(protocol.PCT_ENCODED, decodeUnreserved).replace((components.scheme ? protocol.NOT_PATH : protocol.NOT_PATH_NOSCHEME), pctEncChar).replace(protocol.PCT_ENCODED, toUpperCase);
if (components.query !== undefined) components.query = String(components.query).replace(protocol.PCT_ENCODED, decodeUnreserved).replace(protocol.NOT_QUERY, pctEncChar).replace(protocol.PCT_ENCODED, toUpperCase);
if (components.fragment !== undefined) components.fragment = String(components.fragment).replace(protocol.PCT_ENCODED, decodeUnreserved).replace(protocol.NOT_FRAGMENT, pctEncChar).replace(protocol.PCT_ENCODED, toUpperCase);
return components;
};
function parse(uriString:string, options:URIOptions = {}):URIComponents {
var
protocol = (URI__IRI_SUPPORT && options.iri !== false ? IRI_PROTOCOL : URI_PROTOCOL),
matches:RegExpMatchArray,
parseError = false,
components:URIComponents = {},
schemeHandler:URISchemeHandler
;
if (options.reference === "suffix") uriString = (options.scheme ? options.scheme + ":" : "") + "//" + uriString;
if (URI__VALIDATE_SUPPORT) {
matches = uriString.match(protocol.URI_REF);
if (components.scheme) components.scheme = String(components.scheme).replace(protocol.PCT_ENCODED, decodeUnreserved).toLowerCase().replace(protocol.NOT_SCHEME, "");
if (components.userinfo !== undefined) components.userinfo = String(components.userinfo).replace(protocol.PCT_ENCODED, decodeUnreserved).replace(protocol.NOT_USERINFO, pctEncChar).replace(protocol.PCT_ENCODED, toUpperCase);
if (components.host !== undefined) components.host = String(components.host).replace(protocol.PCT_ENCODED, decodeUnreserved).toLowerCase().replace(protocol.NOT_HOST, pctEncChar).replace(protocol.PCT_ENCODED, toUpperCase);
if (components.path !== undefined) components.path = String(components.path).replace(protocol.PCT_ENCODED, decodeUnreserved).replace((components.scheme ? protocol.NOT_PATH : protocol.NOT_PATH_NOSCHEME), pctEncChar).replace(protocol.PCT_ENCODED, toUpperCase);
if (components.query !== undefined) components.query = String(components.query).replace(protocol.PCT_ENCODED, decodeUnreserved).replace(protocol.NOT_QUERY, pctEncChar).replace(protocol.PCT_ENCODED, toUpperCase);
if (components.fragment !== undefined) components.fragment = String(components.fragment).replace(protocol.PCT_ENCODED, decodeUnreserved).replace(protocol.NOT_FRAGMENT, pctEncChar).replace(protocol.PCT_ENCODED, toUpperCase);
if (matches) {
if (matches[1]) {
//generic URI
matches = matches.slice(1, 10);
} else {
//relative URI
matches = matches.slice(10, 19);
}
return components;
};
const URI_PARSE = /^(?:([^:\/?#]+):)?(?:\/\/((?:([^\/?#@]*)@)?(\[[\dA-F:.]+\]|[^\/?#:]*)(?:\:(\d*))?))?([^?#]*)(?:\?([^#]*))?(?:#((?:.|\n)*))?/i;
const NO_MATCH_IS_UNDEFINED = (<RegExpMatchArray>("").match(/(){0}/))[1] === undefined;
export function parse(uriString:string, options:URIOptions = {}):URIComponents {
const components:URIComponents = {};
const protocol = (options.iri !== false ? IRI_PROTOCOL : URI_PROTOCOL);
if (options.reference === "suffix") uriString = (options.scheme ? options.scheme + ":" : "") + "//" + uriString;
const matches = uriString.match(URI_PARSE);
if (matches) {
if (NO_MATCH_IS_UNDEFINED) {
//store each component
components.scheme = matches[1];
components.userinfo = matches[3];
components.host = matches[4];
components.port = parseInt(matches[5], 10);
components.path = matches[6] || "";
components.query = matches[7];
components.fragment = matches[8];
//fix port number
if (isNaN(components.port)) {
components.port = matches[5];
}
} else { //IE FIX for improper RegExp matching
//store each component
components.scheme = matches[1] || undefined;
components.userinfo = (uriString.indexOf("@") !== -1 ? matches[3] : undefined);
components.host = (uriString.indexOf("//") !== -1 ? matches[4] : undefined);
components.port = parseInt(matches[5], 10);
components.path = matches[6] || "";
components.query = (uriString.indexOf("?") !== -1 ? matches[7] : undefined);
components.fragment = (uriString.indexOf("#") !== -1 ? matches[8] : undefined);
if (!matches) {
parseError = true;
if (!options.tolerant) components.error = components.error || "URI is not strictly valid.";
matches = uriString.match(URI_PARSE);
//fix port number
if (isNaN(components.port)) {
components.port = (uriString.match(/\/\/(?:.|\n)*\:(?:\/|\?|\#|$)/) ? matches[4] : undefined);
}
}
//strip brackets from IPv6 hosts
if (components.host) {
components.host = components.host.replace(protocol.IPV6ADDRESS, "$1");
}
//determine reference type
if (components.scheme === undefined && components.userinfo === undefined && components.host === undefined && components.port === undefined && !components.path && components.query === undefined) {
components.reference = "same-document";
} else if (components.scheme === undefined) {
components.reference = "relative";
} else if (components.fragment === undefined) {
components.reference = "absolute";
} else {
matches = uriString.match(URI_PARSE);
components.reference = "uri";
}
if (matches) {
if (NO_MATCH_IS_UNDEFINED) {
//store each component
components.scheme = matches[1];
//components.authority = matches[2];
components.userinfo = matches[3];
components.host = matches[4];
components.port = parseInt(matches[5], 10);
components.path = matches[6] || "";
components.query = matches[7];
components.fragment = matches[8];
//fix port number
if (isNaN(<number>components.port)) {
components.port = matches[5];
//check for reference errors
if (options.reference && options.reference !== "suffix" && options.reference !== components.reference) {
components.error = components.error || "URI is not a " + options.reference + " reference.";
}
//find scheme handler
const schemeHandler = SCHEMES[(options.scheme || components.scheme || "").toLowerCase()];
//check if scheme can't handle IRIs
if (!options.unicodeSupport && (!schemeHandler || !schemeHandler.unicodeSupport)) {
//if host component is a domain name
if (components.host && (options.domainHost || (schemeHandler && schemeHandler.domainHost))) {
//convert Unicode IDN -> ASCII IDN
try {
components.host = punycode.toASCII(components.host.replace(protocol.PCT_ENCODED, pctDecChars).toLowerCase());
} catch (e) {
components.error = components.error || "Host's domain name can not be converted to ASCII via punycode: " + e;
}
} else { //IE FIX for improper RegExp matching
//store each component
components.scheme = matches[1] || undefined;
//components.authority = (uriString.indexOf("//") !== -1 ? matches[2] : undefined);
components.userinfo = (uriString.indexOf("@") !== -1 ? matches[3] : undefined);
components.host = (uriString.indexOf("//") !== -1 ? matches[4] : undefined);
components.port = parseInt(matches[5], 10);
components.path = matches[6] || "";
components.query = (uriString.indexOf("?") !== -1 ? matches[7] : undefined);
components.fragment = (uriString.indexOf("#") !== -1 ? matches[8] : undefined);
//fix port number
if (isNaN(<number>components.port)) {
components.port = (uriString.match(/\/\/(?:.|\n)*\:(?:\/|\?|\#|$)/) ? matches[4] : undefined);
}
}
//determine reference type
if (components.scheme === undefined && components.userinfo === undefined && components.host === undefined && components.port === undefined && !components.path && components.query === undefined) {
components.reference = "same-document";
} else if (components.scheme === undefined) {
components.reference = "relative";
} else if (components.fragment === undefined) {
components.reference = "absolute";
} else {
components.reference = "uri";
}
//check for reference errors
if (options.reference && options.reference !== "suffix" && options.reference !== components.reference) {
components.error = components.error || "URI is not a " + options.reference + " reference.";
}
//find scheme handler
schemeHandler = SCHEMES[(options.scheme || components.scheme || "").toLowerCase()];
//check if scheme can't handle IRIs
if (URI__IRI_SUPPORT && typeof punycode !== "undefined" && !options.unicodeSupport && (!schemeHandler || !schemeHandler.unicodeSupport)) {
//if host component is a domain name
if (components.host && (options.domainHost || (schemeHandler && schemeHandler.domainHost))) {
//convert Unicode IDN -> ASCII IDN
try {
components.host = punycode.toASCII(components.host.replace(protocol.PCT_ENCODED, pctDecChars).toLowerCase());
} catch (e) {
components.error = components.error || "Host's domain name can not be converted to ASCII via punycode: " + e;
}
}
//convert IRI -> URI
_normalizeComponentEncoding(components, URI_PROTOCOL);
} else {
//normalize encodings
_normalizeComponentEncoding(components, protocol);
}
//perform scheme specific parsing
if (schemeHandler && schemeHandler.parse) {
schemeHandler.parse(components, options);
}
//convert IRI -> URI
_normalizeComponentEncoding(components, URI_PROTOCOL);
} else {
parseError = true;
components.error = components.error || "URI can not be parsed.";
//normalize encodings
_normalizeComponentEncoding(components, protocol);
}
return components;
};
function _recomposeAuthority(components:URIComponents, options:URIOptions):string {
var uriTokens:Array<string> = [];
if (components.userinfo !== undefined) {
uriTokens.push(components.userinfo);
uriTokens.push("@");
//perform scheme specific parsing
if (schemeHandler && schemeHandler.parse) {
schemeHandler.parse(components, options);
}
if (components.host !== undefined) {
uriTokens.push(components.host);
}
if (typeof components.port === "number") {
uriTokens.push(":");
uriTokens.push((<number>components.port).toString(10));
}
return uriTokens.length ? uriTokens.join("") : undefined;
};
function removeDotSegments(input:string):string {
var output:Array<string> = [], s:string;
while (input.length) {
if (input.match(RDS1)) {
input = input.replace(RDS1, "");
} else if (input.match(RDS2)) {
input = input.replace(RDS2, "/");
} else if (input.match(RDS3)) {
input = input.replace(RDS3, "/");
output.pop();
} else if (input === "." || input === "..") {
input = "";
} else {
s = input.match(RDS5)[0];
} else {
components.error = components.error || "URI can not be parsed.";
}
return components;
};
function _recomposeAuthority(components:URIComponents, options:URIOptions):string|undefined {
const protocol = (options.iri !== false ? IRI_PROTOCOL : URI_PROTOCOL);
const uriTokens:Array<string> = [];
if (components.userinfo !== undefined) {
uriTokens.push(components.userinfo);
uriTokens.push("@");
}
if (components.host !== undefined) {
//ensure IPv6 addresses are bracketed
uriTokens.push(String(components.host).replace(protocol.IPV6ADDRESS, "[$1]"));
}
if (typeof components.port === "number") {
uriTokens.push(":");
uriTokens.push(components.port.toString(10));
}
return uriTokens.length ? uriTokens.join("") : undefined;
};
const RDS1 = /^\.\.?\//;
const RDS2 = /^\/\.(\/|$)/;
const RDS3 = /^\/\.\.(\/|$)/;
const RDS4 = /^\.\.?$/;
const RDS5 = /^\/?(?:.|\n)*?(?=\/|$)/;
export function removeDotSegments(input:string):string {
const output:Array<string> = [];
while (input.length) {
if (input.match(RDS1)) {
input = input.replace(RDS1, "");
} else if (input.match(RDS2)) {
input = input.replace(RDS2, "/");
} else if (input.match(RDS3)) {
input = input.replace(RDS3, "/");
output.pop();
} else if (input === "." || input === "..") {
input = "";
} else {
const im = input.match(RDS5);
if (im) {
const s = im[0];
input = input.slice(s.length);
output.push(s);
} else {
throw new Error("Unexpected dot segment condition");
}
}
return output.join("");
};
function serialize(components:URIComponents, options:URIOptions = {}):string {
var protocol = (URI__IRI_SUPPORT && options.iri ? IRI_PROTOCOL : URI_PROTOCOL),
uriTokens:Array<string> = [],
schemeHandler:URISchemeHandler,
authority:string,
s:string
;
//find scheme handler
schemeHandler = SCHEMES[(options.scheme || components.scheme || "").toLowerCase()];
//perform scheme specific serialization
if (schemeHandler && schemeHandler.serialize) schemeHandler.serialize(components, options);
}
return output.join("");
};
export function serialize(components:URIComponents, options:URIOptions = {}):string {
const protocol = (options.iri ? IRI_PROTOCOL : URI_PROTOCOL);
const uriTokens:Array<string> = [];
//find scheme handler
const schemeHandler = SCHEMES[(options.scheme || components.scheme || "").toLowerCase()];
//perform scheme specific serialization
if (schemeHandler && schemeHandler.serialize) schemeHandler.serialize(components, options);
if (components.host) {
//if host component is an IPv6 address
if (protocol.IPV6ADDRESS.test(components.host)) {
//TODO: normalize IPv6 address as per RFC 5952
}
//if host component is a domain name
if (URI__IRI_SUPPORT && typeof punycode !== "undefined" && components.host && (options.domainHost || (schemeHandler && schemeHandler.domainHost))) {
else if (options.domainHost || (schemeHandler && schemeHandler.domainHost)) {
//convert IDN via punycode

@@ -477,62 +341,71 @@ try {

}
//normalize encoding
_normalizeComponentEncoding(components, protocol);
if (options.reference !== "suffix" && components.scheme) {
uriTokens.push(components.scheme);
uriTokens.push(":");
}
//normalize encoding
_normalizeComponentEncoding(components, protocol);
if (options.reference !== "suffix" && components.scheme) {
uriTokens.push(components.scheme);
uriTokens.push(":");
}
const authority = _recomposeAuthority(components, options);
if (authority !== undefined) {
if (options.reference !== "suffix") {
uriTokens.push("//");
}
authority = _recomposeAuthority(components, options);
if (authority !== undefined) {
if (options.reference !== "suffix") {
uriTokens.push("//");
}
uriTokens.push(authority);
if (components.path && components.path.charAt(0) !== "/") {
uriTokens.push("/");
}
uriTokens.push(authority);
if (components.path && components.path.charAt(0) !== "/") {
uriTokens.push("/");
}
if (components.path !== undefined) {
s = components.path;
if (!options.absolutePath && (!schemeHandler || !schemeHandler.absolutePath)) {
s = removeDotSegments(s);
}
if (authority === undefined) {
s = s.replace(/^\/\//, "/%2F"); //don't allow the path to start with "//"
}
uriTokens.push(s);
}
if (components.path !== undefined) {
let s = components.path;
if (!options.absolutePath && (!schemeHandler || !schemeHandler.absolutePath)) {
s = removeDotSegments(s);
}
if (components.query !== undefined) {
uriTokens.push("?");
uriTokens.push(components.query);
if (authority === undefined) {
s = s.replace(/^\/\//, "/%2F"); //don't allow the path to start with "//"
}
if (components.fragment !== undefined) {
uriTokens.push("#");
uriTokens.push(components.fragment);
}
return uriTokens.join(''); //merge tokens into a string
};
function resolveComponents(base:URIComponents, relative:URIComponents, options:URIOptions = {}, skipNormalization?:boolean):URIComponents {
var target:URIComponents = {};
if (!skipNormalization) {
base = parse(serialize(base, options), options); //normalize base components
relative = parse(serialize(relative, options), options); //normalize relative components
}
options = options || {};
if (!options.tolerant && relative.scheme) {
target.scheme = relative.scheme;
uriTokens.push(s);
}
if (components.query !== undefined) {
uriTokens.push("?");
uriTokens.push(components.query);
}
if (components.fragment !== undefined) {
uriTokens.push("#");
uriTokens.push(components.fragment);
}
return uriTokens.join(""); //merge tokens into a string
};
export function resolveComponents(base:URIComponents, relative:URIComponents, options:URIOptions = {}, skipNormalization?:boolean):URIComponents {
const target:URIComponents = {};
if (!skipNormalization) {
base = parse(serialize(base, options), options); //normalize base components
relative = parse(serialize(relative, options), options); //normalize relative components
}
options = options || {};
if (!options.tolerant && relative.scheme) {
target.scheme = relative.scheme;
//target.authority = relative.authority;
target.userinfo = relative.userinfo;
target.host = relative.host;
target.port = relative.port;
target.path = removeDotSegments(relative.path || "");
target.query = relative.query;
} else {
if (relative.userinfo !== undefined || relative.host !== undefined || relative.port !== undefined) {
//target.authority = relative.authority;

@@ -542,113 +415,80 @@ target.userinfo = relative.userinfo;

target.port = relative.port;
target.path = removeDotSegments(relative.path);
target.path = removeDotSegments(relative.path || "");
target.query = relative.query;
} else {
if (relative.userinfo !== undefined || relative.host !== undefined || relative.port !== undefined) {
//target.authority = relative.authority;
target.userinfo = relative.userinfo;
target.host = relative.host;
target.port = relative.port;
target.path = removeDotSegments(relative.path);
target.query = relative.query;
if (!relative.path) {
target.path = base.path;
if (relative.query !== undefined) {
target.query = relative.query;
} else {
target.query = base.query;
}
} else {
if (!relative.path) {
target.path = base.path;
if (relative.query !== undefined) {
target.query = relative.query;
} else {
target.query = base.query;
}
if (relative.path.charAt(0) === "/") {
target.path = removeDotSegments(relative.path);
} else {
if (relative.path.charAt(0) === "/") {
target.path = removeDotSegments(relative.path);
if ((base.userinfo !== undefined || base.host !== undefined || base.port !== undefined) && !base.path) {
target.path = "/" + relative.path;
} else if (!base.path) {
target.path = relative.path;
} else {
if ((base.userinfo !== undefined || base.host !== undefined || base.port !== undefined) && !base.path) {
target.path = "/" + relative.path;
} else if (!base.path) {
target.path = relative.path;
} else {
target.path = base.path.slice(0, base.path.lastIndexOf("/") + 1) + relative.path;
}
target.path = removeDotSegments(target.path);
target.path = base.path.slice(0, base.path.lastIndexOf("/") + 1) + relative.path;
}
target.query = relative.query;
target.path = removeDotSegments(target.path);
}
//target.authority = base.authority;
target.userinfo = base.userinfo;
target.host = base.host;
target.port = base.port;
target.query = relative.query;
}
target.scheme = base.scheme;
//target.authority = base.authority;
target.userinfo = base.userinfo;
target.host = base.host;
target.port = base.port;
}
target.fragment = relative.fragment;
return target;
};
function resolve(baseURI:string, relativeURI:string, options?:URIOptions):string {
return serialize(resolveComponents(parse(baseURI, options), parse(relativeURI, options), options, true), options);
};
function normalize(uri:string, options?:URIOptions):string;
function normalize(uri:URIComponents, options?:URIOptions):URIComponents;
function normalize(uri:any, options?:URIOptions):any {
if (typeof uri === "string") {
uri = serialize(parse(<string>uri, options), options);
} else if (typeOf(uri) === "object") {
uri = parse(serialize(<URIComponents>uri, options), options);
}
return uri;
};
function equal(uriA:string, uriB:string, options?: URIOptions):boolean;
function equal(uriA:URIComponents, uriB:URIComponents, options?:URIOptions):boolean;
function equal(uriA:any, uriB:any, options?:URIOptions):boolean {
if (typeof uriA === "string") {
uriA = serialize(parse(uriA, options), options);
} else if (typeOf(uriA) === "object") {
uriA = serialize(uriA, options);
}
if (typeof uriB === "string") {
uriB = serialize(parse(uriB, options), options);
} else if (typeOf(uriB) === "object") {
uriB = serialize(uriB, options);
}
return uriA === uriB;
};
function escapeComponent(str:string, options?:URIOptions):string {
return str && str.toString().replace((!URI__IRI_SUPPORT || !options || !options.iri ? URI_PROTOCOL.ESCAPE : IRI_PROTOCOL.ESCAPE), pctEncChar);
};
function unescapeComponent(str:string, options?:URIOptions):string {
return str && str.toString().replace((!URI__IRI_SUPPORT || !options || !options.iri ? URI_PROTOCOL.PCT_ENCODED : IRI_PROTOCOL.PCT_ENCODED), pctDecChars);
};
target.scheme = base.scheme;
}
return {
IRI_SUPPORT: URI__IRI_SUPPORT,
VALIDATE_SUPPORT: URI__VALIDATE_SUPPORT,
pctEncChar,
pctDecChars,
SCHEMES,
parse,
_recomposeAuthority,
removeDotSegments,
serialize,
resolveComponents,
resolve,
normalize,
equal,
escapeComponent,
unescapeComponent
};
})();
target.fragment = relative.fragment;
if (!COMPILED && typeof module !== "undefined" && typeof require === "function") {
var punycode = <typeof punycode>require("./punycode");
module.exports = URI;
require("./schemes");
}
return target;
};
export function resolve(baseURI:string, relativeURI:string, options?:URIOptions):string {
return serialize(resolveComponents(parse(baseURI, options), parse(relativeURI, options), options, true), options);
};
export function normalize(uri:string, options?:URIOptions):string;
export function normalize(uri:URIComponents, options?:URIOptions):URIComponents;
export function normalize(uri:any, options?:URIOptions):any {
if (typeof uri === "string") {
uri = serialize(parse(uri, options), options);
} else if (typeOf(uri) === "object") {
uri = parse(serialize(<URIComponents>uri, options), options);
}
return uri;
};
export function equal(uriA:string, uriB:string, options?: URIOptions):boolean;
export function equal(uriA:URIComponents, uriB:URIComponents, options?:URIOptions):boolean;
export function equal(uriA:any, uriB:any, options?:URIOptions):boolean {
if (typeof uriA === "string") {
uriA = serialize(parse(uriA, options), options);
} else if (typeOf(uriA) === "object") {
uriA = serialize(<URIComponents>uriA, options);
}
if (typeof uriB === "string") {
uriB = serialize(parse(uriB, options), options);
} else if (typeOf(uriB) === "object") {
uriB = serialize(<URIComponents>uriB, options);
}
return uriA === uriB;
};
export function escapeComponent(str:string, options?:URIOptions):string {
return str && str.toString().replace((!options || !options.iri ? URI_PROTOCOL.ESCAPE : IRI_PROTOCOL.ESCAPE), pctEncChar);
};
export function unescapeComponent(str:string, options?:URIOptions):string {
return str && str.toString().replace((!options || !options.iri ? URI_PROTOCOL.PCT_ENCODED : IRI_PROTOCOL.PCT_ENCODED), pctDecChars);
};

@@ -6,3 +6,3 @@ /*

*
* Copyright (c) 2009 John Resig, J�rn Zaefferer
* Copyright (c) 2009 John Resig, Jörn Zaefferer
* Dual licensed under the MIT (MIT-LICENSE.txt)

@@ -678,3 +678,3 @@ * and GPL (GPL-LICENSE.txt) licenses.

// Test suites: http://philrathe.com/tests/equiv
// Author: Philippe Rath� <prathe@gmail.com>
// Author: Philippe Rathé <prathe@gmail.com>
QUnit.equiv = function () {

@@ -1044,2 +1044,2 @@

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

@@ -8,3 +8,3 @@ //

if (typeof URI === "undefined") {
var URI = require("../build/uri");
var URI = require("../dist/es5/uri.all");
}

@@ -19,3 +19,3 @@

var components;
//scheme

@@ -32,3 +32,3 @@ components = URI.parse("uri:");

strictEqual(components.fragment, undefined, "fragment");
//userinfo

@@ -45,3 +45,3 @@ components = URI.parse("//@");

strictEqual(components.fragment, undefined, "fragment");
//host

@@ -58,3 +58,3 @@ components = URI.parse("//");

strictEqual(components.fragment, undefined, "fragment");
//port

@@ -71,3 +71,3 @@ components = URI.parse("//:");

strictEqual(components.fragment, undefined, "fragment");
//path

@@ -84,3 +84,3 @@ components = URI.parse("");

strictEqual(components.fragment, undefined, "fragment");
//query

@@ -97,3 +97,3 @@ components = URI.parse("?");

strictEqual(components.fragment, undefined, "fragment");
//fragment

@@ -110,3 +110,3 @@ components = URI.parse("#");

strictEqual(components.fragment, "", "fragment");
//all

@@ -123,5 +123,5 @@ components = URI.parse("uri://user:pass@example.com:123/one/two.three?q1=a1&q2=a2#body");

strictEqual(components.fragment, "body", "fragment");
//IPv4address
components = URI.parse("//10.10.10.10/test");
components = URI.parse("//10.10.10.10");
strictEqual(components.error, undefined, "IPv4address errors");

@@ -132,6 +132,28 @@ strictEqual(components.scheme, undefined, "scheme");

strictEqual(components.port, undefined, "port");
strictEqual(components.path, "/test", "path");
strictEqual(components.path, "", "path");
strictEqual(components.query, undefined, "query");
strictEqual(components.fragment, undefined, "fragment");
//IPv6address
components = URI.parse("//[2001:db8::7]");
strictEqual(components.error, undefined, "IPv4address errors");
strictEqual(components.scheme, undefined, "scheme");
strictEqual(components.userinfo, undefined, "userinfo");
strictEqual(components.host, "2001:db8::7", "host");
strictEqual(components.port, undefined, "port");
strictEqual(components.path, "", "path");
strictEqual(components.query, undefined, "query");
strictEqual(components.fragment, undefined, "fragment");
//mixed IPv4address & IPv6address
components = URI.parse("//[::ffff:129.144.52.38]");
strictEqual(components.error, undefined, "IPv4address errors");
strictEqual(components.scheme, undefined, "scheme");
strictEqual(components.userinfo, undefined, "userinfo");
strictEqual(components.host, "::ffff:129.144.52.38", "host");
strictEqual(components.port, undefined, "port");
strictEqual(components.path, "", "path");
strictEqual(components.query, undefined, "query");
strictEqual(components.fragment, undefined, "fragment");
//mixed IPv4address & reg-name, example from terion-name (https://github.com/garycourt/uri-js/issues/4)

@@ -147,2 +169,13 @@ components = URI.parse("uri://10.10.10.10.example.com/en/process");

strictEqual(components.fragment, undefined, "fragment");
//IPv6address, example from bkw (https://github.com/garycourt/uri-js/pull/16)
components = URI.parse("//[2606:2800:220:1:248:1893:25c8:1946]/test");
strictEqual(components.error, undefined, "IPv6address errors");
strictEqual(components.scheme, undefined, "scheme");
strictEqual(components.userinfo, undefined, "userinfo");
strictEqual(components.host, "2606:2800:220:1:248:1893:25c8:1946", "host");
strictEqual(components.port, undefined, "port");
strictEqual(components.path, "/test", "path");
strictEqual(components.query, undefined, "query");
strictEqual(components.fragment, undefined, "fragment");
});

@@ -161,3 +194,3 @@

strictEqual(URI.serialize(components), "", "Undefined Components");
components = {

@@ -173,3 +206,3 @@ scheme : "",

strictEqual(URI.serialize(components), "//@:0?#", "Empty Components");
components = {

@@ -185,3 +218,3 @@ scheme : "uri",

strictEqual(URI.serialize(components), "uri://foo:bar@example.com:1/path?query#fragment", "All Components");
strictEqual(URI.serialize({path:"//path"}), "/%2Fpath", "Double slash path");

@@ -219,7 +252,7 @@ strictEqual(URI.serialize({path:"foo:bar"}), "foo%3Abar", "Colon path");

strictEqual(URI.resolve(base, "../../g"), "uri://a/g", "../../g");
//abnormal examples from RFC 3986
strictEqual(URI.resolve(base, "../../../g"), "uri://a/g", "../../../g");
strictEqual(URI.resolve(base, "../../../../g"), "uri://a/g", "../../../../g");
strictEqual(URI.resolve(base, "/./g"), "uri://a/g", "/./g");

@@ -231,3 +264,3 @@ strictEqual(URI.resolve(base, "/../g"), "uri://a/g", "/../g");

strictEqual(URI.resolve(base, "..g"), "uri://a/b/c/..g", "..g");
strictEqual(URI.resolve(base, "./../g"), "uri://a/b/g", "./../g");

@@ -239,3 +272,3 @@ strictEqual(URI.resolve(base, "./g/."), "uri://a/b/c/g/", "./g/.");

strictEqual(URI.resolve(base, "g;x=1/../y"), "uri://a/b/c/y", "g;x=1/../y");
strictEqual(URI.resolve(base, "g?y/./x"), "uri://a/b/c/g?y/./x", "g?y/./x");

@@ -245,6 +278,6 @@ strictEqual(URI.resolve(base, "g?y/../x"), "uri://a/b/c/g?y/../x", "g?y/../x");

strictEqual(URI.resolve(base, "g#s/../x"), "uri://a/b/c/g#s/../x", "g#s/../x");
strictEqual(URI.resolve(base, "uri:g"), "uri:g", "uri:g");
strictEqual(URI.resolve(base, "uri:g", {tolerant:true}), "uri://a/b/c/g", "uri:g");
//examples by PAEz

@@ -258,2 +291,5 @@ strictEqual(URI.resolve("//www.g.com/","/adf\ngf"), "//www.g.com/adf%0Agf", "/adf\\ngf");

strictEqual(URI.normalize("uri://www.example.org/red%09ros\xE9#red"), "uri://www.example.org/red%09ros%C3%A9#red");
//IPv6address, example from RFC 3513
strictEqual(URI.normalize("http://[1080::8:800:200C:417A]/"), "http://[1080::8:800:200c:417a]/");
});

@@ -264,3 +300,3 @@

strictEqual(URI.equal("example://a/b/c/%7Bfoo%7D", "eXAMPLE://a/./b/../b/%63/%7bfoo%7d"), true);
//test from RFC 3987

@@ -302,61 +338,59 @@ strictEqual(URI.equal("http://example.org/~user", "http://example.org/%7euser"), true);

if (URI.IRI_SUPPORT) {
var IRI_OPTION = { iri : true, unicodeSupport : true };
test("IRI Parsing", function () {
var components = URI.parse("uri://us\xA0er:pa\uD7FFss@example.com:123/o\uF900ne/t\uFDCFwo.t\uFDF0hree?q1=a1\uF8FF\uE000&q2=a2#bo\uFFEFdy", IRI_OPTION);
strictEqual(components.error, undefined, "all errors");
strictEqual(components.scheme, "uri", "scheme");
//strictEqual(components.authority, "us\xA0er:pa\uD7FFss@example.com:123", "authority");
strictEqual(components.userinfo, "us\xA0er:pa\uD7FFss", "userinfo");
strictEqual(components.host, "example.com", "host");
strictEqual(components.port, 123, "port");
strictEqual(components.path, "/o\uF900ne/t\uFDCFwo.t\uFDF0hree", "path");
strictEqual(components.query, "q1=a1\uF8FF\uE000&q2=a2", "query");
strictEqual(components.fragment, "bo\uFFEFdy", "fragment");
});
var IRI_OPTION = { iri : true, unicodeSupport : true };
test("IRI Serialization", function () {
var components = {
scheme : "uri",
userinfo : "us\xA0er:pa\uD7FFss",
host : "example.com",
port : 123,
path : "/o\uF900ne/t\uFDCFwo.t\uFDF0hree",
query : "q1=a1\uF8FF\uE000&q2=a2",
fragment : "bo\uFFEFdy\uE001"
};
strictEqual(URI.serialize(components, IRI_OPTION), "uri://us\xA0er:pa\uD7FFss@example.com:123/o\uF900ne/t\uFDCFwo.t\uFDF0hree?q1=a1\uF8FF\uE000&q2=a2#bo\uFFEFdy%EE%80%81");
});
test("IRI Parsing", function () {
var components = URI.parse("uri://us\xA0er:pa\uD7FFss@example.com:123/o\uF900ne/t\uFDCFwo.t\uFDF0hree?q1=a1\uF8FF\uE000&q2=a2#bo\uFFEFdy", IRI_OPTION);
strictEqual(components.error, undefined, "all errors");
strictEqual(components.scheme, "uri", "scheme");
//strictEqual(components.authority, "us\xA0er:pa\uD7FFss@example.com:123", "authority");
strictEqual(components.userinfo, "us\xA0er:pa\uD7FFss", "userinfo");
strictEqual(components.host, "example.com", "host");
strictEqual(components.port, 123, "port");
strictEqual(components.path, "/o\uF900ne/t\uFDCFwo.t\uFDF0hree", "path");
strictEqual(components.query, "q1=a1\uF8FF\uE000&q2=a2", "query");
strictEqual(components.fragment, "bo\uFFEFdy", "fragment");
});
test("IRI Normalizing", function () {
strictEqual(URI.normalize("uri://www.example.org/red%09ros\xE9#red", IRI_OPTION), "uri://www.example.org/red%09ros\xE9#red");
});
test("IRI Serialization", function () {
var components = {
scheme : "uri",
userinfo : "us\xA0er:pa\uD7FFss",
host : "example.com",
port : 123,
path : "/o\uF900ne/t\uFDCFwo.t\uFDF0hree",
query : "q1=a1\uF8FF\uE000&q2=a2",
fragment : "bo\uFFEFdy\uE001"
};
strictEqual(URI.serialize(components, IRI_OPTION), "uri://us\xA0er:pa\uD7FFss@example.com:123/o\uF900ne/t\uFDCFwo.t\uFDF0hree?q1=a1\uF8FF\uE000&q2=a2#bo\uFFEFdy%EE%80%81");
});
test("IRI Equals", function () {
//example from RFC 3987
strictEqual(URI.equal("example://a/b/c/%7Bfoo%7D/ros\xE9", "eXAMPLE://a/./b/../b/%63/%7bfoo%7d/ros%C3%A9", IRI_OPTION), true);
});
test("IRI Normalizing", function () {
strictEqual(URI.normalize("uri://www.example.org/red%09ros\xE9#red", IRI_OPTION), "uri://www.example.org/red%09ros\xE9#red");
});
test("Convert IRI to URI", function () {
//example from RFC 3987
strictEqual(URI.serialize(URI.parse("uri://www.example.org/red%09ros\xE9#red", IRI_OPTION)), "uri://www.example.org/red%09ros%C3%A9#red");
//Internationalized Domain Name conversion via punycode example from RFC 3987
strictEqual(URI.serialize(URI.parse("uri://r\xE9sum\xE9.example.org", {iri:true, domainHost:true}), {domainHost:true}), "uri://xn--rsum-bpad.example.org");
});
test("IRI Equals", function () {
//example from RFC 3987
strictEqual(URI.equal("example://a/b/c/%7Bfoo%7D/ros\xE9", "eXAMPLE://a/./b/../b/%63/%7bfoo%7d/ros%C3%A9", IRI_OPTION), true);
});
test("Convert URI to IRI", function () {
//examples from RFC 3987
strictEqual(URI.serialize(URI.parse("uri://www.example.org/D%C3%BCrst"), IRI_OPTION), "uri://www.example.org/D\xFCrst");
strictEqual(URI.serialize(URI.parse("uri://www.example.org/D%FCrst"), IRI_OPTION), "uri://www.example.org/D%FCrst");
strictEqual(URI.serialize(URI.parse("uri://xn--99zt52a.example.org/%e2%80%ae"), IRI_OPTION), "uri://xn--99zt52a.example.org/%E2%80%AE"); //or uri://\u7D0D\u8C46.example.org/%E2%80%AE
//Internationalized Domain Name conversion via punycode example from RFC 3987
strictEqual(URI.serialize(URI.parse("uri://xn--rsum-bpad.example.org", {domainHost:true}), {iri:true, domainHost:true}), "uri://r\xE9sum\xE9.example.org");
});
test("Convert IRI to URI", function () {
//example from RFC 3987
strictEqual(URI.serialize(URI.parse("uri://www.example.org/red%09ros\xE9#red", IRI_OPTION)), "uri://www.example.org/red%09ros%C3%A9#red");
}
//Internationalized Domain Name conversion via punycode example from RFC 3987
strictEqual(URI.serialize(URI.parse("uri://r\xE9sum\xE9.example.org", {iri:true, domainHost:true}), {domainHost:true}), "uri://xn--rsum-bpad.example.org");
});
test("Convert URI to IRI", function () {
//examples from RFC 3987
strictEqual(URI.serialize(URI.parse("uri://www.example.org/D%C3%BCrst"), IRI_OPTION), "uri://www.example.org/D\xFCrst");
strictEqual(URI.serialize(URI.parse("uri://www.example.org/D%FCrst"), IRI_OPTION), "uri://www.example.org/D%FCrst");
strictEqual(URI.serialize(URI.parse("uri://xn--99zt52a.example.org/%e2%80%ae"), IRI_OPTION), "uri://xn--99zt52a.example.org/%E2%80%AE"); //or uri://\u7D0D\u8C46.example.org/%E2%80%AE
//Internationalized Domain Name conversion via punycode example from RFC 3987
strictEqual(URI.serialize(URI.parse("uri://xn--rsum-bpad.example.org", {domainHost:true}), {iri:true, domainHost:true}), "uri://r\xE9sum\xE9.example.org");
});
//

@@ -443,3 +477,3 @@ // HTTP

strictEqual(components.path, "f81d4fae-7dec-11d0-a765-00a0c91e6bf6", "path");
components = URI.parse("urn:uuid:notauuid-7dec-11d0-a765-00a0c91e6bf6");

@@ -456,3 +490,3 @@ notStrictEqual(components.error, undefined, "errors");

strictEqual(URI.serialize(components), "urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6");
components = {

@@ -497,3 +531,3 @@ scheme : "urn:uuid",

strictEqual(components.headers, undefined, "headers");
components = URI.parse("mailto:infobot@example.com?subject=current-issue");

@@ -533,3 +567,3 @@ deepEqual(components.to, ["infobot@example.com"], "to");

deepEqual(components.headers, {"blat":"foop"}, "headers");
components = URI.parse("mailto:Mike%26family@example.org");

@@ -606,2 +640,2 @@ deepEqual(components.to, ["Mike&family@example.org"], "to Mike&family@example.org");

}
}
{
"compilerOptions": {
"module": "commonjs",
"target": "ES3",
"noImplicitAny": true,
"removeComments": false,
"preserveConstEnums": true,
"rootDir": "src",
"outDir": "build",
"sourceMap": false
},
"files": [
"src/uri.ts",
"src/schemes.ts",
"src/schemes/http.ts",
"src/schemes/urn.ts",
"src/schemes/mailto.ts"
]
}
"compilerOptions": {
"module": "es2015",
"target": "esnext",
"noImplicitAny": true,
"sourceMap": true,
"alwaysStrict": true,
"declaration": true,
"experimentalDecorators": true,
"forceConsistentCasingInFileNames": true,
"importHelpers": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"outDir": "dist/esnext",
"strictNullChecks": true
},
"include": [
"src/**/*"
]
}

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc