uri.all.js 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389
  1. /** @license URI.js v4.2.1 (c) 2011 Gary Court. License: http://github.com/garycourt/uri-js */
  2. (function (global, factory) {
  3. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  4. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  5. (factory((global.URI = global.URI || {})));
  6. }(this, (function (exports) { 'use strict';
  7. function merge() {
  8. for (var _len = arguments.length, sets = Array(_len), _key = 0; _key < _len; _key++) {
  9. sets[_key] = arguments[_key];
  10. }
  11. if (sets.length > 1) {
  12. sets[0] = sets[0].slice(0, -1);
  13. var xl = sets.length - 1;
  14. for (var x = 1; x < xl; ++x) {
  15. sets[x] = sets[x].slice(1, -1);
  16. }
  17. sets[xl] = sets[xl].slice(1);
  18. return sets.join('');
  19. } else {
  20. return sets[0];
  21. }
  22. }
  23. function subexp(str) {
  24. return "(?:" + str + ")";
  25. }
  26. function typeOf(o) {
  27. return o === undefined ? "undefined" : o === null ? "null" : Object.prototype.toString.call(o).split(" ").pop().split("]").shift().toLowerCase();
  28. }
  29. function toUpperCase(str) {
  30. return str.toUpperCase();
  31. }
  32. function toArray(obj) {
  33. 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) : [];
  34. }
  35. function assign(target, source) {
  36. var obj = target;
  37. if (source) {
  38. for (var key in source) {
  39. obj[key] = source[key];
  40. }
  41. }
  42. return obj;
  43. }
  44. function buildExps(isIRI) {
  45. var ALPHA$$ = "[A-Za-z]",
  46. CR$ = "[\\x0D]",
  47. DIGIT$$ = "[0-9]",
  48. DQUOTE$$ = "[\\x22]",
  49. HEXDIG$$ = merge(DIGIT$$, "[A-Fa-f]"),
  50. //case-insensitive
  51. LF$$ = "[\\x0A]",
  52. SP$$ = "[\\x20]",
  53. PCT_ENCODED$ = subexp(subexp("%[EFef]" + HEXDIG$$ + "%" + HEXDIG$$ + HEXDIG$$ + "%" + HEXDIG$$ + HEXDIG$$) + "|" + subexp("%[89A-Fa-f]" + HEXDIG$$ + "%" + HEXDIG$$ + HEXDIG$$) + "|" + subexp("%" + HEXDIG$$ + HEXDIG$$)),
  54. //expanded
  55. GEN_DELIMS$$ = "[\\:\\/\\?\\#\\[\\]\\@]",
  56. SUB_DELIMS$$ = "[\\!\\$\\&\\'\\(\\)\\*\\+\\,\\;\\=]",
  57. RESERVED$$ = merge(GEN_DELIMS$$, SUB_DELIMS$$),
  58. UCSCHAR$$ = isIRI ? "[\\xA0-\\u200D\\u2010-\\u2029\\u202F-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF]" : "[]",
  59. //subset, excludes bidi control characters
  60. IPRIVATE$$ = isIRI ? "[\\uE000-\\uF8FF]" : "[]",
  61. //subset
  62. UNRESERVED$$ = merge(ALPHA$$, DIGIT$$, "[\\-\\.\\_\\~]", UCSCHAR$$),
  63. SCHEME$ = subexp(ALPHA$$ + merge(ALPHA$$, DIGIT$$, "[\\+\\-\\.]") + "*"),
  64. USERINFO$ = subexp(subexp(PCT_ENCODED$ + "|" + merge(UNRESERVED$$, SUB_DELIMS$$, "[\\:]")) + "*"),
  65. DEC_OCTET$ = subexp(subexp("25[0-5]") + "|" + subexp("2[0-4]" + DIGIT$$) + "|" + subexp("1" + DIGIT$$ + DIGIT$$) + "|" + subexp("[1-9]" + DIGIT$$) + "|" + DIGIT$$),
  66. 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$$),
  67. //relaxed parsing rules
  68. IPV4ADDRESS$ = subexp(DEC_OCTET_RELAXED$ + "\\." + DEC_OCTET_RELAXED$ + "\\." + DEC_OCTET_RELAXED$ + "\\." + DEC_OCTET_RELAXED$),
  69. H16$ = subexp(HEXDIG$$ + "{1,4}"),
  70. LS32$ = subexp(subexp(H16$ + "\\:" + H16$) + "|" + IPV4ADDRESS$),
  71. IPV6ADDRESS1$ = subexp(subexp(H16$ + "\\:") + "{6}" + LS32$),
  72. // 6( h16 ":" ) ls32
  73. IPV6ADDRESS2$ = subexp("\\:\\:" + subexp(H16$ + "\\:") + "{5}" + LS32$),
  74. // "::" 5( h16 ":" ) ls32
  75. IPV6ADDRESS3$ = subexp(subexp(H16$) + "?\\:\\:" + subexp(H16$ + "\\:") + "{4}" + LS32$),
  76. //[ h16 ] "::" 4( h16 ":" ) ls32
  77. IPV6ADDRESS4$ = subexp(subexp(subexp(H16$ + "\\:") + "{0,1}" + H16$) + "?\\:\\:" + subexp(H16$ + "\\:") + "{3}" + LS32$),
  78. //[ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32
  79. IPV6ADDRESS5$ = subexp(subexp(subexp(H16$ + "\\:") + "{0,2}" + H16$) + "?\\:\\:" + subexp(H16$ + "\\:") + "{2}" + LS32$),
  80. //[ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32
  81. IPV6ADDRESS6$ = subexp(subexp(subexp(H16$ + "\\:") + "{0,3}" + H16$) + "?\\:\\:" + H16$ + "\\:" + LS32$),
  82. //[ *3( h16 ":" ) h16 ] "::" h16 ":" ls32
  83. IPV6ADDRESS7$ = subexp(subexp(subexp(H16$ + "\\:") + "{0,4}" + H16$) + "?\\:\\:" + LS32$),
  84. //[ *4( h16 ":" ) h16 ] "::" ls32
  85. IPV6ADDRESS8$ = subexp(subexp(subexp(H16$ + "\\:") + "{0,5}" + H16$) + "?\\:\\:" + H16$),
  86. //[ *5( h16 ":" ) h16 ] "::" h16
  87. IPV6ADDRESS9$ = subexp(subexp(subexp(H16$ + "\\:") + "{0,6}" + H16$) + "?\\:\\:"),
  88. //[ *6( h16 ":" ) h16 ] "::"
  89. IPV6ADDRESS$ = subexp([IPV6ADDRESS1$, IPV6ADDRESS2$, IPV6ADDRESS3$, IPV6ADDRESS4$, IPV6ADDRESS5$, IPV6ADDRESS6$, IPV6ADDRESS7$, IPV6ADDRESS8$, IPV6ADDRESS9$].join("|")),
  90. ZONEID$ = subexp(subexp(UNRESERVED$$ + "|" + PCT_ENCODED$) + "+"),
  91. //RFC 6874
  92. IPV6ADDRZ$ = subexp(IPV6ADDRESS$ + "\\%25" + ZONEID$),
  93. //RFC 6874
  94. IPV6ADDRZ_RELAXED$ = subexp(IPV6ADDRESS$ + subexp("\\%25|\\%(?!" + HEXDIG$$ + "{2})") + ZONEID$),
  95. //RFC 6874, with relaxed parsing rules
  96. IPVFUTURE$ = subexp("[vV]" + HEXDIG$$ + "+\\." + merge(UNRESERVED$$, SUB_DELIMS$$, "[\\:]") + "+"),
  97. IP_LITERAL$ = subexp("\\[" + subexp(IPV6ADDRZ_RELAXED$ + "|" + IPV6ADDRESS$ + "|" + IPVFUTURE$) + "\\]"),
  98. //RFC 6874
  99. REG_NAME$ = subexp(subexp(PCT_ENCODED$ + "|" + merge(UNRESERVED$$, SUB_DELIMS$$)) + "*"),
  100. HOST$ = subexp(IP_LITERAL$ + "|" + IPV4ADDRESS$ + "(?!" + REG_NAME$ + ")" + "|" + REG_NAME$),
  101. PORT$ = subexp(DIGIT$$ + "*"),
  102. AUTHORITY$ = subexp(subexp(USERINFO$ + "@") + "?" + HOST$ + subexp("\\:" + PORT$) + "?"),
  103. PCHAR$ = subexp(PCT_ENCODED$ + "|" + merge(UNRESERVED$$, SUB_DELIMS$$, "[\\:\\@]")),
  104. SEGMENT$ = subexp(PCHAR$ + "*"),
  105. SEGMENT_NZ$ = subexp(PCHAR$ + "+"),
  106. SEGMENT_NZ_NC$ = subexp(subexp(PCT_ENCODED$ + "|" + merge(UNRESERVED$$, SUB_DELIMS$$, "[\\@]")) + "+"),
  107. PATH_ABEMPTY$ = subexp(subexp("\\/" + SEGMENT$) + "*"),
  108. PATH_ABSOLUTE$ = subexp("\\/" + subexp(SEGMENT_NZ$ + PATH_ABEMPTY$) + "?"),
  109. //simplified
  110. PATH_NOSCHEME$ = subexp(SEGMENT_NZ_NC$ + PATH_ABEMPTY$),
  111. //simplified
  112. PATH_ROOTLESS$ = subexp(SEGMENT_NZ$ + PATH_ABEMPTY$),
  113. //simplified
  114. PATH_EMPTY$ = "(?!" + PCHAR$ + ")",
  115. PATH$ = subexp(PATH_ABEMPTY$ + "|" + PATH_ABSOLUTE$ + "|" + PATH_NOSCHEME$ + "|" + PATH_ROOTLESS$ + "|" + PATH_EMPTY$),
  116. QUERY$ = subexp(subexp(PCHAR$ + "|" + merge("[\\/\\?]", IPRIVATE$$)) + "*"),
  117. FRAGMENT$ = subexp(subexp(PCHAR$ + "|[\\/\\?]") + "*"),
  118. HIER_PART$ = subexp(subexp("\\/\\/" + AUTHORITY$ + PATH_ABEMPTY$) + "|" + PATH_ABSOLUTE$ + "|" + PATH_ROOTLESS$ + "|" + PATH_EMPTY$),
  119. URI$ = subexp(SCHEME$ + "\\:" + HIER_PART$ + subexp("\\?" + QUERY$) + "?" + subexp("\\#" + FRAGMENT$) + "?"),
  120. RELATIVE_PART$ = subexp(subexp("\\/\\/" + AUTHORITY$ + PATH_ABEMPTY$) + "|" + PATH_ABSOLUTE$ + "|" + PATH_NOSCHEME$ + "|" + PATH_EMPTY$),
  121. RELATIVE$ = subexp(RELATIVE_PART$ + subexp("\\?" + QUERY$) + "?" + subexp("\\#" + FRAGMENT$) + "?"),
  122. URI_REFERENCE$ = subexp(URI$ + "|" + RELATIVE$),
  123. ABSOLUTE_URI$ = subexp(SCHEME$ + "\\:" + HIER_PART$ + subexp("\\?" + QUERY$) + "?"),
  124. GENERIC_REF$ = "^(" + SCHEME$ + ")\\:" + subexp(subexp("\\/\\/(" + subexp("(" + USERINFO$ + ")@") + "?(" + HOST$ + ")" + subexp("\\:(" + PORT$ + ")") + "?)") + "?(" + PATH_ABEMPTY$ + "|" + PATH_ABSOLUTE$ + "|" + PATH_ROOTLESS$ + "|" + PATH_EMPTY$ + ")") + subexp("\\?(" + QUERY$ + ")") + "?" + subexp("\\#(" + FRAGMENT$ + ")") + "?$",
  125. RELATIVE_REF$ = "^(){0}" + subexp(subexp("\\/\\/(" + subexp("(" + USERINFO$ + ")@") + "?(" + HOST$ + ")" + subexp("\\:(" + PORT$ + ")") + "?)") + "?(" + PATH_ABEMPTY$ + "|" + PATH_ABSOLUTE$ + "|" + PATH_NOSCHEME$ + "|" + PATH_EMPTY$ + ")") + subexp("\\?(" + QUERY$ + ")") + "?" + subexp("\\#(" + FRAGMENT$ + ")") + "?$",
  126. ABSOLUTE_REF$ = "^(" + SCHEME$ + ")\\:" + subexp(subexp("\\/\\/(" + subexp("(" + USERINFO$ + ")@") + "?(" + HOST$ + ")" + subexp("\\:(" + PORT$ + ")") + "?)") + "?(" + PATH_ABEMPTY$ + "|" + PATH_ABSOLUTE$ + "|" + PATH_ROOTLESS$ + "|" + PATH_EMPTY$ + ")") + subexp("\\?(" + QUERY$ + ")") + "?$",
  127. SAMEDOC_REF$ = "^" + subexp("\\#(" + FRAGMENT$ + ")") + "?$",
  128. AUTHORITY_REF$ = "^" + subexp("(" + USERINFO$ + ")@") + "?(" + HOST$ + ")" + subexp("\\:(" + PORT$ + ")") + "?$";
  129. return {
  130. NOT_SCHEME: new RegExp(merge("[^]", ALPHA$$, DIGIT$$, "[\\+\\-\\.]"), "g"),
  131. NOT_USERINFO: new RegExp(merge("[^\\%\\:]", UNRESERVED$$, SUB_DELIMS$$), "g"),
  132. NOT_HOST: new RegExp(merge("[^\\%\\[\\]\\:]", UNRESERVED$$, SUB_DELIMS$$), "g"),
  133. NOT_PATH: new RegExp(merge("[^\\%\\/\\:\\@]", UNRESERVED$$, SUB_DELIMS$$), "g"),
  134. NOT_PATH_NOSCHEME: new RegExp(merge("[^\\%\\/\\@]", UNRESERVED$$, SUB_DELIMS$$), "g"),
  135. NOT_QUERY: new RegExp(merge("[^\\%]", UNRESERVED$$, SUB_DELIMS$$, "[\\:\\@\\/\\?]", IPRIVATE$$), "g"),
  136. NOT_FRAGMENT: new RegExp(merge("[^\\%]", UNRESERVED$$, SUB_DELIMS$$, "[\\:\\@\\/\\?]"), "g"),
  137. ESCAPE: new RegExp(merge("[^]", UNRESERVED$$, SUB_DELIMS$$), "g"),
  138. UNRESERVED: new RegExp(UNRESERVED$$, "g"),
  139. OTHER_CHARS: new RegExp(merge("[^\\%]", UNRESERVED$$, RESERVED$$), "g"),
  140. PCT_ENCODED: new RegExp(PCT_ENCODED$, "g"),
  141. IPV4ADDRESS: new RegExp("^(" + IPV4ADDRESS$ + ")$"),
  142. IPV6ADDRESS: new RegExp("^\\[?(" + IPV6ADDRESS$ + ")" + subexp(subexp("\\%25|\\%(?!" + HEXDIG$$ + "{2})") + "(" + ZONEID$ + ")") + "?\\]?$") //RFC 6874, with relaxed parsing rules
  143. };
  144. }
  145. var URI_PROTOCOL = buildExps(false);
  146. var IRI_PROTOCOL = buildExps(true);
  147. var slicedToArray = function () {
  148. function sliceIterator(arr, i) {
  149. var _arr = [];
  150. var _n = true;
  151. var _d = false;
  152. var _e = undefined;
  153. try {
  154. for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
  155. _arr.push(_s.value);
  156. if (i && _arr.length === i) break;
  157. }
  158. } catch (err) {
  159. _d = true;
  160. _e = err;
  161. } finally {
  162. try {
  163. if (!_n && _i["return"]) _i["return"]();
  164. } finally {
  165. if (_d) throw _e;
  166. }
  167. }
  168. return _arr;
  169. }
  170. return function (arr, i) {
  171. if (Array.isArray(arr)) {
  172. return arr;
  173. } else if (Symbol.iterator in Object(arr)) {
  174. return sliceIterator(arr, i);
  175. } else {
  176. throw new TypeError("Invalid attempt to destructure non-iterable instance");
  177. }
  178. };
  179. }();
  180. var toConsumableArray = function (arr) {
  181. if (Array.isArray(arr)) {
  182. for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
  183. return arr2;
  184. } else {
  185. return Array.from(arr);
  186. }
  187. };
  188. /** Highest positive signed 32-bit float value */
  189. var maxInt = 2147483647; // aka. 0x7FFFFFFF or 2^31-1
  190. /** Bootstring parameters */
  191. var base = 36;
  192. var tMin = 1;
  193. var tMax = 26;
  194. var skew = 38;
  195. var damp = 700;
  196. var initialBias = 72;
  197. var initialN = 128; // 0x80
  198. var delimiter = '-'; // '\x2D'
  199. /** Regular expressions */
  200. var regexPunycode = /^xn--/;
  201. var regexNonASCII = /[^\0-\x7E]/; // non-ASCII chars
  202. var regexSeparators = /[\x2E\u3002\uFF0E\uFF61]/g; // RFC 3490 separators
  203. /** Error messages */
  204. var errors = {
  205. 'overflow': 'Overflow: input needs wider integers to process',
  206. 'not-basic': 'Illegal input >= 0x80 (not a basic code point)',
  207. 'invalid-input': 'Invalid input'
  208. };
  209. /** Convenience shortcuts */
  210. var baseMinusTMin = base - tMin;
  211. var floor = Math.floor;
  212. var stringFromCharCode = String.fromCharCode;
  213. /*--------------------------------------------------------------------------*/
  214. /**
  215. * A generic error utility function.
  216. * @private
  217. * @param {String} type The error type.
  218. * @returns {Error} Throws a `RangeError` with the applicable error message.
  219. */
  220. function error$1(type) {
  221. throw new RangeError(errors[type]);
  222. }
  223. /**
  224. * A generic `Array#map` utility function.
  225. * @private
  226. * @param {Array} array The array to iterate over.
  227. * @param {Function} callback The function that gets called for every array
  228. * item.
  229. * @returns {Array} A new array of values returned by the callback function.
  230. */
  231. function map(array, fn) {
  232. var result = [];
  233. var length = array.length;
  234. while (length--) {
  235. result[length] = fn(array[length]);
  236. }
  237. return result;
  238. }
  239. /**
  240. * A simple `Array#map`-like wrapper to work with domain name strings or email
  241. * addresses.
  242. * @private
  243. * @param {String} domain The domain name or email address.
  244. * @param {Function} callback The function that gets called for every
  245. * character.
  246. * @returns {Array} A new string of characters returned by the callback
  247. * function.
  248. */
  249. function mapDomain(string, fn) {
  250. var parts = string.split('@');
  251. var result = '';
  252. if (parts.length > 1) {
  253. // In email addresses, only the domain name should be punycoded. Leave
  254. // the local part (i.e. everything up to `@`) intact.
  255. result = parts[0] + '@';
  256. string = parts[1];
  257. }
  258. // Avoid `split(regex)` for IE8 compatibility. See #17.
  259. string = string.replace(regexSeparators, '\x2E');
  260. var labels = string.split('.');
  261. var encoded = map(labels, fn).join('.');
  262. return result + encoded;
  263. }
  264. /**
  265. * Creates an array containing the numeric code points of each Unicode
  266. * character in the string. While JavaScript uses UCS-2 internally,
  267. * this function will convert a pair of surrogate halves (each of which
  268. * UCS-2 exposes as separate characters) into a single code point,
  269. * matching UTF-16.
  270. * @see `punycode.ucs2.encode`
  271. * @see <https://mathiasbynens.be/notes/javascript-encoding>
  272. * @memberOf punycode.ucs2
  273. * @name decode
  274. * @param {String} string The Unicode input string (UCS-2).
  275. * @returns {Array} The new array of code points.
  276. */
  277. function ucs2decode(string) {
  278. var output = [];
  279. var counter = 0;
  280. var length = string.length;
  281. while (counter < length) {
  282. var value = string.charCodeAt(counter++);
  283. if (value >= 0xD800 && value <= 0xDBFF && counter < length) {
  284. // It's a high surrogate, and there is a next character.
  285. var extra = string.charCodeAt(counter++);
  286. if ((extra & 0xFC00) == 0xDC00) {
  287. // Low surrogate.
  288. output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000);
  289. } else {
  290. // It's an unmatched surrogate; only append this code unit, in case the
  291. // next code unit is the high surrogate of a surrogate pair.
  292. output.push(value);
  293. counter--;
  294. }
  295. } else {
  296. output.push(value);
  297. }
  298. }
  299. return output;
  300. }
  301. /**
  302. * Creates a string based on an array of numeric code points.
  303. * @see `punycode.ucs2.decode`
  304. * @memberOf punycode.ucs2
  305. * @name encode
  306. * @param {Array} codePoints The array of numeric code points.
  307. * @returns {String} The new Unicode string (UCS-2).
  308. */
  309. var ucs2encode = function ucs2encode(array) {
  310. return String.fromCodePoint.apply(String, toConsumableArray(array));
  311. };
  312. /**
  313. * Converts a basic code point into a digit/integer.
  314. * @see `digitToBasic()`
  315. * @private
  316. * @param {Number} codePoint The basic numeric code point value.
  317. * @returns {Number} The numeric value of a basic code point (for use in
  318. * representing integers) in the range `0` to `base - 1`, or `base` if
  319. * the code point does not represent a value.
  320. */
  321. var basicToDigit = function basicToDigit(codePoint) {
  322. if (codePoint - 0x30 < 0x0A) {
  323. return codePoint - 0x16;
  324. }
  325. if (codePoint - 0x41 < 0x1A) {
  326. return codePoint - 0x41;
  327. }
  328. if (codePoint - 0x61 < 0x1A) {
  329. return codePoint - 0x61;
  330. }
  331. return base;
  332. };
  333. /**
  334. * Converts a digit/integer into a basic code point.
  335. * @see `basicToDigit()`
  336. * @private
  337. * @param {Number} digit The numeric value of a basic code point.
  338. * @returns {Number} The basic code point whose value (when used for
  339. * representing integers) is `digit`, which needs to be in the range
  340. * `0` to `base - 1`. If `flag` is non-zero, the uppercase form is
  341. * used; else, the lowercase form is used. The behavior is undefined
  342. * if `flag` is non-zero and `digit` has no uppercase form.
  343. */
  344. var digitToBasic = function digitToBasic(digit, flag) {
  345. // 0..25 map to ASCII a..z or A..Z
  346. // 26..35 map to ASCII 0..9
  347. return digit + 22 + 75 * (digit < 26) - ((flag != 0) << 5);
  348. };
  349. /**
  350. * Bias adaptation function as per section 3.4 of RFC 3492.
  351. * https://tools.ietf.org/html/rfc3492#section-3.4
  352. * @private
  353. */
  354. var adapt = function adapt(delta, numPoints, firstTime) {
  355. var k = 0;
  356. delta = firstTime ? floor(delta / damp) : delta >> 1;
  357. delta += floor(delta / numPoints);
  358. for (; /* no initialization */delta > baseMinusTMin * tMax >> 1; k += base) {
  359. delta = floor(delta / baseMinusTMin);
  360. }
  361. return floor(k + (baseMinusTMin + 1) * delta / (delta + skew));
  362. };
  363. /**
  364. * Converts a Punycode string of ASCII-only symbols to a string of Unicode
  365. * symbols.
  366. * @memberOf punycode
  367. * @param {String} input The Punycode string of ASCII-only symbols.
  368. * @returns {String} The resulting string of Unicode symbols.
  369. */
  370. var decode = function decode(input) {
  371. // Don't use UCS-2.
  372. var output = [];
  373. var inputLength = input.length;
  374. var i = 0;
  375. var n = initialN;
  376. var bias = initialBias;
  377. // Handle the basic code points: let `basic` be the number of input code
  378. // points before the last delimiter, or `0` if there is none, then copy
  379. // the first basic code points to the output.
  380. var basic = input.lastIndexOf(delimiter);
  381. if (basic < 0) {
  382. basic = 0;
  383. }
  384. for (var j = 0; j < basic; ++j) {
  385. // if it's not a basic code point
  386. if (input.charCodeAt(j) >= 0x80) {
  387. error$1('not-basic');
  388. }
  389. output.push(input.charCodeAt(j));
  390. }
  391. // Main decoding loop: start just after the last delimiter if any basic code
  392. // points were copied; start at the beginning otherwise.
  393. for (var index = basic > 0 ? basic + 1 : 0; index < inputLength;) /* no final expression */{
  394. // `index` is the index of the next character to be consumed.
  395. // Decode a generalized variable-length integer into `delta`,
  396. // which gets added to `i`. The overflow checking is easier
  397. // if we increase `i` as we go, then subtract off its starting
  398. // value at the end to obtain `delta`.
  399. var oldi = i;
  400. for (var w = 1, k = base;; /* no condition */k += base) {
  401. if (index >= inputLength) {
  402. error$1('invalid-input');
  403. }
  404. var digit = basicToDigit(input.charCodeAt(index++));
  405. if (digit >= base || digit > floor((maxInt - i) / w)) {
  406. error$1('overflow');
  407. }
  408. i += digit * w;
  409. var t = k <= bias ? tMin : k >= bias + tMax ? tMax : k - bias;
  410. if (digit < t) {
  411. break;
  412. }
  413. var baseMinusT = base - t;
  414. if (w > floor(maxInt / baseMinusT)) {
  415. error$1('overflow');
  416. }
  417. w *= baseMinusT;
  418. }
  419. var out = output.length + 1;
  420. bias = adapt(i - oldi, out, oldi == 0);
  421. // `i` was supposed to wrap around from `out` to `0`,
  422. // incrementing `n` each time, so we'll fix that now:
  423. if (floor(i / out) > maxInt - n) {
  424. error$1('overflow');
  425. }
  426. n += floor(i / out);
  427. i %= out;
  428. // Insert `n` at position `i` of the output.
  429. output.splice(i++, 0, n);
  430. }
  431. return String.fromCodePoint.apply(String, output);
  432. };
  433. /**
  434. * Converts a string of Unicode symbols (e.g. a domain name label) to a
  435. * Punycode string of ASCII-only symbols.
  436. * @memberOf punycode
  437. * @param {String} input The string of Unicode symbols.
  438. * @returns {String} The resulting Punycode string of ASCII-only symbols.
  439. */
  440. var encode = function encode(input) {
  441. var output = [];
  442. // Convert the input in UCS-2 to an array of Unicode code points.
  443. input = ucs2decode(input);
  444. // Cache the length.
  445. var inputLength = input.length;
  446. // Initialize the state.
  447. var n = initialN;
  448. var delta = 0;
  449. var bias = initialBias;
  450. // Handle the basic code points.
  451. var _iteratorNormalCompletion = true;
  452. var _didIteratorError = false;
  453. var _iteratorError = undefined;
  454. try {
  455. for (var _iterator = input[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  456. var _currentValue2 = _step.value;
  457. if (_currentValue2 < 0x80) {
  458. output.push(stringFromCharCode(_currentValue2));
  459. }
  460. }
  461. } catch (err) {
  462. _didIteratorError = true;
  463. _iteratorError = err;
  464. } finally {
  465. try {
  466. if (!_iteratorNormalCompletion && _iterator.return) {
  467. _iterator.return();
  468. }
  469. } finally {
  470. if (_didIteratorError) {
  471. throw _iteratorError;
  472. }
  473. }
  474. }
  475. var basicLength = output.length;
  476. var handledCPCount = basicLength;
  477. // `handledCPCount` is the number of code points that have been handled;
  478. // `basicLength` is the number of basic code points.
  479. // Finish the basic string with a delimiter unless it's empty.
  480. if (basicLength) {
  481. output.push(delimiter);
  482. }
  483. // Main encoding loop:
  484. while (handledCPCount < inputLength) {
  485. // All non-basic code points < n have been handled already. Find the next
  486. // larger one:
  487. var m = maxInt;
  488. var _iteratorNormalCompletion2 = true;
  489. var _didIteratorError2 = false;
  490. var _iteratorError2 = undefined;
  491. try {
  492. for (var _iterator2 = input[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  493. var currentValue = _step2.value;
  494. if (currentValue >= n && currentValue < m) {
  495. m = currentValue;
  496. }
  497. }
  498. // Increase `delta` enough to advance the decoder's <n,i> state to <m,0>,
  499. // but guard against overflow.
  500. } catch (err) {
  501. _didIteratorError2 = true;
  502. _iteratorError2 = err;
  503. } finally {
  504. try {
  505. if (!_iteratorNormalCompletion2 && _iterator2.return) {
  506. _iterator2.return();
  507. }
  508. } finally {
  509. if (_didIteratorError2) {
  510. throw _iteratorError2;
  511. }
  512. }
  513. }
  514. var handledCPCountPlusOne = handledCPCount + 1;
  515. if (m - n > floor((maxInt - delta) / handledCPCountPlusOne)) {
  516. error$1('overflow');
  517. }
  518. delta += (m - n) * handledCPCountPlusOne;
  519. n = m;
  520. var _iteratorNormalCompletion3 = true;
  521. var _didIteratorError3 = false;
  522. var _iteratorError3 = undefined;
  523. try {
  524. for (var _iterator3 = input[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
  525. var _currentValue = _step3.value;
  526. if (_currentValue < n && ++delta > maxInt) {
  527. error$1('overflow');
  528. }
  529. if (_currentValue == n) {
  530. // Represent delta as a generalized variable-length integer.
  531. var q = delta;
  532. for (var k = base;; /* no condition */k += base) {
  533. var t = k <= bias ? tMin : k >= bias + tMax ? tMax : k - bias;
  534. if (q < t) {
  535. break;
  536. }
  537. var qMinusT = q - t;
  538. var baseMinusT = base - t;
  539. output.push(stringFromCharCode(digitToBasic(t + qMinusT % baseMinusT, 0)));
  540. q = floor(qMinusT / baseMinusT);
  541. }
  542. output.push(stringFromCharCode(digitToBasic(q, 0)));
  543. bias = adapt(delta, handledCPCountPlusOne, handledCPCount == basicLength);
  544. delta = 0;
  545. ++handledCPCount;
  546. }
  547. }
  548. } catch (err) {
  549. _didIteratorError3 = true;
  550. _iteratorError3 = err;
  551. } finally {
  552. try {
  553. if (!_iteratorNormalCompletion3 && _iterator3.return) {
  554. _iterator3.return();
  555. }
  556. } finally {
  557. if (_didIteratorError3) {
  558. throw _iteratorError3;
  559. }
  560. }
  561. }
  562. ++delta;
  563. ++n;
  564. }
  565. return output.join('');
  566. };
  567. /**
  568. * Converts a Punycode string representing a domain name or an email address
  569. * to Unicode. Only the Punycoded parts of the input will be converted, i.e.
  570. * it doesn't matter if you call it on a string that has already been
  571. * converted to Unicode.
  572. * @memberOf punycode
  573. * @param {String} input The Punycoded domain name or email address to
  574. * convert to Unicode.
  575. * @returns {String} The Unicode representation of the given Punycode
  576. * string.
  577. */
  578. var toUnicode = function toUnicode(input) {
  579. return mapDomain(input, function (string) {
  580. return regexPunycode.test(string) ? decode(string.slice(4).toLowerCase()) : string;
  581. });
  582. };
  583. /**
  584. * Converts a Unicode string representing a domain name or an email address to
  585. * Punycode. Only the non-ASCII parts of the domain name will be converted,
  586. * i.e. it doesn't matter if you call it with a domain that's already in
  587. * ASCII.
  588. * @memberOf punycode
  589. * @param {String} input The domain name or email address to convert, as a
  590. * Unicode string.
  591. * @returns {String} The Punycode representation of the given domain name or
  592. * email address.
  593. */
  594. var toASCII = function toASCII(input) {
  595. return mapDomain(input, function (string) {
  596. return regexNonASCII.test(string) ? 'xn--' + encode(string) : string;
  597. });
  598. };
  599. /*--------------------------------------------------------------------------*/
  600. /** Define the public API */
  601. var punycode = {
  602. /**
  603. * A string representing the current Punycode.js version number.
  604. * @memberOf punycode
  605. * @type String
  606. */
  607. 'version': '2.1.0',
  608. /**
  609. * An object of methods to convert from JavaScript's internal character
  610. * representation (UCS-2) to Unicode code points, and back.
  611. * @see <https://mathiasbynens.be/notes/javascript-encoding>
  612. * @memberOf punycode
  613. * @type Object
  614. */
  615. 'ucs2': {
  616. 'decode': ucs2decode,
  617. 'encode': ucs2encode
  618. },
  619. 'decode': decode,
  620. 'encode': encode,
  621. 'toASCII': toASCII,
  622. 'toUnicode': toUnicode
  623. };
  624. /**
  625. * URI.js
  626. *
  627. * @fileoverview An RFC 3986 compliant, scheme extendable URI parsing/validating/resolving library for JavaScript.
  628. * @author <a href="mailto:gary.court@gmail.com">Gary Court</a>
  629. * @see http://github.com/garycourt/uri-js
  630. */
  631. /**
  632. * Copyright 2011 Gary Court. All rights reserved.
  633. *
  634. * Redistribution and use in source and binary forms, with or without modification, are
  635. * permitted provided that the following conditions are met:
  636. *
  637. * 1. Redistributions of source code must retain the above copyright notice, this list of
  638. * conditions and the following disclaimer.
  639. *
  640. * 2. Redistributions in binary form must reproduce the above copyright notice, this list
  641. * of conditions and the following disclaimer in the documentation and/or other materials
  642. * provided with the distribution.
  643. *
  644. * THIS SOFTWARE IS PROVIDED BY GARY COURT ``AS IS'' AND ANY EXPRESS OR IMPLIED
  645. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  646. * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GARY COURT OR
  647. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  648. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  649. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  650. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  651. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  652. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  653. *
  654. * The views and conclusions contained in the software and documentation are those of the
  655. * authors and should not be interpreted as representing official policies, either expressed
  656. * or implied, of Gary Court.
  657. */
  658. var SCHEMES = {};
  659. function pctEncChar(chr) {
  660. var c = chr.charCodeAt(0);
  661. var e = void 0;
  662. 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();
  663. return e;
  664. }
  665. function pctDecChars(str) {
  666. var newStr = "";
  667. var i = 0;
  668. var il = str.length;
  669. while (i < il) {
  670. var c = parseInt(str.substr(i + 1, 2), 16);
  671. if (c < 128) {
  672. newStr += String.fromCharCode(c);
  673. i += 3;
  674. } else if (c >= 194 && c < 224) {
  675. if (il - i >= 6) {
  676. var c2 = parseInt(str.substr(i + 4, 2), 16);
  677. newStr += String.fromCharCode((c & 31) << 6 | c2 & 63);
  678. } else {
  679. newStr += str.substr(i, 6);
  680. }
  681. i += 6;
  682. } else if (c >= 224) {
  683. if (il - i >= 9) {
  684. var _c = parseInt(str.substr(i + 4, 2), 16);
  685. var c3 = parseInt(str.substr(i + 7, 2), 16);
  686. newStr += String.fromCharCode((c & 15) << 12 | (_c & 63) << 6 | c3 & 63);
  687. } else {
  688. newStr += str.substr(i, 9);
  689. }
  690. i += 9;
  691. } else {
  692. newStr += str.substr(i, 3);
  693. i += 3;
  694. }
  695. }
  696. return newStr;
  697. }
  698. function _normalizeComponentEncoding(components, protocol) {
  699. function decodeUnreserved(str) {
  700. var decStr = pctDecChars(str);
  701. return !decStr.match(protocol.UNRESERVED) ? str : decStr;
  702. }
  703. if (components.scheme) components.scheme = String(components.scheme).replace(protocol.PCT_ENCODED, decodeUnreserved).toLowerCase().replace(protocol.NOT_SCHEME, "");
  704. if (components.userinfo !== undefined) components.userinfo = String(components.userinfo).replace(protocol.PCT_ENCODED, decodeUnreserved).replace(protocol.NOT_USERINFO, pctEncChar).replace(protocol.PCT_ENCODED, toUpperCase);
  705. 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);
  706. 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);
  707. if (components.query !== undefined) components.query = String(components.query).replace(protocol.PCT_ENCODED, decodeUnreserved).replace(protocol.NOT_QUERY, pctEncChar).replace(protocol.PCT_ENCODED, toUpperCase);
  708. if (components.fragment !== undefined) components.fragment = String(components.fragment).replace(protocol.PCT_ENCODED, decodeUnreserved).replace(protocol.NOT_FRAGMENT, pctEncChar).replace(protocol.PCT_ENCODED, toUpperCase);
  709. return components;
  710. }
  711. function _stripLeadingZeros(str) {
  712. return str.replace(/^0*(.*)/, "$1") || "0";
  713. }
  714. function _normalizeIPv4(host, protocol) {
  715. var matches = host.match(protocol.IPV4ADDRESS) || [];
  716. var _matches = slicedToArray(matches, 2),
  717. address = _matches[1];
  718. if (address) {
  719. return address.split(".").map(_stripLeadingZeros).join(".");
  720. } else {
  721. return host;
  722. }
  723. }
  724. function _normalizeIPv6(host, protocol) {
  725. var matches = host.match(protocol.IPV6ADDRESS) || [];
  726. var _matches2 = slicedToArray(matches, 3),
  727. address = _matches2[1],
  728. zone = _matches2[2];
  729. if (address) {
  730. var _address$toLowerCase$ = address.toLowerCase().split('::').reverse(),
  731. _address$toLowerCase$2 = slicedToArray(_address$toLowerCase$, 2),
  732. last = _address$toLowerCase$2[0],
  733. first = _address$toLowerCase$2[1];
  734. var firstFields = first ? first.split(":").map(_stripLeadingZeros) : [];
  735. var lastFields = last.split(":").map(_stripLeadingZeros);
  736. var isLastFieldIPv4Address = protocol.IPV4ADDRESS.test(lastFields[lastFields.length - 1]);
  737. var fieldCount = isLastFieldIPv4Address ? 7 : 8;
  738. var lastFieldsStart = lastFields.length - fieldCount;
  739. var fields = Array(fieldCount);
  740. for (var x = 0; x < fieldCount; ++x) {
  741. fields[x] = firstFields[x] || lastFields[lastFieldsStart + x] || '';
  742. }
  743. if (isLastFieldIPv4Address) {
  744. fields[fieldCount - 1] = _normalizeIPv4(fields[fieldCount - 1], protocol);
  745. }
  746. var allZeroFields = fields.reduce(function (acc, field, index) {
  747. if (!field || field === "0") {
  748. var lastLongest = acc[acc.length - 1];
  749. if (lastLongest && lastLongest.index + lastLongest.length === index) {
  750. lastLongest.length++;
  751. } else {
  752. acc.push({ index: index, length: 1 });
  753. }
  754. }
  755. return acc;
  756. }, []);
  757. var longestZeroFields = allZeroFields.sort(function (a, b) {
  758. return b.length - a.length;
  759. })[0];
  760. var newHost = void 0;
  761. if (longestZeroFields && longestZeroFields.length > 1) {
  762. var newFirst = fields.slice(0, longestZeroFields.index);
  763. var newLast = fields.slice(longestZeroFields.index + longestZeroFields.length);
  764. newHost = newFirst.join(":") + "::" + newLast.join(":");
  765. } else {
  766. newHost = fields.join(":");
  767. }
  768. if (zone) {
  769. newHost += "%" + zone;
  770. }
  771. return newHost;
  772. } else {
  773. return host;
  774. }
  775. }
  776. var URI_PARSE = /^(?:([^:\/?#]+):)?(?:\/\/((?:([^\/?#@]*)@)?(\[[^\/?#\]]+\]|[^\/?#:]*)(?:\:(\d*))?))?([^?#]*)(?:\?([^#]*))?(?:#((?:.|\n|\r)*))?/i;
  777. var NO_MATCH_IS_UNDEFINED = "".match(/(){0}/)[1] === undefined;
  778. function parse(uriString) {
  779. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  780. var components = {};
  781. var protocol = options.iri !== false ? IRI_PROTOCOL : URI_PROTOCOL;
  782. if (options.reference === "suffix") uriString = (options.scheme ? options.scheme + ":" : "") + "//" + uriString;
  783. var matches = uriString.match(URI_PARSE);
  784. if (matches) {
  785. if (NO_MATCH_IS_UNDEFINED) {
  786. //store each component
  787. components.scheme = matches[1];
  788. components.userinfo = matches[3];
  789. components.host = matches[4];
  790. components.port = parseInt(matches[5], 10);
  791. components.path = matches[6] || "";
  792. components.query = matches[7];
  793. components.fragment = matches[8];
  794. //fix port number
  795. if (isNaN(components.port)) {
  796. components.port = matches[5];
  797. }
  798. } else {
  799. //IE FIX for improper RegExp matching
  800. //store each component
  801. components.scheme = matches[1] || undefined;
  802. components.userinfo = uriString.indexOf("@") !== -1 ? matches[3] : undefined;
  803. components.host = uriString.indexOf("//") !== -1 ? matches[4] : undefined;
  804. components.port = parseInt(matches[5], 10);
  805. components.path = matches[6] || "";
  806. components.query = uriString.indexOf("?") !== -1 ? matches[7] : undefined;
  807. components.fragment = uriString.indexOf("#") !== -1 ? matches[8] : undefined;
  808. //fix port number
  809. if (isNaN(components.port)) {
  810. components.port = uriString.match(/\/\/(?:.|\n)*\:(?:\/|\?|\#|$)/) ? matches[4] : undefined;
  811. }
  812. }
  813. if (components.host) {
  814. //normalize IP hosts
  815. components.host = _normalizeIPv6(_normalizeIPv4(components.host, protocol), protocol);
  816. }
  817. //determine reference type
  818. if (components.scheme === undefined && components.userinfo === undefined && components.host === undefined && components.port === undefined && !components.path && components.query === undefined) {
  819. components.reference = "same-document";
  820. } else if (components.scheme === undefined) {
  821. components.reference = "relative";
  822. } else if (components.fragment === undefined) {
  823. components.reference = "absolute";
  824. } else {
  825. components.reference = "uri";
  826. }
  827. //check for reference errors
  828. if (options.reference && options.reference !== "suffix" && options.reference !== components.reference) {
  829. components.error = components.error || "URI is not a " + options.reference + " reference.";
  830. }
  831. //find scheme handler
  832. var schemeHandler = SCHEMES[(options.scheme || components.scheme || "").toLowerCase()];
  833. //check if scheme can't handle IRIs
  834. if (!options.unicodeSupport && (!schemeHandler || !schemeHandler.unicodeSupport)) {
  835. //if host component is a domain name
  836. if (components.host && (options.domainHost || schemeHandler && schemeHandler.domainHost)) {
  837. //convert Unicode IDN -> ASCII IDN
  838. try {
  839. components.host = punycode.toASCII(components.host.replace(protocol.PCT_ENCODED, pctDecChars).toLowerCase());
  840. } catch (e) {
  841. components.error = components.error || "Host's domain name can not be converted to ASCII via punycode: " + e;
  842. }
  843. }
  844. //convert IRI -> URI
  845. _normalizeComponentEncoding(components, URI_PROTOCOL);
  846. } else {
  847. //normalize encodings
  848. _normalizeComponentEncoding(components, protocol);
  849. }
  850. //perform scheme specific parsing
  851. if (schemeHandler && schemeHandler.parse) {
  852. schemeHandler.parse(components, options);
  853. }
  854. } else {
  855. components.error = components.error || "URI can not be parsed.";
  856. }
  857. return components;
  858. }
  859. function _recomposeAuthority(components, options) {
  860. var protocol = options.iri !== false ? IRI_PROTOCOL : URI_PROTOCOL;
  861. var uriTokens = [];
  862. if (components.userinfo !== undefined) {
  863. uriTokens.push(components.userinfo);
  864. uriTokens.push("@");
  865. }
  866. if (components.host !== undefined) {
  867. //normalize IP hosts, add brackets and escape zone separator for IPv6
  868. uriTokens.push(_normalizeIPv6(_normalizeIPv4(String(components.host), protocol), protocol).replace(protocol.IPV6ADDRESS, function (_, $1, $2) {
  869. return "[" + $1 + ($2 ? "%25" + $2 : "") + "]";
  870. }));
  871. }
  872. if (typeof components.port === "number") {
  873. uriTokens.push(":");
  874. uriTokens.push(components.port.toString(10));
  875. }
  876. return uriTokens.length ? uriTokens.join("") : undefined;
  877. }
  878. var RDS1 = /^\.\.?\//;
  879. var RDS2 = /^\/\.(\/|$)/;
  880. var RDS3 = /^\/\.\.(\/|$)/;
  881. var RDS5 = /^\/?(?:.|\n)*?(?=\/|$)/;
  882. function removeDotSegments(input) {
  883. var output = [];
  884. while (input.length) {
  885. if (input.match(RDS1)) {
  886. input = input.replace(RDS1, "");
  887. } else if (input.match(RDS2)) {
  888. input = input.replace(RDS2, "/");
  889. } else if (input.match(RDS3)) {
  890. input = input.replace(RDS3, "/");
  891. output.pop();
  892. } else if (input === "." || input === "..") {
  893. input = "";
  894. } else {
  895. var im = input.match(RDS5);
  896. if (im) {
  897. var s = im[0];
  898. input = input.slice(s.length);
  899. output.push(s);
  900. } else {
  901. throw new Error("Unexpected dot segment condition");
  902. }
  903. }
  904. }
  905. return output.join("");
  906. }
  907. function serialize(components) {
  908. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  909. var protocol = options.iri ? IRI_PROTOCOL : URI_PROTOCOL;
  910. var uriTokens = [];
  911. //find scheme handler
  912. var schemeHandler = SCHEMES[(options.scheme || components.scheme || "").toLowerCase()];
  913. //perform scheme specific serialization
  914. if (schemeHandler && schemeHandler.serialize) schemeHandler.serialize(components, options);
  915. if (components.host) {
  916. //if host component is an IPv6 address
  917. if (protocol.IPV6ADDRESS.test(components.host)) {}
  918. //TODO: normalize IPv6 address as per RFC 5952
  919. //if host component is a domain name
  920. else if (options.domainHost || schemeHandler && schemeHandler.domainHost) {
  921. //convert IDN via punycode
  922. try {
  923. components.host = !options.iri ? punycode.toASCII(components.host.replace(protocol.PCT_ENCODED, pctDecChars).toLowerCase()) : punycode.toUnicode(components.host);
  924. } catch (e) {
  925. components.error = components.error || "Host's domain name can not be converted to " + (!options.iri ? "ASCII" : "Unicode") + " via punycode: " + e;
  926. }
  927. }
  928. }
  929. //normalize encoding
  930. _normalizeComponentEncoding(components, protocol);
  931. if (options.reference !== "suffix" && components.scheme) {
  932. uriTokens.push(components.scheme);
  933. uriTokens.push(":");
  934. }
  935. var authority = _recomposeAuthority(components, options);
  936. if (authority !== undefined) {
  937. if (options.reference !== "suffix") {
  938. uriTokens.push("//");
  939. }
  940. uriTokens.push(authority);
  941. if (components.path && components.path.charAt(0) !== "/") {
  942. uriTokens.push("/");
  943. }
  944. }
  945. if (components.path !== undefined) {
  946. var s = components.path;
  947. if (!options.absolutePath && (!schemeHandler || !schemeHandler.absolutePath)) {
  948. s = removeDotSegments(s);
  949. }
  950. if (authority === undefined) {
  951. s = s.replace(/^\/\//, "/%2F"); //don't allow the path to start with "//"
  952. }
  953. uriTokens.push(s);
  954. }
  955. if (components.query !== undefined) {
  956. uriTokens.push("?");
  957. uriTokens.push(components.query);
  958. }
  959. if (components.fragment !== undefined) {
  960. uriTokens.push("#");
  961. uriTokens.push(components.fragment);
  962. }
  963. return uriTokens.join(""); //merge tokens into a string
  964. }
  965. function resolveComponents(base, relative) {
  966. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  967. var skipNormalization = arguments[3];
  968. var target = {};
  969. if (!skipNormalization) {
  970. base = parse(serialize(base, options), options); //normalize base components
  971. relative = parse(serialize(relative, options), options); //normalize relative components
  972. }
  973. options = options || {};
  974. if (!options.tolerant && relative.scheme) {
  975. target.scheme = relative.scheme;
  976. //target.authority = relative.authority;
  977. target.userinfo = relative.userinfo;
  978. target.host = relative.host;
  979. target.port = relative.port;
  980. target.path = removeDotSegments(relative.path || "");
  981. target.query = relative.query;
  982. } else {
  983. if (relative.userinfo !== undefined || relative.host !== undefined || relative.port !== undefined) {
  984. //target.authority = relative.authority;
  985. target.userinfo = relative.userinfo;
  986. target.host = relative.host;
  987. target.port = relative.port;
  988. target.path = removeDotSegments(relative.path || "");
  989. target.query = relative.query;
  990. } else {
  991. if (!relative.path) {
  992. target.path = base.path;
  993. if (relative.query !== undefined) {
  994. target.query = relative.query;
  995. } else {
  996. target.query = base.query;
  997. }
  998. } else {
  999. if (relative.path.charAt(0) === "/") {
  1000. target.path = removeDotSegments(relative.path);
  1001. } else {
  1002. if ((base.userinfo !== undefined || base.host !== undefined || base.port !== undefined) && !base.path) {
  1003. target.path = "/" + relative.path;
  1004. } else if (!base.path) {
  1005. target.path = relative.path;
  1006. } else {
  1007. target.path = base.path.slice(0, base.path.lastIndexOf("/") + 1) + relative.path;
  1008. }
  1009. target.path = removeDotSegments(target.path);
  1010. }
  1011. target.query = relative.query;
  1012. }
  1013. //target.authority = base.authority;
  1014. target.userinfo = base.userinfo;
  1015. target.host = base.host;
  1016. target.port = base.port;
  1017. }
  1018. target.scheme = base.scheme;
  1019. }
  1020. target.fragment = relative.fragment;
  1021. return target;
  1022. }
  1023. function resolve(baseURI, relativeURI, options) {
  1024. var schemelessOptions = assign({ scheme: 'null' }, options);
  1025. return serialize(resolveComponents(parse(baseURI, schemelessOptions), parse(relativeURI, schemelessOptions), schemelessOptions, true), schemelessOptions);
  1026. }
  1027. function normalize(uri, options) {
  1028. if (typeof uri === "string") {
  1029. uri = serialize(parse(uri, options), options);
  1030. } else if (typeOf(uri) === "object") {
  1031. uri = parse(serialize(uri, options), options);
  1032. }
  1033. return uri;
  1034. }
  1035. function equal(uriA, uriB, options) {
  1036. if (typeof uriA === "string") {
  1037. uriA = serialize(parse(uriA, options), options);
  1038. } else if (typeOf(uriA) === "object") {
  1039. uriA = serialize(uriA, options);
  1040. }
  1041. if (typeof uriB === "string") {
  1042. uriB = serialize(parse(uriB, options), options);
  1043. } else if (typeOf(uriB) === "object") {
  1044. uriB = serialize(uriB, options);
  1045. }
  1046. return uriA === uriB;
  1047. }
  1048. function escapeComponent(str, options) {
  1049. return str && str.toString().replace(!options || !options.iri ? URI_PROTOCOL.ESCAPE : IRI_PROTOCOL.ESCAPE, pctEncChar);
  1050. }
  1051. function unescapeComponent(str, options) {
  1052. return str && str.toString().replace(!options || !options.iri ? URI_PROTOCOL.PCT_ENCODED : IRI_PROTOCOL.PCT_ENCODED, pctDecChars);
  1053. }
  1054. var handler = {
  1055. scheme: "http",
  1056. domainHost: true,
  1057. parse: function parse(components, options) {
  1058. //report missing host
  1059. if (!components.host) {
  1060. components.error = components.error || "HTTP URIs must have a host.";
  1061. }
  1062. return components;
  1063. },
  1064. serialize: function serialize(components, options) {
  1065. //normalize the default port
  1066. if (components.port === (String(components.scheme).toLowerCase() !== "https" ? 80 : 443) || components.port === "") {
  1067. components.port = undefined;
  1068. }
  1069. //normalize the empty path
  1070. if (!components.path) {
  1071. components.path = "/";
  1072. }
  1073. //NOTE: We do not parse query strings for HTTP URIs
  1074. //as WWW Form Url Encoded query strings are part of the HTML4+ spec,
  1075. //and not the HTTP spec.
  1076. return components;
  1077. }
  1078. };
  1079. var handler$1 = {
  1080. scheme: "https",
  1081. domainHost: handler.domainHost,
  1082. parse: handler.parse,
  1083. serialize: handler.serialize
  1084. };
  1085. var O = {};
  1086. var isIRI = true;
  1087. //RFC 3986
  1088. var UNRESERVED$$ = "[A-Za-z0-9\\-\\.\\_\\~" + (isIRI ? "\\xA0-\\u200D\\u2010-\\u2029\\u202F-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF" : "") + "]";
  1089. var HEXDIG$$ = "[0-9A-Fa-f]"; //case-insensitive
  1090. var PCT_ENCODED$ = subexp(subexp("%[EFef]" + HEXDIG$$ + "%" + HEXDIG$$ + HEXDIG$$ + "%" + HEXDIG$$ + HEXDIG$$) + "|" + subexp("%[89A-Fa-f]" + HEXDIG$$ + "%" + HEXDIG$$ + HEXDIG$$) + "|" + subexp("%" + HEXDIG$$ + HEXDIG$$)); //expanded
  1091. //RFC 5322, except these symbols as per RFC 6068: @ : / ? # [ ] & ; =
  1092. //const ATEXT$$ = "[A-Za-z0-9\\!\\#\\$\\%\\&\\'\\*\\+\\-\\/\\=\\?\\^\\_\\`\\{\\|\\}\\~]";
  1093. //const WSP$$ = "[\\x20\\x09]";
  1094. //const OBS_QTEXT$$ = "[\\x01-\\x08\\x0B\\x0C\\x0E-\\x1F\\x7F]"; //(%d1-8 / %d11-12 / %d14-31 / %d127)
  1095. //const QTEXT$$ = merge("[\\x21\\x23-\\x5B\\x5D-\\x7E]", OBS_QTEXT$$); //%d33 / %d35-91 / %d93-126 / obs-qtext
  1096. //const VCHAR$$ = "[\\x21-\\x7E]";
  1097. //const WSP$$ = "[\\x20\\x09]";
  1098. //const OBS_QP$ = subexp("\\\\" + merge("[\\x00\\x0D\\x0A]", OBS_QTEXT$$)); //%d0 / CR / LF / obs-qtext
  1099. //const FWS$ = subexp(subexp(WSP$$ + "*" + "\\x0D\\x0A") + "?" + WSP$$ + "+");
  1100. //const QUOTED_PAIR$ = subexp(subexp("\\\\" + subexp(VCHAR$$ + "|" + WSP$$)) + "|" + OBS_QP$);
  1101. //const QUOTED_STRING$ = subexp('\\"' + subexp(FWS$ + "?" + QCONTENT$) + "*" + FWS$ + "?" + '\\"');
  1102. var ATEXT$$ = "[A-Za-z0-9\\!\\$\\%\\'\\*\\+\\-\\^\\_\\`\\{\\|\\}\\~]";
  1103. var QTEXT$$ = "[\\!\\$\\%\\'\\(\\)\\*\\+\\,\\-\\.0-9\\<\\>A-Z\\x5E-\\x7E]";
  1104. var VCHAR$$ = merge(QTEXT$$, "[\\\"\\\\]");
  1105. var SOME_DELIMS$$ = "[\\!\\$\\'\\(\\)\\*\\+\\,\\;\\:\\@]";
  1106. var UNRESERVED = new RegExp(UNRESERVED$$, "g");
  1107. var PCT_ENCODED = new RegExp(PCT_ENCODED$, "g");
  1108. var NOT_LOCAL_PART = new RegExp(merge("[^]", ATEXT$$, "[\\.]", '[\\"]', VCHAR$$), "g");
  1109. var NOT_HFNAME = new RegExp(merge("[^]", UNRESERVED$$, SOME_DELIMS$$), "g");
  1110. var NOT_HFVALUE = NOT_HFNAME;
  1111. function decodeUnreserved(str) {
  1112. var decStr = pctDecChars(str);
  1113. return !decStr.match(UNRESERVED) ? str : decStr;
  1114. }
  1115. var handler$2 = {
  1116. scheme: "mailto",
  1117. parse: function parse$$1(components, options) {
  1118. var mailtoComponents = components;
  1119. var to = mailtoComponents.to = mailtoComponents.path ? mailtoComponents.path.split(",") : [];
  1120. mailtoComponents.path = undefined;
  1121. if (mailtoComponents.query) {
  1122. var unknownHeaders = false;
  1123. var headers = {};
  1124. var hfields = mailtoComponents.query.split("&");
  1125. for (var x = 0, xl = hfields.length; x < xl; ++x) {
  1126. var hfield = hfields[x].split("=");
  1127. switch (hfield[0]) {
  1128. case "to":
  1129. var toAddrs = hfield[1].split(",");
  1130. for (var _x = 0, _xl = toAddrs.length; _x < _xl; ++_x) {
  1131. to.push(toAddrs[_x]);
  1132. }
  1133. break;
  1134. case "subject":
  1135. mailtoComponents.subject = unescapeComponent(hfield[1], options);
  1136. break;
  1137. case "body":
  1138. mailtoComponents.body = unescapeComponent(hfield[1], options);
  1139. break;
  1140. default:
  1141. unknownHeaders = true;
  1142. headers[unescapeComponent(hfield[0], options)] = unescapeComponent(hfield[1], options);
  1143. break;
  1144. }
  1145. }
  1146. if (unknownHeaders) mailtoComponents.headers = headers;
  1147. }
  1148. mailtoComponents.query = undefined;
  1149. for (var _x2 = 0, _xl2 = to.length; _x2 < _xl2; ++_x2) {
  1150. var addr = to[_x2].split("@");
  1151. addr[0] = unescapeComponent(addr[0]);
  1152. if (!options.unicodeSupport) {
  1153. //convert Unicode IDN -> ASCII IDN
  1154. try {
  1155. addr[1] = punycode.toASCII(unescapeComponent(addr[1], options).toLowerCase());
  1156. } catch (e) {
  1157. mailtoComponents.error = mailtoComponents.error || "Email address's domain name can not be converted to ASCII via punycode: " + e;
  1158. }
  1159. } else {
  1160. addr[1] = unescapeComponent(addr[1], options).toLowerCase();
  1161. }
  1162. to[_x2] = addr.join("@");
  1163. }
  1164. return mailtoComponents;
  1165. },
  1166. serialize: function serialize$$1(mailtoComponents, options) {
  1167. var components = mailtoComponents;
  1168. var to = toArray(mailtoComponents.to);
  1169. if (to) {
  1170. for (var x = 0, xl = to.length; x < xl; ++x) {
  1171. var toAddr = String(to[x]);
  1172. var atIdx = toAddr.lastIndexOf("@");
  1173. var localPart = toAddr.slice(0, atIdx).replace(PCT_ENCODED, decodeUnreserved).replace(PCT_ENCODED, toUpperCase).replace(NOT_LOCAL_PART, pctEncChar);
  1174. var domain = toAddr.slice(atIdx + 1);
  1175. //convert IDN via punycode
  1176. try {
  1177. domain = !options.iri ? punycode.toASCII(unescapeComponent(domain, options).toLowerCase()) : punycode.toUnicode(domain);
  1178. } catch (e) {
  1179. components.error = components.error || "Email address's domain name can not be converted to " + (!options.iri ? "ASCII" : "Unicode") + " via punycode: " + e;
  1180. }
  1181. to[x] = localPart + "@" + domain;
  1182. }
  1183. components.path = to.join(",");
  1184. }
  1185. var headers = mailtoComponents.headers = mailtoComponents.headers || {};
  1186. if (mailtoComponents.subject) headers["subject"] = mailtoComponents.subject;
  1187. if (mailtoComponents.body) headers["body"] = mailtoComponents.body;
  1188. var fields = [];
  1189. for (var name in headers) {
  1190. if (headers[name] !== O[name]) {
  1191. 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));
  1192. }
  1193. }
  1194. if (fields.length) {
  1195. components.query = fields.join("&");
  1196. }
  1197. return components;
  1198. }
  1199. };
  1200. var URN_PARSE = /^([^\:]+)\:(.*)/;
  1201. //RFC 2141
  1202. var handler$3 = {
  1203. scheme: "urn",
  1204. parse: function parse$$1(components, options) {
  1205. var matches = components.path && components.path.match(URN_PARSE);
  1206. var urnComponents = components;
  1207. if (matches) {
  1208. var scheme = options.scheme || urnComponents.scheme || "urn";
  1209. var nid = matches[1].toLowerCase();
  1210. var nss = matches[2];
  1211. var urnScheme = scheme + ":" + (options.nid || nid);
  1212. var schemeHandler = SCHEMES[urnScheme];
  1213. urnComponents.nid = nid;
  1214. urnComponents.nss = nss;
  1215. urnComponents.path = undefined;
  1216. if (schemeHandler) {
  1217. urnComponents = schemeHandler.parse(urnComponents, options);
  1218. }
  1219. } else {
  1220. urnComponents.error = urnComponents.error || "URN can not be parsed.";
  1221. }
  1222. return urnComponents;
  1223. },
  1224. serialize: function serialize$$1(urnComponents, options) {
  1225. var scheme = options.scheme || urnComponents.scheme || "urn";
  1226. var nid = urnComponents.nid;
  1227. var urnScheme = scheme + ":" + (options.nid || nid);
  1228. var schemeHandler = SCHEMES[urnScheme];
  1229. if (schemeHandler) {
  1230. urnComponents = schemeHandler.serialize(urnComponents, options);
  1231. }
  1232. var uriComponents = urnComponents;
  1233. var nss = urnComponents.nss;
  1234. uriComponents.path = (nid || options.nid) + ":" + nss;
  1235. return uriComponents;
  1236. }
  1237. };
  1238. var UUID = /^[0-9A-Fa-f]{8}(?:\-[0-9A-Fa-f]{4}){3}\-[0-9A-Fa-f]{12}$/;
  1239. //RFC 4122
  1240. var handler$4 = {
  1241. scheme: "urn:uuid",
  1242. parse: function parse(urnComponents, options) {
  1243. var uuidComponents = urnComponents;
  1244. uuidComponents.uuid = uuidComponents.nss;
  1245. uuidComponents.nss = undefined;
  1246. if (!options.tolerant && (!uuidComponents.uuid || !uuidComponents.uuid.match(UUID))) {
  1247. uuidComponents.error = uuidComponents.error || "UUID is not valid.";
  1248. }
  1249. return uuidComponents;
  1250. },
  1251. serialize: function serialize(uuidComponents, options) {
  1252. var urnComponents = uuidComponents;
  1253. //normalize UUID
  1254. urnComponents.nss = (uuidComponents.uuid || "").toLowerCase();
  1255. return urnComponents;
  1256. }
  1257. };
  1258. SCHEMES[handler.scheme] = handler;
  1259. SCHEMES[handler$1.scheme] = handler$1;
  1260. SCHEMES[handler$2.scheme] = handler$2;
  1261. SCHEMES[handler$3.scheme] = handler$3;
  1262. SCHEMES[handler$4.scheme] = handler$4;
  1263. exports.SCHEMES = SCHEMES;
  1264. exports.pctEncChar = pctEncChar;
  1265. exports.pctDecChars = pctDecChars;
  1266. exports.parse = parse;
  1267. exports.removeDotSegments = removeDotSegments;
  1268. exports.serialize = serialize;
  1269. exports.resolveComponents = resolveComponents;
  1270. exports.resolve = resolve;
  1271. exports.normalize = normalize;
  1272. exports.equal = equal;
  1273. exports.escapeComponent = escapeComponent;
  1274. exports.unescapeComponent = unescapeComponent;
  1275. Object.defineProperty(exports, '__esModule', { value: true });
  1276. })));
  1277. //# sourceMappingURL=uri.all.js.map