uri.all.js (55217B)
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 8 function merge() { 9 for (var _len = arguments.length, sets = Array(_len), _key = 0; _key < _len; _key++) { 10 sets[_key] = arguments[_key]; 11 } 12 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); 18 } 19 sets[xl] = sets[xl].slice(1); 20 return sets.join(''); 21 } else { 22 return sets[0]; 23 } 24 } 25 function subexp(str) { 26 return "(?:" + str + ")"; 27 } 28 function typeOf(o) { 29 return o === undefined ? "undefined" : o === null ? "null" : Object.prototype.toString.call(o).split(" ").pop().split("]").shift().toLowerCase(); 30 } 31 function toUpperCase(str) { 32 return str.toUpperCase(); 33 } 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) : []; 36 } 37 function assign(target, source) { 38 var obj = target; 39 if (source) { 40 for (var key in source) { 41 obj[key] = source[key]; 42 } 43 } 44 return obj; 45 } 46 47 function buildExps(isIRI) { 48 var ALPHA$$ = "[A-Za-z]", 49 CR$ = "[\\x0D]", 50 DIGIT$$ = "[0-9]", 51 DQUOTE$$ = "[\\x22]", 52 HEXDIG$$ = merge(DIGIT$$, "[A-Fa-f]"), 53 //case-insensitive 54 LF$$ = "[\\x0A]", 55 SP$$ = "[\\x20]", 56 PCT_ENCODED$ = subexp(subexp("%[EFef]" + HEXDIG$$ + "%" + HEXDIG$$ + HEXDIG$$ + "%" + HEXDIG$$ + HEXDIG$$) + "|" + subexp("%[89A-Fa-f]" + HEXDIG$$ + "%" + HEXDIG$$ + HEXDIG$$) + "|" + subexp("%" + HEXDIG$$ + HEXDIG$$)), 57 //expanded 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]" : "[]", 64 //subset 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$), 75 // 6( h16 ":" ) 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$) + "+"), 94 //RFC 6874 95 IPV6ADDRZ$ = subexp(IPV6ADDRESS$ + "\\%25" + ZONEID$), 96 //RFC 6874 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$) + "\\]"), 101 //RFC 6874 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$) + "?"), 112 //simplified 113 PATH_NOSCHEME$ = subexp(SEGMENT_NZ_NC$ + PATH_ABEMPTY$), 114 //simplified 115 PATH_ROOTLESS$ = subexp(SEGMENT_NZ$ + PATH_ABEMPTY$), 116 //simplified 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$ + ")") + "?$"; 132 return { 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 146 }; 147 } 148 var URI_PROTOCOL = buildExps(false); 149 150 var IRI_PROTOCOL = buildExps(true); 151 152 var slicedToArray = function () { 153 function sliceIterator(arr, i) { 154 var _arr = []; 155 var _n = true; 156 var _d = false; 157 var _e = undefined; 158 159 try { 160 for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { 161 _arr.push(_s.value); 162 163 if (i && _arr.length === i) break; 164 } 165 } catch (err) { 166 _d = true; 167 _e = err; 168 } finally { 169 try { 170 if (!_n && _i["return"]) _i["return"](); 171 } finally { 172 if (_d) throw _e; 173 } 174 } 175 176 return _arr; 177 } 178 179 return function (arr, i) { 180 if (Array.isArray(arr)) { 181 return arr; 182 } else if (Symbol.iterator in Object(arr)) { 183 return sliceIterator(arr, i); 184 } else { 185 throw new TypeError("Invalid attempt to destructure non-iterable instance"); 186 } 187 }; 188 }(); 189 190 191 192 193 194 195 196 197 198 199 200 201 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]; 205 206 return arr2; 207 } else { 208 return Array.from(arr); 209 } 210 }; 211 212 /** Highest positive signed 32-bit float value */ 213 214 var maxInt = 2147483647; // aka. 0x7FFFFFFF or 2^31-1 215 216 /** Bootstring parameters */ 217 var base = 36; 218 var tMin = 1; 219 var tMax = 26; 220 var skew = 38; 221 var damp = 700; 222 var initialBias = 72; 223 var initialN = 128; // 0x80 224 var delimiter = '-'; // '\x2D' 225 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 230 231 /** Error messages */ 232 var errors = { 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' 236 }; 237 238 /** Convenience shortcuts */ 239 var baseMinusTMin = base - tMin; 240 var floor = Math.floor; 241 var stringFromCharCode = String.fromCharCode; 242 243 /*--------------------------------------------------------------------------*/ 244 245 /** 246 * A generic error utility function. 247 * @private 248 * @param {String} type The error type. 249 * @returns {Error} Throws a `RangeError` with the applicable error message. 250 */ 251 function error$1(type) { 252 throw new RangeError(errors[type]); 253 } 254 255 /** 256 * A generic `Array#map` utility function. 257 * @private 258 * @param {Array} array The array to iterate over. 259 * @param {Function} callback The function that gets called for every array 260 * item. 261 * @returns {Array} A new array of values returned by the callback function. 262 */ 263 function map(array, fn) { 264 var result = []; 265 var length = array.length; 266 while (length--) { 267 result[length] = fn(array[length]); 268 } 269 return result; 270 } 271 272 /** 273 * A simple `Array#map`-like wrapper to work with domain name strings or email 274 * addresses. 275 * @private 276 * @param {String} domain The domain name or email address. 277 * @param {Function} callback The function that gets called for every 278 * character. 279 * @returns {Array} A new string of characters returned by the callback 280 * function. 281 */ 282 function mapDomain(string, fn) { 283 var parts = string.split('@'); 284 var result = ''; 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] + '@'; 289 string = parts[1]; 290 } 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; 296 } 297 298 /** 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, 303 * matching UTF-16. 304 * @see `punycode.ucs2.encode` 305 * @see <https://mathiasbynens.be/notes/javascript-encoding> 306 * @memberOf punycode.ucs2 307 * @name decode 308 * @param {String} string The Unicode input string (UCS-2). 309 * @returns {Array} The new array of code points. 310 */ 311 function ucs2decode(string) { 312 var output = []; 313 var counter = 0; 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) { 321 // Low surrogate. 322 output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000); 323 } else { 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. 326 output.push(value); 327 counter--; 328 } 329 } else { 330 output.push(value); 331 } 332 } 333 return output; 334 } 335 336 /** 337 * Creates a string based on an array of numeric code points. 338 * @see `punycode.ucs2.decode` 339 * @memberOf punycode.ucs2 340 * @name encode 341 * @param {Array} codePoints The array of numeric code points. 342 * @returns {String} The new Unicode string (UCS-2). 343 */ 344 var ucs2encode = function ucs2encode(array) { 345 return String.fromCodePoint.apply(String, toConsumableArray(array)); 346 }; 347 348 /** 349 * Converts a basic code point into a digit/integer. 350 * @see `digitToBasic()` 351 * @private 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. 356 */ 357 var basicToDigit = function basicToDigit(codePoint) { 358 if (codePoint - 0x30 < 0x0A) { 359 return codePoint - 0x16; 360 } 361 if (codePoint - 0x41 < 0x1A) { 362 return codePoint - 0x41; 363 } 364 if (codePoint - 0x61 < 0x1A) { 365 return codePoint - 0x61; 366 } 367 return base; 368 }; 369 370 /** 371 * Converts a digit/integer into a basic code point. 372 * @see `basicToDigit()` 373 * @private 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. 380 */ 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); 385 }; 386 387 /** 388 * Bias adaptation function as per section 3.4 of RFC 3492. 389 * https://tools.ietf.org/html/rfc3492#section-3.4 390 * @private 391 */ 392 var adapt = function adapt(delta, numPoints, firstTime) { 393 var k = 0; 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); 398 } 399 return floor(k + (baseMinusTMin + 1) * delta / (delta + skew)); 400 }; 401 402 /** 403 * Converts a Punycode string of ASCII-only symbols to a string of Unicode 404 * symbols. 405 * @memberOf punycode 406 * @param {String} input The Punycode string of ASCII-only symbols. 407 * @returns {String} The resulting string of Unicode symbols. 408 */ 409 var decode = function decode(input) { 410 // Don't use UCS-2. 411 var output = []; 412 var inputLength = input.length; 413 var i = 0; 414 var n = initialN; 415 var bias = initialBias; 416 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. 420 421 var basic = input.lastIndexOf(delimiter); 422 if (basic < 0) { 423 basic = 0; 424 } 425 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'); 430 } 431 output.push(input.charCodeAt(j)); 432 } 433 434 // Main decoding loop: start just after the last delimiter if any basic code 435 // points were copied; start at the beginning otherwise. 436 437 for (var index = basic > 0 ? basic + 1 : 0; index < inputLength;) /* no final expression */{ 438 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`. 444 var oldi = i; 445 for (var w = 1, k = base;; /* no condition */k += base) { 446 447 if (index >= inputLength) { 448 error$1('invalid-input'); 449 } 450 451 var digit = basicToDigit(input.charCodeAt(index++)); 452 453 if (digit >= base || digit > floor((maxInt - i) / w)) { 454 error$1('overflow'); 455 } 456 457 i += digit * w; 458 var t = k <= bias ? tMin : k >= bias + tMax ? tMax : k - bias; 459 460 if (digit < t) { 461 break; 462 } 463 464 var baseMinusT = base - t; 465 if (w > floor(maxInt / baseMinusT)) { 466 error$1('overflow'); 467 } 468 469 w *= baseMinusT; 470 } 471 472 var out = output.length + 1; 473 bias = adapt(i - oldi, out, oldi == 0); 474 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) { 478 error$1('overflow'); 479 } 480 481 n += floor(i / out); 482 i %= out; 483 484 // Insert `n` at position `i` of the output. 485 output.splice(i++, 0, n); 486 } 487 488 return String.fromCodePoint.apply(String, output); 489 }; 490 491 /** 492 * Converts a string of Unicode symbols (e.g. a domain name label) to a 493 * Punycode string of ASCII-only symbols. 494 * @memberOf punycode 495 * @param {String} input The string of Unicode symbols. 496 * @returns {String} The resulting Punycode string of ASCII-only symbols. 497 */ 498 var encode = function encode(input) { 499 var output = []; 500 501 // Convert the input in UCS-2 to an array of Unicode code points. 502 input = ucs2decode(input); 503 504 // Cache the length. 505 var inputLength = input.length; 506 507 // Initialize the state. 508 var n = initialN; 509 var delta = 0; 510 var bias = initialBias; 511 512 // Handle the basic code points. 513 var _iteratorNormalCompletion = true; 514 var _didIteratorError = false; 515 var _iteratorError = undefined; 516 517 try { 518 for (var _iterator = input[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { 519 var _currentValue2 = _step.value; 520 521 if (_currentValue2 < 0x80) { 522 output.push(stringFromCharCode(_currentValue2)); 523 } 524 } 525 } catch (err) { 526 _didIteratorError = true; 527 _iteratorError = err; 528 } finally { 529 try { 530 if (!_iteratorNormalCompletion && _iterator.return) { 531 _iterator.return(); 532 } 533 } finally { 534 if (_didIteratorError) { 535 throw _iteratorError; 536 } 537 } 538 } 539 540 var basicLength = output.length; 541 var handledCPCount = basicLength; 542 543 // `handledCPCount` is the number of code points that have been handled; 544 // `basicLength` is the number of basic code points. 545 546 // Finish the basic string with a delimiter unless it's empty. 547 if (basicLength) { 548 output.push(delimiter); 549 } 550 551 // Main encoding loop: 552 while (handledCPCount < inputLength) { 553 554 // All non-basic code points < n have been handled already. Find the next 555 // larger one: 556 var m = maxInt; 557 var _iteratorNormalCompletion2 = true; 558 var _didIteratorError2 = false; 559 var _iteratorError2 = undefined; 560 561 try { 562 for (var _iterator2 = input[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { 563 var currentValue = _step2.value; 564 565 if (currentValue >= n && currentValue < m) { 566 m = currentValue; 567 } 568 } 569 570 // Increase `delta` enough to advance the decoder's <n,i> state to <m,0>, 571 // but guard against overflow. 572 } catch (err) { 573 _didIteratorError2 = true; 574 _iteratorError2 = err; 575 } finally { 576 try { 577 if (!_iteratorNormalCompletion2 && _iterator2.return) { 578 _iterator2.return(); 579 } 580 } finally { 581 if (_didIteratorError2) { 582 throw _iteratorError2; 583 } 584 } 585 } 586 587 var handledCPCountPlusOne = handledCPCount + 1; 588 if (m - n > floor((maxInt - delta) / handledCPCountPlusOne)) { 589 error$1('overflow'); 590 } 591 592 delta += (m - n) * handledCPCountPlusOne; 593 n = m; 594 595 var _iteratorNormalCompletion3 = true; 596 var _didIteratorError3 = false; 597 var _iteratorError3 = undefined; 598 599 try { 600 for (var _iterator3 = input[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { 601 var _currentValue = _step3.value; 602 603 if (_currentValue < n && ++delta > maxInt) { 604 error$1('overflow'); 605 } 606 if (_currentValue == n) { 607 // Represent delta as a generalized variable-length integer. 608 var q = delta; 609 for (var k = base;; /* no condition */k += base) { 610 var t = k <= bias ? tMin : k >= bias + tMax ? tMax : k - bias; 611 if (q < t) { 612 break; 613 } 614 var qMinusT = q - t; 615 var baseMinusT = base - t; 616 output.push(stringFromCharCode(digitToBasic(t + qMinusT % baseMinusT, 0))); 617 q = floor(qMinusT / baseMinusT); 618 } 619 620 output.push(stringFromCharCode(digitToBasic(q, 0))); 621 bias = adapt(delta, handledCPCountPlusOne, handledCPCount == basicLength); 622 delta = 0; 623 ++handledCPCount; 624 } 625 } 626 } catch (err) { 627 _didIteratorError3 = true; 628 _iteratorError3 = err; 629 } finally { 630 try { 631 if (!_iteratorNormalCompletion3 && _iterator3.return) { 632 _iterator3.return(); 633 } 634 } finally { 635 if (_didIteratorError3) { 636 throw _iteratorError3; 637 } 638 } 639 } 640 641 ++delta; 642 ++n; 643 } 644 return output.join(''); 645 }; 646 647 /** 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. 652 * @memberOf punycode 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 656 * string. 657 */ 658 var toUnicode = function toUnicode(input) { 659 return mapDomain(input, function (string) { 660 return regexPunycode.test(string) ? decode(string.slice(4).toLowerCase()) : string; 661 }); 662 }; 663 664 /** 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 668 * ASCII. 669 * @memberOf punycode 670 * @param {String} input The domain name or email address to convert, as a 671 * Unicode string. 672 * @returns {String} The Punycode representation of the given domain name or 673 * email address. 674 */ 675 var toASCII = function toASCII(input) { 676 return mapDomain(input, function (string) { 677 return regexNonASCII.test(string) ? 'xn--' + encode(string) : string; 678 }); 679 }; 680 681 /*--------------------------------------------------------------------------*/ 682 683 /** Define the public API */ 684 var punycode = { 685 /** 686 * A string representing the current Punycode.js version number. 687 * @memberOf punycode 688 * @type String 689 */ 690 'version': '2.1.0', 691 /** 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> 695 * @memberOf punycode 696 * @type Object 697 */ 698 'ucs2': { 699 'decode': ucs2decode, 700 'encode': ucs2encode 701 }, 702 'decode': decode, 703 'encode': encode, 704 'toASCII': toASCII, 705 'toUnicode': toUnicode 706 }; 707 708 /** 709 * URI.js 710 * 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 714 */ 715 /** 716 * Copyright 2011 Gary Court. All rights reserved. 717 * 718 * Redistribution and use in source and binary forms, with or without modification, are 719 * permitted provided that the following conditions are met: 720 * 721 * 1. Redistributions of source code must retain the above copyright notice, this list of 722 * conditions and the following disclaimer. 723 * 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. 727 * 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. 737 * 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. 741 */ 742 var SCHEMES = {}; 743 function pctEncChar(chr) { 744 var c = chr.charCodeAt(0); 745 var e = void 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(); 747 return e; 748 } 749 function pctDecChars(str) { 750 var newStr = ""; 751 var i = 0; 752 var il = str.length; 753 while (i < il) { 754 var c = parseInt(str.substr(i + 1, 2), 16); 755 if (c < 128) { 756 newStr += String.fromCharCode(c); 757 i += 3; 758 } else if (c >= 194 && c < 224) { 759 if (il - i >= 6) { 760 var c2 = parseInt(str.substr(i + 4, 2), 16); 761 newStr += String.fromCharCode((c & 31) << 6 | c2 & 63); 762 } else { 763 newStr += str.substr(i, 6); 764 } 765 i += 6; 766 } else if (c >= 224) { 767 if (il - i >= 9) { 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); 771 } else { 772 newStr += str.substr(i, 9); 773 } 774 i += 9; 775 } else { 776 newStr += str.substr(i, 3); 777 i += 3; 778 } 779 } 780 return newStr; 781 } 782 function _normalizeComponentEncoding(components, protocol) { 783 function decodeUnreserved(str) { 784 var decStr = pctDecChars(str); 785 return !decStr.match(protocol.UNRESERVED) ? str : decStr; 786 } 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); 793 return components; 794 } 795 796 function _stripLeadingZeros(str) { 797 return str.replace(/^0*(.*)/, "$1") || "0"; 798 } 799 function _normalizeIPv4(host, protocol) { 800 var matches = host.match(protocol.IPV4ADDRESS) || []; 801 802 var _matches = slicedToArray(matches, 2), 803 address = _matches[1]; 804 805 if (address) { 806 return address.split(".").map(_stripLeadingZeros).join("."); 807 } else { 808 return host; 809 } 810 } 811 function _normalizeIPv6(host, protocol) { 812 var matches = host.match(protocol.IPV6ADDRESS) || []; 813 814 var _matches2 = slicedToArray(matches, 3), 815 address = _matches2[1], 816 zone = _matches2[2]; 817 818 if (address) { 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]; 823 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] || ''; 832 } 833 if (isLastFieldIPv4Address) { 834 fields[fieldCount - 1] = _normalizeIPv4(fields[fieldCount - 1], protocol); 835 } 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++; 841 } else { 842 acc.push({ index: index, length: 1 }); 843 } 844 } 845 return acc; 846 }, []); 847 var longestZeroFields = allZeroFields.sort(function (a, b) { 848 return b.length - a.length; 849 })[0]; 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(":"); 855 } else { 856 newHost = fields.join(":"); 857 } 858 if (zone) { 859 newHost += "%" + zone; 860 } 861 return newHost; 862 } else { 863 return host; 864 } 865 } 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] : {}; 870 871 var components = {}; 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); 875 if (matches) { 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]; 885 //fix port number 886 if (isNaN(components.port)) { 887 components.port = matches[5]; 888 } 889 } else { 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; 899 //fix port number 900 if (isNaN(components.port)) { 901 components.port = uriString.match(/\/\/(?:.|\n)*\:(?:\/|\?|\#|$)/) ? matches[4] : undefined; 902 } 903 } 904 if (components.host) { 905 //normalize IP hosts 906 components.host = _normalizeIPv6(_normalizeIPv4(components.host, protocol), protocol); 907 } 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"; 915 } else { 916 components.reference = "uri"; 917 } 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."; 921 } 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 929 try { 930 components.host = punycode.toASCII(components.host.replace(protocol.PCT_ENCODED, pctDecChars).toLowerCase()); 931 } catch (e) { 932 components.error = components.error || "Host's domain name can not be converted to ASCII via punycode: " + e; 933 } 934 } 935 //convert IRI -> URI 936 _normalizeComponentEncoding(components, URI_PROTOCOL); 937 } else { 938 //normalize encodings 939 _normalizeComponentEncoding(components, protocol); 940 } 941 //perform scheme specific parsing 942 if (schemeHandler && schemeHandler.parse) { 943 schemeHandler.parse(components, options); 944 } 945 } else { 946 components.error = components.error || "URI can not be parsed."; 947 } 948 return components; 949 } 950 951 function _recomposeAuthority(components, options) { 952 var protocol = options.iri !== false ? IRI_PROTOCOL : URI_PROTOCOL; 953 var uriTokens = []; 954 if (components.userinfo !== undefined) { 955 uriTokens.push(components.userinfo); 956 uriTokens.push("@"); 957 } 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 : "") + "]"; 962 })); 963 } 964 if (typeof components.port === "number") { 965 uriTokens.push(":"); 966 uriTokens.push(components.port.toString(10)); 967 } 968 return uriTokens.length ? uriTokens.join("") : undefined; 969 } 970 971 var RDS1 = /^\.\.?\//; 972 var RDS2 = /^\/\.(\/|$)/; 973 var RDS3 = /^\/\.\.(\/|$)/; 974 var RDS5 = /^\/?(?:.|\n)*?(?=\/|$)/; 975 function removeDotSegments(input) { 976 var output = []; 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, "/"); 984 output.pop(); 985 } else if (input === "." || input === "..") { 986 input = ""; 987 } else { 988 var im = input.match(RDS5); 989 if (im) { 990 var s = im[0]; 991 input = input.slice(s.length); 992 output.push(s); 993 } else { 994 throw new Error("Unexpected dot segment condition"); 995 } 996 } 997 } 998 return output.join(""); 999 } 1000 1001 function serialize(components) { 1002 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; 1003 1004 var protocol = options.iri ? IRI_PROTOCOL : URI_PROTOCOL; 1005 var uriTokens = []; 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 1014 1015 //if host component is a domain name 1016 else if (options.domainHost || schemeHandler && schemeHandler.domainHost) { 1017 //convert IDN via punycode 1018 try { 1019 components.host = !options.iri ? punycode.toASCII(components.host.replace(protocol.PCT_ENCODED, pctDecChars).toLowerCase()) : punycode.toUnicode(components.host); 1020 } catch (e) { 1021 components.error = components.error || "Host's domain name can not be converted to " + (!options.iri ? "ASCII" : "Unicode") + " via punycode: " + e; 1022 } 1023 } 1024 } 1025 //normalize encoding 1026 _normalizeComponentEncoding(components, protocol); 1027 if (options.reference !== "suffix" && components.scheme) { 1028 uriTokens.push(components.scheme); 1029 uriTokens.push(":"); 1030 } 1031 var authority = _recomposeAuthority(components, options); 1032 if (authority !== undefined) { 1033 if (options.reference !== "suffix") { 1034 uriTokens.push("//"); 1035 } 1036 uriTokens.push(authority); 1037 if (components.path && components.path.charAt(0) !== "/") { 1038 uriTokens.push("/"); 1039 } 1040 } 1041 if (components.path !== undefined) { 1042 var s = components.path; 1043 if (!options.absolutePath && (!schemeHandler || !schemeHandler.absolutePath)) { 1044 s = removeDotSegments(s); 1045 } 1046 if (authority === undefined) { 1047 s = s.replace(/^\/\//, "/%2F"); //don't allow the path to start with "//" 1048 } 1049 uriTokens.push(s); 1050 } 1051 if (components.query !== undefined) { 1052 uriTokens.push("?"); 1053 uriTokens.push(components.query); 1054 } 1055 if (components.fragment !== undefined) { 1056 uriTokens.push("#"); 1057 uriTokens.push(components.fragment); 1058 } 1059 return uriTokens.join(""); //merge tokens into a string 1060 } 1061 1062 function resolveComponents(base, relative) { 1063 var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; 1064 var skipNormalization = arguments[3]; 1065 1066 var target = {}; 1067 if (!skipNormalization) { 1068 base = parse(serialize(base, options), options); //normalize base components 1069 relative = parse(serialize(relative, options), options); //normalize relative components 1070 } 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; 1080 } else { 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; 1088 } else { 1089 if (!relative.path) { 1090 target.path = base.path; 1091 if (relative.query !== undefined) { 1092 target.query = relative.query; 1093 } else { 1094 target.query = base.query; 1095 } 1096 } else { 1097 if (relative.path.charAt(0) === "/") { 1098 target.path = removeDotSegments(relative.path); 1099 } else { 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; 1104 } else { 1105 target.path = base.path.slice(0, base.path.lastIndexOf("/") + 1) + relative.path; 1106 } 1107 target.path = removeDotSegments(target.path); 1108 } 1109 target.query = relative.query; 1110 } 1111 //target.authority = base.authority; 1112 target.userinfo = base.userinfo; 1113 target.host = base.host; 1114 target.port = base.port; 1115 } 1116 target.scheme = base.scheme; 1117 } 1118 target.fragment = relative.fragment; 1119 return target; 1120 } 1121 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); 1125 } 1126 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); 1132 } 1133 return uri; 1134 } 1135 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); 1141 } 1142 if (typeof uriB === "string") { 1143 uriB = serialize(parse(uriB, options), options); 1144 } else if (typeOf(uriB) === "object") { 1145 uriB = serialize(uriB, options); 1146 } 1147 return uriA === uriB; 1148 } 1149 1150 function escapeComponent(str, options) { 1151 return str && str.toString().replace(!options || !options.iri ? URI_PROTOCOL.ESCAPE : IRI_PROTOCOL.ESCAPE, pctEncChar); 1152 } 1153 1154 function unescapeComponent(str, options) { 1155 return str && str.toString().replace(!options || !options.iri ? URI_PROTOCOL.PCT_ENCODED : IRI_PROTOCOL.PCT_ENCODED, pctDecChars); 1156 } 1157 1158 var handler = { 1159 scheme: "http", 1160 domainHost: true, 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."; 1165 } 1166 return components; 1167 }, 1168 serialize: function serialize(components, options) { 1169 //normalize the default port 1170 if (components.port === (String(components.scheme).toLowerCase() !== "https" ? 80 : 443) || components.port === "") { 1171 components.port = undefined; 1172 } 1173 //normalize the empty path 1174 if (!components.path) { 1175 components.path = "/"; 1176 } 1177 //NOTE: We do not parse query strings for HTTP URIs 1178 //as WWW Form Url Encoded query strings are part of the HTML4+ spec, 1179 //and not the HTTP spec. 1180 return components; 1181 } 1182 }; 1183 1184 var handler$1 = { 1185 scheme: "https", 1186 domainHost: handler.domainHost, 1187 parse: handler.parse, 1188 serialize: handler.serialize 1189 }; 1190 1191 var O = {}; 1192 var isIRI = true; 1193 //RFC 3986 1194 var UNRESERVED$$ = "[A-Za-z0-9\\-\\.\\_\\~" + (isIRI ? "\\xA0-\\u200D\\u2010-\\u2029\\u202F-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF" : "") + "]"; 1195 var HEXDIG$$ = "[0-9A-Fa-f]"; //case-insensitive 1196 var PCT_ENCODED$ = subexp(subexp("%[EFef]" + HEXDIG$$ + "%" + HEXDIG$$ + HEXDIG$$ + "%" + HEXDIG$$ + HEXDIG$$) + "|" + subexp("%[89A-Fa-f]" + HEXDIG$$ + "%" + HEXDIG$$ + HEXDIG$$) + "|" + subexp("%" + HEXDIG$$ + HEXDIG$$)); //expanded 1197 //RFC 5322, except these symbols as per RFC 6068: @ : / ? # [ ] & ; = 1198 //const ATEXT$$ = "[A-Za-z0-9\\!\\#\\$\\%\\&\\'\\*\\+\\-\\/\\=\\?\\^\\_\\`\\{\\|\\}\\~]"; 1199 //const WSP$$ = "[\\x20\\x09]"; 1200 //const OBS_QTEXT$$ = "[\\x01-\\x08\\x0B\\x0C\\x0E-\\x1F\\x7F]"; //(%d1-8 / %d11-12 / %d14-31 / %d127) 1201 //const QTEXT$$ = merge("[\\x21\\x23-\\x5B\\x5D-\\x7E]", OBS_QTEXT$$); //%d33 / %d35-91 / %d93-126 / obs-qtext 1202 //const VCHAR$$ = "[\\x21-\\x7E]"; 1203 //const WSP$$ = "[\\x20\\x09]"; 1204 //const OBS_QP$ = subexp("\\\\" + merge("[\\x00\\x0D\\x0A]", OBS_QTEXT$$)); //%d0 / CR / LF / obs-qtext 1205 //const FWS$ = subexp(subexp(WSP$$ + "*" + "\\x0D\\x0A") + "?" + WSP$$ + "+"); 1206 //const QUOTED_PAIR$ = subexp(subexp("\\\\" + subexp(VCHAR$$ + "|" + WSP$$)) + "|" + OBS_QP$); 1207 //const QUOTED_STRING$ = subexp('\\"' + subexp(FWS$ + "?" + QCONTENT$) + "*" + FWS$ + "?" + '\\"'); 1208 var ATEXT$$ = "[A-Za-z0-9\\!\\$\\%\\'\\*\\+\\-\\^\\_\\`\\{\\|\\}\\~]"; 1209 var QTEXT$$ = "[\\!\\$\\%\\'\\(\\)\\*\\+\\,\\-\\.0-9\\<\\>A-Z\\x5E-\\x7E]"; 1210 var VCHAR$$ = merge(QTEXT$$, "[\\\"\\\\]"); 1211 var SOME_DELIMS$$ = "[\\!\\$\\'\\(\\)\\*\\+\\,\\;\\:\\@]"; 1212 var UNRESERVED = new RegExp(UNRESERVED$$, "g"); 1213 var PCT_ENCODED = new RegExp(PCT_ENCODED$, "g"); 1214 var NOT_LOCAL_PART = new RegExp(merge("[^]", ATEXT$$, "[\\.]", '[\\"]', VCHAR$$), "g"); 1215 var NOT_HFNAME = new RegExp(merge("[^]", UNRESERVED$$, SOME_DELIMS$$), "g"); 1216 var NOT_HFVALUE = NOT_HFNAME; 1217 function decodeUnreserved(str) { 1218 var decStr = pctDecChars(str); 1219 return !decStr.match(UNRESERVED) ? str : decStr; 1220 } 1221 var handler$2 = { 1222 scheme: "mailto", 1223 parse: function parse$$1(components, options) { 1224 var mailtoComponents = components; 1225 var to = mailtoComponents.to = mailtoComponents.path ? mailtoComponents.path.split(",") : []; 1226 mailtoComponents.path = undefined; 1227 if (mailtoComponents.query) { 1228 var unknownHeaders = false; 1229 var headers = {}; 1230 var hfields = mailtoComponents.query.split("&"); 1231 for (var x = 0, xl = hfields.length; x < xl; ++x) { 1232 var hfield = hfields[x].split("="); 1233 switch (hfield[0]) { 1234 case "to": 1235 var toAddrs = hfield[1].split(","); 1236 for (var _x = 0, _xl = toAddrs.length; _x < _xl; ++_x) { 1237 to.push(toAddrs[_x]); 1238 } 1239 break; 1240 case "subject": 1241 mailtoComponents.subject = unescapeComponent(hfield[1], options); 1242 break; 1243 case "body": 1244 mailtoComponents.body = unescapeComponent(hfield[1], options); 1245 break; 1246 default: 1247 unknownHeaders = true; 1248 headers[unescapeComponent(hfield[0], options)] = unescapeComponent(hfield[1], options); 1249 break; 1250 } 1251 } 1252 if (unknownHeaders) mailtoComponents.headers = headers; 1253 } 1254 mailtoComponents.query = undefined; 1255 for (var _x2 = 0, _xl2 = to.length; _x2 < _xl2; ++_x2) { 1256 var addr = to[_x2].split("@"); 1257 addr[0] = unescapeComponent(addr[0]); 1258 if (!options.unicodeSupport) { 1259 //convert Unicode IDN -> ASCII IDN 1260 try { 1261 addr[1] = punycode.toASCII(unescapeComponent(addr[1], options).toLowerCase()); 1262 } catch (e) { 1263 mailtoComponents.error = mailtoComponents.error || "Email address's domain name can not be converted to ASCII via punycode: " + e; 1264 } 1265 } else { 1266 addr[1] = unescapeComponent(addr[1], options).toLowerCase(); 1267 } 1268 to[_x2] = addr.join("@"); 1269 } 1270 return mailtoComponents; 1271 }, 1272 serialize: function serialize$$1(mailtoComponents, options) { 1273 var components = mailtoComponents; 1274 var to = toArray(mailtoComponents.to); 1275 if (to) { 1276 for (var x = 0, xl = to.length; x < xl; ++x) { 1277 var toAddr = String(to[x]); 1278 var atIdx = toAddr.lastIndexOf("@"); 1279 var localPart = toAddr.slice(0, atIdx).replace(PCT_ENCODED, decodeUnreserved).replace(PCT_ENCODED, toUpperCase).replace(NOT_LOCAL_PART, pctEncChar); 1280 var domain = toAddr.slice(atIdx + 1); 1281 //convert IDN via punycode 1282 try { 1283 domain = !options.iri ? punycode.toASCII(unescapeComponent(domain, options).toLowerCase()) : punycode.toUnicode(domain); 1284 } catch (e) { 1285 components.error = components.error || "Email address's domain name can not be converted to " + (!options.iri ? "ASCII" : "Unicode") + " via punycode: " + e; 1286 } 1287 to[x] = localPart + "@" + domain; 1288 } 1289 components.path = to.join(","); 1290 } 1291 var headers = mailtoComponents.headers = mailtoComponents.headers || {}; 1292 if (mailtoComponents.subject) headers["subject"] = mailtoComponents.subject; 1293 if (mailtoComponents.body) headers["body"] = mailtoComponents.body; 1294 var fields = []; 1295 for (var name in headers) { 1296 if (headers[name] !== O[name]) { 1297 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)); 1298 } 1299 } 1300 if (fields.length) { 1301 components.query = fields.join("&"); 1302 } 1303 return components; 1304 } 1305 }; 1306 1307 var URN_PARSE = /^([^\:]+)\:(.*)/; 1308 //RFC 2141 1309 var handler$3 = { 1310 scheme: "urn", 1311 parse: function parse$$1(components, options) { 1312 var matches = components.path && components.path.match(URN_PARSE); 1313 var urnComponents = components; 1314 if (matches) { 1315 var scheme = options.scheme || urnComponents.scheme || "urn"; 1316 var nid = matches[1].toLowerCase(); 1317 var nss = matches[2]; 1318 var urnScheme = scheme + ":" + (options.nid || nid); 1319 var schemeHandler = SCHEMES[urnScheme]; 1320 urnComponents.nid = nid; 1321 urnComponents.nss = nss; 1322 urnComponents.path = undefined; 1323 if (schemeHandler) { 1324 urnComponents = schemeHandler.parse(urnComponents, options); 1325 } 1326 } else { 1327 urnComponents.error = urnComponents.error || "URN can not be parsed."; 1328 } 1329 return urnComponents; 1330 }, 1331 serialize: function serialize$$1(urnComponents, options) { 1332 var scheme = options.scheme || urnComponents.scheme || "urn"; 1333 var nid = urnComponents.nid; 1334 var urnScheme = scheme + ":" + (options.nid || nid); 1335 var schemeHandler = SCHEMES[urnScheme]; 1336 if (schemeHandler) { 1337 urnComponents = schemeHandler.serialize(urnComponents, options); 1338 } 1339 var uriComponents = urnComponents; 1340 var nss = urnComponents.nss; 1341 uriComponents.path = (nid || options.nid) + ":" + nss; 1342 return uriComponents; 1343 } 1344 }; 1345 1346 var UUID = /^[0-9A-Fa-f]{8}(?:\-[0-9A-Fa-f]{4}){3}\-[0-9A-Fa-f]{12}$/; 1347 //RFC 4122 1348 var handler$4 = { 1349 scheme: "urn:uuid", 1350 parse: function parse(urnComponents, options) { 1351 var uuidComponents = urnComponents; 1352 uuidComponents.uuid = uuidComponents.nss; 1353 uuidComponents.nss = undefined; 1354 if (!options.tolerant && (!uuidComponents.uuid || !uuidComponents.uuid.match(UUID))) { 1355 uuidComponents.error = uuidComponents.error || "UUID is not valid."; 1356 } 1357 return uuidComponents; 1358 }, 1359 serialize: function serialize(uuidComponents, options) { 1360 var urnComponents = uuidComponents; 1361 //normalize UUID 1362 urnComponents.nss = (uuidComponents.uuid || "").toLowerCase(); 1363 return urnComponents; 1364 } 1365 }; 1366 1367 SCHEMES[handler.scheme] = handler; 1368 SCHEMES[handler$1.scheme] = handler$1; 1369 SCHEMES[handler$2.scheme] = handler$2; 1370 SCHEMES[handler$3.scheme] = handler$3; 1371 SCHEMES[handler$4.scheme] = handler$4; 1372 1373 exports.SCHEMES = SCHEMES; 1374 exports.pctEncChar = pctEncChar; 1375 exports.pctDecChars = pctDecChars; 1376 exports.parse = parse; 1377 exports.removeDotSegments = removeDotSegments; 1378 exports.serialize = serialize; 1379 exports.resolveComponents = resolveComponents; 1380 exports.resolve = resolve; 1381 exports.normalize = normalize; 1382 exports.equal = equal; 1383 exports.escapeComponent = escapeComponent; 1384 exports.unescapeComponent = unescapeComponent; 1385 1386 Object.defineProperty(exports, '__esModule', { value: true }); 1387 1388 }))); 1389 //# sourceMappingURL=uri.all.js.map