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