Beta 7 with some repo names changed.
This commit is contained in:
1 parent
0f7b40cca7
commit
963c19493a
3408 files changed
+462217
-15516
No files matched your search
+1443
File diff suppressed because it is too large.
Load diff
+3
@@ -0,0 +1,3 @@
|
||||
/** @license URI.js v4.4.0 (c) 2011 Gary Court. License: http://github.com/garycourt/uri-js */
|
||||
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r(e.URI=e.URI||{})}(this,function(e){"use strict";function r(){for(var e=arguments.length,r=Array(e),n=0;n<e;n++)r[n]=arguments[n];if(r.length>1){r[0]=r[0].slice(0,-1);for(var t=r.length-1,o=1;o<t;++o)r[o]=r[o].slice(1,-1);return r[t]=r[t].slice(1),r.join("")}return r[0]}function n(e){return"(?:"+e+")"}function t(e){return e===undefined?"undefined":null===e?"null":Object.prototype.toString.call(e).split(" ").pop().split("]").shift().toLowerCase()}function o(e){return e.toUpperCase()}function a(e){return e!==undefined&&null!==e?e instanceof Array?e:"number"!=typeof e.length||e.split||e.setInterval||e.call?[e]:Array.prototype.slice.call(e):[]}function i(e,r){var n=e;if(r)for(var t in r)n[t]=r[t];return n}function u(e){var t=r("[0-9]","[A-Fa-f]"),o=n(n("%[EFef]"+t+"%"+t+t+"%"+t+t)+"|"+n("%[89A-Fa-f]"+t+"%"+t+t)+"|"+n("%"+t+t)),a="[\\!\\$\\&\\'\\(\\)\\*\\+\\,\\;\\=]",i=r("[\\:\\/\\?\\#\\[\\]\\@]",a),u=e?"[\\xA0-\\u200D\\u2010-\\u2029\\u202F-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF]":"[]",s=e?"[\\uE000-\\uF8FF]":"[]",f=r("[A-Za-z]","[0-9]","[\\-\\.\\_\\~]",u),c=n(n("25[0-5]")+"|"+n("2[0-4][0-9]")+"|"+n("1[0-9][0-9]")+"|"+n("0?[1-9][0-9]")+"|0?0?[0-9]"),p=n(c+"\\."+c+"\\."+c+"\\."+c),h=n(t+"{1,4}"),d=n(n(h+"\\:"+h)+"|"+p),l=n(n(h+"\\:")+"{6}"+d),m=n("\\:\\:"+n(h+"\\:")+"{5}"+d),g=n(n(h)+"?\\:\\:"+n(h+"\\:")+"{4}"+d),v=n(n(n(h+"\\:")+"{0,1}"+h)+"?\\:\\:"+n(h+"\\:")+"{3}"+d),E=n(n(n(h+"\\:")+"{0,2}"+h)+"?\\:\\:"+n(h+"\\:")+"{2}"+d),C=n(n(n(h+"\\:")+"{0,3}"+h)+"?\\:\\:"+h+"\\:"+d),y=n(n(n(h+"\\:")+"{0,4}"+h)+"?\\:\\:"+d),S=n(n(n(h+"\\:")+"{0,5}"+h)+"?\\:\\:"+h),A=n(n(n(h+"\\:")+"{0,6}"+h)+"?\\:\\:"),D=n([l,m,g,v,E,C,y,S,A].join("|")),w=n(n(f+"|"+o)+"+");return{NOT_SCHEME:new RegExp(r("[^]","[A-Za-z]","[0-9]","[\\+\\-\\.]"),"g"),NOT_USERINFO:new RegExp(r("[^\\%\\:]",f,a),"g"),NOT_HOST:new RegExp(r("[^\\%\\[\\]\\:]",f,a),"g"),NOT_PATH:new RegExp(r("[^\\%\\/\\:\\@]",f,a),"g"),NOT_PATH_NOSCHEME:new RegExp(r("[^\\%\\/\\@]",f,a),"g"),NOT_QUERY:new RegExp(r("[^\\%]",f,a,"[\\:\\@\\/\\?]",s),"g"),NOT_FRAGMENT:new RegExp(r("[^\\%]",f,a,"[\\:\\@\\/\\?]"),"g"),ESCAPE:new RegExp(r("[^]",f,a),"g"),UNRESERVED:new RegExp(f,"g"),OTHER_CHARS:new RegExp(r("[^\\%]",f,i),"g"),PCT_ENCODED:new RegExp(o,"g"),IPV4ADDRESS:new RegExp("^("+p+")$"),IPV6ADDRESS:new RegExp("^\\[?("+D+")"+n(n("\\%25|\\%(?!"+t+"{2})")+"("+w+")")+"?\\]?$")}}function s(e){throw new RangeError(H[e])}function f(e,r){for(var n=[],t=e.length;t--;)n[t]=r(e[t]);return n}function c(e,r){var n=e.split("@"),t="";return n.length>1&&(t=n[0]+"@",e=n[1]),e=e.replace(j,"."),t+f(e.split("."),r).join(".")}function p(e){for(var r=[],n=0,t=e.length;n<t;){var o=e.charCodeAt(n++);if(o>=55296&&o<=56319&&n<t){var a=e.charCodeAt(n++);56320==(64512&a)?r.push(((1023&o)<<10)+(1023&a)+65536):(r.push(o),n--)}else r.push(o)}return r}function h(e){var r=e.charCodeAt(0);return r<16?"%0"+r.toString(16).toUpperCase():r<128?"%"+r.toString(16).toUpperCase():r<2048?"%"+(r>>6|192).toString(16).toUpperCase()+"%"+(63&r|128).toString(16).toUpperCase():"%"+(r>>12|224).toString(16).toUpperCase()+"%"+(r>>6&63|128).toString(16).toUpperCase()+"%"+(63&r|128).toString(16).toUpperCase()}function d(e){for(var r="",n=0,t=e.length;n<t;){var o=parseInt(e.substr(n+1,2),16);if(o<128)r+=String.fromCharCode(o),n+=3;else if(o>=194&&o<224){if(t-n>=6){var a=parseInt(e.substr(n+4,2),16);r+=String.fromCharCode((31&o)<<6|63&a)}else r+=e.substr(n,6);n+=6}else if(o>=224){if(t-n>=9){var i=parseInt(e.substr(n+4,2),16),u=parseInt(e.substr(n+7,2),16);r+=String.fromCharCode((15&o)<<12|(63&i)<<6|63&u)}else r+=e.substr(n,9);n+=9}else r+=e.substr(n,3),n+=3}return r}function l(e,r){function n(e){var n=d(e);return n.match(r.UNRESERVED)?n:e}return e.scheme&&(e.scheme=String(e.scheme).replace(r.PCT_ENCODED,n).toLowerCase().replace(r.NOT_SCHEME,"")),e.userinfo!==undefined&&(e.userinfo=String(e.userinfo).replace(r.PCT_ENCODED,n).replace(r.NOT_USERINFO,h).replace(r.PCT_ENCODED,o)),e.host!==undefined&&(e.host=String(e.host).replace(r.PCT_ENCODED,n).toLowerCase().replace(r.NOT_HOST,h).replace(r.PCT_ENCODED,o)),e.path!==undefined&&(e.path=String(e.path).replace(r.PCT_ENCODED,n).replace(e.scheme?r.NOT_PATH:r.NOT_PATH_NOSCHEME,h).replace(r.PCT_ENCODED,o)),e.query!==undefined&&(e.query=String(e.query).replace(r.PCT_ENCODED,n).replace(r.NOT_QUERY,h).replace(r.PCT_ENCODED,o)),e.fragment!==undefined&&(e.fragment=String(e.fragment).replace(r.PCT_ENCODED,n).replace(r.NOT_FRAGMENT,h).replace(r.PCT_ENCODED,o)),e}function m(e){return e.replace(/^0*(.*)/,"$1")||"0"}function g(e,r){var n=e.match(r.IPV4ADDRESS)||[],t=T(n,2),o=t[1];return o?o.split(".").map(m).join("."):e}function v(e,r){var n=e.match(r.IPV6ADDRESS)||[],t=T(n,3),o=t[1],a=t[2];if(o){for(var i=o.toLowerCase().split("::").reverse(),u=T(i,2),s=u[0],f=u[1],c=f?f.split(":").map(m):[],p=s.split(":").map(m),h=r.IPV4ADDRESS.test(p[p.length-1]),d=h?7:8,l=p.length-d,v=ArrLine truncated
|
||||
//# sourceMappingURL=uri.all.min.js.map
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
import { SCHEMES } from "./uri";
|
||||
import http from "./schemes/http";
|
||||
SCHEMES[http.scheme] = http;
|
||||
import https from "./schemes/https";
|
||||
SCHEMES[https.scheme] = https;
|
||||
import ws from "./schemes/ws";
|
||||
SCHEMES[ws.scheme] = ws;
|
||||
import wss from "./schemes/wss";
|
||||
SCHEMES[wss.scheme] = wss;
|
||||
import mailto from "./schemes/mailto";
|
||||
SCHEMES[mailto.scheme] = mailto;
|
||||
import urn from "./schemes/urn";
|
||||
SCHEMES[urn.scheme] = urn;
|
||||
import uuid from "./schemes/urn-uuid";
|
||||
SCHEMES[uuid.scheme] = uuid;
|
||||
export * from "./uri";
|
||||
//# sourceMappingURL=index.js.map
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
import { buildExps } from "./regexps-uri";
|
||||
export default buildExps(true);
|
||||
//# sourceMappingURL=regexps-iri.js.map
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
import { merge, subexp } from "./util";
|
||||
export function buildExps(isIRI) {
|
||||
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$$), DEC_OCTET_RELAXED$ = subexp(subexp("25[0-5]") + "|" + subexp("2[0-4]" + DIGIT$$) + "|" + subexp("1" + DIGIT$$ + DIGIT$$) + "|" + subexp("0?[1-9]" + DIGIT$$) + "|0?0?" + DIGIT$$), //relaxed parsing rules
|
||||
IPV4ADDRESS$ = subexp(DEC_OCTET_RELAXED$ + "\\." + DEC_OCTET_RELAXED$ + "\\." + DEC_OCTET_RELAXED$ + "\\." + DEC_OCTET_RELAXED$), H16$ = subexp(HEXDIG$$ + "{1,4}"), LS32$ = subexp(subexp(H16$ + "\\:" + H16$) + "|" + IPV4ADDRESS$), IPV6ADDRESS1$ = subexp(subexp(H16$ + "\\:") + "{6}" + LS32$), // 6( h16 ":" ) ls32
|
||||
IPV6ADDRESS2$ = subexp("\\:\\:" + subexp(H16$ + "\\:") + "{5}" + LS32$), // "::" 5( h16 ":" ) ls32
|
||||
IPV6ADDRESS3$ = subexp(subexp(H16$) + "?\\:\\:" + subexp(H16$ + "\\:") + "{4}" + LS32$), //[ h16 ] "::" 4( h16 ":" ) ls32
|
||||
IPV6ADDRESS4$ = subexp(subexp(subexp(H16$ + "\\:") + "{0,1}" + H16$) + "?\\:\\:" + subexp(H16$ + "\\:") + "{3}" + LS32$), //[ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32
|
||||
IPV6ADDRESS5$ = subexp(subexp(subexp(H16$ + "\\:") + "{0,2}" + H16$) + "?\\:\\:" + subexp(H16$ + "\\:") + "{2}" + LS32$), //[ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32
|
||||
IPV6ADDRESS6$ = subexp(subexp(subexp(H16$ + "\\:") + "{0,3}" + H16$) + "?\\:\\:" + H16$ + "\\:" + LS32$), //[ *3( h16 ":" ) h16 ] "::" h16 ":" ls32
|
||||
IPV6ADDRESS7$ = subexp(subexp(subexp(H16$ + "\\:") + "{0,4}" + H16$) + "?\\:\\:" + LS32$), //[ *4( h16 ":" ) h16 ] "::" ls32
|
||||
IPV6ADDRESS8$ = subexp(subexp(subexp(H16$ + "\\:") + "{0,5}" + H16$) + "?\\:\\:" + H16$), //[ *5( h16 ":" ) h16 ] "::" h16
|
||||
IPV6ADDRESS9$ = subexp(subexp(subexp(H16$ + "\\:") + "{0,6}" + H16$) + "?\\:\\:"), //[ *6( h16 ":" ) h16 ] "::"
|
||||
IPV6ADDRESS$ = subexp([IPV6ADDRESS1$, IPV6ADDRESS2$, IPV6ADDRESS3$, IPV6ADDRESS4$, IPV6ADDRESS5$, IPV6ADDRESS6$, IPV6ADDRESS7$, IPV6ADDRESS8$, IPV6ADDRESS9$].join("|")), ZONEID$ = subexp(subexp(UNRESERVED$$ + "|" + PCT_ENCODED$) + "+"), //RFC 6874
|
||||
IPV6ADDRZ$ = subexp(IPV6ADDRESS$ + "\\%25" + ZONEID$), //RFC 6874
|
||||
IPV6ADDRZ_RELAXED$ = subexp(IPV6ADDRESS$ + subexp("\\%25|\\%(?!" + HEXDIG$$ + "{2})") + ZONEID$), //RFC 6874, with relaxed parsing rules
|
||||
IPVFUTURE$ = subexp("[vV]" + HEXDIG$$ + "+\\." + merge(UNRESERVED$$, SUB_DELIMS$$, "[\\:]") + "+"), IP_LITERAL$ = subexp("\\[" + subexp(IPV6ADDRZ_RELAXED$ + "|" + IPV6ADDRESS$ + "|" + IPVFUTURE$) + "\\]"), //RFC 6874
|
||||
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 {
|
||||
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"),
|
||||
IPV4ADDRESS: new RegExp("^(" + IPV4ADDRESS$ + ")$"),
|
||||
IPV6ADDRESS: new RegExp("^\\[?(" + IPV6ADDRESS$ + ")" + subexp(subexp("\\%25|\\%(?!" + HEXDIG$$ + "{2})") + "(" + ZONEID$ + ")") + "?\\]?$") //RFC 6874, with relaxed parsing rules
|
||||
};
|
||||
}
|
||||
export default buildExps(false);
|
||||
//# sourceMappingURL=regexps-uri.js.map
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
const handler = {
|
||||
scheme: "http",
|
||||
domainHost: true,
|
||||
parse: function (components, options) {
|
||||
//report missing host
|
||||
if (!components.host) {
|
||||
components.error = components.error || "HTTP URIs must have a host.";
|
||||
}
|
||||
return components;
|
||||
},
|
||||
serialize: function (components, options) {
|
||||
const secure = String(components.scheme).toLowerCase() === "https";
|
||||
//normalize the default port
|
||||
if (components.port === (secure ? 443 : 80) || components.port === "") {
|
||||
components.port = undefined;
|
||||
}
|
||||
//normalize the empty path
|
||||
if (!components.path) {
|
||||
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.
|
||||
return components;
|
||||
}
|
||||
};
|
||||
export default handler;
|
||||
//# sourceMappingURL=http.js.map
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
import http from "./http";
|
||||
const handler = {
|
||||
scheme: "https",
|
||||
domainHost: http.domainHost,
|
||||
parse: http.parse,
|
||||
serialize: http.serialize
|
||||
};
|
||||
export default handler;
|
||||
//# sourceMappingURL=https.js.map
|
||||
+148
@@ -0,0 +1,148 @@
|
||||
import { pctEncChar, pctDecChars, unescapeComponent } from "../uri";
|
||||
import punycode from "punycode";
|
||||
import { merge, subexp, toUpperCase, toArray } from "../util";
|
||||
const O = {};
|
||||
const isIRI = true;
|
||||
//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
|
||||
//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 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$ + "?$");
|
||||
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$ + "$");
|
||||
function decodeUnreserved(str) {
|
||||
const decStr = pctDecChars(str);
|
||||
return (!decStr.match(UNRESERVED) ? str : decStr);
|
||||
}
|
||||
const handler = {
|
||||
scheme: "mailto",
|
||||
parse: function (components, options) {
|
||||
const mailtoComponents = components;
|
||||
const to = mailtoComponents.to = (mailtoComponents.path ? mailtoComponents.path.split(",") : []);
|
||||
mailtoComponents.path = undefined;
|
||||
if (mailtoComponents.query) {
|
||||
let unknownHeaders = false;
|
||||
const headers = {};
|
||||
const hfields = mailtoComponents.query.split("&");
|
||||
for (let x = 0, xl = hfields.length; x < xl; ++x) {
|
||||
const hfield = hfields[x].split("=");
|
||||
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":
|
||||
mailtoComponents.subject = unescapeComponent(hfield[1], options);
|
||||
break;
|
||||
case "body":
|
||||
mailtoComponents.body = unescapeComponent(hfield[1], options);
|
||||
break;
|
||||
default:
|
||||
unknownHeaders = true;
|
||||
headers[unescapeComponent(hfield[0], options)] = unescapeComponent(hfield[1], options);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (unknownHeaders)
|
||||
mailtoComponents.headers = headers;
|
||||
}
|
||||
mailtoComponents.query = undefined;
|
||||
for (let x = 0, xl = to.length; x < xl; ++x) {
|
||||
const addr = to[x].split("@");
|
||||
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) {
|
||||
mailtoComponents.error = mailtoComponents.error || "Email address's domain name can not be converted to ASCII via punycode: " + e;
|
||||
}
|
||||
}
|
||||
else {
|
||||
addr[1] = unescapeComponent(addr[1], options).toLowerCase();
|
||||
}
|
||||
to[x] = addr.join("@");
|
||||
}
|
||||
return mailtoComponents;
|
||||
},
|
||||
serialize: function (mailtoComponents, options) {
|
||||
const components = mailtoComponents;
|
||||
const to = toArray(mailtoComponents.to);
|
||||
if (to) {
|
||||
for (let x = 0, xl = to.length; x < xl; ++x) {
|
||||
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);
|
||||
//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] = localPart + "@" + domain;
|
||||
}
|
||||
components.path = to.join(",");
|
||||
}
|
||||
const headers = mailtoComponents.headers = mailtoComponents.headers || {};
|
||||
if (mailtoComponents.subject)
|
||||
headers["subject"] = mailtoComponents.subject;
|
||||
if (mailtoComponents.body)
|
||||
headers["body"] = mailtoComponents.body;
|
||||
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("&");
|
||||
}
|
||||
return components;
|
||||
}
|
||||
};
|
||||
export default handler;
|
||||
//# sourceMappingURL=mailto.js.map
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
const UUID = /^[0-9A-Fa-f]{8}(?:\-[0-9A-Fa-f]{4}){3}\-[0-9A-Fa-f]{12}$/;
|
||||
const UUID_PARSE = /^[0-9A-Fa-f\-]{36}/;
|
||||
//RFC 4122
|
||||
const handler = {
|
||||
scheme: "urn:uuid",
|
||||
parse: function (urnComponents, options) {
|
||||
const uuidComponents = urnComponents;
|
||||
uuidComponents.uuid = uuidComponents.nss;
|
||||
uuidComponents.nss = undefined;
|
||||
if (!options.tolerant && (!uuidComponents.uuid || !uuidComponents.uuid.match(UUID))) {
|
||||
uuidComponents.error = uuidComponents.error || "UUID is not valid.";
|
||||
}
|
||||
return uuidComponents;
|
||||
},
|
||||
serialize: function (uuidComponents, options) {
|
||||
const urnComponents = uuidComponents;
|
||||
//normalize UUID
|
||||
urnComponents.nss = (uuidComponents.uuid || "").toLowerCase();
|
||||
return urnComponents;
|
||||
},
|
||||
};
|
||||
export default handler;
|
||||
//# sourceMappingURL=urn-uuid.js.map
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
import { SCHEMES } from "../uri";
|
||||
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
|
||||
const handler = {
|
||||
scheme: "urn",
|
||||
parse: function (components, options) {
|
||||
const matches = components.path && components.path.match(URN_PARSE);
|
||||
let urnComponents = components;
|
||||
if (matches) {
|
||||
const scheme = options.scheme || urnComponents.scheme || "urn";
|
||||
const nid = matches[1].toLowerCase();
|
||||
const nss = matches[2];
|
||||
const urnScheme = `${scheme}:${options.nid || nid}`;
|
||||
const schemeHandler = SCHEMES[urnScheme];
|
||||
urnComponents.nid = nid;
|
||||
urnComponents.nss = nss;
|
||||
urnComponents.path = undefined;
|
||||
if (schemeHandler) {
|
||||
urnComponents = schemeHandler.parse(urnComponents, options);
|
||||
}
|
||||
}
|
||||
else {
|
||||
urnComponents.error = urnComponents.error || "URN can not be parsed.";
|
||||
}
|
||||
return urnComponents;
|
||||
},
|
||||
serialize: function (urnComponents, options) {
|
||||
const scheme = options.scheme || urnComponents.scheme || "urn";
|
||||
const nid = urnComponents.nid;
|
||||
const urnScheme = `${scheme}:${options.nid || nid}`;
|
||||
const schemeHandler = SCHEMES[urnScheme];
|
||||
if (schemeHandler) {
|
||||
urnComponents = schemeHandler.serialize(urnComponents, options);
|
||||
}
|
||||
const uriComponents = urnComponents;
|
||||
const nss = urnComponents.nss;
|
||||
uriComponents.path = `${nid || options.nid}:${nss}`;
|
||||
return uriComponents;
|
||||
},
|
||||
};
|
||||
export default handler;
|
||||
//# sourceMappingURL=urn.js.map
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
function isSecure(wsComponents) {
|
||||
return typeof wsComponents.secure === 'boolean' ? wsComponents.secure : String(wsComponents.scheme).toLowerCase() === "wss";
|
||||
}
|
||||
//RFC 6455
|
||||
const handler = {
|
||||
scheme: "ws",
|
||||
domainHost: true,
|
||||
parse: function (components, options) {
|
||||
const wsComponents = components;
|
||||
//indicate if the secure flag is set
|
||||
wsComponents.secure = isSecure(wsComponents);
|
||||
//construct resouce name
|
||||
wsComponents.resourceName = (wsComponents.path || '/') + (wsComponents.query ? '?' + wsComponents.query : '');
|
||||
wsComponents.path = undefined;
|
||||
wsComponents.query = undefined;
|
||||
return wsComponents;
|
||||
},
|
||||
serialize: function (wsComponents, options) {
|
||||
//normalize the default port
|
||||
if (wsComponents.port === (isSecure(wsComponents) ? 443 : 80) || wsComponents.port === "") {
|
||||
wsComponents.port = undefined;
|
||||
}
|
||||
//ensure scheme matches secure flag
|
||||
if (typeof wsComponents.secure === 'boolean') {
|
||||
wsComponents.scheme = (wsComponents.secure ? 'wss' : 'ws');
|
||||
wsComponents.secure = undefined;
|
||||
}
|
||||
//reconstruct path from resource name
|
||||
if (wsComponents.resourceName) {
|
||||
const [path, query] = wsComponents.resourceName.split('?');
|
||||
wsComponents.path = (path && path !== '/' ? path : undefined);
|
||||
wsComponents.query = query;
|
||||
wsComponents.resourceName = undefined;
|
||||
}
|
||||
//forbid fragment component
|
||||
wsComponents.fragment = undefined;
|
||||
return wsComponents;
|
||||
}
|
||||
};
|
||||
export default handler;
|
||||
//# sourceMappingURL=ws.js.map
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
import ws from "./ws";
|
||||
const handler = {
|
||||
scheme: "wss",
|
||||
domainHost: ws.domainHost,
|
||||
parse: ws.parse,
|
||||
serialize: ws.serialize
|
||||
};
|
||||
export default handler;
|
||||
//# sourceMappingURL=wss.js.map
|
||||
+480
@@ -0,0 +1,480 @@
|
||||
/**
|
||||
* 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>
|
||||
* @see http://github.com/garycourt/uri-js
|
||||
*/
|
||||
/**
|
||||
* 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
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GARY COURT OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
import URI_PROTOCOL from "./regexps-uri";
|
||||
import IRI_PROTOCOL from "./regexps-iri";
|
||||
import punycode from "punycode";
|
||||
import { toUpperCase, typeOf, assign } from "./util";
|
||||
export const SCHEMES = {};
|
||||
export function pctEncChar(chr) {
|
||||
const c = chr.charCodeAt(0);
|
||||
let e;
|
||||
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) {
|
||||
let newStr = "";
|
||||
let i = 0;
|
||||
const il = str.length;
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
i += 9;
|
||||
}
|
||||
else {
|
||||
newStr += str.substr(i, 3);
|
||||
i += 3;
|
||||
}
|
||||
}
|
||||
return newStr;
|
||||
}
|
||||
function _normalizeComponentEncoding(components, protocol) {
|
||||
function decodeUnreserved(str) {
|
||||
const 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 _stripLeadingZeros(str) {
|
||||
return str.replace(/^0*(.*)/, "$1") || "0";
|
||||
}
|
||||
function _normalizeIPv4(host, protocol) {
|
||||
const matches = host.match(protocol.IPV4ADDRESS) || [];
|
||||
const [, address] = matches;
|
||||
if (address) {
|
||||
return address.split(".").map(_stripLeadingZeros).join(".");
|
||||
}
|
||||
else {
|
||||
return host;
|
||||
}
|
||||
}
|
||||
function _normalizeIPv6(host, protocol) {
|
||||
const matches = host.match(protocol.IPV6ADDRESS) || [];
|
||||
const [, address, zone] = matches;
|
||||
if (address) {
|
||||
const [last, first] = address.toLowerCase().split('::').reverse();
|
||||
const firstFields = first ? first.split(":").map(_stripLeadingZeros) : [];
|
||||
const lastFields = last.split(":").map(_stripLeadingZeros);
|
||||
const isLastFieldIPv4Address = protocol.IPV4ADDRESS.test(lastFields[lastFields.length - 1]);
|
||||
const fieldCount = isLastFieldIPv4Address ? 7 : 8;
|
||||
const lastFieldsStart = lastFields.length - fieldCount;
|
||||
const fields = Array(fieldCount);
|
||||
for (let x = 0; x < fieldCount; ++x) {
|
||||
fields[x] = firstFields[x] || lastFields[lastFieldsStart + x] || '';
|
||||
}
|
||||
if (isLastFieldIPv4Address) {
|
||||
fields[fieldCount - 1] = _normalizeIPv4(fields[fieldCount - 1], protocol);
|
||||
}
|
||||
const allZeroFields = fields.reduce((acc, field, index) => {
|
||||
if (!field || field === "0") {
|
||||
const lastLongest = acc[acc.length - 1];
|
||||
if (lastLongest && lastLongest.index + lastLongest.length === index) {
|
||||
lastLongest.length++;
|
||||
}
|
||||
else {
|
||||
acc.push({ index, length: 1 });
|
||||
}
|
||||
}
|
||||
return acc;
|
||||
}, []);
|
||||
const longestZeroFields = allZeroFields.sort((a, b) => b.length - a.length)[0];
|
||||
let newHost;
|
||||
if (longestZeroFields && longestZeroFields.length > 1) {
|
||||
const newFirst = fields.slice(0, longestZeroFields.index);
|
||||
const newLast = fields.slice(longestZeroFields.index + longestZeroFields.length);
|
||||
newHost = newFirst.join(":") + "::" + newLast.join(":");
|
||||
}
|
||||
else {
|
||||
newHost = fields.join(":");
|
||||
}
|
||||
if (zone) {
|
||||
newHost += "%" + zone;
|
||||
}
|
||||
return newHost;
|
||||
}
|
||||
else {
|
||||
return host;
|
||||
}
|
||||
}
|
||||
const URI_PARSE = /^(?:([^:\/?#]+):)?(?:\/\/((?:([^\/?#@]*)@)?(\[[^\/?#\]]+\]|[^\/?#:]*)(?:\:(\d*))?))?([^?#]*)(?:\?([^#]*))?(?:#((?:.|\n|\r)*))?/i;
|
||||
const NO_MATCH_IS_UNDEFINED = ("").match(/(){0}/)[1] === undefined;
|
||||
export function parse(uriString, options = {}) {
|
||||
const components = {};
|
||||
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);
|
||||
//fix port number
|
||||
if (isNaN(components.port)) {
|
||||
components.port = (uriString.match(/\/\/(?:.|\n)*\:(?:\/|\?|\#|$)/) ? matches[4] : undefined);
|
||||
}
|
||||
}
|
||||
if (components.host) {
|
||||
//normalize IP hosts
|
||||
components.host = _normalizeIPv6(_normalizeIPv4(components.host, protocol), protocol);
|
||||
}
|
||||
//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
|
||||
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;
|
||||
}
|
||||
}
|
||||
//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);
|
||||
}
|
||||
}
|
||||
else {
|
||||
components.error = components.error || "URI can not be parsed.";
|
||||
}
|
||||
return components;
|
||||
}
|
||||
;
|
||||
function _recomposeAuthority(components, options) {
|
||||
const protocol = (options.iri !== false ? IRI_PROTOCOL : URI_PROTOCOL);
|
||||
const uriTokens = [];
|
||||
if (components.userinfo !== undefined) {
|
||||
uriTokens.push(components.userinfo);
|
||||
uriTokens.push("@");
|
||||
}
|
||||
if (components.host !== undefined) {
|
||||
//normalize IP hosts, add brackets and escape zone separator for IPv6
|
||||
uriTokens.push(_normalizeIPv6(_normalizeIPv4(String(components.host), protocol), protocol).replace(protocol.IPV6ADDRESS, (_, $1, $2) => "[" + $1 + ($2 ? "%25" + $2 : "") + "]"));
|
||||
}
|
||||
if (typeof components.port === "number" || typeof components.port === "string") {
|
||||
uriTokens.push(":");
|
||||
uriTokens.push(String(components.port));
|
||||
}
|
||||
return uriTokens.length ? uriTokens.join("") : undefined;
|
||||
}
|
||||
;
|
||||
const RDS1 = /^\.\.?\//;
|
||||
const RDS2 = /^\/\.(\/|$)/;
|
||||
const RDS3 = /^\/\.\.(\/|$)/;
|
||||
const RDS4 = /^\.\.?$/;
|
||||
const RDS5 = /^\/?(?:.|\n)*?(?=\/|$)/;
|
||||
export function removeDotSegments(input) {
|
||||
const output = [];
|
||||
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("");
|
||||
}
|
||||
;
|
||||
export function serialize(components, options = {}) {
|
||||
const protocol = (options.iri ? IRI_PROTOCOL : URI_PROTOCOL);
|
||||
const uriTokens = [];
|
||||
//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
|
||||
else if (options.domainHost || (schemeHandler && schemeHandler.domainHost)) {
|
||||
//convert IDN via punycode
|
||||
try {
|
||||
components.host = (!options.iri ? punycode.toASCII(components.host.replace(protocol.PCT_ENCODED, pctDecChars).toLowerCase()) : punycode.toUnicode(components.host));
|
||||
}
|
||||
catch (e) {
|
||||
components.error = components.error || "Host's domain name can not be converted to " + (!options.iri ? "ASCII" : "Unicode") + " via punycode: " + e;
|
||||
}
|
||||
}
|
||||
}
|
||||
//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("//");
|
||||
}
|
||||
uriTokens.push(authority);
|
||||
if (components.path && components.path.charAt(0) !== "/") {
|
||||
uriTokens.push("/");
|
||||
}
|
||||
}
|
||||
if (components.path !== undefined) {
|
||||
let 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.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, relative, options = {}, skipNormalization) {
|
||||
const target = {};
|
||||
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;
|
||||
target.userinfo = relative.userinfo;
|
||||
target.host = relative.host;
|
||||
target.port = relative.port;
|
||||
target.path = removeDotSegments(relative.path || "");
|
||||
target.query = relative.query;
|
||||
}
|
||||
else {
|
||||
if (!relative.path) {
|
||||
target.path = base.path;
|
||||
if (relative.query !== undefined) {
|
||||
target.query = relative.query;
|
||||
}
|
||||
else {
|
||||
target.query = base.query;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (relative.path.charAt(0) === "/") {
|
||||
target.path = removeDotSegments(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.query = relative.query;
|
||||
}
|
||||
//target.authority = base.authority;
|
||||
target.userinfo = base.userinfo;
|
||||
target.host = base.host;
|
||||
target.port = base.port;
|
||||
}
|
||||
target.scheme = base.scheme;
|
||||
}
|
||||
target.fragment = relative.fragment;
|
||||
return target;
|
||||
}
|
||||
;
|
||||
export function resolve(baseURI, relativeURI, options) {
|
||||
const schemelessOptions = assign({ scheme: 'null' }, options);
|
||||
return serialize(resolveComponents(parse(baseURI, schemelessOptions), parse(relativeURI, schemelessOptions), schemelessOptions, true), schemelessOptions);
|
||||
}
|
||||
;
|
||||
export function normalize(uri, options) {
|
||||
if (typeof uri === "string") {
|
||||
uri = serialize(parse(uri, options), options);
|
||||
}
|
||||
else if (typeOf(uri) === "object") {
|
||||
uri = parse(serialize(uri, options), options);
|
||||
}
|
||||
return uri;
|
||||
}
|
||||
;
|
||||
export function equal(uriA, uriB, options) {
|
||||
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;
|
||||
}
|
||||
;
|
||||
export function escapeComponent(str, options) {
|
||||
return str && str.toString().replace((!options || !options.iri ? URI_PROTOCOL.ESCAPE : IRI_PROTOCOL.ESCAPE), pctEncChar);
|
||||
}
|
||||
;
|
||||
export function unescapeComponent(str, options) {
|
||||
return str && str.toString().replace((!options || !options.iri ? URI_PROTOCOL.PCT_ENCODED : IRI_PROTOCOL.PCT_ENCODED), pctDecChars);
|
||||
}
|
||||
;
|
||||
//# sourceMappingURL=uri.js.map
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
export function merge(...sets) {
|
||||
if (sets.length > 1) {
|
||||
sets[0] = sets[0].slice(0, -1);
|
||||
const 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 function subexp(str) {
|
||||
return "(?:" + str + ")";
|
||||
}
|
||||
export function typeOf(o) {
|
||||
return o === undefined ? "undefined" : (o === null ? "null" : Object.prototype.toString.call(o).split(" ").pop().split("]").shift().toLowerCase());
|
||||
}
|
||||
export function toUpperCase(str) {
|
||||
return str.toUpperCase();
|
||||
}
|
||||
export function toArray(obj) {
|
||||
return obj !== undefined && obj !== null ? (obj instanceof Array ? obj : (typeof obj.length !== "number" || obj.split || obj.setInterval || obj.call ? [obj] : Array.prototype.slice.call(obj))) : [];
|
||||
}
|
||||
export function assign(target, source) {
|
||||
const obj = target;
|
||||
if (source) {
|
||||
for (const key in source) {
|
||||
obj[key] = source[key];
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
//# sourceMappingURL=util.js.map
|
||||
+105
@@ -0,0 +1,105 @@
|
||||
{
|
||||
"_from": "uri-js@^4.2.2",
|
||||
"_id": "uri-js@4.4.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-B0yRTzYdUCCn9n+F4+Gh4yIDtMQcaJsmYBDsTSG8g/OejKBodLQ2IHfN3bM7jUsRXndopT7OIXWdYqc1fjmV6g==",
|
||||
"_location": "/uri-js",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "uri-js@^4.2.2",
|
||||
"name": "uri-js",
|
||||
"escapedName": "uri-js",
|
||||
"rawSpec": "^4.2.2",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^4.2.2"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/ajv"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.0.tgz",
|
||||
"_shasum": "aa714261de793e8a82347a7bcc9ce74e86f28602",
|
||||
"_spec": "uri-js@^4.2.2",
|
||||
"_where": "C:\\Users\\Luis\\source\\repos\\AAMasters\\BackendServers\\node_modules\\ajv",
|
||||
"author": {
|
||||
"name": "Gary Court",
|
||||
"email": "gary.court@gmail.com"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/garycourt/uri-js/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"punycode": "^2.1.0"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "An RFC 3986/3987 compliant, scheme extendable URI/IRI parsing/validating/resolving library for JavaScript.",
|
||||
"devDependencies": {
|
||||
"babel-cli": "^6.26.0",
|
||||
"babel-plugin-external-helpers": "^6.22.0",
|
||||
"babel-preset-latest": "^6.24.1",
|
||||
"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.8.1",
|
||||
"uglify-js": "^2.8.14"
|
||||
},
|
||||
"directories": {
|
||||
"test": "tests"
|
||||
},
|
||||
"files": [
|
||||
"dist",
|
||||
"package.json",
|
||||
"yarn.lock",
|
||||
"README.md",
|
||||
"CHANGELOG",
|
||||
"LICENSE"
|
||||
],
|
||||
"homepage": "https://github.com/garycourt/uri-js",
|
||||
"keywords": [
|
||||
"URI",
|
||||
"IRI",
|
||||
"IDN",
|
||||
"URN",
|
||||
"UUID",
|
||||
"HTTP",
|
||||
"HTTPS",
|
||||
"WS",
|
||||
"WSS",
|
||||
"MAILTO",
|
||||
"RFC3986",
|
||||
"RFC3987",
|
||||
"RFC5891",
|
||||
"RFC2616",
|
||||
"RFC2818",
|
||||
"RFC2141",
|
||||
"RFC4122",
|
||||
"RFC4291",
|
||||
"RFC5952",
|
||||
"RFC6068",
|
||||
"RFC6455",
|
||||
"RFC6874"
|
||||
],
|
||||
"license": "BSD-2-Clause",
|
||||
"main": "dist/es5/uri.all.js",
|
||||
"name": "uri-js",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+ssh://git@github.com/garycourt/uri-js.git"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "npm run build:esnext && npm run build:es5 && npm run build:es5:min",
|
||||
"build:es5": "rollup -c && cp dist/esnext/uri.d.ts dist/es5/uri.all.d.ts && npm run build:es5:fix-sourcemap",
|
||||
"build:es5:fix-sourcemap": "sorcery -i dist/es5/uri.all.js",
|
||||
"build:es5:min": "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:esnext": "tsc",
|
||||
"clean": "rm -rf dist",
|
||||
"test": "mocha -u mocha-qunit-ui dist/es5/uri.all.js tests/tests.js"
|
||||
},
|
||||
"types": "dist/es5/uri.all.d.ts",
|
||||
"version": "4.4.0"
|
||||
}
|
||||
Reference in new issue
Block a user