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