eslint-vitest-rule-tester
Version:
ESLint rule tester with Vitest
1,082 lines (1,076 loc) • 262 kB
JavaScript
import { Linter } from "eslint";
import { describe, expect, it } from "vitest";
import path from "node:path";
import process from "node:process";
//#region rolldown:runtime
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
key = keys[i];
if (!__hasOwnProp.call(to, key) && key !== except) {
__defProp(to, key, {
get: ((k) => from[k]).bind(null, key),
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
});
}
}
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
value: mod,
enumerable: true
}) : target, mod));
//#endregion
//#region node_modules/.pnpm/@antfu+utils@9.3.0/node_modules/@antfu/utils/dist/index.mjs
function toArray(array) {
array = array ?? [];
return Array.isArray(array) ? array : [array];
}
const toString = (v) => Object.prototype.toString.call(v);
const isObject = (val) => toString(val) === "[object Object]";
const _reFullWs = /^\s*$/;
function unindent(str) {
const lines = (typeof str === "string" ? str : str[0]).split("\n");
const whitespaceLines = lines.map((line) => _reFullWs.test(line));
const commonIndent = lines.reduce((min, line, idx) => {
if (whitespaceLines[idx]) return min;
const indent = line.match(/^\s*/)?.[0].length;
return indent === void 0 ? min : Math.min(min, indent);
}, Number.POSITIVE_INFINITY);
let emptyLinesHead = 0;
while (emptyLinesHead < lines.length && whitespaceLines[emptyLinesHead]) emptyLinesHead++;
let emptyLinesTail = 0;
while (emptyLinesTail < lines.length && whitespaceLines[lines.length - emptyLinesTail - 1]) emptyLinesTail++;
return lines.slice(emptyLinesHead, lines.length - emptyLinesTail).map((line) => line.slice(commonIndent)).join("\n");
}
function objectKeys(obj) {
return Object.keys(obj);
}
function deepMerge(target, ...sources) {
if (!sources.length) return target;
const source = sources.shift();
if (source === void 0) return target;
if (isMergableObject(target) && isMergableObject(source)) objectKeys(source).forEach((key) => {
if (key === "__proto__" || key === "constructor" || key === "prototype") return;
if (isMergableObject(source[key])) {
if (!target[key]) target[key] = {};
if (isMergableObject(target[key])) deepMerge(target[key], source[key]);
else target[key] = source[key];
} else target[key] = source[key];
});
return deepMerge(target, ...sources);
}
function isMergableObject(item) {
return isObject(item) && !Array.isArray(item);
}
function objectPick(obj, keys, omitUndefined = false) {
return keys.reduce((n, k) => {
if (k in obj) {
if (!omitUndefined || obj[k] !== void 0) n[k] = obj[k];
}
return n;
}, {});
}
//#endregion
//#region src/options.ts
function pickFlatConfigFromOptions(options) {
const picked = objectPick(options, [
"parserOptions",
"parser",
"languageOptions",
"linterOptions",
"settings",
"processor",
"files"
]);
if (picked.parserOptions) {
picked.languageOptions ||= {};
picked.languageOptions.parserOptions = picked.parserOptions;
if (picked.parserOptions.ecmaVersion) picked.languageOptions.ecmaVersion ||= picked.parserOptions.ecmaVersion;
if (picked.parserOptions.sourceType) picked.languageOptions.sourceType ||= picked.parserOptions.sourceType;
delete picked.parserOptions;
}
if (picked.parser) {
picked.languageOptions ||= {};
picked.languageOptions.parser = picked.parser;
delete picked.parser;
}
if (Object.keys(picked).length) return picked;
}
//#endregion
//#region src/vendor/interpolate.ts
function interpolate(text, data) {
if (!data) return text;
return text.replace(/\{\{([^{}]+)\}\}/gu, (fullMatch, termWithWhitespace) => {
const term = termWithWhitespace.trim();
if (term in data) return String(data[term]);
return fullMatch;
});
}
//#endregion
//#region src/utils.ts
function normalizeTestCase(c, languageOptions, defaultFilenames, type$1) {
const obj = typeof c === "string" ? { code: c } : { ...c };
const normalized = obj;
normalized.type ||= type$1 || ("errors" in obj || "output" in obj ? "invalid" : "valid");
const parserOptions = {
...languageOptions?.parserOptions,
...normalized.parserOptions,
...normalized.languageOptions?.parserOptions || {}
};
const merged = {
...languageOptions,
...normalized.languageOptions,
parser: normalized.languageOptions?.parser ?? normalized.parser ?? languageOptions?.parser,
parserOptions
};
if (isUsingTypeScriptParser(merged)) {
normalized.filename ||= getDefaultTypeScriptFilename(merged, defaultFilenames);
normalized.languageOptions ||= {};
normalized.languageOptions.parser = merged.parser;
normalized.languageOptions.parserOptions = {
ecmaVersion: "latest",
sourceType: "module",
disallowAutomaticSingleRunInference: true,
...parserOptions
};
} else normalized.filename ||= getDefaultJavaScriptFilename(merged, defaultFilenames);
return normalized;
}
function normalizeCaseError(error, rule) {
if (typeof error === "string") return { messageId: error };
const clone = { ...error };
if ("data" in clone) {
if (!rule) throw new Error(`'data' property in invalid test case requires 'rule' to be provided at the top level`);
if (!clone.messageId) throw new Error(`'data' property is provided but 'messageId' is missing`);
if (clone.message) throw new Error(`'data' and 'message' properties are mutually exclusive`);
const template = rule.meta?.messages?.[clone.messageId];
if (!template) throw new Error(`Message ID '${clone.messageId}' is not found in the rule meta`);
clone.message = interpolate(template, clone.data);
delete clone.data;
}
if ("type" in clone) {
clone.nodeType = clone.type;
delete clone.type;
}
return clone;
}
function getDefaultJavaScriptFilename(parserOptions, defaultFilenames) {
return parserOptions?.ecmaFeatures?.jsx ? defaultFilenames.jsx : defaultFilenames.js;
}
function getDefaultTypeScriptFilename(LanguageOptions, defaultFilenames) {
const rootPath = (isUsingTypeScriptTypings(LanguageOptions) ? LanguageOptions?.parserOptions?.tsconfigRootDir : void 0) ?? process.cwd();
const filename = LanguageOptions?.parserOptions?.ecmaFeatures?.jsx ? defaultFilenames.tsx : defaultFilenames.ts;
return path.join(rootPath, filename);
}
function isUsingTypeScriptParser(languageOptions) {
return languageOptions?.parser?.meta?.name === "typescript-eslint/parser";
}
function isUsingTypeScriptTypings(languageOptions) {
return languageOptions?.parserOptions?.program || languageOptions?.parserOptions?.project || languageOptions?.parserOptions?.projectService;
}
//#endregion
//#region node_modules/.pnpm/uri-js@4.4.1/node_modules/uri-js/dist/es5/uri.all.js
var require_uri_all = /* @__PURE__ */ __commonJSMin(((exports, module) => {
/** @license URI.js v4.4.1 (c) 2011 Gary Court. License: http://github.com/garycourt/uri-js */
(function(global, factory) {
typeof exports === "object" && typeof module !== "undefined" ? factory(exports) : typeof define === "function" && define.amd ? define(["exports"], factory) : factory(global.URI = global.URI || {});
})(exports, (function(exports$1) {
"use strict";
function merge() {
for (var _len = arguments.length, sets = Array(_len), _key = 0; _key < _len; _key++) sets[_key] = arguments[_key];
if (sets.length > 1) {
sets[0] = sets[0].slice(0, -1);
var xl = sets.length - 1;
for (var x = 1; x < xl; ++x) sets[x] = sets[x].slice(1, -1);
sets[xl] = sets[xl].slice(1);
return sets.join("");
} else return sets[0];
}
function subexp(str) {
return "(?:" + str + ")";
}
function typeOf(o) {
return o === void 0 ? "undefined" : o === null ? "null" : Object.prototype.toString.call(o).split(" ").pop().split("]").shift().toLowerCase();
}
function toUpperCase(str) {
return str.toUpperCase();
}
function toArray$1(obj) {
return obj !== void 0 && obj !== null ? obj instanceof Array ? obj : typeof obj.length !== "number" || obj.split || obj.setInterval || obj.call ? [obj] : Array.prototype.slice.call(obj) : [];
}
function assign(target, source) {
var obj = target;
if (source) for (var key in source) obj[key] = source[key];
return obj;
}
function buildExps(isIRI) {
var ALPHA$$ = "[A-Za-z]", DIGIT$$ = "[0-9]", HEXDIG$$$1 = merge(DIGIT$$, "[A-Fa-f]"), PCT_ENCODED$$1 = subexp(subexp("%[EFef]" + HEXDIG$$$1 + "%" + HEXDIG$$$1 + HEXDIG$$$1 + "%" + HEXDIG$$$1 + HEXDIG$$$1) + "|" + subexp("%[89A-Fa-f]" + HEXDIG$$$1 + "%" + HEXDIG$$$1 + HEXDIG$$$1) + "|" + subexp("%" + HEXDIG$$$1 + HEXDIG$$$1)), GEN_DELIMS$$ = "[\\:\\/\\?\\#\\[\\]\\@]", SUB_DELIMS$$ = "[\\!\\$\\&\\'\\(\\)\\*\\+\\,\\;\\=]", RESERVED$$ = merge(GEN_DELIMS$$, SUB_DELIMS$$), UCSCHAR$$ = isIRI ? "[\\xA0-\\u200D\\u2010-\\u2029\\u202F-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF]" : "[]", IPRIVATE$$ = isIRI ? "[\\uE000-\\uF8FF]" : "[]", UNRESERVED$$$1 = merge(ALPHA$$, DIGIT$$, "[\\-\\.\\_\\~]", UCSCHAR$$), SCHEME$ = subexp(ALPHA$$ + merge(ALPHA$$, DIGIT$$, "[\\+\\-\\.]") + "*"), USERINFO$ = subexp(subexp(PCT_ENCODED$$1 + "|" + merge(UNRESERVED$$$1, SUB_DELIMS$$, "[\\:]")) + "*");
subexp(subexp("25[0-5]") + "|" + subexp("2[0-4]" + DIGIT$$) + "|" + subexp("1" + DIGIT$$ + DIGIT$$) + "|" + subexp("[1-9]" + DIGIT$$) + "|" + DIGIT$$);
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$$), IPV4ADDRESS$ = subexp(DEC_OCTET_RELAXED$ + "\\." + DEC_OCTET_RELAXED$ + "\\." + DEC_OCTET_RELAXED$ + "\\." + DEC_OCTET_RELAXED$), H16$ = subexp(HEXDIG$$$1 + "{1,4}"), LS32$ = subexp(subexp(H16$ + "\\:" + H16$) + "|" + IPV4ADDRESS$), IPV6ADDRESS$ = subexp([
subexp(subexp(H16$ + "\\:") + "{6}" + LS32$),
subexp("\\:\\:" + subexp(H16$ + "\\:") + "{5}" + LS32$),
subexp(subexp(H16$) + "?\\:\\:" + subexp(H16$ + "\\:") + "{4}" + LS32$),
subexp(subexp(subexp(H16$ + "\\:") + "{0,1}" + H16$) + "?\\:\\:" + subexp(H16$ + "\\:") + "{3}" + LS32$),
subexp(subexp(subexp(H16$ + "\\:") + "{0,2}" + H16$) + "?\\:\\:" + subexp(H16$ + "\\:") + "{2}" + LS32$),
subexp(subexp(subexp(H16$ + "\\:") + "{0,3}" + H16$) + "?\\:\\:" + H16$ + "\\:" + LS32$),
subexp(subexp(subexp(H16$ + "\\:") + "{0,4}" + H16$) + "?\\:\\:" + LS32$),
subexp(subexp(subexp(H16$ + "\\:") + "{0,5}" + H16$) + "?\\:\\:" + H16$),
subexp(subexp(subexp(H16$ + "\\:") + "{0,6}" + H16$) + "?\\:\\:")
].join("|")), ZONEID$ = subexp(subexp(UNRESERVED$$$1 + "|" + PCT_ENCODED$$1) + "+");
subexp(IPV6ADDRESS$ + "\\%25" + ZONEID$);
var IPV6ADDRZ_RELAXED$ = subexp(IPV6ADDRESS$ + subexp("\\%25|\\%(?!" + HEXDIG$$$1 + "{2})") + ZONEID$), IPVFUTURE$ = subexp("[vV]" + HEXDIG$$$1 + "+\\." + merge(UNRESERVED$$$1, SUB_DELIMS$$, "[\\:]") + "+"), IP_LITERAL$ = subexp("\\[" + subexp(IPV6ADDRZ_RELAXED$ + "|" + IPV6ADDRESS$ + "|" + IPVFUTURE$) + "\\]"), REG_NAME$ = subexp(subexp(PCT_ENCODED$$1 + "|" + merge(UNRESERVED$$$1, SUB_DELIMS$$)) + "*"), HOST$ = subexp(IP_LITERAL$ + "|" + IPV4ADDRESS$ + "(?!" + REG_NAME$ + ")|" + REG_NAME$), PORT$ = subexp(DIGIT$$ + "*"), AUTHORITY$ = subexp(subexp(USERINFO$ + "@") + "?" + HOST$ + subexp("\\:" + PORT$) + "?"), PCHAR$ = subexp(PCT_ENCODED$$1 + "|" + merge(UNRESERVED$$$1, SUB_DELIMS$$, "[\\:\\@]")), SEGMENT$ = subexp(PCHAR$ + "*"), SEGMENT_NZ$ = subexp(PCHAR$ + "+"), SEGMENT_NZ_NC$ = subexp(subexp(PCT_ENCODED$$1 + "|" + merge(UNRESERVED$$$1, SUB_DELIMS$$, "[\\@]")) + "+"), PATH_ABEMPTY$ = subexp(subexp("\\/" + SEGMENT$) + "*"), PATH_ABSOLUTE$ = subexp("\\/" + subexp(SEGMENT_NZ$ + PATH_ABEMPTY$) + "?"), PATH_NOSCHEME$ = subexp(SEGMENT_NZ_NC$ + PATH_ABEMPTY$), PATH_ROOTLESS$ = subexp(SEGMENT_NZ$ + PATH_ABEMPTY$), PATH_EMPTY$ = "(?!" + PCHAR$ + ")";
subexp(PATH_ABEMPTY$ + "|" + PATH_ABSOLUTE$ + "|" + PATH_NOSCHEME$ + "|" + PATH_ROOTLESS$ + "|" + PATH_EMPTY$);
var QUERY$ = subexp(subexp(PCHAR$ + "|" + merge("[\\/\\?]", IPRIVATE$$)) + "*"), FRAGMENT$ = subexp(subexp(PCHAR$ + "|[\\/\\?]") + "*"), HIER_PART$ = subexp(subexp("\\/\\/" + AUTHORITY$ + PATH_ABEMPTY$) + "|" + PATH_ABSOLUTE$ + "|" + PATH_ROOTLESS$ + "|" + PATH_EMPTY$), URI$ = subexp(SCHEME$ + "\\:" + HIER_PART$ + subexp("\\?" + QUERY$) + "?" + subexp("\\#" + FRAGMENT$) + "?"), RELATIVE$ = subexp(subexp(subexp("\\/\\/" + AUTHORITY$ + PATH_ABEMPTY$) + "|" + PATH_ABSOLUTE$ + "|" + PATH_NOSCHEME$ + "|" + PATH_EMPTY$) + subexp("\\?" + QUERY$) + "?" + subexp("\\#" + FRAGMENT$) + "?");
subexp(URI$ + "|" + RELATIVE$);
subexp(SCHEME$ + "\\:" + HIER_PART$ + subexp("\\?" + QUERY$) + "?");
"" + SCHEME$ + subexp(subexp("\\/\\/(" + subexp("(" + USERINFO$ + ")@") + "?(" + HOST$ + ")" + subexp("\\:(" + PORT$ + ")") + "?)") + "?(" + PATH_ABEMPTY$ + "|" + PATH_ABSOLUTE$ + "|" + PATH_ROOTLESS$ + "|" + PATH_EMPTY$ + ")") + subexp("\\?(" + QUERY$ + ")") + subexp("\\#(" + FRAGMENT$ + ")");
"" + subexp(subexp("\\/\\/(" + subexp("(" + USERINFO$ + ")@") + "?(" + HOST$ + ")" + subexp("\\:(" + PORT$ + ")") + "?)") + "?(" + PATH_ABEMPTY$ + "|" + PATH_ABSOLUTE$ + "|" + PATH_NOSCHEME$ + "|" + PATH_EMPTY$ + ")") + subexp("\\?(" + QUERY$ + ")") + subexp("\\#(" + FRAGMENT$ + ")");
"" + SCHEME$ + subexp(subexp("\\/\\/(" + subexp("(" + USERINFO$ + ")@") + "?(" + HOST$ + ")" + subexp("\\:(" + PORT$ + ")") + "?)") + "?(" + PATH_ABEMPTY$ + "|" + PATH_ABSOLUTE$ + "|" + PATH_ROOTLESS$ + "|" + PATH_EMPTY$ + ")") + subexp("\\?(" + QUERY$ + ")");
"" + subexp("\\#(" + FRAGMENT$ + ")");
"" + subexp("(" + USERINFO$ + ")@") + HOST$ + subexp("\\:(" + PORT$ + ")");
return {
NOT_SCHEME: new RegExp(merge("[^]", ALPHA$$, DIGIT$$, "[\\+\\-\\.]"), "g"),
NOT_USERINFO: new RegExp(merge("[^\\%\\:]", UNRESERVED$$$1, SUB_DELIMS$$), "g"),
NOT_HOST: new RegExp(merge("[^\\%\\[\\]\\:]", UNRESERVED$$$1, SUB_DELIMS$$), "g"),
NOT_PATH: new RegExp(merge("[^\\%\\/\\:\\@]", UNRESERVED$$$1, SUB_DELIMS$$), "g"),
NOT_PATH_NOSCHEME: new RegExp(merge("[^\\%\\/\\@]", UNRESERVED$$$1, SUB_DELIMS$$), "g"),
NOT_QUERY: new RegExp(merge("[^\\%]", UNRESERVED$$$1, SUB_DELIMS$$, "[\\:\\@\\/\\?]", IPRIVATE$$), "g"),
NOT_FRAGMENT: new RegExp(merge("[^\\%]", UNRESERVED$$$1, SUB_DELIMS$$, "[\\:\\@\\/\\?]"), "g"),
ESCAPE: new RegExp(merge("[^]", UNRESERVED$$$1, SUB_DELIMS$$), "g"),
UNRESERVED: new RegExp(UNRESERVED$$$1, "g"),
OTHER_CHARS: new RegExp(merge("[^\\%]", UNRESERVED$$$1, RESERVED$$), "g"),
PCT_ENCODED: new RegExp(PCT_ENCODED$$1, "g"),
IPV4ADDRESS: /* @__PURE__ */ new RegExp("^(" + IPV4ADDRESS$ + ")$"),
IPV6ADDRESS: /* @__PURE__ */ new RegExp("^\\[?(" + IPV6ADDRESS$ + ")" + subexp(subexp("\\%25|\\%(?!" + HEXDIG$$$1 + "{2})") + "(" + ZONEID$ + ")") + "?\\]?$")
};
}
var URI_PROTOCOL = buildExps(false);
var IRI_PROTOCOL = buildExps(true);
var slicedToArray = function() {
function sliceIterator(arr, i) {
var _arr = [];
var _n = true;
var _d = false;
var _e = void 0;
try {
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
_arr.push(_s.value);
if (i && _arr.length === i) break;
}
} catch (err) {
_d = true;
_e = err;
} finally {
try {
if (!_n && _i["return"]) _i["return"]();
} finally {
if (_d) throw _e;
}
}
return _arr;
}
return function(arr, i) {
if (Array.isArray(arr)) return arr;
else if (Symbol.iterator in Object(arr)) return sliceIterator(arr, i);
else throw new TypeError("Invalid attempt to destructure non-iterable instance");
};
}();
var toConsumableArray = function(arr) {
if (Array.isArray(arr)) {
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
return arr2;
} else return Array.from(arr);
};
/** Highest positive signed 32-bit float value */
var maxInt = 2147483647;
/** Bootstring parameters */
var base = 36;
var tMin = 1;
var tMax = 26;
var skew = 38;
var damp = 700;
var initialBias = 72;
var initialN = 128;
var delimiter = "-";
/** Regular expressions */
var regexPunycode = /^xn--/;
var regexNonASCII = /[^\0-\x7E]/;
var regexSeparators = /[\x2E\u3002\uFF0E\uFF61]/g;
/** Error messages */
var errors = {
"overflow": "Overflow: input needs wider integers to process",
"not-basic": "Illegal input >= 0x80 (not a basic code point)",
"invalid-input": "Invalid input"
};
/** Convenience shortcuts */
var baseMinusTMin = base - tMin;
var floor = Math.floor;
var stringFromCharCode = String.fromCharCode;
/**
* A generic error utility function.
* @private
* @param {String} type The error type.
* @returns {Error} Throws a `RangeError` with the applicable error message.
*/
function error$1(type$1) {
throw new RangeError(errors[type$1]);
}
/**
* A generic `Array#map` utility function.
* @private
* @param {Array} array The array to iterate over.
* @param {Function} callback The function that gets called for every array
* item.
* @returns {Array} A new array of values returned by the callback function.
*/
function map(array, fn) {
var result = [];
var length = array.length;
while (length--) result[length] = fn(array[length]);
return result;
}
/**
* A simple `Array#map`-like wrapper to work with domain name strings or email
* addresses.
* @private
* @param {String} domain The domain name or email address.
* @param {Function} callback The function that gets called for every
* character.
* @returns {Array} A new string of characters returned by the callback
* function.
*/
function mapDomain(string, fn) {
var parts = string.split("@");
var result = "";
if (parts.length > 1) {
result = parts[0] + "@";
string = parts[1];
}
string = string.replace(regexSeparators, ".");
var encoded = map(string.split("."), fn).join(".");
return result + encoded;
}
/**
* Creates an array containing the numeric code points of each Unicode
* character in the string. While JavaScript uses UCS-2 internally,
* this function will convert a pair of surrogate halves (each of which
* UCS-2 exposes as separate characters) into a single code point,
* matching UTF-16.
* @see `punycode.ucs2.encode`
* @see <https://mathiasbynens.be/notes/javascript-encoding>
* @memberOf punycode.ucs2
* @name decode
* @param {String} string The Unicode input string (UCS-2).
* @returns {Array} The new array of code points.
*/
function ucs2decode(string) {
var output = [];
var counter = 0;
var length = string.length;
while (counter < length) {
var value = string.charCodeAt(counter++);
if (value >= 55296 && value <= 56319 && counter < length) {
var extra = string.charCodeAt(counter++);
if ((extra & 64512) == 56320) output.push(((value & 1023) << 10) + (extra & 1023) + 65536);
else {
output.push(value);
counter--;
}
} else output.push(value);
}
return output;
}
/**
* Creates a string based on an array of numeric code points.
* @see `punycode.ucs2.decode`
* @memberOf punycode.ucs2
* @name encode
* @param {Array} codePoints The array of numeric code points.
* @returns {String} The new Unicode string (UCS-2).
*/
var ucs2encode = function ucs2encode$1(array) {
return String.fromCodePoint.apply(String, toConsumableArray(array));
};
/**
* Converts a basic code point into a digit/integer.
* @see `digitToBasic()`
* @private
* @param {Number} codePoint The basic numeric code point value.
* @returns {Number} The numeric value of a basic code point (for use in
* representing integers) in the range `0` to `base - 1`, or `base` if
* the code point does not represent a value.
*/
var basicToDigit = function basicToDigit$1(codePoint) {
if (codePoint - 48 < 10) return codePoint - 22;
if (codePoint - 65 < 26) return codePoint - 65;
if (codePoint - 97 < 26) return codePoint - 97;
return base;
};
/**
* Converts a digit/integer into a basic code point.
* @see `basicToDigit()`
* @private
* @param {Number} digit The numeric value of a basic code point.
* @returns {Number} The basic code point whose value (when used for
* representing integers) is `digit`, which needs to be in the range
* `0` to `base - 1`. If `flag` is non-zero, the uppercase form is
* used; else, the lowercase form is used. The behavior is undefined
* if `flag` is non-zero and `digit` has no uppercase form.
*/
var digitToBasic = function digitToBasic$1(digit, flag) {
return digit + 22 + 75 * (digit < 26) - ((flag != 0) << 5);
};
/**
* Bias adaptation function as per section 3.4 of RFC 3492.
* https://tools.ietf.org/html/rfc3492#section-3.4
* @private
*/
var adapt = function adapt$1(delta, numPoints, firstTime) {
var k = 0;
delta = firstTime ? floor(delta / damp) : delta >> 1;
delta += floor(delta / numPoints);
for (; delta > baseMinusTMin * tMax >> 1; k += base) delta = floor(delta / baseMinusTMin);
return floor(k + (baseMinusTMin + 1) * delta / (delta + skew));
};
/**
* Converts a Punycode string of ASCII-only symbols to a string of Unicode
* symbols.
* @memberOf punycode
* @param {String} input The Punycode string of ASCII-only symbols.
* @returns {String} The resulting string of Unicode symbols.
*/
var decode = function decode$1(input) {
var output = [];
var inputLength = input.length;
var i = 0;
var n = initialN;
var bias = initialBias;
var basic = input.lastIndexOf(delimiter);
if (basic < 0) basic = 0;
for (var j = 0; j < basic; ++j) {
if (input.charCodeAt(j) >= 128) error$1("not-basic");
output.push(input.charCodeAt(j));
}
for (var index = basic > 0 ? basic + 1 : 0; index < inputLength;) {
var oldi = i;
for (var w = 1, k = base;; k += base) {
if (index >= inputLength) error$1("invalid-input");
var digit = basicToDigit(input.charCodeAt(index++));
if (digit >= base || digit > floor((maxInt - i) / w)) error$1("overflow");
i += digit * w;
var t = k <= bias ? tMin : k >= bias + tMax ? tMax : k - bias;
if (digit < t) break;
var baseMinusT = base - t;
if (w > floor(maxInt / baseMinusT)) error$1("overflow");
w *= baseMinusT;
}
var out = output.length + 1;
bias = adapt(i - oldi, out, oldi == 0);
if (floor(i / out) > maxInt - n) error$1("overflow");
n += floor(i / out);
i %= out;
output.splice(i++, 0, n);
}
return String.fromCodePoint.apply(String, output);
};
/**
* Converts a string of Unicode symbols (e.g. a domain name label) to a
* Punycode string of ASCII-only symbols.
* @memberOf punycode
* @param {String} input The string of Unicode symbols.
* @returns {String} The resulting Punycode string of ASCII-only symbols.
*/
var encode = function encode$1(input) {
var output = [];
input = ucs2decode(input);
var inputLength = input.length;
var n = initialN;
var delta = 0;
var bias = initialBias;
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = void 0;
try {
for (var _iterator = input[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var _currentValue2 = _step.value;
if (_currentValue2 < 128) output.push(stringFromCharCode(_currentValue2));
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) _iterator.return();
} finally {
if (_didIteratorError) throw _iteratorError;
}
}
var basicLength = output.length;
var handledCPCount = basicLength;
if (basicLength) output.push(delimiter);
while (handledCPCount < inputLength) {
var m = maxInt;
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = void 0;
try {
for (var _iterator2 = input[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var currentValue = _step2.value;
if (currentValue >= n && currentValue < m) m = currentValue;
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return) _iterator2.return();
} finally {
if (_didIteratorError2) throw _iteratorError2;
}
}
var handledCPCountPlusOne = handledCPCount + 1;
if (m - n > floor((maxInt - delta) / handledCPCountPlusOne)) error$1("overflow");
delta += (m - n) * handledCPCountPlusOne;
n = m;
var _iteratorNormalCompletion3 = true;
var _didIteratorError3 = false;
var _iteratorError3 = void 0;
try {
for (var _iterator3 = input[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
var _currentValue = _step3.value;
if (_currentValue < n && ++delta > maxInt) error$1("overflow");
if (_currentValue == n) {
var q = delta;
for (var k = base;; k += base) {
var t = k <= bias ? tMin : k >= bias + tMax ? tMax : k - bias;
if (q < t) break;
var qMinusT = q - t;
var baseMinusT = base - t;
output.push(stringFromCharCode(digitToBasic(t + qMinusT % baseMinusT, 0)));
q = floor(qMinusT / baseMinusT);
}
output.push(stringFromCharCode(digitToBasic(q, 0)));
bias = adapt(delta, handledCPCountPlusOne, handledCPCount == basicLength);
delta = 0;
++handledCPCount;
}
}
} catch (err) {
_didIteratorError3 = true;
_iteratorError3 = err;
} finally {
try {
if (!_iteratorNormalCompletion3 && _iterator3.return) _iterator3.return();
} finally {
if (_didIteratorError3) throw _iteratorError3;
}
}
++delta;
++n;
}
return output.join("");
};
/**
* Converts a Punycode string representing a domain name or an email address
* to Unicode. Only the Punycoded parts of the input will be converted, i.e.
* it doesn't matter if you call it on a string that has already been
* converted to Unicode.
* @memberOf punycode
* @param {String} input The Punycoded domain name or email address to
* convert to Unicode.
* @returns {String} The Unicode representation of the given Punycode
* string.
*/
var toUnicode = function toUnicode$1(input) {
return mapDomain(input, function(string) {
return regexPunycode.test(string) ? decode(string.slice(4).toLowerCase()) : string;
});
};
/**
* Converts a Unicode string representing a domain name or an email address to
* Punycode. Only the non-ASCII parts of the domain name will be converted,
* i.e. it doesn't matter if you call it with a domain that's already in
* ASCII.
* @memberOf punycode
* @param {String} input The domain name or email address to convert, as a
* Unicode string.
* @returns {String} The Punycode representation of the given domain name or
* email address.
*/
var toASCII = function toASCII$1(input) {
return mapDomain(input, function(string) {
return regexNonASCII.test(string) ? "xn--" + encode(string) : string;
});
};
/** Define the public API */
var punycode = {
"version": "2.1.0",
"ucs2": {
"decode": ucs2decode,
"encode": ucs2encode
},
"decode": decode,
"encode": encode,
"toASCII": toASCII,
"toUnicode": toUnicode
};
/**
* URI.js
*
* @fileoverview An RFC 3986 compliant, scheme extendable URI parsing/validating/resolving library for JavaScript.
* @author <a href="mailto:gary.court@gmail.com">Gary Court</a>
* @see http://github.com/garycourt/uri-js
*/
/**
* Copyright 2011 Gary Court. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY GARY COURT ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GARY COURT OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of Gary Court.
*/
var SCHEMES = {};
function pctEncChar(chr) {
var c = chr.charCodeAt(0);
var e = void 0;
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();
return e;
}
function pctDecChars(str) {
var newStr = "";
var i = 0;
var il = str.length;
while (i < il) {
var c = parseInt(str.substr(i + 1, 2), 16);
if (c < 128) {
newStr += String.fromCharCode(c);
i += 3;
} else if (c >= 194 && c < 224) {
if (il - i >= 6) {
var c2 = parseInt(str.substr(i + 4, 2), 16);
newStr += String.fromCharCode((c & 31) << 6 | c2 & 63);
} else newStr += str.substr(i, 6);
i += 6;
} else if (c >= 224) {
if (il - i >= 9) {
var _c = parseInt(str.substr(i + 4, 2), 16);
var c3 = parseInt(str.substr(i + 7, 2), 16);
newStr += String.fromCharCode((c & 15) << 12 | (_c & 63) << 6 | c3 & 63);
} else newStr += str.substr(i, 9);
i += 9;
} else {
newStr += str.substr(i, 3);
i += 3;
}
}
return newStr;
}
function _normalizeComponentEncoding(components, protocol) {
function decodeUnreserved$1(str) {
var decStr = pctDecChars(str);
return !decStr.match(protocol.UNRESERVED) ? str : decStr;
}
if (components.scheme) components.scheme = String(components.scheme).replace(protocol.PCT_ENCODED, decodeUnreserved$1).toLowerCase().replace(protocol.NOT_SCHEME, "");
if (components.userinfo !== void 0) components.userinfo = String(components.userinfo).replace(protocol.PCT_ENCODED, decodeUnreserved$1).replace(protocol.NOT_USERINFO, pctEncChar).replace(protocol.PCT_ENCODED, toUpperCase);
if (components.host !== void 0) components.host = String(components.host).replace(protocol.PCT_ENCODED, decodeUnreserved$1).toLowerCase().replace(protocol.NOT_HOST, pctEncChar).replace(protocol.PCT_ENCODED, toUpperCase);
if (components.path !== void 0) components.path = String(components.path).replace(protocol.PCT_ENCODED, decodeUnreserved$1).replace(components.scheme ? protocol.NOT_PATH : protocol.NOT_PATH_NOSCHEME, pctEncChar).replace(protocol.PCT_ENCODED, toUpperCase);
if (components.query !== void 0) components.query = String(components.query).replace(protocol.PCT_ENCODED, decodeUnreserved$1).replace(protocol.NOT_QUERY, pctEncChar).replace(protocol.PCT_ENCODED, toUpperCase);
if (components.fragment !== void 0) components.fragment = String(components.fragment).replace(protocol.PCT_ENCODED, decodeUnreserved$1).replace(protocol.NOT_FRAGMENT, pctEncChar).replace(protocol.PCT_ENCODED, toUpperCase);
return components;
}
function _stripLeadingZeros(str) {
return str.replace(/^0*(.*)/, "$1") || "0";
}
function _normalizeIPv4(host, protocol) {
var address = slicedToArray(host.match(protocol.IPV4ADDRESS) || [], 2)[1];
if (address) return address.split(".").map(_stripLeadingZeros).join(".");
else return host;
}
function _normalizeIPv6(host, protocol) {
var _matches2 = slicedToArray(host.match(protocol.IPV6ADDRESS) || [], 3), address = _matches2[1], zone = _matches2[2];
if (address) {
var _address$toLowerCase$2 = slicedToArray(address.toLowerCase().split("::").reverse(), 2), last = _address$toLowerCase$2[0], first = _address$toLowerCase$2[1];
var firstFields = first ? first.split(":").map(_stripLeadingZeros) : [];
var lastFields = last.split(":").map(_stripLeadingZeros);
var isLastFieldIPv4Address = protocol.IPV4ADDRESS.test(lastFields[lastFields.length - 1]);
var fieldCount = isLastFieldIPv4Address ? 7 : 8;
var lastFieldsStart = lastFields.length - fieldCount;
var fields = Array(fieldCount);
for (var x = 0; x < fieldCount; ++x) fields[x] = firstFields[x] || lastFields[lastFieldsStart + x] || "";
if (isLastFieldIPv4Address) fields[fieldCount - 1] = _normalizeIPv4(fields[fieldCount - 1], protocol);
var longestZeroFields = fields.reduce(function(acc, field, index) {
if (!field || field === "0") {
var lastLongest = acc[acc.length - 1];
if (lastLongest && lastLongest.index + lastLongest.length === index) lastLongest.length++;
else acc.push({
index,
length: 1
});
}
return acc;
}, []).sort(function(a, b) {
return b.length - a.length;
})[0];
var newHost = void 0;
if (longestZeroFields && longestZeroFields.length > 1) {
var newFirst = fields.slice(0, longestZeroFields.index);
var newLast = fields.slice(longestZeroFields.index + longestZeroFields.length);
newHost = newFirst.join(":") + "::" + newLast.join(":");
} else newHost = fields.join(":");
if (zone) newHost += "%" + zone;
return newHost;
} else return host;
}
var URI_PARSE = /^(?:([^:\/?#]+):)?(?:\/\/((?:([^\/?#@]*)@)?(\[[^\/?#\]]+\]|[^\/?#:]*)(?:\:(\d*))?))?([^?#]*)(?:\?([^#]*))?(?:#((?:.|\n|\r)*))?/i;
var NO_MATCH_IS_UNDEFINED = "".match(/(){0}/)[1] === void 0;
function parse(uriString) {
var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
var components = {};
var protocol = options.iri !== false ? IRI_PROTOCOL : URI_PROTOCOL;
if (options.reference === "suffix") uriString = (options.scheme ? options.scheme + ":" : "") + "//" + uriString;
var matches = uriString.match(URI_PARSE);
if (matches) {
if (NO_MATCH_IS_UNDEFINED) {
components.scheme = matches[1];
components.userinfo = matches[3];
components.host = matches[4];
components.port = parseInt(matches[5], 10);
components.path = matches[6] || "";
components.query = matches[7];
components.fragment = matches[8];
if (isNaN(components.port)) components.port = matches[5];
} else {
components.scheme = matches[1] || void 0;
components.userinfo = uriString.indexOf("@") !== -1 ? matches[3] : void 0;
components.host = uriString.indexOf("//") !== -1 ? matches[4] : void 0;
components.port = parseInt(matches[5], 10);
components.path = matches[6] || "";
components.query = uriString.indexOf("?") !== -1 ? matches[7] : void 0;
components.fragment = uriString.indexOf("#") !== -1 ? matches[8] : void 0;
if (isNaN(components.port)) components.port = uriString.match(/\/\/(?:.|\n)*\:(?:\/|\?|\#|$)/) ? matches[4] : void 0;
}
if (components.host) components.host = _normalizeIPv6(_normalizeIPv4(components.host, protocol), protocol);
if (components.scheme === void 0 && components.userinfo === void 0 && components.host === void 0 && components.port === void 0 && !components.path && components.query === void 0) components.reference = "same-document";
else if (components.scheme === void 0) components.reference = "relative";
else if (components.fragment === void 0) components.reference = "absolute";
else components.reference = "uri";
if (options.reference && options.reference !== "suffix" && options.reference !== components.reference) components.error = components.error || "URI is not a " + options.reference + " reference.";
var schemeHandler = SCHEMES[(options.scheme || components.scheme || "").toLowerCase()];
if (!options.unicodeSupport && (!schemeHandler || !schemeHandler.unicodeSupport)) {
if (components.host && (options.domainHost || schemeHandler && schemeHandler.domainHost)) try {
components.host = punycode.toASCII(components.host.replace(protocol.PCT_ENCODED, pctDecChars).toLowerCase());
} catch (e) {
components.error = components.error || "Host's domain name can not be converted to ASCII via punycode: " + e;
}
_normalizeComponentEncoding(components, URI_PROTOCOL);
} else _normalizeComponentEncoding(components, protocol);
if (schemeHandler && schemeHandler.parse) schemeHandler.parse(components, options);
} else components.error = components.error || "URI can not be parsed.";
return components;
}
function _recomposeAuthority(components, options) {
var protocol = options.iri !== false ? IRI_PROTOCOL : URI_PROTOCOL;
var uriTokens = [];
if (components.userinfo !== void 0) {
uriTokens.push(components.userinfo);
uriTokens.push("@");
}
if (components.host !== void 0) uriTokens.push(_normalizeIPv6(_normalizeIPv4(String(components.host), protocol), protocol).replace(protocol.IPV6ADDRESS, function(_, $1, $2) {
return "[" + $1 + ($2 ? "%25" + $2 : "") + "]";
}));
if (typeof components.port === "number" || typeof components.port === "string") {
uriTokens.push(":");
uriTokens.push(String(components.port));
}
return uriTokens.length ? uriTokens.join("") : void 0;
}
var RDS1 = /^\.\.?\//;
var RDS2 = /^\/\.(\/|$)/;
var RDS3 = /^\/\.\.(\/|$)/;
var RDS5 = /^\/?(?:.|\n)*?(?=\/|$)/;
function removeDotSegments(input) {
var output = [];
while (input.length) if (input.match(RDS1)) input = input.replace(RDS1, "");
else if (input.match(RDS2)) input = input.replace(RDS2, "/");
else if (input.match(RDS3)) {
input = input.replace(RDS3, "/");
output.pop();
} else if (input === "." || input === "..") input = "";
else {
var im = input.match(RDS5);
if (im) {
var s = im[0];
input = input.slice(s.length);
output.push(s);
} else throw new Error("Unexpected dot segment condition");
}
return output.join("");
}
function serialize(components) {
var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
var protocol = options.iri ? IRI_PROTOCOL : URI_PROTOCOL;
var uriTokens = [];
var schemeHandler = SCHEMES[(options.scheme || components.scheme || "").toLowerCase()];
if (schemeHandler && schemeHandler.serialize) schemeHandler.serialize(components, options);
if (components.host) {
if (protocol.IPV6ADDRESS.test(components.host)) {} else if (options.domainHost || schemeHandler && schemeHandler.domainHost) try {
components.host = !options.iri ? punycode.toASCII(components.host.replace(protocol.PCT_ENCODED, pctDecChars).toLowerCase()) : punycode.toUnicode(components.host);
} catch (e) {
components.error = components.error || "Host's domain name can not be converted to " + (!options.iri ? "ASCII" : "Unicode") + " via punycode: " + e;
}
}
_normalizeComponentEncoding(components, protocol);
if (options.reference !== "suffix" && components.scheme) {
uriTokens.push(components.scheme);
uriTokens.push(":");
}
var authority = _recomposeAuthority(components, options);
if (authority !== void 0) {
if (options.reference !== "suffix") uriTokens.push("//");
uriTokens.push(authority);
if (components.path && components.path.charAt(0) !== "/") uriTokens.push("/");
}
if (components.path !== void 0) {
var s = components.path;
if (!options.absolutePath && (!schemeHandler || !schemeHandler.absolutePath)) s = removeDotSegments(s);
if (authority === void 0) s = s.replace(/^\/\//, "/%2F");
uriTokens.push(s);
}
if (components.query !== void 0) {
uriTokens.push("?");
uriTokens.push(components.query);
}
if (components.fragment !== void 0) {
uriTokens.push("#");
uriTokens.push(components.fragment);
}
return uriTokens.join("");
}
function resolveComponents(base$1, relative) {
var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
var skipNormalization = arguments[3];
var target = {};
if (!skipNormalization) {
base$1 = parse(serialize(base$1, options), options);
relative = parse(serialize(relative, options), options);
}
options = options || {};
if (!options.tolerant && relative.scheme) {
target.scheme = relative.scheme;
target.userinfo = relative.userinfo;
target.host = relative.host;
target.port = relative.port;
target.path = removeDotSegments(relative.path || "");
target.query = relative.query;
} else {
if (relative.userinfo !== void 0 || relative.host !== void 0 || relative.port !== void 0) {
target.userinfo = relative.userinfo;
target.host = relative.host;
target.port = relative.port;
target.path = removeDotSegments(relative.path || "");
target.query = relative.query;
} else {
if (!relative.path) {
target.path = base$1.path;
if (relative.query !== void 0) target.query = relative.query;
else target.query = base$1.query;
} else {
if (relative.path.charAt(0) === "/") target.path = removeDotSegments(relative.path);
else {
if ((base$1.userinfo !== void 0 || base$1.host !== void 0 || base$1.port !== void 0) && !base$1.path) target.path = "/" + relative.path;
else if (!base$1.path) target.path = relative.path;
else target.path = base$1.path.slice(0, base$1.path.lastIndexOf("/") + 1) + relative.path;
target.path = removeDotSegments(target.path);
}
target.query = relative.query;
}
target.userinfo = base$1.userinfo;
target.host = base$1.host;
target.port = base$1.port;
}
target.scheme = base$1.scheme;
}
target.fragment = relative.fragment;
return target;
}
function resolve$4(baseURI, relativeURI, options) {
var schemelessOptions = assign({ scheme: "null" }, options);
return serialize(resolveComponents(parse(baseURI, schemelessOptions), parse(relativeURI, schemelessOptions), schemelessOptions, true), schemelessOptions);
}
function normalize(uri$1, options) {
if (typeof uri$1 === "string") uri$1 = serialize(parse(uri$1, options), options);
else if (typeOf(uri$1) === "object") uri$1 = parse(serialize(uri$1, options), options);
return uri$1;
}
function equal$2(uriA, uriB, options) {
if (typeof uriA === "string") uriA = serialize(parse(uriA, options), options);
else if (typeOf(uriA) === "object") uriA = serialize(uriA, options);
if (typeof uriB === "string") uriB = serialize(parse(uriB, options), options);
else if (typeOf(uriB) === "object") uriB = serialize(uriB, options);
return uriA === uriB;
}
function escapeComponent(str, options) {
return str && str.toString().replace(!options || !options.iri ? URI_PROTOCOL.ESCAPE : IRI_PROTOCOL.ESCAPE, pctEncChar);
}
function unescapeComponent(str, options) {
return str && str.toString().replace(!options || !options.iri ? URI_PROTOCOL.PCT_ENCODED : IRI_PROTOCOL.PCT_ENCODED, pctDecChars);
}
var handler = {
scheme: "http",
domainHost: true,
parse: function parse$1(components, options) {
if (!components.host) components.error = components.error || "HTTP URIs must have a host.";
return components;
},
serialize: function serialize$1(components, options) {
var secure = String(components.scheme).toLowerCase() === "https";
if (components.port === (secure ? 443 : 80) || components.port === "") components.port = void 0;
if (!components.path) components.path = "/";
return components;
}
};
var handler$1 = {
scheme: "https",
domainHost: handler.domainHost,
parse: handler.parse,
serialize: handler.serialize
};
function isSecure(wsComponents) {
return typeof wsComponents.secure === "boolean" ? wsComponents.secure : String(wsComponents.scheme).toLowerCase() === "wss";
}
var handler$2 = {
scheme: "ws",
domainHost: true,
parse: function parse$1(components, options) {
var wsComponents = components;
wsComponents.secure = isSecure(wsComponents);
wsComponents.resourceName = (wsComponents.path || "/") + (wsComponents.query ? "?" + wsComponents.query : "");
wsComponents.path = void 0;
wsComponents.query = void 0;
return wsComponents;
},
serialize: function serialize$1(wsComponents, options) {
if (wsComponents.port === (isSecure(wsComponents) ? 443 : 80) || wsComponents.port === "") wsComponents.port = void 0;
if (typeof wsComponents.secure === "boolean") {
wsComponents.scheme = wsComponents.secure ? "wss" : "ws";
wsComponents.secure = void 0;
}
if (wsComponents.resourceName) {
var _wsComponents$resourc2 = slicedToArray(wsComponents.resourceName.split("?"), 2), path$1 = _wsComponents$resourc2[0], query = _wsComponents$resourc2[1];
wsComponents.path = path$1 && path$1 !== "/" ? path$1 : void 0;
wsComponents.query = query;
wsComponents.resourceName = void 0;
}
wsComponents.fragment = void 0;
return wsComponents;
}
};
var handler$3 = {
scheme: "wss",
domainHost: handler$2.domainHost,
parse: handler$2.parse,
serialize: handler$2.serialize
};
var O = {};
var UNRESERVED$$ = "[A-Za-z0-9\\-\\.\\_\\~\\xA0-\\u200D\\u2010-\\u2029\\u202F-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF]";
var HEXDIG$$ = "[0-9A-Fa-f]";
var PCT_ENCODED$ = subexp(subexp("%[EFef]" + HEXDIG$$ + "%" + HEXDIG$$ + HEXDIG$$ + "%" + HEXDIG$$ + HEXDIG$$) + "|" + subexp("%[89A-Fa-f]" + HEXDIG$$ + "%" + HEXDIG$$ + HEXDIG$$) + "|" + subexp("%" + HEXDIG$$ + HEXDIG$$));
var ATEXT$$ = "[A-Za-z0-9\\!\\$\\%\\'\\*\\+\\-\\^\\_\\`\\{\\|\\}\\~]";
var VCHAR$$ = merge("[\\!\\$\\%\\'\\(\\)\\*\\+\\,\\-\\.0-9\\<\\>A-Z\\x5E-\\x7E]", "[\\\"\\\\]");
var SOME_DELIMS$$ = "[\\!\\$\\'\\(\\)\\*\\+\\,\\;\\:\\@]";
var UNRESERVED = new RegExp(UNRESERVED$$, "g");
var PCT_ENCODED = new RegExp(PCT_ENCODED$, "g");
var NOT_LOCAL_PART = new RegExp(merge("[^]", ATEXT$$, "[\\.]", "[\\\"]", VCHAR$$), "g");
var NOT_HFNAME = new RegExp(merge("[^]", UNRESERVED$$, SOME_DELIMS$$), "g");
var NOT_HFVALUE = NOT_HFNAME;
function decodeUnreserved(str) {
var decStr = pctDecChars(str);
return !decStr.match(UNRESERVED) ? str : decStr;
}
var handler$4 = {
scheme: "mailto",
parse: function parse$$1(components, options) {
var mailtoComponents = components;
var to = mailtoComponents.to = mailtoComponents.path ? mailtoComponents.path.split(",") : [];
mailtoComponents.path = void 0;
if (mailtoComponents.query) {
var unknownHeaders = false;
var headers = {};
var hfields = mailtoComponents.query.split("&");
for (var x = 0, xl = hfields.length; x < xl; ++x) {
var hfield = hfields[x].split("=");
switch (hfield[0]) {
case "to":
var toAddrs = hfield[1].split(",");
for (var _x = 0, _xl = toAddrs.length; _x < _xl; ++_x) to.push(toAddrs[_x]);
break;
case "subject":
mailtoComponents.subject = unescapeComponent(hfield[1], options);
break;
case "body":
mailtoComponents.body = unescapeComponent(hfield[1], options);
break;
default:
unknownHeaders = true;
headers[unescapeComponent(hfield[0], options)] = unescapeComponent(hfield[1], options);
break;
}
}
if (unknownHeaders) mailtoComponents.headers = headers;
}
mailtoComponents.query = void 0;
for (var _x2 = 0, _xl2 = to.length; _x2 < _xl2; ++_x2) {
var addr = to[_x2].split("@");
addr[0] = unescapeComponent(addr[0]);
if (!options.unicodeSupport) try {
addr[1] = punycode.toASCII(unescapeComponent(addr[1], options).toLowerCase());
} catch (e) {
mailtoComponents.error = mailtoComponents.error || "Email address's domain name can not be converted to ASCII via punycode: " + e;
}
else addr[1] = unescapeComponent(addr[1], options).toLowerCase();
to[_x2] = addr.join("@");
}
return mailtoComponents;
},
serialize: function serialize$$1(mailtoComponents, options) {
var components = mailtoComponents;
var to = toArray$1(mailtoComponents.to);
if (to) {
for (var x = 0, xl = to.length; x < xl; ++x) {
var toAddr = String(to[x]);
var atIdx = toAddr.lastIndexOf("@");
var localPart = toAddr.slice(0, atIdx).replace(PCT_ENCODED, decodeUnreserved).replace(PCT_ENCODED, toUpperCase).replace(NOT_LOCAL_PART, pctEncChar);
var domain = toAddr.slice(atIdx + 1);
try {
domain