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