/*! https://mths.be/punycode v1.3.2 by @mathias */1;(function(root) {23/** Detect free variables */4var freeExports = typeof exports == 'object' && exports &&5!exports.nodeType && exports;6var freeModule = typeof module == 'object' && module &&7!module.nodeType && module;8var freeGlobal = typeof global == 'object' && global;9if (10freeGlobal.global === freeGlobal ||11freeGlobal.window === freeGlobal ||12freeGlobal.self === freeGlobal13) {14root = freeGlobal;15}1617/**18* The `punycode` object.19* @name punycode20* @type Object21*/22var punycode,2324/** Highest positive signed 32-bit float value */25maxInt = 2147483647, // aka. 0x7FFFFFFF or 2^31-12627/** Bootstring parameters */28base = 36,29tMin = 1,30tMax = 26,31skew = 38,32damp = 700,33initialBias = 72,34initialN = 128, // 0x8035delimiter = '-', // '\x2D'3637/** Regular expressions */38regexPunycode = /^xn--/,39regexNonASCII = /[^\x20-\x7E]/, // unprintable ASCII chars + non-ASCII chars40regexSeparators = /[\x2E\u3002\uFF0E\uFF61]/g, // RFC 3490 separators4142/** Error messages */43errors = {44'overflow': 'Overflow: input needs wider integers to process',45'not-basic': 'Illegal input >= 0x80 (not a basic code point)',46'invalid-input': 'Invalid input'47},4849/** Convenience shortcuts */50baseMinusTMin = base - tMin,51floor = Math.floor,52stringFromCharCode = String.fromCharCode,5354/** Temporary variable */55key;5657/*--------------------------------------------------------------------------*/5859/**60* A generic error utility function.61* @private62* @param {String} type The error type.63* @returns {Error} Throws a `RangeError` with the applicable error message.64*/65function error(type) {66throw RangeError(errors[type]);67}6869/**70* A generic `Array#map` utility function.71* @private72* @param {Array} array The array to iterate over.73* @param {Function} callback The function that gets called for every array74* item.75* @returns {Array} A new array of values returned by the callback function.76*/77function map(array, fn) {78var length = array.length;79var result = [];80while (length--) {81result[length] = fn(array[length]);82}83return result;84}8586/**87* A simple `Array#map`-like wrapper to work with domain name strings or email88* addresses.89* @private90* @param {String} domain The domain name or email address.91* @param {Function} callback The function that gets called for every92* character.93* @returns {Array} A new string of characters returned by the callback94* function.95*/96function mapDomain(string, fn) {97var parts = string.split('@');98var result = '';99if (parts.length > 1) {100// In email addresses, only the domain name should be punycoded. Leave101// the local part (i.e. everything up to `@`) intact.102result = parts[0] + '@';103string = parts[1];104}105// Avoid `split(regex)` for IE8 compatibility. See #17.106string = string.replace(regexSeparators, '\x2E');107var labels = string.split('.');108var encoded = map(labels, fn).join('.');109return result + encoded;110}111112/**113* Creates an array containing the numeric code points of each Unicode114* character in the string. While JavaScript uses UCS-2 internally,115* this function will convert a pair of surrogate halves (each of which116* UCS-2 exposes as separate characters) into a single code point,117* matching UTF-16.118* @see `punycode.ucs2.encode`119* @see <https://mathiasbynens.be/notes/javascript-encoding>120* @memberOf punycode.ucs2121* @name decode122* @param {String} string The Unicode input string (UCS-2).123* @returns {Array} The new array of code points.124*/125function ucs2decode(string) {126var output = [],127counter = 0,128length = string.length,129value,130extra;131while (counter < length) {132value = string.charCodeAt(counter++);133if (value >= 0xD800 && value <= 0xDBFF && counter < length) {134// high surrogate, and there is a next character135extra = string.charCodeAt(counter++);136if ((extra & 0xFC00) == 0xDC00) { // low surrogate137output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000);138} else {139// unmatched surrogate; only append this code unit, in case the next140// code unit is the high surrogate of a surrogate pair141output.push(value);142counter--;143}144} else {145output.push(value);146}147}148return output;149}150151/**152* Creates a string based on an array of numeric code points.153* @see `punycode.ucs2.decode`154* @memberOf punycode.ucs2155* @name encode156* @param {Array} codePoints The array of numeric code points.157* @returns {String} The new Unicode string (UCS-2).158*/159function ucs2encode(array) {160return map(array, function(value) {161var output = '';162if (value > 0xFFFF) {163value -= 0x10000;164output += stringFromCharCode(value >>> 10 & 0x3FF | 0xD800);165value = 0xDC00 | value & 0x3FF;166}167output += stringFromCharCode(value);168return output;169}).join('');170}171172/**173* Converts a basic code point into a digit/integer.174* @see `digitToBasic()`175* @private176* @param {Number} codePoint The basic numeric code point value.177* @returns {Number} The numeric value of a basic code point (for use in178* representing integers) in the range `0` to `base - 1`, or `base` if179* the code point does not represent a value.180*/181function basicToDigit(codePoint) {182if (codePoint - 48 < 10) {183return codePoint - 22;184}185if (codePoint - 65 < 26) {186return codePoint - 65;187}188if (codePoint - 97 < 26) {189return codePoint - 97;190}191return base;192}193194/**195* Converts a digit/integer into a basic code point.196* @see `basicToDigit()`197* @private198* @param {Number} digit The numeric value of a basic code point.199* @returns {Number} The basic code point whose value (when used for200* representing integers) is `digit`, which needs to be in the range201* `0` to `base - 1`. If `flag` is non-zero, the uppercase form is202* used; else, the lowercase form is used. The behavior is undefined203* if `flag` is non-zero and `digit` has no uppercase form.204*/205function digitToBasic(digit, flag) {206// 0..25 map to ASCII a..z or A..Z207// 26..35 map to ASCII 0..9208return digit + 22 + 75 * (digit < 26) - ((flag != 0) << 5);209}210211/**212* Bias adaptation function as per section 3.4 of RFC 3492.213* http://tools.ietf.org/html/rfc3492#section-3.4214* @private215*/216function adapt(delta, numPoints, firstTime) {217var k = 0;218delta = firstTime ? floor(delta / damp) : delta >> 1;219delta += floor(delta / numPoints);220for (/* no initialization */; delta > baseMinusTMin * tMax >> 1; k += base) {221delta = floor(delta / baseMinusTMin);222}223return floor(k + (baseMinusTMin + 1) * delta / (delta + skew));224}225226/**227* Converts a Punycode string of ASCII-only symbols to a string of Unicode228* symbols.229* @memberOf punycode230* @param {String} input The Punycode string of ASCII-only symbols.231* @returns {String} The resulting string of Unicode symbols.232*/233function decode(input) {234// Don't use UCS-2235var output = [],236inputLength = input.length,237out,238i = 0,239n = initialN,240bias = initialBias,241basic,242j,243index,244oldi,245w,246k,247digit,248t,249/** Cached calculation results */250baseMinusT;251252// Handle the basic code points: let `basic` be the number of input code253// points before the last delimiter, or `0` if there is none, then copy254// the first basic code points to the output.255256basic = input.lastIndexOf(delimiter);257if (basic < 0) {258basic = 0;259}260261for (j = 0; j < basic; ++j) {262// if it's not a basic code point263if (input.charCodeAt(j) >= 0x80) {264error('not-basic');265}266output.push(input.charCodeAt(j));267}268269// Main decoding loop: start just after the last delimiter if any basic code270// points were copied; start at the beginning otherwise.271272for (index = basic > 0 ? basic + 1 : 0; index < inputLength; /* no final expression */) {273274// `index` is the index of the next character to be consumed.275// Decode a generalized variable-length integer into `delta`,276// which gets added to `i`. The overflow checking is easier277// if we increase `i` as we go, then subtract off its starting278// value at the end to obtain `delta`.279for (oldi = i, w = 1, k = base; /* no condition */; k += base) {280281if (index >= inputLength) {282error('invalid-input');283}284285digit = basicToDigit(input.charCodeAt(index++));286287if (digit >= base || digit > floor((maxInt - i) / w)) {288error('overflow');289}290291i += digit * w;292t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);293294if (digit < t) {295break;296}297298baseMinusT = base - t;299if (w > floor(maxInt / baseMinusT)) {300error('overflow');301}302303w *= baseMinusT;304305}306307out = output.length + 1;308bias = adapt(i - oldi, out, oldi == 0);309310// `i` was supposed to wrap around from `out` to `0`,311// incrementing `n` each time, so we'll fix that now:312if (floor(i / out) > maxInt - n) {313error('overflow');314}315316n += floor(i / out);317i %= out;318319// Insert `n` at position `i` of the output320output.splice(i++, 0, n);321322}323324return ucs2encode(output);325}326327/**328* Converts a string of Unicode symbols (e.g. a domain name label) to a329* Punycode string of ASCII-only symbols.330* @memberOf punycode331* @param {String} input The string of Unicode symbols.332* @returns {String} The resulting Punycode string of ASCII-only symbols.333*/334function encode(input) {335var n,336delta,337handledCPCount,338basicLength,339bias,340j,341m,342q,343k,344t,345currentValue,346output = [],347/** `inputLength` will hold the number of code points in `input`. */348inputLength,349/** Cached calculation results */350handledCPCountPlusOne,351baseMinusT,352qMinusT;353354// Convert the input in UCS-2 to Unicode355input = ucs2decode(input);356357// Cache the length358inputLength = input.length;359360// Initialize the state361n = initialN;362delta = 0;363bias = initialBias;364365// Handle the basic code points366for (j = 0; j < inputLength; ++j) {367currentValue = input[j];368if (currentValue < 0x80) {369output.push(stringFromCharCode(currentValue));370}371}372373handledCPCount = basicLength = output.length;374375// `handledCPCount` is the number of code points that have been handled;376// `basicLength` is the number of basic code points.377378// Finish the basic string - if it is not empty - with a delimiter379if (basicLength) {380output.push(delimiter);381}382383// Main encoding loop:384while (handledCPCount < inputLength) {385386// All non-basic code points < n have been handled already. Find the next387// larger one:388for (m = maxInt, j = 0; j < inputLength; ++j) {389currentValue = input[j];390if (currentValue >= n && currentValue < m) {391m = currentValue;392}393}394395// Increase `delta` enough to advance the decoder's <n,i> state to <m,0>,396// but guard against overflow397handledCPCountPlusOne = handledCPCount + 1;398if (m - n > floor((maxInt - delta) / handledCPCountPlusOne)) {399error('overflow');400}401402delta += (m - n) * handledCPCountPlusOne;403n = m;404405for (j = 0; j < inputLength; ++j) {406currentValue = input[j];407408if (currentValue < n && ++delta > maxInt) {409error('overflow');410}411412if (currentValue == n) {413// Represent delta as a generalized variable-length integer414for (q = delta, k = base; /* no condition */; k += base) {415t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);416if (q < t) {417break;418}419qMinusT = q - t;420baseMinusT = base - t;421output.push(422stringFromCharCode(digitToBasic(t + qMinusT % baseMinusT, 0))423);424q = floor(qMinusT / baseMinusT);425}426427output.push(stringFromCharCode(digitToBasic(q, 0)));428bias = adapt(delta, handledCPCountPlusOne, handledCPCount == basicLength);429delta = 0;430++handledCPCount;431}432}433434++delta;435++n;436437}438return output.join('');439}440441/**442* Converts a Punycode string representing a domain name or an email address443* to Unicode. Only the Punycoded parts of the input will be converted, i.e.444* it doesn't matter if you call it on a string that has already been445* converted to Unicode.446* @memberOf punycode447* @param {String} input The Punycoded domain name or email address to448* convert to Unicode.449* @returns {String} The Unicode representation of the given Punycode450* string.451*/452function toUnicode(input) {453return mapDomain(input, function(string) {454return regexPunycode.test(string)455? decode(string.slice(4).toLowerCase())456: string;457});458}459460/**461* Converts a Unicode string representing a domain name or an email address to462* Punycode. Only the non-ASCII parts of the domain name will be converted,463* i.e. it doesn't matter if you call it with a domain that's already in464* ASCII.465* @memberOf punycode466* @param {String} input The domain name or email address to convert, as a467* Unicode string.468* @returns {String} The Punycode representation of the given domain name or469* email address.470*/471function toASCII(input) {472return mapDomain(input, function(string) {473return regexNonASCII.test(string)474? 'xn--' + encode(string)475: string;476});477}478479/*--------------------------------------------------------------------------*/480481/** Define the public API */482punycode = {483/**484* A string representing the current Punycode.js version number.485* @memberOf punycode486* @type String487*/488'version': '1.3.2',489/**490* An object of methods to convert from JavaScript's internal character491* representation (UCS-2) to Unicode code points, and back.492* @see <https://mathiasbynens.be/notes/javascript-encoding>493* @memberOf punycode494* @type Object495*/496'ucs2': {497'decode': ucs2decode,498'encode': ucs2encode499},500'decode': decode,501'encode': encode,502'toASCII': toASCII,503'toUnicode': toUnicode504};505506/** Expose `punycode` */507// Some AMD build optimizers, like r.js, check for specific condition patterns508// like the following:509if (510typeof define == 'function' &&511typeof define.amd == 'object' &&512define.amd513) {514define('punycode', function() {515return punycode;516});517} else if (freeExports && freeModule) {518if (module.exports == freeExports) { // in Node.js or RingoJS v0.8.0+519freeModule.exports = punycode;520} else { // in Narwhal or RingoJS v0.7.0-521for (key in punycode) {522punycode.hasOwnProperty(key) && (freeExports[key] = punycode[key]);523}524}525} else { // in Rhino or a web browser526root.punycode = punycode;527}528529}(this));530531532