1 /** @license URI.js v4.4.0 (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';
9 for (var _len = arguments.length, sets = Array(_len), _key = 0; _key < _len; _key++) {
10 sets[_key] = arguments[_key];
13 if (sets.length > 1) {
14 sets[0] = sets[0].slice(0, -1);
15 var xl = sets.length - 1;
16 for (var x = 1; x < xl; ++x) {
17 sets[x] = sets[x].slice(1, -1);
19 sets[xl] = sets[xl].slice(1);
25 function subexp(str) {
26 return "(?:" + str + ")";
29 return o === undefined ? "undefined" : o === null ? "null" : Object.prototype.toString.call(o).split(" ").pop().split("]").shift().toLowerCase();
31 function toUpperCase(str) {
32 return str.toUpperCase();
34 function toArray(obj) {
35 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) : [];
37 function assign(target, source) {
40 for (var key in source) {
41 obj[key] = source[key];
47 function buildExps(isIRI) {
48 var ALPHA$$ = "[A-Za-z]",
52 HEXDIG$$ = merge(DIGIT$$, "[A-Fa-f]"),
56 PCT_ENCODED$ = subexp(subexp("%[EFef]" + HEXDIG$$ + "%" + HEXDIG$$ + HEXDIG$$ + "%" + HEXDIG$$ + HEXDIG$$) + "|" + subexp("%[89A-Fa-f]" + HEXDIG$$ + "%" + HEXDIG$$ + HEXDIG$$) + "|" + subexp("%" + HEXDIG$$ + HEXDIG$$)),
58 GEN_DELIMS$$ = "[\\:\\/\\?\\#\\[\\]\\@]",
59 SUB_DELIMS$$ = "[\\!\\$\\&\\'\\(\\)\\*\\+\\,\\;\\=]",
60 RESERVED$$ = merge(GEN_DELIMS$$, SUB_DELIMS$$),
61 UCSCHAR$$ = isIRI ? "[\\xA0-\\u200D\\u2010-\\u2029\\u202F-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF]" : "[]",
62 //subset, excludes bidi control characters
63 IPRIVATE$$ = isIRI ? "[\\uE000-\\uF8FF]" : "[]",
65 UNRESERVED$$ = merge(ALPHA$$, DIGIT$$, "[\\-\\.\\_\\~]", UCSCHAR$$),
66 SCHEME$ = subexp(ALPHA$$ + merge(ALPHA$$, DIGIT$$, "[\\+\\-\\.]") + "*"),
67 USERINFO$ = subexp(subexp(PCT_ENCODED$ + "|" + merge(UNRESERVED$$, SUB_DELIMS$$, "[\\:]")) + "*"),
68 DEC_OCTET$ = subexp(subexp("25[0-5]") + "|" + subexp("2[0-4]" + DIGIT$$) + "|" + subexp("1" + DIGIT$$ + DIGIT$$) + "|" + subexp("[1-9]" + DIGIT$$) + "|" + DIGIT$$),
69 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$$),
70 //relaxed parsing rules
71 IPV4ADDRESS$ = subexp(DEC_OCTET_RELAXED$ + "\\." + DEC_OCTET_RELAXED$ + "\\." + DEC_OCTET_RELAXED$ + "\\." + DEC_OCTET_RELAXED$),
72 H16$ = subexp(HEXDIG$$ + "{1,4}"),
73 LS32$ = subexp(subexp(H16$ + "\\:" + H16$) + "|" + IPV4ADDRESS$),
74 IPV6ADDRESS1$ = subexp(subexp(H16$ + "\\:") + "{6}" + LS32$),
76 IPV6ADDRESS2$ = subexp("\\:\\:" + subexp(H16$ + "\\:") + "{5}" + LS32$),
77 // "::" 5( h16 ":" ) ls32
78 IPV6ADDRESS3$ = subexp(subexp(H16$) + "?\\:\\:" + subexp(H16$ + "\\:") + "{4}" + LS32$),
79 //[ h16 ] "::" 4( h16 ":" ) ls32
80 IPV6ADDRESS4$ = subexp(subexp(subexp(H16$ + "\\:") + "{0,1}" + H16$) + "?\\:\\:" + subexp(H16$ + "\\:") + "{3}" + LS32$),
81 //[ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32
82 IPV6ADDRESS5$ = subexp(subexp(subexp(H16$ + "\\:") + "{0,2}" + H16$) + "?\\:\\:" + subexp(H16$ + "\\:") + "{2}" + LS32$),
83 //[ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32
84 IPV6ADDRESS6$ = subexp(subexp(subexp(H16$ + "\\:") + "{0,3}" + H16$) + "?\\:\\:" + H16$ + "\\:" + LS32$),
85 //[ *3( h16 ":" ) h16 ] "::" h16 ":" ls32
86 IPV6ADDRESS7$ = subexp(subexp(subexp(H16$ + "\\:") + "{0,4}" + H16$) + "?\\:\\:" + LS32$),
87 //[ *4( h16 ":" ) h16 ] "::" ls32
88 IPV6ADDRESS8$ = subexp(subexp(subexp(H16$ + "\\:") + "{0,5}" + H16$) + "?\\:\\:" + H16$),
89 //[ *5( h16 ":" ) h16 ] "::" h16
90 IPV6ADDRESS9$ = subexp(subexp(subexp(H16$ + "\\:") + "{0,6}" + H16$) + "?\\:\\:"),
91 //[ *6( h16 ":" ) h16 ] "::"
92 IPV6ADDRESS$ = subexp([IPV6ADDRESS1$, IPV6ADDRESS2$, IPV6ADDRESS3$, IPV6ADDRESS4$, IPV6ADDRESS5$, IPV6ADDRESS6$, IPV6ADDRESS7$, IPV6ADDRESS8$, IPV6ADDRESS9$].join("|")),
93 ZONEID$ = subexp(subexp(UNRESERVED$$ + "|" + PCT_ENCODED$) + "+"),
95 IPV6ADDRZ$ = subexp(IPV6ADDRESS$ + "\\%25" + ZONEID$),
97 IPV6ADDRZ_RELAXED$ = subexp(IPV6ADDRESS$ + subexp("\\%25|\\%(?!" + HEXDIG$$ + "{2})") + ZONEID$),
98 //RFC 6874, with relaxed parsing rules
99 IPVFUTURE$ = subexp("[vV]" + HEXDIG$$ + "+\\." + merge(UNRESERVED$$, SUB_DELIMS$$, "[\\:]") + "+"),
100 IP_LITERAL$ = subexp("\\[" + subexp(IPV6ADDRZ_RELAXED$ + "|" + IPV6ADDRESS$ + "|" + IPVFUTURE$) + "\\]"),
102 REG_NAME$ = subexp(subexp(PCT_ENCODED$ + "|" + merge(UNRESERVED$$, SUB_DELIMS$$)) + "*"),
103 HOST$ = subexp(IP_LITERAL$ + "|" + IPV4ADDRESS$ + "(?!" + REG_NAME$ + ")" + "|" + REG_NAME$),
104 PORT$ = subexp(DIGIT$$ + "*"),
105 AUTHORITY$ = subexp(subexp(USERINFO$ + "@") + "?" + HOST$ + subexp("\\:" + PORT$) + "?"),
106 PCHAR$ = subexp(PCT_ENCODED$ + "|" + merge(UNRESERVED$$, SUB_DELIMS$$, "[\\:\\@]")),
107 SEGMENT$ = subexp(PCHAR$ + "*"),
108 SEGMENT_NZ$ = subexp(PCHAR$ + "+"),
109 SEGMENT_NZ_NC$ = subexp(subexp(PCT_ENCODED$ + "|" + merge(UNRESERVED$$, SUB_DELIMS$$, "[\\@]")) + "+"),
110 PATH_ABEMPTY$ = subexp(subexp("\\/" + SEGMENT$) + "*"),
111 PATH_ABSOLUTE$ = subexp("\\/" + subexp(SEGMENT_NZ$ + PATH_ABEMPTY$) + "?"),
113 PATH_NOSCHEME$ = subexp(SEGMENT_NZ_NC$ + PATH_ABEMPTY$),
115 PATH_ROOTLESS$ = subexp(SEGMENT_NZ$ + PATH_ABEMPTY$),
117 PATH_EMPTY$ = "(?!" + PCHAR$ + ")",
118 PATH$ = subexp(PATH_ABEMPTY$ + "|" + PATH_ABSOLUTE$ + "|" + PATH_NOSCHEME$ + "|" + PATH_ROOTLESS$ + "|" + PATH_EMPTY$),
119 QUERY$ = subexp(subexp(PCHAR$ + "|" + merge("[\\/\\?]", IPRIVATE$$)) + "*"),
120 FRAGMENT$ = subexp(subexp(PCHAR$ + "|[\\/\\?]") + "*"),
121 HIER_PART$ = subexp(subexp("\\/\\/" + AUTHORITY$ + PATH_ABEMPTY$) + "|" + PATH_ABSOLUTE$ + "|" + PATH_ROOTLESS$ + "|" + PATH_EMPTY$),
122 URI$ = subexp(SCHEME$ + "\\:" + HIER_PART$ + subexp("\\?" + QUERY$) + "?" + subexp("\\#" + FRAGMENT$) + "?"),
123 RELATIVE_PART$ = subexp(subexp("\\/\\/" + AUTHORITY$ + PATH_ABEMPTY$) + "|" + PATH_ABSOLUTE$ + "|" + PATH_NOSCHEME$ + "|" + PATH_EMPTY$),
124 RELATIVE$ = subexp(RELATIVE_PART$ + subexp("\\?" + QUERY$) + "?" + subexp("\\#" + FRAGMENT$) + "?"),
125 URI_REFERENCE$ = subexp(URI$ + "|" + RELATIVE$),
126 ABSOLUTE_URI$ = subexp(SCHEME$ + "\\:" + HIER_PART$ + subexp("\\?" + QUERY$) + "?"),
127 GENERIC_REF$ = "^(" + SCHEME$ + ")\\:" + subexp(subexp("\\/\\/(" + subexp("(" + USERINFO$ + ")@") + "?(" + HOST$ + ")" + subexp("\\:(" + PORT$ + ")") + "?)") + "?(" + PATH_ABEMPTY$ + "|" + PATH_ABSOLUTE$ + "|" + PATH_ROOTLESS$ + "|" + PATH_EMPTY$ + ")") + subexp("\\?(" + QUERY$ + ")") + "?" + subexp("\\#(" + FRAGMENT$ + ")") + "?$",
128 RELATIVE_REF$ = "^(){0}" + subexp(subexp("\\/\\/(" + subexp("(" + USERINFO$ + ")@") + "?(" + HOST$ + ")" + subexp("\\:(" + PORT$ + ")") + "?)") + "?(" + PATH_ABEMPTY$ + "|" + PATH_ABSOLUTE$ + "|" + PATH_NOSCHEME$ + "|" + PATH_EMPTY$ + ")") + subexp("\\?(" + QUERY$ + ")") + "?" + subexp("\\#(" + FRAGMENT$ + ")") + "?$",
129 ABSOLUTE_REF$ = "^(" + SCHEME$ + ")\\:" + subexp(subexp("\\/\\/(" + subexp("(" + USERINFO$ + ")@") + "?(" + HOST$ + ")" + subexp("\\:(" + PORT$ + ")") + "?)") + "?(" + PATH_ABEMPTY$ + "|" + PATH_ABSOLUTE$ + "|" + PATH_ROOTLESS$ + "|" + PATH_EMPTY$ + ")") + subexp("\\?(" + QUERY$ + ")") + "?$",
130 SAMEDOC_REF$ = "^" + subexp("\\#(" + FRAGMENT$ + ")") + "?$",
131 AUTHORITY_REF$ = "^" + subexp("(" + USERINFO$ + ")@") + "?(" + HOST$ + ")" + subexp("\\:(" + PORT$ + ")") + "?$";
133 NOT_SCHEME: new RegExp(merge("[^]", ALPHA$$, DIGIT$$, "[\\+\\-\\.]"), "g"),
134 NOT_USERINFO: new RegExp(merge("[^\\%\\:]", UNRESERVED$$, SUB_DELIMS$$), "g"),
135 NOT_HOST: new RegExp(merge("[^\\%\\[\\]\\:]", UNRESERVED$$, SUB_DELIMS$$), "g"),
136 NOT_PATH: new RegExp(merge("[^\\%\\/\\:\\@]", UNRESERVED$$, SUB_DELIMS$$), "g"),
137 NOT_PATH_NOSCHEME: new RegExp(merge("[^\\%\\/\\@]", UNRESERVED$$, SUB_DELIMS$$), "g"),
138 NOT_QUERY: new RegExp(merge("[^\\%]", UNRESERVED$$, SUB_DELIMS$$, "[\\:\\@\\/\\?]", IPRIVATE$$), "g"),
139 NOT_FRAGMENT: new RegExp(merge("[^\\%]", UNRESERVED$$, SUB_DELIMS$$, "[\\:\\@\\/\\?]"), "g"),
140 ESCAPE: new RegExp(merge("[^]", UNRESERVED$$, SUB_DELIMS$$), "g"),
141 UNRESERVED: new RegExp(UNRESERVED$$, "g"),
142 OTHER_CHARS: new RegExp(merge("[^\\%]", UNRESERVED$$, RESERVED$$), "g"),
143 PCT_ENCODED: new RegExp(PCT_ENCODED$, "g"),
144 IPV4ADDRESS: new RegExp("^(" + IPV4ADDRESS$ + ")$"),
145 IPV6ADDRESS: new RegExp("^\\[?(" + IPV6ADDRESS$ + ")" + subexp(subexp("\\%25|\\%(?!" + HEXDIG$$ + "{2})") + "(" + ZONEID$ + ")") + "?\\]?$") //RFC 6874, with relaxed parsing rules
148 var URI_PROTOCOL = buildExps(false);
150 var IRI_PROTOCOL = buildExps(true);
152 var slicedToArray = function () {
153 function sliceIterator(arr, i) {
160 for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
163 if (i && _arr.length === i) break;
170 if (!_n && _i["return"]) _i["return"]();
179 return function (arr, i) {
180 if (Array.isArray(arr)) {
182 } else if (Symbol.iterator in Object(arr)) {
183 return sliceIterator(arr, i);
185 throw new TypeError("Invalid attempt to destructure non-iterable instance");
202 var toConsumableArray = function (arr) {
203 if (Array.isArray(arr)) {
204 for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
208 return Array.from(arr);
212 /** Highest positive signed 32-bit float value */
214 var maxInt = 2147483647; // aka. 0x7FFFFFFF or 2^31-1
216 /** Bootstring parameters */
222 var initialBias = 72;
223 var initialN = 128; // 0x80
224 var delimiter = '-'; // '\x2D'
226 /** Regular expressions */
227 var regexPunycode = /^xn--/;
228 var regexNonASCII = /[^\0-\x7E]/; // non-ASCII chars
229 var regexSeparators = /[\x2E\u3002\uFF0E\uFF61]/g; // RFC 3490 separators
231 /** Error messages */
233 'overflow': 'Overflow: input needs wider integers to process',
234 'not-basic': 'Illegal input >= 0x80 (not a basic code point)',
235 'invalid-input': 'Invalid input'
238 /** Convenience shortcuts */
239 var baseMinusTMin = base - tMin;
240 var floor = Math.floor;
241 var stringFromCharCode = String.fromCharCode;
243 /*--------------------------------------------------------------------------*/
246 * A generic error utility function.
248 * @param {String} type The error type.
249 * @returns {Error} Throws a `RangeError` with the applicable error message.
251 function error$1(type) {
252 throw new RangeError(errors[type]);
256 * A generic `Array#map` utility function.
258 * @param {Array} array The array to iterate over.
259 * @param {Function} callback The function that gets called for every array
261 * @returns {Array} A new array of values returned by the callback function.
263 function map(array, fn) {
265 var length = array.length;
267 result[length] = fn(array[length]);
273 * A simple `Array#map`-like wrapper to work with domain name strings or email
276 * @param {String} domain The domain name or email address.
277 * @param {Function} callback The function that gets called for every
279 * @returns {Array} A new string of characters returned by the callback
282 function mapDomain(string, fn) {
283 var parts = string.split('@');
285 if (parts.length > 1) {
286 // In email addresses, only the domain name should be punycoded. Leave
287 // the local part (i.e. everything up to `@`) intact.
288 result = parts[0] + '@';
291 // Avoid `split(regex)` for IE8 compatibility. See #17.
292 string = string.replace(regexSeparators, '\x2E');
293 var labels = string.split('.');
294 var encoded = map(labels, fn).join('.');
295 return result + encoded;
299 * Creates an array containing the numeric code points of each Unicode
300 * character in the string. While JavaScript uses UCS-2 internally,
301 * this function will convert a pair of surrogate halves (each of which
302 * UCS-2 exposes as separate characters) into a single code point,
304 * @see `punycode.ucs2.encode`
305 * @see <https://mathiasbynens.be/notes/javascript-encoding>
306 * @memberOf punycode.ucs2
308 * @param {String} string The Unicode input string (UCS-2).
309 * @returns {Array} The new array of code points.
311 function ucs2decode(string) {
314 var length = string.length;
315 while (counter < length) {
316 var value = string.charCodeAt(counter++);
317 if (value >= 0xD800 && value <= 0xDBFF && counter < length) {
318 // It's a high surrogate, and there is a next character.
319 var extra = string.charCodeAt(counter++);
320 if ((extra & 0xFC00) == 0xDC00) {
322 output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000);
324 // It's an unmatched surrogate; only append this code unit, in case the
325 // next code unit is the high surrogate of a surrogate pair.
337 * Creates a string based on an array of numeric code points.
338 * @see `punycode.ucs2.decode`
339 * @memberOf punycode.ucs2
341 * @param {Array} codePoints The array of numeric code points.
342 * @returns {String} The new Unicode string (UCS-2).
344 var ucs2encode = function ucs2encode(array) {
345 return String.fromCodePoint.apply(String, toConsumableArray(array));
349 * Converts a basic code point into a digit/integer.
350 * @see `digitToBasic()`
352 * @param {Number} codePoint The basic numeric code point value.
353 * @returns {Number} The numeric value of a basic code point (for use in
354 * representing integers) in the range `0` to `base - 1`, or `base` if
355 * the code point does not represent a value.
357 var basicToDigit = function basicToDigit(codePoint) {
358 if (codePoint - 0x30 < 0x0A) {
359 return codePoint - 0x16;
361 if (codePoint - 0x41 < 0x1A) {
362 return codePoint - 0x41;
364 if (codePoint - 0x61 < 0x1A) {
365 return codePoint - 0x61;
371 * Converts a digit/integer into a basic code point.
372 * @see `basicToDigit()`
374 * @param {Number} digit The numeric value of a basic code point.
375 * @returns {Number} The basic code point whose value (when used for
376 * representing integers) is `digit`, which needs to be in the range
377 * `0` to `base - 1`. If `flag` is non-zero, the uppercase form is
378 * used; else, the lowercase form is used. The behavior is undefined
379 * if `flag` is non-zero and `digit` has no uppercase form.
381 var digitToBasic = function digitToBasic(digit, flag) {
382 // 0..25 map to ASCII a..z or A..Z
383 // 26..35 map to ASCII 0..9
384 return digit + 22 + 75 * (digit < 26) - ((flag != 0) << 5);
388 * Bias adaptation function as per section 3.4 of RFC 3492.
389 * https://tools.ietf.org/html/rfc3492#section-3.4
392 var adapt = function adapt(delta, numPoints, firstTime) {
394 delta = firstTime ? floor(delta / damp) : delta >> 1;
395 delta += floor(delta / numPoints);
396 for (; /* no initialization */delta > baseMinusTMin * tMax >> 1; k += base) {
397 delta = floor(delta / baseMinusTMin);
399 return floor(k + (baseMinusTMin + 1) * delta / (delta + skew));
403 * Converts a Punycode string of ASCII-only symbols to a string of Unicode
406 * @param {String} input The Punycode string of ASCII-only symbols.
407 * @returns {String} The resulting string of Unicode symbols.
409 var decode = function decode(input) {
412 var inputLength = input.length;
415 var bias = initialBias;
417 // Handle the basic code points: let `basic` be the number of input code
418 // points before the last delimiter, or `0` if there is none, then copy
419 // the first basic code points to the output.
421 var basic = input.lastIndexOf(delimiter);
426 for (var j = 0; j < basic; ++j) {
427 // if it's not a basic code point
428 if (input.charCodeAt(j) >= 0x80) {
429 error$1('not-basic');
431 output.push(input.charCodeAt(j));
434 // Main decoding loop: start just after the last delimiter if any basic code
435 // points were copied; start at the beginning otherwise.
437 for (var index = basic > 0 ? basic + 1 : 0; index < inputLength;) /* no final expression */{
439 // `index` is the index of the next character to be consumed.
440 // Decode a generalized variable-length integer into `delta`,
441 // which gets added to `i`. The overflow checking is easier
442 // if we increase `i` as we go, then subtract off its starting
443 // value at the end to obtain `delta`.
445 for (var w = 1, k = base;; /* no condition */k += base) {
447 if (index >= inputLength) {
448 error$1('invalid-input');
451 var digit = basicToDigit(input.charCodeAt(index++));
453 if (digit >= base || digit > floor((maxInt - i) / w)) {
458 var t = k <= bias ? tMin : k >= bias + tMax ? tMax : k - bias;
464 var baseMinusT = base - t;
465 if (w > floor(maxInt / baseMinusT)) {
472 var out = output.length + 1;
473 bias = adapt(i - oldi, out, oldi == 0);
475 // `i` was supposed to wrap around from `out` to `0`,
476 // incrementing `n` each time, so we'll fix that now:
477 if (floor(i / out) > maxInt - n) {
484 // Insert `n` at position `i` of the output.
485 output.splice(i++, 0, n);
488 return String.fromCodePoint.apply(String, output);
492 * Converts a string of Unicode symbols (e.g. a domain name label) to a
493 * Punycode string of ASCII-only symbols.
495 * @param {String} input The string of Unicode symbols.
496 * @returns {String} The resulting Punycode string of ASCII-only symbols.
498 var encode = function encode(input) {
501 // Convert the input in UCS-2 to an array of Unicode code points.
502 input = ucs2decode(input);
505 var inputLength = input.length;
507 // Initialize the state.
510 var bias = initialBias;
512 // Handle the basic code points.
513 var _iteratorNormalCompletion = true;
514 var _didIteratorError = false;
515 var _iteratorError = undefined;
518 for (var _iterator = input[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
519 var _currentValue2 = _step.value;
521 if (_currentValue2 < 0x80) {
522 output.push(stringFromCharCode(_currentValue2));
526 _didIteratorError = true;
527 _iteratorError = err;
530 if (!_iteratorNormalCompletion && _iterator.return) {
534 if (_didIteratorError) {
535 throw _iteratorError;
540 var basicLength = output.length;
541 var handledCPCount = basicLength;
543 // `handledCPCount` is the number of code points that have been handled;
544 // `basicLength` is the number of basic code points.
546 // Finish the basic string with a delimiter unless it's empty.
548 output.push(delimiter);
551 // Main encoding loop:
552 while (handledCPCount < inputLength) {
554 // All non-basic code points < n have been handled already. Find the next
557 var _iteratorNormalCompletion2 = true;
558 var _didIteratorError2 = false;
559 var _iteratorError2 = undefined;
562 for (var _iterator2 = input[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
563 var currentValue = _step2.value;
565 if (currentValue >= n && currentValue < m) {
570 // Increase `delta` enough to advance the decoder's <n,i> state to <m,0>,
571 // but guard against overflow.
573 _didIteratorError2 = true;
574 _iteratorError2 = err;
577 if (!_iteratorNormalCompletion2 && _iterator2.return) {
581 if (_didIteratorError2) {
582 throw _iteratorError2;
587 var handledCPCountPlusOne = handledCPCount + 1;
588 if (m - n > floor((maxInt - delta) / handledCPCountPlusOne)) {
592 delta += (m - n) * handledCPCountPlusOne;
595 var _iteratorNormalCompletion3 = true;
596 var _didIteratorError3 = false;
597 var _iteratorError3 = undefined;
600 for (var _iterator3 = input[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
601 var _currentValue = _step3.value;
603 if (_currentValue < n && ++delta > maxInt) {
606 if (_currentValue == n) {
607 // Represent delta as a generalized variable-length integer.
609 for (var k = base;; /* no condition */k += base) {
610 var t = k <= bias ? tMin : k >= bias + tMax ? tMax : k - bias;
615 var baseMinusT = base - t;
616 output.push(stringFromCharCode(digitToBasic(t + qMinusT % baseMinusT, 0)));
617 q = floor(qMinusT / baseMinusT);
620 output.push(stringFromCharCode(digitToBasic(q, 0)));
621 bias = adapt(delta, handledCPCountPlusOne, handledCPCount == basicLength);
627 _didIteratorError3 = true;
628 _iteratorError3 = err;
631 if (!_iteratorNormalCompletion3 && _iterator3.return) {
635 if (_didIteratorError3) {
636 throw _iteratorError3;
644 return output.join('');
648 * Converts a Punycode string representing a domain name or an email address
649 * to Unicode. Only the Punycoded parts of the input will be converted, i.e.
650 * it doesn't matter if you call it on a string that has already been
651 * converted to Unicode.
653 * @param {String} input The Punycoded domain name or email address to
654 * convert to Unicode.
655 * @returns {String} The Unicode representation of the given Punycode
658 var toUnicode = function toUnicode(input) {
659 return mapDomain(input, function (string) {
660 return regexPunycode.test(string) ? decode(string.slice(4).toLowerCase()) : string;
665 * Converts a Unicode string representing a domain name or an email address to
666 * Punycode. Only the non-ASCII parts of the domain name will be converted,
667 * i.e. it doesn't matter if you call it with a domain that's already in
670 * @param {String} input The domain name or email address to convert, as a
672 * @returns {String} The Punycode representation of the given domain name or
675 var toASCII = function toASCII(input) {
676 return mapDomain(input, function (string) {
677 return regexNonASCII.test(string) ? 'xn--' + encode(string) : string;
681 /*--------------------------------------------------------------------------*/
683 /** Define the public API */
686 * A string representing the current Punycode.js version number.
692 * An object of methods to convert from JavaScript's internal character
693 * representation (UCS-2) to Unicode code points, and back.
694 * @see <https://mathiasbynens.be/notes/javascript-encoding>
699 'decode': ucs2decode,
705 'toUnicode': toUnicode
711 * @fileoverview An RFC 3986 compliant, scheme extendable URI parsing/validating/resolving library for JavaScript.
712 * @author <a href="mailto:gary.court@gmail.com">Gary Court</a>
713 * @see http://github.com/garycourt/uri-js
716 * Copyright 2011 Gary Court. All rights reserved.
718 * Redistribution and use in source and binary forms, with or without modification, are
719 * permitted provided that the following conditions are met:
721 * 1. Redistributions of source code must retain the above copyright notice, this list of
722 * conditions and the following disclaimer.
724 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
725 * of conditions and the following disclaimer in the documentation and/or other materials
726 * provided with the distribution.
728 * THIS SOFTWARE IS PROVIDED BY GARY COURT ``AS IS'' AND ANY EXPRESS OR IMPLIED
729 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
730 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GARY COURT OR
731 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
732 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
733 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
734 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
735 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
736 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
738 * The views and conclusions contained in the software and documentation are those of the
739 * authors and should not be interpreted as representing official policies, either expressed
740 * or implied, of Gary Court.
743 function pctEncChar(chr) {
744 var c = chr.charCodeAt(0);
746 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();
749 function pctDecChars(str) {
754 var c = parseInt(str.substr(i + 1, 2), 16);
756 newStr += String.fromCharCode(c);
758 } else if (c >= 194 && c < 224) {
760 var c2 = parseInt(str.substr(i + 4, 2), 16);
761 newStr += String.fromCharCode((c & 31) << 6 | c2 & 63);
763 newStr += str.substr(i, 6);
766 } else if (c >= 224) {
768 var _c = parseInt(str.substr(i + 4, 2), 16);
769 var c3 = parseInt(str.substr(i + 7, 2), 16);
770 newStr += String.fromCharCode((c & 15) << 12 | (_c & 63) << 6 | c3 & 63);
772 newStr += str.substr(i, 9);
776 newStr += str.substr(i, 3);
782 function _normalizeComponentEncoding(components, protocol) {
783 function decodeUnreserved(str) {
784 var decStr = pctDecChars(str);
785 return !decStr.match(protocol.UNRESERVED) ? str : decStr;
787 if (components.scheme) components.scheme = String(components.scheme).replace(protocol.PCT_ENCODED, decodeUnreserved).toLowerCase().replace(protocol.NOT_SCHEME, "");
788 if (components.userinfo !== undefined) components.userinfo = String(components.userinfo).replace(protocol.PCT_ENCODED, decodeUnreserved).replace(protocol.NOT_USERINFO, pctEncChar).replace(protocol.PCT_ENCODED, toUpperCase);
789 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);
790 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);
791 if (components.query !== undefined) components.query = String(components.query).replace(protocol.PCT_ENCODED, decodeUnreserved).replace(protocol.NOT_QUERY, pctEncChar).replace(protocol.PCT_ENCODED, toUpperCase);
792 if (components.fragment !== undefined) components.fragment = String(components.fragment).replace(protocol.PCT_ENCODED, decodeUnreserved).replace(protocol.NOT_FRAGMENT, pctEncChar).replace(protocol.PCT_ENCODED, toUpperCase);
796 function _stripLeadingZeros(str) {
797 return str.replace(/^0*(.*)/, "$1") || "0";
799 function _normalizeIPv4(host, protocol) {
800 var matches = host.match(protocol.IPV4ADDRESS) || [];
802 var _matches = slicedToArray(matches, 2),
803 address = _matches[1];
806 return address.split(".").map(_stripLeadingZeros).join(".");
811 function _normalizeIPv6(host, protocol) {
812 var matches = host.match(protocol.IPV6ADDRESS) || [];
814 var _matches2 = slicedToArray(matches, 3),
815 address = _matches2[1],
819 var _address$toLowerCase$ = address.toLowerCase().split('::').reverse(),
820 _address$toLowerCase$2 = slicedToArray(_address$toLowerCase$, 2),
821 last = _address$toLowerCase$2[0],
822 first = _address$toLowerCase$2[1];
824 var firstFields = first ? first.split(":").map(_stripLeadingZeros) : [];
825 var lastFields = last.split(":").map(_stripLeadingZeros);
826 var isLastFieldIPv4Address = protocol.IPV4ADDRESS.test(lastFields[lastFields.length - 1]);
827 var fieldCount = isLastFieldIPv4Address ? 7 : 8;
828 var lastFieldsStart = lastFields.length - fieldCount;
829 var fields = Array(fieldCount);
830 for (var x = 0; x < fieldCount; ++x) {
831 fields[x] = firstFields[x] || lastFields[lastFieldsStart + x] || '';
833 if (isLastFieldIPv4Address) {
834 fields[fieldCount - 1] = _normalizeIPv4(fields[fieldCount - 1], protocol);
836 var allZeroFields = fields.reduce(function (acc, field, index) {
837 if (!field || field === "0") {
838 var lastLongest = acc[acc.length - 1];
839 if (lastLongest && lastLongest.index + lastLongest.length === index) {
840 lastLongest.length++;
842 acc.push({ index: index, length: 1 });
847 var longestZeroFields = allZeroFields.sort(function (a, b) {
848 return b.length - a.length;
850 var newHost = void 0;
851 if (longestZeroFields && longestZeroFields.length > 1) {
852 var newFirst = fields.slice(0, longestZeroFields.index);
853 var newLast = fields.slice(longestZeroFields.index + longestZeroFields.length);
854 newHost = newFirst.join(":") + "::" + newLast.join(":");
856 newHost = fields.join(":");
859 newHost += "%" + zone;
866 var URI_PARSE = /^(?:([^:\/?#]+):)?(?:\/\/((?:([^\/?#@]*)@)?(\[[^\/?#\]]+\]|[^\/?#:]*)(?:\:(\d*))?))?([^?#]*)(?:\?([^#]*))?(?:#((?:.|\n|\r)*))?/i;
867 var NO_MATCH_IS_UNDEFINED = "".match(/(){0}/)[1] === undefined;
868 function parse(uriString) {
869 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
872 var protocol = options.iri !== false ? IRI_PROTOCOL : URI_PROTOCOL;
873 if (options.reference === "suffix") uriString = (options.scheme ? options.scheme + ":" : "") + "//" + uriString;
874 var matches = uriString.match(URI_PARSE);
876 if (NO_MATCH_IS_UNDEFINED) {
877 //store each component
878 components.scheme = matches[1];
879 components.userinfo = matches[3];
880 components.host = matches[4];
881 components.port = parseInt(matches[5], 10);
882 components.path = matches[6] || "";
883 components.query = matches[7];
884 components.fragment = matches[8];
886 if (isNaN(components.port)) {
887 components.port = matches[5];
890 //IE FIX for improper RegExp matching
891 //store each component
892 components.scheme = matches[1] || undefined;
893 components.userinfo = uriString.indexOf("@") !== -1 ? matches[3] : undefined;
894 components.host = uriString.indexOf("//") !== -1 ? matches[4] : undefined;
895 components.port = parseInt(matches[5], 10);
896 components.path = matches[6] || "";
897 components.query = uriString.indexOf("?") !== -1 ? matches[7] : undefined;
898 components.fragment = uriString.indexOf("#") !== -1 ? matches[8] : undefined;
900 if (isNaN(components.port)) {
901 components.port = uriString.match(/\/\/(?:.|\n)*\:(?:\/|\?|\#|$)/) ? matches[4] : undefined;
904 if (components.host) {
906 components.host = _normalizeIPv6(_normalizeIPv4(components.host, protocol), protocol);
908 //determine reference type
909 if (components.scheme === undefined && components.userinfo === undefined && components.host === undefined && components.port === undefined && !components.path && components.query === undefined) {
910 components.reference = "same-document";
911 } else if (components.scheme === undefined) {
912 components.reference = "relative";
913 } else if (components.fragment === undefined) {
914 components.reference = "absolute";
916 components.reference = "uri";
918 //check for reference errors
919 if (options.reference && options.reference !== "suffix" && options.reference !== components.reference) {
920 components.error = components.error || "URI is not a " + options.reference + " reference.";
922 //find scheme handler
923 var schemeHandler = SCHEMES[(options.scheme || components.scheme || "").toLowerCase()];
924 //check if scheme can't handle IRIs
925 if (!options.unicodeSupport && (!schemeHandler || !schemeHandler.unicodeSupport)) {
926 //if host component is a domain name
927 if (components.host && (options.domainHost || schemeHandler && schemeHandler.domainHost)) {
928 //convert Unicode IDN -> ASCII IDN
930 components.host = punycode.toASCII(components.host.replace(protocol.PCT_ENCODED, pctDecChars).toLowerCase());
932 components.error = components.error || "Host's domain name can not be converted to ASCII via punycode: " + e;
936 _normalizeComponentEncoding(components, URI_PROTOCOL);
938 //normalize encodings
939 _normalizeComponentEncoding(components, protocol);
941 //perform scheme specific parsing
942 if (schemeHandler && schemeHandler.parse) {
943 schemeHandler.parse(components, options);
946 components.error = components.error || "URI can not be parsed.";
951 function _recomposeAuthority(components, options) {
952 var protocol = options.iri !== false ? IRI_PROTOCOL : URI_PROTOCOL;
954 if (components.userinfo !== undefined) {
955 uriTokens.push(components.userinfo);
958 if (components.host !== undefined) {
959 //normalize IP hosts, add brackets and escape zone separator for IPv6
960 uriTokens.push(_normalizeIPv6(_normalizeIPv4(String(components.host), protocol), protocol).replace(protocol.IPV6ADDRESS, function (_, $1, $2) {
961 return "[" + $1 + ($2 ? "%25" + $2 : "") + "]";
964 if (typeof components.port === "number" || typeof components.port === "string") {
966 uriTokens.push(String(components.port));
968 return uriTokens.length ? uriTokens.join("") : undefined;
971 var RDS1 = /^\.\.?\//;
972 var RDS2 = /^\/\.(\/|$)/;
973 var RDS3 = /^\/\.\.(\/|$)/;
974 var RDS5 = /^\/?(?:.|\n)*?(?=\/|$)/;
975 function removeDotSegments(input) {
977 while (input.length) {
978 if (input.match(RDS1)) {
979 input = input.replace(RDS1, "");
980 } else if (input.match(RDS2)) {
981 input = input.replace(RDS2, "/");
982 } else if (input.match(RDS3)) {
983 input = input.replace(RDS3, "/");
985 } else if (input === "." || input === "..") {
988 var im = input.match(RDS5);
991 input = input.slice(s.length);
994 throw new Error("Unexpected dot segment condition");
998 return output.join("");
1001 function serialize(components) {
1002 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1004 var protocol = options.iri ? IRI_PROTOCOL : URI_PROTOCOL;
1006 //find scheme handler
1007 var schemeHandler = SCHEMES[(options.scheme || components.scheme || "").toLowerCase()];
1008 //perform scheme specific serialization
1009 if (schemeHandler && schemeHandler.serialize) schemeHandler.serialize(components, options);
1010 if (components.host) {
1011 //if host component is an IPv6 address
1012 if (protocol.IPV6ADDRESS.test(components.host)) {}
1013 //TODO: normalize IPv6 address as per RFC 5952
1015 //if host component is a domain name
1016 else if (options.domainHost || schemeHandler && schemeHandler.domainHost) {
1017 //convert IDN via punycode
1019 components.host = !options.iri ? punycode.toASCII(components.host.replace(protocol.PCT_ENCODED, pctDecChars).toLowerCase()) : punycode.toUnicode(components.host);
1021 components.error = components.error || "Host's domain name can not be converted to " + (!options.iri ? "ASCII" : "Unicode") + " via punycode: " + e;
1025 //normalize encoding
1026 _normalizeComponentEncoding(components, protocol);
1027 if (options.reference !== "suffix" && components.scheme) {
1028 uriTokens.push(components.scheme);
1029 uriTokens.push(":");
1031 var authority = _recomposeAuthority(components, options);
1032 if (authority !== undefined) {
1033 if (options.reference !== "suffix") {
1034 uriTokens.push("//");
1036 uriTokens.push(authority);
1037 if (components.path && components.path.charAt(0) !== "/") {
1038 uriTokens.push("/");
1041 if (components.path !== undefined) {
1042 var s = components.path;
1043 if (!options.absolutePath && (!schemeHandler || !schemeHandler.absolutePath)) {
1044 s = removeDotSegments(s);
1046 if (authority === undefined) {
1047 s = s.replace(/^\/\//, "/%2F"); //don't allow the path to start with "//"
1051 if (components.query !== undefined) {
1052 uriTokens.push("?");
1053 uriTokens.push(components.query);
1055 if (components.fragment !== undefined) {
1056 uriTokens.push("#");
1057 uriTokens.push(components.fragment);
1059 return uriTokens.join(""); //merge tokens into a string
1062 function resolveComponents(base, relative) {
1063 var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1064 var skipNormalization = arguments[3];
1067 if (!skipNormalization) {
1068 base = parse(serialize(base, options), options); //normalize base components
1069 relative = parse(serialize(relative, options), options); //normalize relative components
1071 options = options || {};
1072 if (!options.tolerant && relative.scheme) {
1073 target.scheme = relative.scheme;
1074 //target.authority = relative.authority;
1075 target.userinfo = relative.userinfo;
1076 target.host = relative.host;
1077 target.port = relative.port;
1078 target.path = removeDotSegments(relative.path || "");
1079 target.query = relative.query;
1081 if (relative.userinfo !== undefined || relative.host !== undefined || relative.port !== undefined) {
1082 //target.authority = relative.authority;
1083 target.userinfo = relative.userinfo;
1084 target.host = relative.host;
1085 target.port = relative.port;
1086 target.path = removeDotSegments(relative.path || "");
1087 target.query = relative.query;
1089 if (!relative.path) {
1090 target.path = base.path;
1091 if (relative.query !== undefined) {
1092 target.query = relative.query;
1094 target.query = base.query;
1097 if (relative.path.charAt(0) === "/") {
1098 target.path = removeDotSegments(relative.path);
1100 if ((base.userinfo !== undefined || base.host !== undefined || base.port !== undefined) && !base.path) {
1101 target.path = "/" + relative.path;
1102 } else if (!base.path) {
1103 target.path = relative.path;
1105 target.path = base.path.slice(0, base.path.lastIndexOf("/") + 1) + relative.path;
1107 target.path = removeDotSegments(target.path);
1109 target.query = relative.query;
1111 //target.authority = base.authority;
1112 target.userinfo = base.userinfo;
1113 target.host = base.host;
1114 target.port = base.port;
1116 target.scheme = base.scheme;
1118 target.fragment = relative.fragment;
1122 function resolve(baseURI, relativeURI, options) {
1123 var schemelessOptions = assign({ scheme: 'null' }, options);
1124 return serialize(resolveComponents(parse(baseURI, schemelessOptions), parse(relativeURI, schemelessOptions), schemelessOptions, true), schemelessOptions);
1127 function normalize(uri, options) {
1128 if (typeof uri === "string") {
1129 uri = serialize(parse(uri, options), options);
1130 } else if (typeOf(uri) === "object") {
1131 uri = parse(serialize(uri, options), options);
1136 function equal(uriA, uriB, options) {
1137 if (typeof uriA === "string") {
1138 uriA = serialize(parse(uriA, options), options);
1139 } else if (typeOf(uriA) === "object") {
1140 uriA = serialize(uriA, options);
1142 if (typeof uriB === "string") {
1143 uriB = serialize(parse(uriB, options), options);
1144 } else if (typeOf(uriB) === "object") {
1145 uriB = serialize(uriB, options);
1147 return uriA === uriB;
1150 function escapeComponent(str, options) {
1151 return str && str.toString().replace(!options || !options.iri ? URI_PROTOCOL.ESCAPE : IRI_PROTOCOL.ESCAPE, pctEncChar);
1154 function unescapeComponent(str, options) {
1155 return str && str.toString().replace(!options || !options.iri ? URI_PROTOCOL.PCT_ENCODED : IRI_PROTOCOL.PCT_ENCODED, pctDecChars);
1161 parse: function parse(components, options) {
1162 //report missing host
1163 if (!components.host) {
1164 components.error = components.error || "HTTP URIs must have a host.";
1168 serialize: function serialize(components, options) {
1169 var secure = String(components.scheme).toLowerCase() === "https";
1170 //normalize the default port
1171 if (components.port === (secure ? 443 : 80) || components.port === "") {
1172 components.port = undefined;
1174 //normalize the empty path
1175 if (!components.path) {
1176 components.path = "/";
1178 //NOTE: We do not parse query strings for HTTP URIs
1179 //as WWW Form Url Encoded query strings are part of the HTML4+ spec,
1180 //and not the HTTP spec.
1187 domainHost: handler.domainHost,
1188 parse: handler.parse,
1189 serialize: handler.serialize
1192 function isSecure(wsComponents) {
1193 return typeof wsComponents.secure === 'boolean' ? wsComponents.secure : String(wsComponents.scheme).toLowerCase() === "wss";
1199 parse: function parse(components, options) {
1200 var wsComponents = components;
1201 //indicate if the secure flag is set
1202 wsComponents.secure = isSecure(wsComponents);
1203 //construct resouce name
1204 wsComponents.resourceName = (wsComponents.path || '/') + (wsComponents.query ? '?' + wsComponents.query : '');
1205 wsComponents.path = undefined;
1206 wsComponents.query = undefined;
1207 return wsComponents;
1209 serialize: function serialize(wsComponents, options) {
1210 //normalize the default port
1211 if (wsComponents.port === (isSecure(wsComponents) ? 443 : 80) || wsComponents.port === "") {
1212 wsComponents.port = undefined;
1214 //ensure scheme matches secure flag
1215 if (typeof wsComponents.secure === 'boolean') {
1216 wsComponents.scheme = wsComponents.secure ? 'wss' : 'ws';
1217 wsComponents.secure = undefined;
1219 //reconstruct path from resource name
1220 if (wsComponents.resourceName) {
1221 var _wsComponents$resourc = wsComponents.resourceName.split('?'),
1222 _wsComponents$resourc2 = slicedToArray(_wsComponents$resourc, 2),
1223 path = _wsComponents$resourc2[0],
1224 query = _wsComponents$resourc2[1];
1226 wsComponents.path = path && path !== '/' ? path : undefined;
1227 wsComponents.query = query;
1228 wsComponents.resourceName = undefined;
1230 //forbid fragment component
1231 wsComponents.fragment = undefined;
1232 return wsComponents;
1238 domainHost: handler$2.domainHost,
1239 parse: handler$2.parse,
1240 serialize: handler$2.serialize
1246 var UNRESERVED$$ = "[A-Za-z0-9\\-\\.\\_\\~" + (isIRI ? "\\xA0-\\u200D\\u2010-\\u2029\\u202F-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF" : "") + "]";
1247 var HEXDIG$$ = "[0-9A-Fa-f]"; //case-insensitive
1248 var PCT_ENCODED$ = subexp(subexp("%[EFef]" + HEXDIG$$ + "%" + HEXDIG$$ + HEXDIG$$ + "%" + HEXDIG$$ + HEXDIG$$) + "|" + subexp("%[89A-Fa-f]" + HEXDIG$$ + "%" + HEXDIG$$ + HEXDIG$$) + "|" + subexp("%" + HEXDIG$$ + HEXDIG$$)); //expanded
1249 //RFC 5322, except these symbols as per RFC 6068: @ : / ? # [ ] & ; =
1250 //const ATEXT$$ = "[A-Za-z0-9\\!\\#\\$\\%\\&\\'\\*\\+\\-\\/\\=\\?\\^\\_\\`\\{\\|\\}\\~]";
1251 //const WSP$$ = "[\\x20\\x09]";
1252 //const OBS_QTEXT$$ = "[\\x01-\\x08\\x0B\\x0C\\x0E-\\x1F\\x7F]"; //(%d1-8 / %d11-12 / %d14-31 / %d127)
1253 //const QTEXT$$ = merge("[\\x21\\x23-\\x5B\\x5D-\\x7E]", OBS_QTEXT$$); //%d33 / %d35-91 / %d93-126 / obs-qtext
1254 //const VCHAR$$ = "[\\x21-\\x7E]";
1255 //const WSP$$ = "[\\x20\\x09]";
1256 //const OBS_QP$ = subexp("\\\\" + merge("[\\x00\\x0D\\x0A]", OBS_QTEXT$$)); //%d0 / CR / LF / obs-qtext
1257 //const FWS$ = subexp(subexp(WSP$$ + "*" + "\\x0D\\x0A") + "?" + WSP$$ + "+");
1258 //const QUOTED_PAIR$ = subexp(subexp("\\\\" + subexp(VCHAR$$ + "|" + WSP$$)) + "|" + OBS_QP$);
1259 //const QUOTED_STRING$ = subexp('\\"' + subexp(FWS$ + "?" + QCONTENT$) + "*" + FWS$ + "?" + '\\"');
1260 var ATEXT$$ = "[A-Za-z0-9\\!\\$\\%\\'\\*\\+\\-\\^\\_\\`\\{\\|\\}\\~]";
1261 var QTEXT$$ = "[\\!\\$\\%\\'\\(\\)\\*\\+\\,\\-\\.0-9\\<\\>A-Z\\x5E-\\x7E]";
1262 var VCHAR$$ = merge(QTEXT$$, "[\\\"\\\\]");
1263 var SOME_DELIMS$$ = "[\\!\\$\\'\\(\\)\\*\\+\\,\\;\\:\\@]";
1264 var UNRESERVED = new RegExp(UNRESERVED$$, "g");
1265 var PCT_ENCODED = new RegExp(PCT_ENCODED$, "g");
1266 var NOT_LOCAL_PART = new RegExp(merge("[^]", ATEXT$$, "[\\.]", '[\\"]', VCHAR$$), "g");
1267 var NOT_HFNAME = new RegExp(merge("[^]", UNRESERVED$$, SOME_DELIMS$$), "g");
1268 var NOT_HFVALUE = NOT_HFNAME;
1269 function decodeUnreserved(str) {
1270 var decStr = pctDecChars(str);
1271 return !decStr.match(UNRESERVED) ? str : decStr;
1275 parse: function parse$$1(components, options) {
1276 var mailtoComponents = components;
1277 var to = mailtoComponents.to = mailtoComponents.path ? mailtoComponents.path.split(",") : [];
1278 mailtoComponents.path = undefined;
1279 if (mailtoComponents.query) {
1280 var unknownHeaders = false;
1282 var hfields = mailtoComponents.query.split("&");
1283 for (var x = 0, xl = hfields.length; x < xl; ++x) {
1284 var hfield = hfields[x].split("=");
1285 switch (hfield[0]) {
1287 var toAddrs = hfield[1].split(",");
1288 for (var _x = 0, _xl = toAddrs.length; _x < _xl; ++_x) {
1289 to.push(toAddrs[_x]);
1293 mailtoComponents.subject = unescapeComponent(hfield[1], options);
1296 mailtoComponents.body = unescapeComponent(hfield[1], options);
1299 unknownHeaders = true;
1300 headers[unescapeComponent(hfield[0], options)] = unescapeComponent(hfield[1], options);
1304 if (unknownHeaders) mailtoComponents.headers = headers;
1306 mailtoComponents.query = undefined;
1307 for (var _x2 = 0, _xl2 = to.length; _x2 < _xl2; ++_x2) {
1308 var addr = to[_x2].split("@");
1309 addr[0] = unescapeComponent(addr[0]);
1310 if (!options.unicodeSupport) {
1311 //convert Unicode IDN -> ASCII IDN
1313 addr[1] = punycode.toASCII(unescapeComponent(addr[1], options).toLowerCase());
1315 mailtoComponents.error = mailtoComponents.error || "Email address's domain name can not be converted to ASCII via punycode: " + e;
1318 addr[1] = unescapeComponent(addr[1], options).toLowerCase();
1320 to[_x2] = addr.join("@");
1322 return mailtoComponents;
1324 serialize: function serialize$$1(mailtoComponents, options) {
1325 var components = mailtoComponents;
1326 var to = toArray(mailtoComponents.to);
1328 for (var x = 0, xl = to.length; x < xl; ++x) {
1329 var toAddr = String(to[x]);
1330 var atIdx = toAddr.lastIndexOf("@");
1331 var localPart = toAddr.slice(0, atIdx).replace(PCT_ENCODED, decodeUnreserved).replace(PCT_ENCODED, toUpperCase).replace(NOT_LOCAL_PART, pctEncChar);
1332 var domain = toAddr.slice(atIdx + 1);
1333 //convert IDN via punycode
1335 domain = !options.iri ? punycode.toASCII(unescapeComponent(domain, options).toLowerCase()) : punycode.toUnicode(domain);
1337 components.error = components.error || "Email address's domain name can not be converted to " + (!options.iri ? "ASCII" : "Unicode") + " via punycode: " + e;
1339 to[x] = localPart + "@" + domain;
1341 components.path = to.join(",");
1343 var headers = mailtoComponents.headers = mailtoComponents.headers || {};
1344 if (mailtoComponents.subject) headers["subject"] = mailtoComponents.subject;
1345 if (mailtoComponents.body) headers["body"] = mailtoComponents.body;
1347 for (var name in headers) {
1348 if (headers[name] !== O[name]) {
1349 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));
1352 if (fields.length) {
1353 components.query = fields.join("&");
1359 var URN_PARSE = /^([^\:]+)\:(.*)/;
1363 parse: function parse$$1(components, options) {
1364 var matches = components.path && components.path.match(URN_PARSE);
1365 var urnComponents = components;
1367 var scheme = options.scheme || urnComponents.scheme || "urn";
1368 var nid = matches[1].toLowerCase();
1369 var nss = matches[2];
1370 var urnScheme = scheme + ":" + (options.nid || nid);
1371 var schemeHandler = SCHEMES[urnScheme];
1372 urnComponents.nid = nid;
1373 urnComponents.nss = nss;
1374 urnComponents.path = undefined;
1375 if (schemeHandler) {
1376 urnComponents = schemeHandler.parse(urnComponents, options);
1379 urnComponents.error = urnComponents.error || "URN can not be parsed.";
1381 return urnComponents;
1383 serialize: function serialize$$1(urnComponents, options) {
1384 var scheme = options.scheme || urnComponents.scheme || "urn";
1385 var nid = urnComponents.nid;
1386 var urnScheme = scheme + ":" + (options.nid || nid);
1387 var schemeHandler = SCHEMES[urnScheme];
1388 if (schemeHandler) {
1389 urnComponents = schemeHandler.serialize(urnComponents, options);
1391 var uriComponents = urnComponents;
1392 var nss = urnComponents.nss;
1393 uriComponents.path = (nid || options.nid) + ":" + nss;
1394 return uriComponents;
1398 var UUID = /^[0-9A-Fa-f]{8}(?:\-[0-9A-Fa-f]{4}){3}\-[0-9A-Fa-f]{12}$/;
1402 parse: function parse(urnComponents, options) {
1403 var uuidComponents = urnComponents;
1404 uuidComponents.uuid = uuidComponents.nss;
1405 uuidComponents.nss = undefined;
1406 if (!options.tolerant && (!uuidComponents.uuid || !uuidComponents.uuid.match(UUID))) {
1407 uuidComponents.error = uuidComponents.error || "UUID is not valid.";
1409 return uuidComponents;
1411 serialize: function serialize(uuidComponents, options) {
1412 var urnComponents = uuidComponents;
1414 urnComponents.nss = (uuidComponents.uuid || "").toLowerCase();
1415 return urnComponents;
1419 SCHEMES[handler.scheme] = handler;
1420 SCHEMES[handler$1.scheme] = handler$1;
1421 SCHEMES[handler$2.scheme] = handler$2;
1422 SCHEMES[handler$3.scheme] = handler$3;
1423 SCHEMES[handler$4.scheme] = handler$4;
1424 SCHEMES[handler$5.scheme] = handler$5;
1425 SCHEMES[handler$6.scheme] = handler$6;
1427 exports.SCHEMES = SCHEMES;
1428 exports.pctEncChar = pctEncChar;
1429 exports.pctDecChars = pctDecChars;
1430 exports.parse = parse;
1431 exports.removeDotSegments = removeDotSegments;
1432 exports.serialize = serialize;
1433 exports.resolveComponents = resolveComponents;
1434 exports.resolve = resolve;
1435 exports.normalize = normalize;
1436 exports.equal = equal;
1437 exports.escapeComponent = escapeComponent;
1438 exports.unescapeComponent = unescapeComponent;
1440 Object.defineProperty(exports, '__esModule', { value: true });
1443 //# sourceMappingURL=uri.all.js.map