@hyperjump/json-schema 0.18.3 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -44,6 +44,10 @@ var JsonSchema = (function (exports) {
44
44
 
45
45
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
46
46
 
47
+ function unwrapExports (x) {
48
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
49
+ }
50
+
47
51
  function createCommonjsModule(fn, module) {
48
52
  return module = { exports: {} }, fn(module, module.exports), module.exports;
49
53
  }
@@ -403,216 +407,1412 @@ var JsonSchema = (function (exports) {
403
407
  });
404
408
  pubsub.PubSub;
405
409
 
406
- var urlResolveBrowser = urlResolve;
410
+ var uri_all = createCommonjsModule(function (module, exports) {
411
+ /** @license URI.js v4.4.1 (c) 2011 Gary Court. License: http://github.com/garycourt/uri-js */
412
+ (function (global, factory) {
413
+ factory(exports) ;
414
+ }(commonjsGlobal, (function (exports) {
415
+ function merge() {
416
+ for (var _len = arguments.length, sets = Array(_len), _key = 0; _key < _len; _key++) {
417
+ sets[_key] = arguments[_key];
418
+ }
407
419
 
408
- /*
409
- The majority of the module is built by following RFC1808
410
- url: https://tools.ietf.org/html/rfc1808
411
- */
420
+ if (sets.length > 1) {
421
+ sets[0] = sets[0].slice(0, -1);
422
+ var xl = sets.length - 1;
423
+ for (var x = 1; x < xl; ++x) {
424
+ sets[x] = sets[x].slice(1, -1);
425
+ }
426
+ sets[xl] = sets[xl].slice(1);
427
+ return sets.join('');
428
+ } else {
429
+ return sets[0];
430
+ }
431
+ }
432
+ function subexp(str) {
433
+ return "(?:" + str + ")";
434
+ }
435
+ function typeOf(o) {
436
+ return o === undefined ? "undefined" : o === null ? "null" : Object.prototype.toString.call(o).split(" ").pop().split("]").shift().toLowerCase();
437
+ }
438
+ function toUpperCase(str) {
439
+ return str.toUpperCase();
440
+ }
441
+ function toArray(obj) {
442
+ 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) : [];
443
+ }
444
+ function assign(target, source) {
445
+ var obj = target;
446
+ if (source) {
447
+ for (var key in source) {
448
+ obj[key] = source[key];
449
+ }
450
+ }
451
+ return obj;
452
+ }
412
453
 
413
- // adds a slash at end if not present
414
- function _addSlash (url) {
415
- return url + (url[url.length-1] === '/' ? '' : '/');
454
+ function buildExps(isIRI) {
455
+ var ALPHA$$ = "[A-Za-z]",
456
+ DIGIT$$ = "[0-9]",
457
+ HEXDIG$$ = merge(DIGIT$$, "[A-Fa-f]"),
458
+ PCT_ENCODED$ = subexp(subexp("%[EFef]" + HEXDIG$$ + "%" + HEXDIG$$ + HEXDIG$$ + "%" + HEXDIG$$ + HEXDIG$$) + "|" + subexp("%[89A-Fa-f]" + HEXDIG$$ + "%" + HEXDIG$$ + HEXDIG$$) + "|" + subexp("%" + HEXDIG$$ + HEXDIG$$)),
459
+ //expanded
460
+ GEN_DELIMS$$ = "[\\:\\/\\?\\#\\[\\]\\@]",
461
+ SUB_DELIMS$$ = "[\\!\\$\\&\\'\\(\\)\\*\\+\\,\\;\\=]",
462
+ RESERVED$$ = merge(GEN_DELIMS$$, SUB_DELIMS$$),
463
+ UCSCHAR$$ = isIRI ? "[\\xA0-\\u200D\\u2010-\\u2029\\u202F-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF]" : "[]",
464
+ //subset, excludes bidi control characters
465
+ IPRIVATE$$ = isIRI ? "[\\uE000-\\uF8FF]" : "[]",
466
+ //subset
467
+ UNRESERVED$$ = merge(ALPHA$$, DIGIT$$, "[\\-\\.\\_\\~]", UCSCHAR$$);
468
+ subexp(ALPHA$$ + merge(ALPHA$$, DIGIT$$, "[\\+\\-\\.]") + "*");
469
+ subexp(subexp(PCT_ENCODED$ + "|" + merge(UNRESERVED$$, SUB_DELIMS$$, "[\\:]")) + "*");
470
+ var 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$$),
471
+ //relaxed parsing rules
472
+ IPV4ADDRESS$ = subexp(DEC_OCTET_RELAXED$ + "\\." + DEC_OCTET_RELAXED$ + "\\." + DEC_OCTET_RELAXED$ + "\\." + DEC_OCTET_RELAXED$),
473
+ H16$ = subexp(HEXDIG$$ + "{1,4}"),
474
+ LS32$ = subexp(subexp(H16$ + "\\:" + H16$) + "|" + IPV4ADDRESS$),
475
+ IPV6ADDRESS1$ = subexp(subexp(H16$ + "\\:") + "{6}" + LS32$),
476
+ // 6( h16 ":" ) ls32
477
+ IPV6ADDRESS2$ = subexp("\\:\\:" + subexp(H16$ + "\\:") + "{5}" + LS32$),
478
+ // "::" 5( h16 ":" ) ls32
479
+ IPV6ADDRESS3$ = subexp(subexp(H16$) + "?\\:\\:" + subexp(H16$ + "\\:") + "{4}" + LS32$),
480
+ //[ h16 ] "::" 4( h16 ":" ) ls32
481
+ IPV6ADDRESS4$ = subexp(subexp(subexp(H16$ + "\\:") + "{0,1}" + H16$) + "?\\:\\:" + subexp(H16$ + "\\:") + "{3}" + LS32$),
482
+ //[ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32
483
+ IPV6ADDRESS5$ = subexp(subexp(subexp(H16$ + "\\:") + "{0,2}" + H16$) + "?\\:\\:" + subexp(H16$ + "\\:") + "{2}" + LS32$),
484
+ //[ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32
485
+ IPV6ADDRESS6$ = subexp(subexp(subexp(H16$ + "\\:") + "{0,3}" + H16$) + "?\\:\\:" + H16$ + "\\:" + LS32$),
486
+ //[ *3( h16 ":" ) h16 ] "::" h16 ":" ls32
487
+ IPV6ADDRESS7$ = subexp(subexp(subexp(H16$ + "\\:") + "{0,4}" + H16$) + "?\\:\\:" + LS32$),
488
+ //[ *4( h16 ":" ) h16 ] "::" ls32
489
+ IPV6ADDRESS8$ = subexp(subexp(subexp(H16$ + "\\:") + "{0,5}" + H16$) + "?\\:\\:" + H16$),
490
+ //[ *5( h16 ":" ) h16 ] "::" h16
491
+ IPV6ADDRESS9$ = subexp(subexp(subexp(H16$ + "\\:") + "{0,6}" + H16$) + "?\\:\\:"),
492
+ //[ *6( h16 ":" ) h16 ] "::"
493
+ IPV6ADDRESS$ = subexp([IPV6ADDRESS1$, IPV6ADDRESS2$, IPV6ADDRESS3$, IPV6ADDRESS4$, IPV6ADDRESS5$, IPV6ADDRESS6$, IPV6ADDRESS7$, IPV6ADDRESS8$, IPV6ADDRESS9$].join("|")),
494
+ ZONEID$ = subexp(subexp(UNRESERVED$$ + "|" + PCT_ENCODED$) + "+");
495
+ //RFC 6874, with relaxed parsing rules
496
+ subexp("[vV]" + HEXDIG$$ + "+\\." + merge(UNRESERVED$$, SUB_DELIMS$$, "[\\:]") + "+");
497
+ //RFC 6874
498
+ subexp(subexp(PCT_ENCODED$ + "|" + merge(UNRESERVED$$, SUB_DELIMS$$)) + "*");
499
+ var PCHAR$ = subexp(PCT_ENCODED$ + "|" + merge(UNRESERVED$$, SUB_DELIMS$$, "[\\:\\@]"));
500
+ subexp(subexp(PCT_ENCODED$ + "|" + merge(UNRESERVED$$, SUB_DELIMS$$, "[\\@]")) + "+");
501
+ subexp(subexp(PCHAR$ + "|" + merge("[\\/\\?]", IPRIVATE$$)) + "*");
502
+ return {
503
+ NOT_SCHEME: new RegExp(merge("[^]", ALPHA$$, DIGIT$$, "[\\+\\-\\.]"), "g"),
504
+ NOT_USERINFO: new RegExp(merge("[^\\%\\:]", UNRESERVED$$, SUB_DELIMS$$), "g"),
505
+ NOT_HOST: new RegExp(merge("[^\\%\\[\\]\\:]", UNRESERVED$$, SUB_DELIMS$$), "g"),
506
+ NOT_PATH: new RegExp(merge("[^\\%\\/\\:\\@]", UNRESERVED$$, SUB_DELIMS$$), "g"),
507
+ NOT_PATH_NOSCHEME: new RegExp(merge("[^\\%\\/\\@]", UNRESERVED$$, SUB_DELIMS$$), "g"),
508
+ NOT_QUERY: new RegExp(merge("[^\\%]", UNRESERVED$$, SUB_DELIMS$$, "[\\:\\@\\/\\?]", IPRIVATE$$), "g"),
509
+ NOT_FRAGMENT: new RegExp(merge("[^\\%]", UNRESERVED$$, SUB_DELIMS$$, "[\\:\\@\\/\\?]"), "g"),
510
+ ESCAPE: new RegExp(merge("[^]", UNRESERVED$$, SUB_DELIMS$$), "g"),
511
+ UNRESERVED: new RegExp(UNRESERVED$$, "g"),
512
+ OTHER_CHARS: new RegExp(merge("[^\\%]", UNRESERVED$$, RESERVED$$), "g"),
513
+ PCT_ENCODED: new RegExp(PCT_ENCODED$, "g"),
514
+ IPV4ADDRESS: new RegExp("^(" + IPV4ADDRESS$ + ")$"),
515
+ IPV6ADDRESS: new RegExp("^\\[?(" + IPV6ADDRESS$ + ")" + subexp(subexp("\\%25|\\%(?!" + HEXDIG$$ + "{2})") + "(" + ZONEID$ + ")") + "?\\]?$") //RFC 6874, with relaxed parsing rules
516
+ };
416
517
  }
518
+ var URI_PROTOCOL = buildExps(false);
417
519
 
418
- // resolve the ..'s (directory up) and such
419
- function _pathResolve (path) {
420
- let pathSplit = path.split('/');
520
+ var IRI_PROTOCOL = buildExps(true);
421
521
 
422
- // happens when path starts with /
423
- if (pathSplit[0] === '') {
424
- pathSplit = pathSplit.slice(1);
425
- }
522
+ var slicedToArray = function () {
523
+ function sliceIterator(arr, i) {
524
+ var _arr = [];
525
+ var _n = true;
526
+ var _d = false;
527
+ var _e = undefined;
426
528
 
427
- // let segmentCount = 0; // number of segments that have been passed
428
- let resultArray = [];
429
- pathSplit.forEach((current, index) => {
430
- // skip occurances of '.'
431
- if (current !== '.') {
432
- if (current === '..') {
433
- resultArray.pop(); // remove previous
434
- } else if (current !== '' || index === pathSplit.length - 1) {
435
- resultArray.push(current);
529
+ try {
530
+ for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
531
+ _arr.push(_s.value);
532
+
533
+ if (i && _arr.length === i) break;
534
+ }
535
+ } catch (err) {
536
+ _d = true;
537
+ _e = err;
538
+ } finally {
539
+ try {
540
+ if (!_n && _i["return"]) _i["return"]();
541
+ } finally {
542
+ if (_d) throw _e;
436
543
  }
437
544
  }
438
- });
439
- return '/' + resultArray.join('/');
440
- }
441
545
 
442
- // parses a base url string into an object containing host, path and query
443
- function _baseParse (base) {
444
- const resultObject = {
445
- host: '',
446
- path: '',
447
- query: '',
448
- protocol: ''
546
+ return _arr;
547
+ }
548
+
549
+ return function (arr, i) {
550
+ if (Array.isArray(arr)) {
551
+ return arr;
552
+ } else if (Symbol.iterator in Object(arr)) {
553
+ return sliceIterator(arr, i);
554
+ } else {
555
+ throw new TypeError("Invalid attempt to destructure non-iterable instance");
556
+ }
449
557
  };
558
+ }();
450
559
 
451
- let path = base;
452
- let protocolEndIndex = base.indexOf('//');
453
560
 
454
- resultObject.protocol = path.substring(0, protocolEndIndex);
455
561
 
456
- protocolEndIndex += 2; // add two to pass double slash
457
562
 
458
- const pathIndex = base.indexOf('/', protocolEndIndex);
459
- const queryIndex = base.indexOf('?');
460
- const hashIndex = base.indexOf('#');
461
563
 
462
- if (hashIndex !== -1) {
463
- path = path.substring(0, hashIndex); // remove hash, not needed for base
464
- }
465
564
 
466
- if (queryIndex !== -1) {
467
- const query = path.substring(queryIndex); // remove query, save in return obj
468
- resultObject.query = query;
469
- path = path.substring(0, queryIndex);
470
- }
471
565
 
472
- if (pathIndex !== -1) {
473
- const host = path.substring(0, pathIndex); // separate host & path
474
- resultObject.host = host;
475
- path = path.substring(pathIndex);
476
- resultObject.path = path;
477
- } else {
478
- resultObject.host = path; // there was no path, therefore path is host
479
- }
480
566
 
481
- return resultObject;
482
- }
483
567
 
484
- // https://tools.ietf.org/html/rfc3986#section-3.1
485
- const _scheme = '[a-z][a-z0-9+.-]*'; // ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )]
486
- const _isAbsolute = new RegExp(`^(${_scheme}:)?//`, 'i');
487
-
488
- // parses a relative url string into an object containing the href,
489
- // hash, query and whether it is a net path, absolute path or relative path
490
- function _relativeParse (relative) {
491
- const resultObject = {
492
- href: relative, // href is always what was passed through
493
- hash: '',
494
- query: '',
495
- netPath: false,
496
- absolutePath: false,
497
- relativePath: false
498
- };
499
- // check for protocol
500
- // if protocol exists, is net path (absolute URL)
501
- if (_isAbsolute.test(relative)) {
502
- resultObject.netPath = true;
503
- // return, in this case the relative is the resolved url, no need to parse.
504
- return resultObject;
505
- }
506
568
 
507
- // if / is first, this is an absolute path,
508
- // I.E. it overwrites the base URL's path
509
- if (relative[0] === '/') {
510
- resultObject.absolutePath = true;
511
- // return resultObject
512
- } else if (relative !== '') {
513
- resultObject.relativePath = true;
514
- }
515
569
 
516
- let path = relative;
517
- const queryIndex = relative.indexOf('?');
518
- const hashIndex = relative.indexOf('#');
519
570
 
520
- if (hashIndex !== -1) {
521
- const hash = path.substring(hashIndex);
522
- resultObject.hash = hash;
523
- path = path.substring(0, hashIndex);
524
- }
525
571
 
526
- if (queryIndex !== -1) {
527
- const query = path.substring(queryIndex);
528
- resultObject.query = query;
529
- path = path.substring(0, queryIndex);
572
+ var toConsumableArray = function (arr) {
573
+ if (Array.isArray(arr)) {
574
+ for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
575
+
576
+ return arr2;
577
+ } else {
578
+ return Array.from(arr);
530
579
  }
580
+ };
581
+
582
+ /** Highest positive signed 32-bit float value */
583
+
584
+ var maxInt = 2147483647; // aka. 0x7FFFFFFF or 2^31-1
585
+
586
+ /** Bootstring parameters */
587
+ var base = 36;
588
+ var tMin = 1;
589
+ var tMax = 26;
590
+ var skew = 38;
591
+ var damp = 700;
592
+ var initialBias = 72;
593
+ var initialN = 128; // 0x80
594
+ var delimiter = '-'; // '\x2D'
595
+
596
+ /** Regular expressions */
597
+ var regexPunycode = /^xn--/;
598
+ var regexNonASCII = /[^\0-\x7E]/; // non-ASCII chars
599
+ var regexSeparators = /[\x2E\u3002\uFF0E\uFF61]/g; // RFC 3490 separators
600
+
601
+ /** Error messages */
602
+ var errors = {
603
+ 'overflow': 'Overflow: input needs wider integers to process',
604
+ 'not-basic': 'Illegal input >= 0x80 (not a basic code point)',
605
+ 'invalid-input': 'Invalid input'
606
+ };
607
+
608
+ /** Convenience shortcuts */
609
+ var baseMinusTMin = base - tMin;
610
+ var floor = Math.floor;
611
+ var stringFromCharCode = String.fromCharCode;
531
612
 
532
- resultObject.path = path; // whatever is left is path
533
- return resultObject;
613
+ /*--------------------------------------------------------------------------*/
614
+
615
+ /**
616
+ * A generic error utility function.
617
+ * @private
618
+ * @param {String} type The error type.
619
+ * @returns {Error} Throws a `RangeError` with the applicable error message.
620
+ */
621
+ function error$1(type) {
622
+ throw new RangeError(errors[type]);
534
623
  }
535
624
 
536
- function _shouldAddSlash (url) {
537
- const protocolIndex = url.indexOf('//') + 2;
538
- const noPath = !(url.includes('/', protocolIndex));
539
- const noQuery = !(url.includes('?', protocolIndex));
540
- const noHash = !(url.includes('#', protocolIndex));
541
- return (noPath && noQuery && noHash);
625
+ /**
626
+ * A generic `Array#map` utility function.
627
+ * @private
628
+ * @param {Array} array The array to iterate over.
629
+ * @param {Function} callback The function that gets called for every array
630
+ * item.
631
+ * @returns {Array} A new array of values returned by the callback function.
632
+ */
633
+ function map(array, fn) {
634
+ var result = [];
635
+ var length = array.length;
636
+ while (length--) {
637
+ result[length] = fn(array[length]);
638
+ }
639
+ return result;
542
640
  }
543
641
 
544
- function _shouldAddProtocol (url) {
545
- return url.startsWith('//');
642
+ /**
643
+ * A simple `Array#map`-like wrapper to work with domain name strings or email
644
+ * addresses.
645
+ * @private
646
+ * @param {String} domain The domain name or email address.
647
+ * @param {Function} callback The function that gets called for every
648
+ * character.
649
+ * @returns {Array} A new string of characters returned by the callback
650
+ * function.
651
+ */
652
+ function mapDomain(string, fn) {
653
+ var parts = string.split('@');
654
+ var result = '';
655
+ if (parts.length > 1) {
656
+ // In email addresses, only the domain name should be punycoded. Leave
657
+ // the local part (i.e. everything up to `@`) intact.
658
+ result = parts[0] + '@';
659
+ string = parts[1];
660
+ }
661
+ // Avoid `split(regex)` for IE8 compatibility. See #17.
662
+ string = string.replace(regexSeparators, '\x2E');
663
+ var labels = string.split('.');
664
+ var encoded = map(labels, fn).join('.');
665
+ return result + encoded;
546
666
  }
547
667
 
548
- /*
549
- * PRECONDITION: Base is a fully qualified URL. e.g. http://example.com/
550
- * optional: path, query or hash
551
- * returns the resolved url
552
- */
553
- function urlResolve (base, relative) {
554
- base = base.trim();
555
- relative = relative.trim();
668
+ /**
669
+ * Creates an array containing the numeric code points of each Unicode
670
+ * character in the string. While JavaScript uses UCS-2 internally,
671
+ * this function will convert a pair of surrogate halves (each of which
672
+ * UCS-2 exposes as separate characters) into a single code point,
673
+ * matching UTF-16.
674
+ * @see `punycode.ucs2.encode`
675
+ * @see <https://mathiasbynens.be/notes/javascript-encoding>
676
+ * @memberOf punycode.ucs2
677
+ * @name decode
678
+ * @param {String} string The Unicode input string (UCS-2).
679
+ * @returns {Array} The new array of code points.
680
+ */
681
+ function ucs2decode(string) {
682
+ var output = [];
683
+ var counter = 0;
684
+ var length = string.length;
685
+ while (counter < length) {
686
+ var value = string.charCodeAt(counter++);
687
+ if (value >= 0xD800 && value <= 0xDBFF && counter < length) {
688
+ // It's a high surrogate, and there is a next character.
689
+ var extra = string.charCodeAt(counter++);
690
+ if ((extra & 0xFC00) == 0xDC00) {
691
+ // Low surrogate.
692
+ output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000);
693
+ } else {
694
+ // It's an unmatched surrogate; only append this code unit, in case the
695
+ // next code unit is the high surrogate of a surrogate pair.
696
+ output.push(value);
697
+ counter--;
698
+ }
699
+ } else {
700
+ output.push(value);
701
+ }
702
+ }
703
+ return output;
704
+ }
556
705
 
557
- // about is always absolute
558
- if (relative.startsWith('about:')) {
559
- return relative;
560
- }
706
+ /**
707
+ * Creates a string based on an array of numeric code points.
708
+ * @see `punycode.ucs2.decode`
709
+ * @memberOf punycode.ucs2
710
+ * @name encode
711
+ * @param {Array} codePoints The array of numeric code points.
712
+ * @returns {String} The new Unicode string (UCS-2).
713
+ */
714
+ var ucs2encode = function ucs2encode(array) {
715
+ return String.fromCodePoint.apply(String, toConsumableArray(array));
716
+ };
561
717
 
562
- const baseObj = _baseParse(base);
563
- const relativeObj = _relativeParse(relative);
718
+ /**
719
+ * Converts a basic code point into a digit/integer.
720
+ * @see `digitToBasic()`
721
+ * @private
722
+ * @param {Number} codePoint The basic numeric code point value.
723
+ * @returns {Number} The numeric value of a basic code point (for use in
724
+ * representing integers) in the range `0` to `base - 1`, or `base` if
725
+ * the code point does not represent a value.
726
+ */
727
+ var basicToDigit = function basicToDigit(codePoint) {
728
+ if (codePoint - 0x30 < 0x0A) {
729
+ return codePoint - 0x16;
730
+ }
731
+ if (codePoint - 0x41 < 0x1A) {
732
+ return codePoint - 0x41;
733
+ }
734
+ if (codePoint - 0x61 < 0x1A) {
735
+ return codePoint - 0x61;
736
+ }
737
+ return base;
738
+ };
564
739
 
565
- if (!baseObj.protocol && !relativeObj.netPath) {
566
- throw new Error('Error, protocol is not specified');
567
- }
740
+ /**
741
+ * Converts a digit/integer into a basic code point.
742
+ * @see `basicToDigit()`
743
+ * @private
744
+ * @param {Number} digit The numeric value of a basic code point.
745
+ * @returns {Number} The basic code point whose value (when used for
746
+ * representing integers) is `digit`, which needs to be in the range
747
+ * `0` to `base - 1`. If `flag` is non-zero, the uppercase form is
748
+ * used; else, the lowercase form is used. The behavior is undefined
749
+ * if `flag` is non-zero and `digit` has no uppercase form.
750
+ */
751
+ var digitToBasic = function digitToBasic(digit, flag) {
752
+ // 0..25 map to ASCII a..z or A..Z
753
+ // 26..35 map to ASCII 0..9
754
+ return digit + 22 + 75 * (digit < 26) - ((flag != 0) << 5);
755
+ };
756
+
757
+ /**
758
+ * Bias adaptation function as per section 3.4 of RFC 3492.
759
+ * https://tools.ietf.org/html/rfc3492#section-3.4
760
+ * @private
761
+ */
762
+ var adapt = function adapt(delta, numPoints, firstTime) {
763
+ var k = 0;
764
+ delta = firstTime ? floor(delta / damp) : delta >> 1;
765
+ delta += floor(delta / numPoints);
766
+ for (; /* no initialization */delta > baseMinusTMin * tMax >> 1; k += base) {
767
+ delta = floor(delta / baseMinusTMin);
768
+ }
769
+ return floor(k + (baseMinusTMin + 1) * delta / (delta + skew));
770
+ };
771
+
772
+ /**
773
+ * Converts a Punycode string of ASCII-only symbols to a string of Unicode
774
+ * symbols.
775
+ * @memberOf punycode
776
+ * @param {String} input The Punycode string of ASCII-only symbols.
777
+ * @returns {String} The resulting string of Unicode symbols.
778
+ */
779
+ var decode = function decode(input) {
780
+ // Don't use UCS-2.
781
+ var output = [];
782
+ var inputLength = input.length;
783
+ var i = 0;
784
+ var n = initialN;
785
+ var bias = initialBias;
786
+
787
+ // Handle the basic code points: let `basic` be the number of input code
788
+ // points before the last delimiter, or `0` if there is none, then copy
789
+ // the first basic code points to the output.
790
+
791
+ var basic = input.lastIndexOf(delimiter);
792
+ if (basic < 0) {
793
+ basic = 0;
794
+ }
795
+
796
+ for (var j = 0; j < basic; ++j) {
797
+ // if it's not a basic code point
798
+ if (input.charCodeAt(j) >= 0x80) {
799
+ error$1('not-basic');
800
+ }
801
+ output.push(input.charCodeAt(j));
802
+ }
803
+
804
+ // Main decoding loop: start just after the last delimiter if any basic code
805
+ // points were copied; start at the beginning otherwise.
806
+
807
+ for (var index = basic > 0 ? basic + 1 : 0; index < inputLength;) /* no final expression */{
808
+
809
+ // `index` is the index of the next character to be consumed.
810
+ // Decode a generalized variable-length integer into `delta`,
811
+ // which gets added to `i`. The overflow checking is easier
812
+ // if we increase `i` as we go, then subtract off its starting
813
+ // value at the end to obtain `delta`.
814
+ var oldi = i;
815
+ for (var w = 1, k = base;; /* no condition */k += base) {
816
+
817
+ if (index >= inputLength) {
818
+ error$1('invalid-input');
819
+ }
820
+
821
+ var digit = basicToDigit(input.charCodeAt(index++));
822
+
823
+ if (digit >= base || digit > floor((maxInt - i) / w)) {
824
+ error$1('overflow');
825
+ }
826
+
827
+ i += digit * w;
828
+ var t = k <= bias ? tMin : k >= bias + tMax ? tMax : k - bias;
829
+
830
+ if (digit < t) {
831
+ break;
832
+ }
833
+
834
+ var baseMinusT = base - t;
835
+ if (w > floor(maxInt / baseMinusT)) {
836
+ error$1('overflow');
837
+ }
838
+
839
+ w *= baseMinusT;
840
+ }
841
+
842
+ var out = output.length + 1;
843
+ bias = adapt(i - oldi, out, oldi == 0);
844
+
845
+ // `i` was supposed to wrap around from `out` to `0`,
846
+ // incrementing `n` each time, so we'll fix that now:
847
+ if (floor(i / out) > maxInt - n) {
848
+ error$1('overflow');
849
+ }
850
+
851
+ n += floor(i / out);
852
+ i %= out;
853
+
854
+ // Insert `n` at position `i` of the output.
855
+ output.splice(i++, 0, n);
856
+ }
857
+
858
+ return String.fromCodePoint.apply(String, output);
859
+ };
568
860
 
569
- if (relativeObj.netPath) { // relative is full qualified URL
570
- if (_shouldAddProtocol(relativeObj.href)) {
571
- relativeObj.href = baseObj.protocol + relativeObj.href;
861
+ /**
862
+ * Converts a string of Unicode symbols (e.g. a domain name label) to a
863
+ * Punycode string of ASCII-only symbols.
864
+ * @memberOf punycode
865
+ * @param {String} input The string of Unicode symbols.
866
+ * @returns {String} The resulting Punycode string of ASCII-only symbols.
867
+ */
868
+ var encode = function encode(input) {
869
+ var output = [];
870
+
871
+ // Convert the input in UCS-2 to an array of Unicode code points.
872
+ input = ucs2decode(input);
873
+
874
+ // Cache the length.
875
+ var inputLength = input.length;
876
+
877
+ // Initialize the state.
878
+ var n = initialN;
879
+ var delta = 0;
880
+ var bias = initialBias;
881
+
882
+ // Handle the basic code points.
883
+ var _iteratorNormalCompletion = true;
884
+ var _didIteratorError = false;
885
+ var _iteratorError = undefined;
886
+
887
+ try {
888
+ for (var _iterator = input[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
889
+ var _currentValue2 = _step.value;
890
+
891
+ if (_currentValue2 < 0x80) {
892
+ output.push(stringFromCharCode(_currentValue2));
893
+ }
894
+ }
895
+ } catch (err) {
896
+ _didIteratorError = true;
897
+ _iteratorError = err;
898
+ } finally {
899
+ try {
900
+ if (!_iteratorNormalCompletion && _iterator.return) {
901
+ _iterator.return();
902
+ }
903
+ } finally {
904
+ if (_didIteratorError) {
905
+ throw _iteratorError;
906
+ }
907
+ }
908
+ }
909
+
910
+ var basicLength = output.length;
911
+ var handledCPCount = basicLength;
912
+
913
+ // `handledCPCount` is the number of code points that have been handled;
914
+ // `basicLength` is the number of basic code points.
915
+
916
+ // Finish the basic string with a delimiter unless it's empty.
917
+ if (basicLength) {
918
+ output.push(delimiter);
919
+ }
920
+
921
+ // Main encoding loop:
922
+ while (handledCPCount < inputLength) {
923
+
924
+ // All non-basic code points < n have been handled already. Find the next
925
+ // larger one:
926
+ var m = maxInt;
927
+ var _iteratorNormalCompletion2 = true;
928
+ var _didIteratorError2 = false;
929
+ var _iteratorError2 = undefined;
930
+
931
+ try {
932
+ for (var _iterator2 = input[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
933
+ var currentValue = _step2.value;
934
+
935
+ if (currentValue >= n && currentValue < m) {
936
+ m = currentValue;
937
+ }
938
+ }
939
+
940
+ // Increase `delta` enough to advance the decoder's <n,i> state to <m,0>,
941
+ // but guard against overflow.
942
+ } catch (err) {
943
+ _didIteratorError2 = true;
944
+ _iteratorError2 = err;
945
+ } finally {
946
+ try {
947
+ if (!_iteratorNormalCompletion2 && _iterator2.return) {
948
+ _iterator2.return();
949
+ }
950
+ } finally {
951
+ if (_didIteratorError2) {
952
+ throw _iteratorError2;
953
+ }
954
+ }
955
+ }
956
+
957
+ var handledCPCountPlusOne = handledCPCount + 1;
958
+ if (m - n > floor((maxInt - delta) / handledCPCountPlusOne)) {
959
+ error$1('overflow');
960
+ }
961
+
962
+ delta += (m - n) * handledCPCountPlusOne;
963
+ n = m;
964
+
965
+ var _iteratorNormalCompletion3 = true;
966
+ var _didIteratorError3 = false;
967
+ var _iteratorError3 = undefined;
968
+
969
+ try {
970
+ for (var _iterator3 = input[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
971
+ var _currentValue = _step3.value;
972
+
973
+ if (_currentValue < n && ++delta > maxInt) {
974
+ error$1('overflow');
975
+ }
976
+ if (_currentValue == n) {
977
+ // Represent delta as a generalized variable-length integer.
978
+ var q = delta;
979
+ for (var k = base;; /* no condition */k += base) {
980
+ var t = k <= bias ? tMin : k >= bias + tMax ? tMax : k - bias;
981
+ if (q < t) {
982
+ break;
983
+ }
984
+ var qMinusT = q - t;
985
+ var baseMinusT = base - t;
986
+ output.push(stringFromCharCode(digitToBasic(t + qMinusT % baseMinusT, 0)));
987
+ q = floor(qMinusT / baseMinusT);
988
+ }
989
+
990
+ output.push(stringFromCharCode(digitToBasic(q, 0)));
991
+ bias = adapt(delta, handledCPCountPlusOne, handledCPCount == basicLength);
992
+ delta = 0;
993
+ ++handledCPCount;
994
+ }
995
+ }
996
+ } catch (err) {
997
+ _didIteratorError3 = true;
998
+ _iteratorError3 = err;
999
+ } finally {
1000
+ try {
1001
+ if (!_iteratorNormalCompletion3 && _iterator3.return) {
1002
+ _iterator3.return();
1003
+ }
1004
+ } finally {
1005
+ if (_didIteratorError3) {
1006
+ throw _iteratorError3;
1007
+ }
1008
+ }
1009
+ }
1010
+
1011
+ ++delta;
1012
+ ++n;
1013
+ }
1014
+ return output.join('');
1015
+ };
1016
+
1017
+ /**
1018
+ * Converts a Punycode string representing a domain name or an email address
1019
+ * to Unicode. Only the Punycoded parts of the input will be converted, i.e.
1020
+ * it doesn't matter if you call it on a string that has already been
1021
+ * converted to Unicode.
1022
+ * @memberOf punycode
1023
+ * @param {String} input The Punycoded domain name or email address to
1024
+ * convert to Unicode.
1025
+ * @returns {String} The Unicode representation of the given Punycode
1026
+ * string.
1027
+ */
1028
+ var toUnicode = function toUnicode(input) {
1029
+ return mapDomain(input, function (string) {
1030
+ return regexPunycode.test(string) ? decode(string.slice(4).toLowerCase()) : string;
1031
+ });
1032
+ };
1033
+
1034
+ /**
1035
+ * Converts a Unicode string representing a domain name or an email address to
1036
+ * Punycode. Only the non-ASCII parts of the domain name will be converted,
1037
+ * i.e. it doesn't matter if you call it with a domain that's already in
1038
+ * ASCII.
1039
+ * @memberOf punycode
1040
+ * @param {String} input The domain name or email address to convert, as a
1041
+ * Unicode string.
1042
+ * @returns {String} The Punycode representation of the given domain name or
1043
+ * email address.
1044
+ */
1045
+ var toASCII = function toASCII(input) {
1046
+ return mapDomain(input, function (string) {
1047
+ return regexNonASCII.test(string) ? 'xn--' + encode(string) : string;
1048
+ });
1049
+ };
1050
+
1051
+ /*--------------------------------------------------------------------------*/
1052
+
1053
+ /** Define the public API */
1054
+ var punycode = {
1055
+ /**
1056
+ * A string representing the current Punycode.js version number.
1057
+ * @memberOf punycode
1058
+ * @type String
1059
+ */
1060
+ 'version': '2.1.0',
1061
+ /**
1062
+ * An object of methods to convert from JavaScript's internal character
1063
+ * representation (UCS-2) to Unicode code points, and back.
1064
+ * @see <https://mathiasbynens.be/notes/javascript-encoding>
1065
+ * @memberOf punycode
1066
+ * @type Object
1067
+ */
1068
+ 'ucs2': {
1069
+ 'decode': ucs2decode,
1070
+ 'encode': ucs2encode
1071
+ },
1072
+ 'decode': decode,
1073
+ 'encode': encode,
1074
+ 'toASCII': toASCII,
1075
+ 'toUnicode': toUnicode
1076
+ };
1077
+
1078
+ /**
1079
+ * URI.js
1080
+ *
1081
+ * @fileoverview An RFC 3986 compliant, scheme extendable URI parsing/validating/resolving library for JavaScript.
1082
+ * @author <a href="mailto:gary.court@gmail.com">Gary Court</a>
1083
+ * @see http://github.com/garycourt/uri-js
1084
+ */
1085
+ /**
1086
+ * Copyright 2011 Gary Court. All rights reserved.
1087
+ *
1088
+ * Redistribution and use in source and binary forms, with or without modification, are
1089
+ * permitted provided that the following conditions are met:
1090
+ *
1091
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
1092
+ * conditions and the following disclaimer.
1093
+ *
1094
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
1095
+ * of conditions and the following disclaimer in the documentation and/or other materials
1096
+ * provided with the distribution.
1097
+ *
1098
+ * THIS SOFTWARE IS PROVIDED BY GARY COURT ``AS IS'' AND ANY EXPRESS OR IMPLIED
1099
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
1100
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GARY COURT OR
1101
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
1102
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
1103
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
1104
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
1105
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
1106
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1107
+ *
1108
+ * The views and conclusions contained in the software and documentation are those of the
1109
+ * authors and should not be interpreted as representing official policies, either expressed
1110
+ * or implied, of Gary Court.
1111
+ */
1112
+ var SCHEMES = {};
1113
+ function pctEncChar(chr) {
1114
+ var c = chr.charCodeAt(0);
1115
+ var e = void 0;
1116
+ 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();
1117
+ return e;
1118
+ }
1119
+ function pctDecChars(str) {
1120
+ var newStr = "";
1121
+ var i = 0;
1122
+ var il = str.length;
1123
+ while (i < il) {
1124
+ var c = parseInt(str.substr(i + 1, 2), 16);
1125
+ if (c < 128) {
1126
+ newStr += String.fromCharCode(c);
1127
+ i += 3;
1128
+ } else if (c >= 194 && c < 224) {
1129
+ if (il - i >= 6) {
1130
+ var c2 = parseInt(str.substr(i + 4, 2), 16);
1131
+ newStr += String.fromCharCode((c & 31) << 6 | c2 & 63);
1132
+ } else {
1133
+ newStr += str.substr(i, 6);
1134
+ }
1135
+ i += 6;
1136
+ } else if (c >= 224) {
1137
+ if (il - i >= 9) {
1138
+ var _c = parseInt(str.substr(i + 4, 2), 16);
1139
+ var c3 = parseInt(str.substr(i + 7, 2), 16);
1140
+ newStr += String.fromCharCode((c & 15) << 12 | (_c & 63) << 6 | c3 & 63);
1141
+ } else {
1142
+ newStr += str.substr(i, 9);
1143
+ }
1144
+ i += 9;
1145
+ } else {
1146
+ newStr += str.substr(i, 3);
1147
+ i += 3;
1148
+ }
1149
+ }
1150
+ return newStr;
1151
+ }
1152
+ function _normalizeComponentEncoding(components, protocol) {
1153
+ function decodeUnreserved(str) {
1154
+ var decStr = pctDecChars(str);
1155
+ return !decStr.match(protocol.UNRESERVED) ? str : decStr;
572
1156
  }
1157
+ if (components.scheme) components.scheme = String(components.scheme).replace(protocol.PCT_ENCODED, decodeUnreserved).toLowerCase().replace(protocol.NOT_SCHEME, "");
1158
+ if (components.userinfo !== undefined) components.userinfo = String(components.userinfo).replace(protocol.PCT_ENCODED, decodeUnreserved).replace(protocol.NOT_USERINFO, pctEncChar).replace(protocol.PCT_ENCODED, toUpperCase);
1159
+ 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);
1160
+ 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);
1161
+ if (components.query !== undefined) components.query = String(components.query).replace(protocol.PCT_ENCODED, decodeUnreserved).replace(protocol.NOT_QUERY, pctEncChar).replace(protocol.PCT_ENCODED, toUpperCase);
1162
+ if (components.fragment !== undefined) components.fragment = String(components.fragment).replace(protocol.PCT_ENCODED, decodeUnreserved).replace(protocol.NOT_FRAGMENT, pctEncChar).replace(protocol.PCT_ENCODED, toUpperCase);
1163
+ return components;
1164
+ }
1165
+
1166
+ function _stripLeadingZeros(str) {
1167
+ return str.replace(/^0*(.*)/, "$1") || "0";
1168
+ }
1169
+ function _normalizeIPv4(host, protocol) {
1170
+ var matches = host.match(protocol.IPV4ADDRESS) || [];
573
1171
 
574
- if (_shouldAddSlash(relativeObj.href)) {
575
- return _addSlash(relativeObj.href);
1172
+ var _matches = slicedToArray(matches, 2),
1173
+ address = _matches[1];
1174
+
1175
+ if (address) {
1176
+ return address.split(".").map(_stripLeadingZeros).join(".");
1177
+ } else {
1178
+ return host;
576
1179
  }
1180
+ }
1181
+ function _normalizeIPv6(host, protocol) {
1182
+ var matches = host.match(protocol.IPV6ADDRESS) || [];
1183
+
1184
+ var _matches2 = slicedToArray(matches, 3),
1185
+ address = _matches2[1],
1186
+ zone = _matches2[2];
1187
+
1188
+ if (address) {
1189
+ var _address$toLowerCase$ = address.toLowerCase().split('::').reverse(),
1190
+ _address$toLowerCase$2 = slicedToArray(_address$toLowerCase$, 2),
1191
+ last = _address$toLowerCase$2[0],
1192
+ first = _address$toLowerCase$2[1];
1193
+
1194
+ var firstFields = first ? first.split(":").map(_stripLeadingZeros) : [];
1195
+ var lastFields = last.split(":").map(_stripLeadingZeros);
1196
+ var isLastFieldIPv4Address = protocol.IPV4ADDRESS.test(lastFields[lastFields.length - 1]);
1197
+ var fieldCount = isLastFieldIPv4Address ? 7 : 8;
1198
+ var lastFieldsStart = lastFields.length - fieldCount;
1199
+ var fields = Array(fieldCount);
1200
+ for (var x = 0; x < fieldCount; ++x) {
1201
+ fields[x] = firstFields[x] || lastFields[lastFieldsStart + x] || '';
1202
+ }
1203
+ if (isLastFieldIPv4Address) {
1204
+ fields[fieldCount - 1] = _normalizeIPv4(fields[fieldCount - 1], protocol);
1205
+ }
1206
+ var allZeroFields = fields.reduce(function (acc, field, index) {
1207
+ if (!field || field === "0") {
1208
+ var lastLongest = acc[acc.length - 1];
1209
+ if (lastLongest && lastLongest.index + lastLongest.length === index) {
1210
+ lastLongest.length++;
1211
+ } else {
1212
+ acc.push({ index: index, length: 1 });
1213
+ }
1214
+ }
1215
+ return acc;
1216
+ }, []);
1217
+ var longestZeroFields = allZeroFields.sort(function (a, b) {
1218
+ return b.length - a.length;
1219
+ })[0];
1220
+ var newHost = void 0;
1221
+ if (longestZeroFields && longestZeroFields.length > 1) {
1222
+ var newFirst = fields.slice(0, longestZeroFields.index);
1223
+ var newLast = fields.slice(longestZeroFields.index + longestZeroFields.length);
1224
+ newHost = newFirst.join(":") + "::" + newLast.join(":");
1225
+ } else {
1226
+ newHost = fields.join(":");
1227
+ }
1228
+ if (zone) {
1229
+ newHost += "%" + zone;
1230
+ }
1231
+ return newHost;
1232
+ } else {
1233
+ return host;
1234
+ }
1235
+ }
1236
+ var URI_PARSE = /^(?:([^:\/?#]+):)?(?:\/\/((?:([^\/?#@]*)@)?(\[[^\/?#\]]+\]|[^\/?#:]*)(?:\:(\d*))?))?([^?#]*)(?:\?([^#]*))?(?:#((?:.|\n|\r)*))?/i;
1237
+ var NO_MATCH_IS_UNDEFINED = "".match(/(){0}/)[1] === undefined;
1238
+ function parse(uriString) {
1239
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1240
+
1241
+ var components = {};
1242
+ var protocol = options.iri !== false ? IRI_PROTOCOL : URI_PROTOCOL;
1243
+ if (options.reference === "suffix") uriString = (options.scheme ? options.scheme + ":" : "") + "//" + uriString;
1244
+ var matches = uriString.match(URI_PARSE);
1245
+ if (matches) {
1246
+ if (NO_MATCH_IS_UNDEFINED) {
1247
+ //store each component
1248
+ components.scheme = matches[1];
1249
+ components.userinfo = matches[3];
1250
+ components.host = matches[4];
1251
+ components.port = parseInt(matches[5], 10);
1252
+ components.path = matches[6] || "";
1253
+ components.query = matches[7];
1254
+ components.fragment = matches[8];
1255
+ //fix port number
1256
+ if (isNaN(components.port)) {
1257
+ components.port = matches[5];
1258
+ }
1259
+ } else {
1260
+ //IE FIX for improper RegExp matching
1261
+ //store each component
1262
+ components.scheme = matches[1] || undefined;
1263
+ components.userinfo = uriString.indexOf("@") !== -1 ? matches[3] : undefined;
1264
+ components.host = uriString.indexOf("//") !== -1 ? matches[4] : undefined;
1265
+ components.port = parseInt(matches[5], 10);
1266
+ components.path = matches[6] || "";
1267
+ components.query = uriString.indexOf("?") !== -1 ? matches[7] : undefined;
1268
+ components.fragment = uriString.indexOf("#") !== -1 ? matches[8] : undefined;
1269
+ //fix port number
1270
+ if (isNaN(components.port)) {
1271
+ components.port = uriString.match(/\/\/(?:.|\n)*\:(?:\/|\?|\#|$)/) ? matches[4] : undefined;
1272
+ }
1273
+ }
1274
+ if (components.host) {
1275
+ //normalize IP hosts
1276
+ components.host = _normalizeIPv6(_normalizeIPv4(components.host, protocol), protocol);
1277
+ }
1278
+ //determine reference type
1279
+ if (components.scheme === undefined && components.userinfo === undefined && components.host === undefined && components.port === undefined && !components.path && components.query === undefined) {
1280
+ components.reference = "same-document";
1281
+ } else if (components.scheme === undefined) {
1282
+ components.reference = "relative";
1283
+ } else if (components.fragment === undefined) {
1284
+ components.reference = "absolute";
1285
+ } else {
1286
+ components.reference = "uri";
1287
+ }
1288
+ //check for reference errors
1289
+ if (options.reference && options.reference !== "suffix" && options.reference !== components.reference) {
1290
+ components.error = components.error || "URI is not a " + options.reference + " reference.";
1291
+ }
1292
+ //find scheme handler
1293
+ var schemeHandler = SCHEMES[(options.scheme || components.scheme || "").toLowerCase()];
1294
+ //check if scheme can't handle IRIs
1295
+ if (!options.unicodeSupport && (!schemeHandler || !schemeHandler.unicodeSupport)) {
1296
+ //if host component is a domain name
1297
+ if (components.host && (options.domainHost || schemeHandler && schemeHandler.domainHost)) {
1298
+ //convert Unicode IDN -> ASCII IDN
1299
+ try {
1300
+ components.host = punycode.toASCII(components.host.replace(protocol.PCT_ENCODED, pctDecChars).toLowerCase());
1301
+ } catch (e) {
1302
+ components.error = components.error || "Host's domain name can not be converted to ASCII via punycode: " + e;
1303
+ }
1304
+ }
1305
+ //convert IRI -> URI
1306
+ _normalizeComponentEncoding(components, URI_PROTOCOL);
1307
+ } else {
1308
+ //normalize encodings
1309
+ _normalizeComponentEncoding(components, protocol);
1310
+ }
1311
+ //perform scheme specific parsing
1312
+ if (schemeHandler && schemeHandler.parse) {
1313
+ schemeHandler.parse(components, options);
1314
+ }
1315
+ } else {
1316
+ components.error = components.error || "URI can not be parsed.";
1317
+ }
1318
+ return components;
1319
+ }
577
1320
 
578
- return relativeObj.href;
579
- } else if (relativeObj.absolutePath) { // relative is an absolute path
580
- const {path, query, hash} = relativeObj;
1321
+ function _recomposeAuthority(components, options) {
1322
+ var protocol = options.iri !== false ? IRI_PROTOCOL : URI_PROTOCOL;
1323
+ var uriTokens = [];
1324
+ if (components.userinfo !== undefined) {
1325
+ uriTokens.push(components.userinfo);
1326
+ uriTokens.push("@");
1327
+ }
1328
+ if (components.host !== undefined) {
1329
+ //normalize IP hosts, add brackets and escape zone separator for IPv6
1330
+ uriTokens.push(_normalizeIPv6(_normalizeIPv4(String(components.host), protocol), protocol).replace(protocol.IPV6ADDRESS, function (_, $1, $2) {
1331
+ return "[" + $1 + ($2 ? "%25" + $2 : "") + "]";
1332
+ }));
1333
+ }
1334
+ if (typeof components.port === "number" || typeof components.port === "string") {
1335
+ uriTokens.push(":");
1336
+ uriTokens.push(String(components.port));
1337
+ }
1338
+ return uriTokens.length ? uriTokens.join("") : undefined;
1339
+ }
581
1340
 
582
- return baseObj.host + _pathResolve(path) + query + hash;
583
- } else if (relativeObj.relativePath) { // relative is a relative path
584
- const {path, query, hash} = relativeObj;
1341
+ var RDS1 = /^\.\.?\//;
1342
+ var RDS2 = /^\/\.(\/|$)/;
1343
+ var RDS3 = /^\/\.\.(\/|$)/;
1344
+ var RDS5 = /^\/?(?:.|\n)*?(?=\/|$)/;
1345
+ function removeDotSegments(input) {
1346
+ var output = [];
1347
+ while (input.length) {
1348
+ if (input.match(RDS1)) {
1349
+ input = input.replace(RDS1, "");
1350
+ } else if (input.match(RDS2)) {
1351
+ input = input.replace(RDS2, "/");
1352
+ } else if (input.match(RDS3)) {
1353
+ input = input.replace(RDS3, "/");
1354
+ output.pop();
1355
+ } else if (input === "." || input === "..") {
1356
+ input = "";
1357
+ } else {
1358
+ var im = input.match(RDS5);
1359
+ if (im) {
1360
+ var s = im[0];
1361
+ input = input.slice(s.length);
1362
+ output.push(s);
1363
+ } else {
1364
+ throw new Error("Unexpected dot segment condition");
1365
+ }
1366
+ }
1367
+ }
1368
+ return output.join("");
1369
+ }
585
1370
 
586
- let basePath = baseObj.path;
587
- let resultString = baseObj.host;
1371
+ function serialize(components) {
1372
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1373
+
1374
+ var protocol = options.iri ? IRI_PROTOCOL : URI_PROTOCOL;
1375
+ var uriTokens = [];
1376
+ //find scheme handler
1377
+ var schemeHandler = SCHEMES[(options.scheme || components.scheme || "").toLowerCase()];
1378
+ //perform scheme specific serialization
1379
+ if (schemeHandler && schemeHandler.serialize) schemeHandler.serialize(components, options);
1380
+ if (components.host) {
1381
+ //if host component is an IPv6 address
1382
+ if (protocol.IPV6ADDRESS.test(components.host)) ;
1383
+ //TODO: normalize IPv6 address as per RFC 5952
1384
+
1385
+ //if host component is a domain name
1386
+ else if (options.domainHost || schemeHandler && schemeHandler.domainHost) {
1387
+ //convert IDN via punycode
1388
+ try {
1389
+ components.host = !options.iri ? punycode.toASCII(components.host.replace(protocol.PCT_ENCODED, pctDecChars).toLowerCase()) : punycode.toUnicode(components.host);
1390
+ } catch (e) {
1391
+ components.error = components.error || "Host's domain name can not be converted to " + (!options.iri ? "ASCII" : "Unicode") + " via punycode: " + e;
1392
+ }
1393
+ }
1394
+ }
1395
+ //normalize encoding
1396
+ _normalizeComponentEncoding(components, protocol);
1397
+ if (options.reference !== "suffix" && components.scheme) {
1398
+ uriTokens.push(components.scheme);
1399
+ uriTokens.push(":");
1400
+ }
1401
+ var authority = _recomposeAuthority(components, options);
1402
+ if (authority !== undefined) {
1403
+ if (options.reference !== "suffix") {
1404
+ uriTokens.push("//");
1405
+ }
1406
+ uriTokens.push(authority);
1407
+ if (components.path && components.path.charAt(0) !== "/") {
1408
+ uriTokens.push("/");
1409
+ }
1410
+ }
1411
+ if (components.path !== undefined) {
1412
+ var s = components.path;
1413
+ if (!options.absolutePath && (!schemeHandler || !schemeHandler.absolutePath)) {
1414
+ s = removeDotSegments(s);
1415
+ }
1416
+ if (authority === undefined) {
1417
+ s = s.replace(/^\/\//, "/%2F"); //don't allow the path to start with "//"
1418
+ }
1419
+ uriTokens.push(s);
1420
+ }
1421
+ if (components.query !== undefined) {
1422
+ uriTokens.push("?");
1423
+ uriTokens.push(components.query);
1424
+ }
1425
+ if (components.fragment !== undefined) {
1426
+ uriTokens.push("#");
1427
+ uriTokens.push(components.fragment);
1428
+ }
1429
+ return uriTokens.join(""); //merge tokens into a string
1430
+ }
588
1431
 
589
- let resolvePath;
1432
+ function resolveComponents(base, relative) {
1433
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1434
+ var skipNormalization = arguments[3];
590
1435
 
591
- if (path.length === 0) {
592
- resolvePath = basePath;
1436
+ var target = {};
1437
+ if (!skipNormalization) {
1438
+ base = parse(serialize(base, options), options); //normalize base components
1439
+ relative = parse(serialize(relative, options), options); //normalize relative components
1440
+ }
1441
+ options = options || {};
1442
+ if (!options.tolerant && relative.scheme) {
1443
+ target.scheme = relative.scheme;
1444
+ //target.authority = relative.authority;
1445
+ target.userinfo = relative.userinfo;
1446
+ target.host = relative.host;
1447
+ target.port = relative.port;
1448
+ target.path = removeDotSegments(relative.path || "");
1449
+ target.query = relative.query;
593
1450
  } else {
594
- // remove last segment if no slash at end
595
- basePath = basePath.substring(0, basePath.lastIndexOf('/'));
596
- resolvePath = _pathResolve(basePath + '/' + path);
1451
+ if (relative.userinfo !== undefined || relative.host !== undefined || relative.port !== undefined) {
1452
+ //target.authority = relative.authority;
1453
+ target.userinfo = relative.userinfo;
1454
+ target.host = relative.host;
1455
+ target.port = relative.port;
1456
+ target.path = removeDotSegments(relative.path || "");
1457
+ target.query = relative.query;
1458
+ } else {
1459
+ if (!relative.path) {
1460
+ target.path = base.path;
1461
+ if (relative.query !== undefined) {
1462
+ target.query = relative.query;
1463
+ } else {
1464
+ target.query = base.query;
1465
+ }
1466
+ } else {
1467
+ if (relative.path.charAt(0) === "/") {
1468
+ target.path = removeDotSegments(relative.path);
1469
+ } else {
1470
+ if ((base.userinfo !== undefined || base.host !== undefined || base.port !== undefined) && !base.path) {
1471
+ target.path = "/" + relative.path;
1472
+ } else if (!base.path) {
1473
+ target.path = relative.path;
1474
+ } else {
1475
+ target.path = base.path.slice(0, base.path.lastIndexOf("/") + 1) + relative.path;
1476
+ }
1477
+ target.path = removeDotSegments(target.path);
1478
+ }
1479
+ target.query = relative.query;
1480
+ }
1481
+ //target.authority = base.authority;
1482
+ target.userinfo = base.userinfo;
1483
+ target.host = base.host;
1484
+ target.port = base.port;
1485
+ }
1486
+ target.scheme = base.scheme;
597
1487
  }
1488
+ target.fragment = relative.fragment;
1489
+ return target;
1490
+ }
598
1491
 
599
- // if result is just the base host, add /
600
- if ((resolvePath === '') && (!query) && (!hash)) {
601
- resultString += '/';
602
- } else {
603
- resultString += resolvePath + query + hash;
1492
+ function resolve(baseURI, relativeURI, options) {
1493
+ var schemelessOptions = assign({ scheme: 'null' }, options);
1494
+ return serialize(resolveComponents(parse(baseURI, schemelessOptions), parse(relativeURI, schemelessOptions), schemelessOptions, true), schemelessOptions);
1495
+ }
1496
+
1497
+ function normalize(uri, options) {
1498
+ if (typeof uri === "string") {
1499
+ uri = serialize(parse(uri, options), options);
1500
+ } else if (typeOf(uri) === "object") {
1501
+ uri = parse(serialize(uri, options), options);
604
1502
  }
1503
+ return uri;
1504
+ }
605
1505
 
606
- return resultString;
607
- } else {
608
- const {host, path, query} = baseObj;
609
- // when path and query aren't supplied add slash
610
- if ((!path) && (!query)) {
611
- return _addSlash(host);
1506
+ function equal(uriA, uriB, options) {
1507
+ if (typeof uriA === "string") {
1508
+ uriA = serialize(parse(uriA, options), options);
1509
+ } else if (typeOf(uriA) === "object") {
1510
+ uriA = serialize(uriA, options);
612
1511
  }
613
- return host + path + query + relativeObj.hash;
614
- }
1512
+ if (typeof uriB === "string") {
1513
+ uriB = serialize(parse(uriB, options), options);
1514
+ } else if (typeOf(uriB) === "object") {
1515
+ uriB = serialize(uriB, options);
1516
+ }
1517
+ return uriA === uriB;
1518
+ }
1519
+
1520
+ function escapeComponent(str, options) {
1521
+ return str && str.toString().replace(!options || !options.iri ? URI_PROTOCOL.ESCAPE : IRI_PROTOCOL.ESCAPE, pctEncChar);
1522
+ }
1523
+
1524
+ function unescapeComponent(str, options) {
1525
+ return str && str.toString().replace(!options || !options.iri ? URI_PROTOCOL.PCT_ENCODED : IRI_PROTOCOL.PCT_ENCODED, pctDecChars);
1526
+ }
1527
+
1528
+ var handler = {
1529
+ scheme: "http",
1530
+ domainHost: true,
1531
+ parse: function parse(components, options) {
1532
+ //report missing host
1533
+ if (!components.host) {
1534
+ components.error = components.error || "HTTP URIs must have a host.";
1535
+ }
1536
+ return components;
1537
+ },
1538
+ serialize: function serialize(components, options) {
1539
+ var secure = String(components.scheme).toLowerCase() === "https";
1540
+ //normalize the default port
1541
+ if (components.port === (secure ? 443 : 80) || components.port === "") {
1542
+ components.port = undefined;
1543
+ }
1544
+ //normalize the empty path
1545
+ if (!components.path) {
1546
+ components.path = "/";
1547
+ }
1548
+ //NOTE: We do not parse query strings for HTTP URIs
1549
+ //as WWW Form Url Encoded query strings are part of the HTML4+ spec,
1550
+ //and not the HTTP spec.
1551
+ return components;
1552
+ }
1553
+ };
1554
+
1555
+ var handler$1 = {
1556
+ scheme: "https",
1557
+ domainHost: handler.domainHost,
1558
+ parse: handler.parse,
1559
+ serialize: handler.serialize
1560
+ };
1561
+
1562
+ function isSecure(wsComponents) {
1563
+ return typeof wsComponents.secure === 'boolean' ? wsComponents.secure : String(wsComponents.scheme).toLowerCase() === "wss";
615
1564
  }
1565
+ //RFC 6455
1566
+ var handler$2 = {
1567
+ scheme: "ws",
1568
+ domainHost: true,
1569
+ parse: function parse(components, options) {
1570
+ var wsComponents = components;
1571
+ //indicate if the secure flag is set
1572
+ wsComponents.secure = isSecure(wsComponents);
1573
+ //construct resouce name
1574
+ wsComponents.resourceName = (wsComponents.path || '/') + (wsComponents.query ? '?' + wsComponents.query : '');
1575
+ wsComponents.path = undefined;
1576
+ wsComponents.query = undefined;
1577
+ return wsComponents;
1578
+ },
1579
+ serialize: function serialize(wsComponents, options) {
1580
+ //normalize the default port
1581
+ if (wsComponents.port === (isSecure(wsComponents) ? 443 : 80) || wsComponents.port === "") {
1582
+ wsComponents.port = undefined;
1583
+ }
1584
+ //ensure scheme matches secure flag
1585
+ if (typeof wsComponents.secure === 'boolean') {
1586
+ wsComponents.scheme = wsComponents.secure ? 'wss' : 'ws';
1587
+ wsComponents.secure = undefined;
1588
+ }
1589
+ //reconstruct path from resource name
1590
+ if (wsComponents.resourceName) {
1591
+ var _wsComponents$resourc = wsComponents.resourceName.split('?'),
1592
+ _wsComponents$resourc2 = slicedToArray(_wsComponents$resourc, 2),
1593
+ path = _wsComponents$resourc2[0],
1594
+ query = _wsComponents$resourc2[1];
1595
+
1596
+ wsComponents.path = path && path !== '/' ? path : undefined;
1597
+ wsComponents.query = query;
1598
+ wsComponents.resourceName = undefined;
1599
+ }
1600
+ //forbid fragment component
1601
+ wsComponents.fragment = undefined;
1602
+ return wsComponents;
1603
+ }
1604
+ };
1605
+
1606
+ var handler$3 = {
1607
+ scheme: "wss",
1608
+ domainHost: handler$2.domainHost,
1609
+ parse: handler$2.parse,
1610
+ serialize: handler$2.serialize
1611
+ };
1612
+
1613
+ var O = {};
1614
+ //RFC 3986
1615
+ var UNRESERVED$$ = "[A-Za-z0-9\\-\\.\\_\\~" + ("\\xA0-\\u200D\\u2010-\\u2029\\u202F-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF" ) + "]";
1616
+ var HEXDIG$$ = "[0-9A-Fa-f]"; //case-insensitive
1617
+ var PCT_ENCODED$ = subexp(subexp("%[EFef]" + HEXDIG$$ + "%" + HEXDIG$$ + HEXDIG$$ + "%" + HEXDIG$$ + HEXDIG$$) + "|" + subexp("%[89A-Fa-f]" + HEXDIG$$ + "%" + HEXDIG$$ + HEXDIG$$) + "|" + subexp("%" + HEXDIG$$ + HEXDIG$$)); //expanded
1618
+ //RFC 5322, except these symbols as per RFC 6068: @ : / ? # [ ] & ; =
1619
+ //const ATEXT$$ = "[A-Za-z0-9\\!\\#\\$\\%\\&\\'\\*\\+\\-\\/\\=\\?\\^\\_\\`\\{\\|\\}\\~]";
1620
+ //const WSP$$ = "[\\x20\\x09]";
1621
+ //const OBS_QTEXT$$ = "[\\x01-\\x08\\x0B\\x0C\\x0E-\\x1F\\x7F]"; //(%d1-8 / %d11-12 / %d14-31 / %d127)
1622
+ //const QTEXT$$ = merge("[\\x21\\x23-\\x5B\\x5D-\\x7E]", OBS_QTEXT$$); //%d33 / %d35-91 / %d93-126 / obs-qtext
1623
+ //const VCHAR$$ = "[\\x21-\\x7E]";
1624
+ //const WSP$$ = "[\\x20\\x09]";
1625
+ //const OBS_QP$ = subexp("\\\\" + merge("[\\x00\\x0D\\x0A]", OBS_QTEXT$$)); //%d0 / CR / LF / obs-qtext
1626
+ //const FWS$ = subexp(subexp(WSP$$ + "*" + "\\x0D\\x0A") + "?" + WSP$$ + "+");
1627
+ //const QUOTED_PAIR$ = subexp(subexp("\\\\" + subexp(VCHAR$$ + "|" + WSP$$)) + "|" + OBS_QP$);
1628
+ //const QUOTED_STRING$ = subexp('\\"' + subexp(FWS$ + "?" + QCONTENT$) + "*" + FWS$ + "?" + '\\"');
1629
+ var ATEXT$$ = "[A-Za-z0-9\\!\\$\\%\\'\\*\\+\\-\\^\\_\\`\\{\\|\\}\\~]";
1630
+ var QTEXT$$ = "[\\!\\$\\%\\'\\(\\)\\*\\+\\,\\-\\.0-9\\<\\>A-Z\\x5E-\\x7E]";
1631
+ var VCHAR$$ = merge(QTEXT$$, "[\\\"\\\\]");
1632
+ var SOME_DELIMS$$ = "[\\!\\$\\'\\(\\)\\*\\+\\,\\;\\:\\@]";
1633
+ var UNRESERVED = new RegExp(UNRESERVED$$, "g");
1634
+ var PCT_ENCODED = new RegExp(PCT_ENCODED$, "g");
1635
+ var NOT_LOCAL_PART = new RegExp(merge("[^]", ATEXT$$, "[\\.]", '[\\"]', VCHAR$$), "g");
1636
+ var NOT_HFNAME = new RegExp(merge("[^]", UNRESERVED$$, SOME_DELIMS$$), "g");
1637
+ var NOT_HFVALUE = NOT_HFNAME;
1638
+ function decodeUnreserved(str) {
1639
+ var decStr = pctDecChars(str);
1640
+ return !decStr.match(UNRESERVED) ? str : decStr;
1641
+ }
1642
+ var handler$4 = {
1643
+ scheme: "mailto",
1644
+ parse: function parse$$1(components, options) {
1645
+ var mailtoComponents = components;
1646
+ var to = mailtoComponents.to = mailtoComponents.path ? mailtoComponents.path.split(",") : [];
1647
+ mailtoComponents.path = undefined;
1648
+ if (mailtoComponents.query) {
1649
+ var unknownHeaders = false;
1650
+ var headers = {};
1651
+ var hfields = mailtoComponents.query.split("&");
1652
+ for (var x = 0, xl = hfields.length; x < xl; ++x) {
1653
+ var hfield = hfields[x].split("=");
1654
+ switch (hfield[0]) {
1655
+ case "to":
1656
+ var toAddrs = hfield[1].split(",");
1657
+ for (var _x = 0, _xl = toAddrs.length; _x < _xl; ++_x) {
1658
+ to.push(toAddrs[_x]);
1659
+ }
1660
+ break;
1661
+ case "subject":
1662
+ mailtoComponents.subject = unescapeComponent(hfield[1], options);
1663
+ break;
1664
+ case "body":
1665
+ mailtoComponents.body = unescapeComponent(hfield[1], options);
1666
+ break;
1667
+ default:
1668
+ unknownHeaders = true;
1669
+ headers[unescapeComponent(hfield[0], options)] = unescapeComponent(hfield[1], options);
1670
+ break;
1671
+ }
1672
+ }
1673
+ if (unknownHeaders) mailtoComponents.headers = headers;
1674
+ }
1675
+ mailtoComponents.query = undefined;
1676
+ for (var _x2 = 0, _xl2 = to.length; _x2 < _xl2; ++_x2) {
1677
+ var addr = to[_x2].split("@");
1678
+ addr[0] = unescapeComponent(addr[0]);
1679
+ if (!options.unicodeSupport) {
1680
+ //convert Unicode IDN -> ASCII IDN
1681
+ try {
1682
+ addr[1] = punycode.toASCII(unescapeComponent(addr[1], options).toLowerCase());
1683
+ } catch (e) {
1684
+ mailtoComponents.error = mailtoComponents.error || "Email address's domain name can not be converted to ASCII via punycode: " + e;
1685
+ }
1686
+ } else {
1687
+ addr[1] = unescapeComponent(addr[1], options).toLowerCase();
1688
+ }
1689
+ to[_x2] = addr.join("@");
1690
+ }
1691
+ return mailtoComponents;
1692
+ },
1693
+ serialize: function serialize$$1(mailtoComponents, options) {
1694
+ var components = mailtoComponents;
1695
+ var to = toArray(mailtoComponents.to);
1696
+ if (to) {
1697
+ for (var x = 0, xl = to.length; x < xl; ++x) {
1698
+ var toAddr = String(to[x]);
1699
+ var atIdx = toAddr.lastIndexOf("@");
1700
+ var localPart = toAddr.slice(0, atIdx).replace(PCT_ENCODED, decodeUnreserved).replace(PCT_ENCODED, toUpperCase).replace(NOT_LOCAL_PART, pctEncChar);
1701
+ var domain = toAddr.slice(atIdx + 1);
1702
+ //convert IDN via punycode
1703
+ try {
1704
+ domain = !options.iri ? punycode.toASCII(unescapeComponent(domain, options).toLowerCase()) : punycode.toUnicode(domain);
1705
+ } catch (e) {
1706
+ components.error = components.error || "Email address's domain name can not be converted to " + (!options.iri ? "ASCII" : "Unicode") + " via punycode: " + e;
1707
+ }
1708
+ to[x] = localPart + "@" + domain;
1709
+ }
1710
+ components.path = to.join(",");
1711
+ }
1712
+ var headers = mailtoComponents.headers = mailtoComponents.headers || {};
1713
+ if (mailtoComponents.subject) headers["subject"] = mailtoComponents.subject;
1714
+ if (mailtoComponents.body) headers["body"] = mailtoComponents.body;
1715
+ var fields = [];
1716
+ for (var name in headers) {
1717
+ if (headers[name] !== O[name]) {
1718
+ 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));
1719
+ }
1720
+ }
1721
+ if (fields.length) {
1722
+ components.query = fields.join("&");
1723
+ }
1724
+ return components;
1725
+ }
1726
+ };
1727
+
1728
+ var URN_PARSE = /^([^\:]+)\:(.*)/;
1729
+ //RFC 2141
1730
+ var handler$5 = {
1731
+ scheme: "urn",
1732
+ parse: function parse$$1(components, options) {
1733
+ var matches = components.path && components.path.match(URN_PARSE);
1734
+ var urnComponents = components;
1735
+ if (matches) {
1736
+ var scheme = options.scheme || urnComponents.scheme || "urn";
1737
+ var nid = matches[1].toLowerCase();
1738
+ var nss = matches[2];
1739
+ var urnScheme = scheme + ":" + (options.nid || nid);
1740
+ var schemeHandler = SCHEMES[urnScheme];
1741
+ urnComponents.nid = nid;
1742
+ urnComponents.nss = nss;
1743
+ urnComponents.path = undefined;
1744
+ if (schemeHandler) {
1745
+ urnComponents = schemeHandler.parse(urnComponents, options);
1746
+ }
1747
+ } else {
1748
+ urnComponents.error = urnComponents.error || "URN can not be parsed.";
1749
+ }
1750
+ return urnComponents;
1751
+ },
1752
+ serialize: function serialize$$1(urnComponents, options) {
1753
+ var scheme = options.scheme || urnComponents.scheme || "urn";
1754
+ var nid = urnComponents.nid;
1755
+ var urnScheme = scheme + ":" + (options.nid || nid);
1756
+ var schemeHandler = SCHEMES[urnScheme];
1757
+ if (schemeHandler) {
1758
+ urnComponents = schemeHandler.serialize(urnComponents, options);
1759
+ }
1760
+ var uriComponents = urnComponents;
1761
+ var nss = urnComponents.nss;
1762
+ uriComponents.path = (nid || options.nid) + ":" + nss;
1763
+ return uriComponents;
1764
+ }
1765
+ };
1766
+
1767
+ var UUID = /^[0-9A-Fa-f]{8}(?:\-[0-9A-Fa-f]{4}){3}\-[0-9A-Fa-f]{12}$/;
1768
+ //RFC 4122
1769
+ var handler$6 = {
1770
+ scheme: "urn:uuid",
1771
+ parse: function parse(urnComponents, options) {
1772
+ var uuidComponents = urnComponents;
1773
+ uuidComponents.uuid = uuidComponents.nss;
1774
+ uuidComponents.nss = undefined;
1775
+ if (!options.tolerant && (!uuidComponents.uuid || !uuidComponents.uuid.match(UUID))) {
1776
+ uuidComponents.error = uuidComponents.error || "UUID is not valid.";
1777
+ }
1778
+ return uuidComponents;
1779
+ },
1780
+ serialize: function serialize(uuidComponents, options) {
1781
+ var urnComponents = uuidComponents;
1782
+ //normalize UUID
1783
+ urnComponents.nss = (uuidComponents.uuid || "").toLowerCase();
1784
+ return urnComponents;
1785
+ }
1786
+ };
1787
+
1788
+ SCHEMES[handler.scheme] = handler;
1789
+ SCHEMES[handler$1.scheme] = handler$1;
1790
+ SCHEMES[handler$2.scheme] = handler$2;
1791
+ SCHEMES[handler$3.scheme] = handler$3;
1792
+ SCHEMES[handler$4.scheme] = handler$4;
1793
+ SCHEMES[handler$5.scheme] = handler$5;
1794
+ SCHEMES[handler$6.scheme] = handler$6;
1795
+
1796
+ exports.SCHEMES = SCHEMES;
1797
+ exports.pctEncChar = pctEncChar;
1798
+ exports.pctDecChars = pctDecChars;
1799
+ exports.parse = parse;
1800
+ exports.removeDotSegments = removeDotSegments;
1801
+ exports.serialize = serialize;
1802
+ exports.resolveComponents = resolveComponents;
1803
+ exports.resolve = resolve;
1804
+ exports.normalize = normalize;
1805
+ exports.equal = equal;
1806
+ exports.escapeComponent = escapeComponent;
1807
+ exports.unescapeComponent = unescapeComponent;
1808
+
1809
+ Object.defineProperty(exports, '__esModule', { value: true });
1810
+
1811
+ })));
1812
+
1813
+ });
1814
+
1815
+ unwrapExports(uri_all);
616
1816
 
617
1817
  const isObject$1 = (value) => typeof value === "object" && !Array.isArray(value) && value !== null;
618
1818
  const isType = {
@@ -626,29 +1826,17 @@ var JsonSchema = (function (exports) {
626
1826
  };
627
1827
  const jsonTypeOf$2 = (value, type) => isType[type](value);
628
1828
 
629
- const splitUrl$4 = (url) => {
630
- const indexOfHash = url.indexOf("#");
631
- const ndx = indexOfHash === -1 ? url.length : indexOfHash;
632
- const urlReference = url.slice(0, ndx);
633
- const urlFragment = url.slice(ndx + 1);
634
-
635
- return [decodeURI(urlReference), decodeURI(urlFragment)];
636
- };
637
-
638
- const getScheme = (url) => {
639
- const matches = RegExp(/^(.+):\/\//).exec(url);
640
- return matches ? matches[1] : "";
641
- };
642
-
643
- const safeResolveUrl$1 = (contextUrl, url) => {
644
- const resolvedUrl = urlResolveBrowser(contextUrl, url);
645
- const contextId = splitUrl$4(contextUrl)[0];
646
- if (contextId && getScheme(resolvedUrl) === "file" && getScheme(contextId) !== "file") {
1829
+ const resolveUrl$3 = (contextUrl, url) => {
1830
+ const resolvedUrl = uri_all.resolve(contextUrl, url, { iri: true });
1831
+ const contextId = uri_all.resolve(contextUrl, "", { iri: true });
1832
+ if (contextId && uri_all.parse(resolvedUrl).scheme === "file" && uri_all.parse(contextUrl).scheme !== "file") {
647
1833
  throw Error(`Can't access file '${resolvedUrl}' resource from network context '${contextUrl}'`);
648
1834
  }
649
1835
  return resolvedUrl;
650
1836
  };
651
1837
 
1838
+ const urlFragment$1 = (uri) => uri_all.unescapeComponent(uri_all.parse(uri).fragment) || "";
1839
+
652
1840
  const CHAR_BACKWARD_SLASH = 47;
653
1841
 
654
1842
  const pathRelative$1 = (from, to) => {
@@ -712,7 +1900,7 @@ var JsonSchema = (function (exports) {
712
1900
  return to.slice(toStart, to.length);
713
1901
  };
714
1902
 
715
- var common$1 = { jsonTypeOf: jsonTypeOf$2, splitUrl: splitUrl$4, safeResolveUrl: safeResolveUrl$1, pathRelative: pathRelative$1 };
1903
+ var common$1 = { jsonTypeOf: jsonTypeOf$2, resolveUrl: resolveUrl$3, urlFragment: urlFragment$1, pathRelative: pathRelative$1 };
716
1904
 
717
1905
  const nil$2 = "";
718
1906
 
@@ -870,12 +2058,12 @@ var JsonSchema = (function (exports) {
870
2058
  reference.href;
871
2059
  reference.value;
872
2060
 
873
- const { jsonTypeOf: jsonTypeOf$1 } = common$1;
2061
+ const { resolveUrl: resolveUrl$2, jsonTypeOf: jsonTypeOf$1 } = common$1;
874
2062
 
875
2063
 
876
2064
 
877
2065
  const nil$1 = Object.freeze({ id: "", pointer: "", instance: undefined, value: undefined });
878
- const cons = (instance, id = "") => Object.freeze({ ...nil$1, id, instance, value: instance });
2066
+ const cons = (instance, id = "") => Object.freeze({ ...nil$1, id: resolveUrl$2(id, ""), instance, value: instance });
879
2067
  const uri$1 = (doc) => `${doc.id}#${encodeURI(doc.pointer)}`;
880
2068
  const value$1 = (doc) => reference.isReference(doc.value) ? reference.value(doc.value) : doc.value;
881
2069
  const has$1 = (key, doc) => key in value$1(doc);
@@ -1218,7 +2406,7 @@ var JsonSchema = (function (exports) {
1218
2406
 
1219
2407
  var fetch_browser = fetch;
1220
2408
 
1221
- const { jsonTypeOf, splitUrl: splitUrl$3, safeResolveUrl, pathRelative } = common$1;
2409
+ const { jsonTypeOf, resolveUrl: resolveUrl$1, urlFragment, pathRelative } = common$1;
1222
2410
 
1223
2411
 
1224
2412
 
@@ -1249,7 +2437,7 @@ var JsonSchema = (function (exports) {
1249
2437
  schema = JSON.parse(JSON.stringify(schema));
1250
2438
 
1251
2439
  // Schema Version
1252
- const schemaVersion = splitUrl$3(schema["$schema"] || defaultSchemaVersion)[0];
2440
+ const schemaVersion = resolveUrl$1(schema["$schema"] || defaultSchemaVersion, "");
1253
2441
  if (!schemaVersion) {
1254
2442
  throw Error("Couldn't determine schema version");
1255
2443
  }
@@ -1258,12 +2446,13 @@ var JsonSchema = (function (exports) {
1258
2446
  // Identifier
1259
2447
  const baseToken = getConfig(schemaVersion, "baseToken");
1260
2448
  const anchorToken = getConfig(schemaVersion, "anchorToken");
1261
- const externalId = splitUrl$3(url)[0];
1262
- if (!externalId && !splitUrl$3(schema[baseToken] || "")[0]) {
2449
+ const externalId = resolveUrl$1(url, "");
2450
+ if (!externalId && !resolveUrl$1(schema[baseToken] || "", "")) {
1263
2451
  throw Error("Couldn't determine an identifier for the schema");
1264
2452
  }
1265
- const internalUrl = safeResolveUrl(externalId, schema[baseToken] || "");
1266
- const [id, fragment] = splitUrl$3(internalUrl);
2453
+ const internalUrl = resolveUrl$1(externalId, schema[baseToken] || "");
2454
+ const id = resolveUrl$1(internalUrl, "");
2455
+ const fragment = urlFragment(internalUrl);
1267
2456
  delete schema[baseToken];
1268
2457
  if (fragment && baseToken === anchorToken) {
1269
2458
  schema[anchorToken] = anchorToken !== baseToken ? encodeURI(fragment) : `#${encodeURI(fragment)}`;
@@ -1310,11 +2499,11 @@ var JsonSchema = (function (exports) {
1310
2499
 
1311
2500
  const processSchema = (subject, id, schemaVersion, pointer, anchors, dynamicAnchors) => {
1312
2501
  if (jsonTypeOf(subject, "object")) {
1313
- const embeddedSchemaVersion = typeof subject["$schema"] === "string" ? splitUrl$3(subject["$schema"])[0] : schemaVersion;
2502
+ const embeddedSchemaVersion = typeof subject["$schema"] === "string" ? resolveUrl$1(subject["$schema"], "") : schemaVersion;
1314
2503
  const embeddedEmbeddedToken = getConfig(embeddedSchemaVersion, "embeddedToken");
1315
2504
  const embeddedAnchorToken = getConfig(embeddedSchemaVersion, "anchorToken");
1316
2505
  if (typeof subject[embeddedEmbeddedToken] === "string" && (embeddedEmbeddedToken !== embeddedAnchorToken || subject[embeddedEmbeddedToken][0] !== "#")) {
1317
- const ref = safeResolveUrl(id, subject[embeddedEmbeddedToken]);
2506
+ const ref = resolveUrl$1(id, subject[embeddedEmbeddedToken]);
1318
2507
  subject[embeddedEmbeddedToken] = ref;
1319
2508
  add$1(subject, ref, schemaVersion);
1320
2509
  return reference.cons(subject[embeddedEmbeddedToken], subject);
@@ -1373,8 +2562,9 @@ var JsonSchema = (function (exports) {
1373
2562
  });
1374
2563
 
1375
2564
  const get = async (url, contextDoc = nil) => {
1376
- const resolvedUrl = safeResolveUrl(uri(contextDoc), url);
1377
- const [id, fragment] = splitUrl$3(resolvedUrl);
2565
+ const resolvedUrl = resolveUrl$1(uri(contextDoc), url);
2566
+ const id = resolveUrl$1(resolvedUrl, "");
2567
+ const fragment = urlFragment(resolvedUrl);
1378
2568
 
1379
2569
  if (!hasStoredSchema(id)) {
1380
2570
  const response = await fetch_browser(id, { headers: { Accept: "application/schema+json" } });
@@ -1474,7 +2664,7 @@ var JsonSchema = (function (exports) {
1474
2664
  const dynamicAnchorToken = getConfig(schemaDoc.schemaVersion, "dynamicAnchorToken");
1475
2665
  Object.entries(schemaDoc.dynamicAnchors)
1476
2666
  .forEach(([anchor, uri]) => {
1477
- const pointer = splitUrl$3(uri)[1];
2667
+ const pointer = urlFragment(uri);
1478
2668
  lib$3.assign(pointer, schema, {
1479
2669
  [dynamicAnchorToken]: anchor,
1480
2670
  ...lib$3.get(pointer, schema)
@@ -1543,7 +2733,7 @@ var JsonSchema = (function (exports) {
1543
2733
 
1544
2734
  var invalidSchemaError = InvalidSchemaError$1;
1545
2735
 
1546
- const { splitUrl: splitUrl$2 } = common$1;
2736
+ const { resolveUrl } = common$1;
1547
2737
 
1548
2738
 
1549
2739
 
@@ -1702,7 +2892,7 @@ var JsonSchema = (function (exports) {
1702
2892
 
1703
2893
  const interpretSchema = (schemaUri, instance, ast, dynamicAnchors) => {
1704
2894
  const keywordId = getKeywordId(schemaUri, ast);
1705
- const id = splitUrl$2(schemaUri)[0];
2895
+ const id = resolveUrl(schemaUri, "");
1706
2896
  return getKeyword(keywordId).interpret(schemaUri, instance, ast, { ...ast.metaData[id].dynamicAnchors, ...dynamicAnchors });
1707
2897
  };
1708
2898