index.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. module.exports = (function() {
  2. var __MODS__ = {};
  3. var __DEFINE__ = function(modId, func, req) { var m = { exports: {}, _tempexports: {} }; __MODS__[modId] = { status: 0, func: func, req: req, m: m }; };
  4. var __REQUIRE__ = function(modId, source) { if(!__MODS__[modId]) return require(source); if(!__MODS__[modId].status) { var m = __MODS__[modId].m; m._exports = m._tempexports; var desp = Object.getOwnPropertyDescriptor(m, "exports"); if (desp && desp.configurable) Object.defineProperty(m, "exports", { set: function (val) { if(typeof val === "object" && val !== m._exports) { m._exports.__proto__ = val.__proto__; Object.keys(val).forEach(function (k) { m._exports[k] = val[k]; }); } m._tempexports = val }, get: function () { return m._tempexports; } }); __MODS__[modId].status = 1; __MODS__[modId].func(__MODS__[modId].req, m, m.exports); } return __MODS__[modId].m.exports; };
  5. var __REQUIRE_WILDCARD__ = function(obj) { if(obj && obj.__esModule) { return obj; } else { var newObj = {}; if(obj != null) { for(var k in obj) { if (Object.prototype.hasOwnProperty.call(obj, k)) newObj[k] = obj[k]; } } newObj.default = obj; return newObj; } };
  6. var __REQUIRE_DEFAULT__ = function(obj) { return obj && obj.__esModule ? obj.default : obj; };
  7. __DEFINE__(1609944441876, function(require, module, exports) {
  8. /** Highest positive signed 32-bit float value */
  9. const maxInt = 2147483647; // aka. 0x7FFFFFFF or 2^31-1
  10. /** Bootstring parameters */
  11. const base = 36;
  12. const tMin = 1;
  13. const tMax = 26;
  14. const skew = 38;
  15. const damp = 700;
  16. const initialBias = 72;
  17. const initialN = 128; // 0x80
  18. const delimiter = '-'; // '\x2D'
  19. /** Regular expressions */
  20. const regexPunycode = /^xn--/;
  21. const regexNonASCII = /[^\0-\x7E]/; // non-ASCII chars
  22. const regexSeparators = /[\x2E\u3002\uFF0E\uFF61]/g; // RFC 3490 separators
  23. /** Error messages */
  24. const errors = {
  25. 'overflow': 'Overflow: input needs wider integers to process',
  26. 'not-basic': 'Illegal input >= 0x80 (not a basic code point)',
  27. 'invalid-input': 'Invalid input'
  28. };
  29. /** Convenience shortcuts */
  30. const baseMinusTMin = base - tMin;
  31. const floor = Math.floor;
  32. const stringFromCharCode = String.fromCharCode;
  33. /*--------------------------------------------------------------------------*/
  34. /**
  35. * A generic error utility function.
  36. * @private
  37. * @param {String} type The error type.
  38. * @returns {Error} Throws a `RangeError` with the applicable error message.
  39. */
  40. function error(type) {
  41. throw new RangeError(errors[type]);
  42. }
  43. /**
  44. * A generic `Array#map` utility function.
  45. * @private
  46. * @param {Array} array The array to iterate over.
  47. * @param {Function} callback The function that gets called for every array
  48. * item.
  49. * @returns {Array} A new array of values returned by the callback function.
  50. */
  51. function map(array, fn) {
  52. const result = [];
  53. let length = array.length;
  54. while (length--) {
  55. result[length] = fn(array[length]);
  56. }
  57. return result;
  58. }
  59. /**
  60. * A simple `Array#map`-like wrapper to work with domain name strings or email
  61. * addresses.
  62. * @private
  63. * @param {String} domain The domain name or email address.
  64. * @param {Function} callback The function that gets called for every
  65. * character.
  66. * @returns {Array} A new string of characters returned by the callback
  67. * function.
  68. */
  69. function mapDomain(string, fn) {
  70. const parts = string.split('@');
  71. let result = '';
  72. if (parts.length > 1) {
  73. // In email addresses, only the domain name should be punycoded. Leave
  74. // the local part (i.e. everything up to `@`) intact.
  75. result = parts[0] + '@';
  76. string = parts[1];
  77. }
  78. // Avoid `split(regex)` for IE8 compatibility. See #17.
  79. string = string.replace(regexSeparators, '\x2E');
  80. const labels = string.split('.');
  81. const encoded = map(labels, fn).join('.');
  82. return result + encoded;
  83. }
  84. /**
  85. * Creates an array containing the numeric code points of each Unicode
  86. * character in the string. While JavaScript uses UCS-2 internally,
  87. * this function will convert a pair of surrogate halves (each of which
  88. * UCS-2 exposes as separate characters) into a single code point,
  89. * matching UTF-16.
  90. * @see `punycode.ucs2.encode`
  91. * @see <https://mathiasbynens.be/notes/javascript-encoding>
  92. * @memberOf punycode.ucs2
  93. * @name decode
  94. * @param {String} string The Unicode input string (UCS-2).
  95. * @returns {Array} The new array of code points.
  96. */
  97. function ucs2decode(string) {
  98. const output = [];
  99. let counter = 0;
  100. const length = string.length;
  101. while (counter < length) {
  102. const value = string.charCodeAt(counter++);
  103. if (value >= 0xD800 && value <= 0xDBFF && counter < length) {
  104. // It's a high surrogate, and there is a next character.
  105. const extra = string.charCodeAt(counter++);
  106. if ((extra & 0xFC00) == 0xDC00) { // Low surrogate.
  107. output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000);
  108. } else {
  109. // It's an unmatched surrogate; only append this code unit, in case the
  110. // next code unit is the high surrogate of a surrogate pair.
  111. output.push(value);
  112. counter--;
  113. }
  114. } else {
  115. output.push(value);
  116. }
  117. }
  118. return output;
  119. }
  120. /**
  121. * Creates a string based on an array of numeric code points.
  122. * @see `punycode.ucs2.decode`
  123. * @memberOf punycode.ucs2
  124. * @name encode
  125. * @param {Array} codePoints The array of numeric code points.
  126. * @returns {String} The new Unicode string (UCS-2).
  127. */
  128. const ucs2encode = array => String.fromCodePoint(...array);
  129. /**
  130. * Converts a basic code point into a digit/integer.
  131. * @see `digitToBasic()`
  132. * @private
  133. * @param {Number} codePoint The basic numeric code point value.
  134. * @returns {Number} The numeric value of a basic code point (for use in
  135. * representing integers) in the range `0` to `base - 1`, or `base` if
  136. * the code point does not represent a value.
  137. */
  138. const basicToDigit = function(codePoint) {
  139. if (codePoint - 0x30 < 0x0A) {
  140. return codePoint - 0x16;
  141. }
  142. if (codePoint - 0x41 < 0x1A) {
  143. return codePoint - 0x41;
  144. }
  145. if (codePoint - 0x61 < 0x1A) {
  146. return codePoint - 0x61;
  147. }
  148. return base;
  149. };
  150. /**
  151. * Converts a digit/integer into a basic code point.
  152. * @see `basicToDigit()`
  153. * @private
  154. * @param {Number} digit The numeric value of a basic code point.
  155. * @returns {Number} The basic code point whose value (when used for
  156. * representing integers) is `digit`, which needs to be in the range
  157. * `0` to `base - 1`. If `flag` is non-zero, the uppercase form is
  158. * used; else, the lowercase form is used. The behavior is undefined
  159. * if `flag` is non-zero and `digit` has no uppercase form.
  160. */
  161. const digitToBasic = function(digit, flag) {
  162. // 0..25 map to ASCII a..z or A..Z
  163. // 26..35 map to ASCII 0..9
  164. return digit + 22 + 75 * (digit < 26) - ((flag != 0) << 5);
  165. };
  166. /**
  167. * Bias adaptation function as per section 3.4 of RFC 3492.
  168. * https://tools.ietf.org/html/rfc3492#section-3.4
  169. * @private
  170. */
  171. const adapt = function(delta, numPoints, firstTime) {
  172. let k = 0;
  173. delta = firstTime ? floor(delta / damp) : delta >> 1;
  174. delta += floor(delta / numPoints);
  175. for (/* no initialization */; delta > baseMinusTMin * tMax >> 1; k += base) {
  176. delta = floor(delta / baseMinusTMin);
  177. }
  178. return floor(k + (baseMinusTMin + 1) * delta / (delta + skew));
  179. };
  180. /**
  181. * Converts a Punycode string of ASCII-only symbols to a string of Unicode
  182. * symbols.
  183. * @memberOf punycode
  184. * @param {String} input The Punycode string of ASCII-only symbols.
  185. * @returns {String} The resulting string of Unicode symbols.
  186. */
  187. const decode = function(input) {
  188. // Don't use UCS-2.
  189. const output = [];
  190. const inputLength = input.length;
  191. let i = 0;
  192. let n = initialN;
  193. let bias = initialBias;
  194. // Handle the basic code points: let `basic` be the number of input code
  195. // points before the last delimiter, or `0` if there is none, then copy
  196. // the first basic code points to the output.
  197. let basic = input.lastIndexOf(delimiter);
  198. if (basic < 0) {
  199. basic = 0;
  200. }
  201. for (let j = 0; j < basic; ++j) {
  202. // if it's not a basic code point
  203. if (input.charCodeAt(j) >= 0x80) {
  204. error('not-basic');
  205. }
  206. output.push(input.charCodeAt(j));
  207. }
  208. // Main decoding loop: start just after the last delimiter if any basic code
  209. // points were copied; start at the beginning otherwise.
  210. for (let index = basic > 0 ? basic + 1 : 0; index < inputLength; /* no final expression */) {
  211. // `index` is the index of the next character to be consumed.
  212. // Decode a generalized variable-length integer into `delta`,
  213. // which gets added to `i`. The overflow checking is easier
  214. // if we increase `i` as we go, then subtract off its starting
  215. // value at the end to obtain `delta`.
  216. let oldi = i;
  217. for (let w = 1, k = base; /* no condition */; k += base) {
  218. if (index >= inputLength) {
  219. error('invalid-input');
  220. }
  221. const digit = basicToDigit(input.charCodeAt(index++));
  222. if (digit >= base || digit > floor((maxInt - i) / w)) {
  223. error('overflow');
  224. }
  225. i += digit * w;
  226. const t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
  227. if (digit < t) {
  228. break;
  229. }
  230. const baseMinusT = base - t;
  231. if (w > floor(maxInt / baseMinusT)) {
  232. error('overflow');
  233. }
  234. w *= baseMinusT;
  235. }
  236. const out = output.length + 1;
  237. bias = adapt(i - oldi, out, oldi == 0);
  238. // `i` was supposed to wrap around from `out` to `0`,
  239. // incrementing `n` each time, so we'll fix that now:
  240. if (floor(i / out) > maxInt - n) {
  241. error('overflow');
  242. }
  243. n += floor(i / out);
  244. i %= out;
  245. // Insert `n` at position `i` of the output.
  246. output.splice(i++, 0, n);
  247. }
  248. return String.fromCodePoint(...output);
  249. };
  250. /**
  251. * Converts a string of Unicode symbols (e.g. a domain name label) to a
  252. * Punycode string of ASCII-only symbols.
  253. * @memberOf punycode
  254. * @param {String} input The string of Unicode symbols.
  255. * @returns {String} The resulting Punycode string of ASCII-only symbols.
  256. */
  257. const encode = function(input) {
  258. const output = [];
  259. // Convert the input in UCS-2 to an array of Unicode code points.
  260. input = ucs2decode(input);
  261. // Cache the length.
  262. let inputLength = input.length;
  263. // Initialize the state.
  264. let n = initialN;
  265. let delta = 0;
  266. let bias = initialBias;
  267. // Handle the basic code points.
  268. for (const currentValue of input) {
  269. if (currentValue < 0x80) {
  270. output.push(stringFromCharCode(currentValue));
  271. }
  272. }
  273. let basicLength = output.length;
  274. let handledCPCount = basicLength;
  275. // `handledCPCount` is the number of code points that have been handled;
  276. // `basicLength` is the number of basic code points.
  277. // Finish the basic string with a delimiter unless it's empty.
  278. if (basicLength) {
  279. output.push(delimiter);
  280. }
  281. // Main encoding loop:
  282. while (handledCPCount < inputLength) {
  283. // All non-basic code points < n have been handled already. Find the next
  284. // larger one:
  285. let m = maxInt;
  286. for (const currentValue of input) {
  287. if (currentValue >= n && currentValue < m) {
  288. m = currentValue;
  289. }
  290. }
  291. // Increase `delta` enough to advance the decoder's <n,i> state to <m,0>,
  292. // but guard against overflow.
  293. const handledCPCountPlusOne = handledCPCount + 1;
  294. if (m - n > floor((maxInt - delta) / handledCPCountPlusOne)) {
  295. error('overflow');
  296. }
  297. delta += (m - n) * handledCPCountPlusOne;
  298. n = m;
  299. for (const currentValue of input) {
  300. if (currentValue < n && ++delta > maxInt) {
  301. error('overflow');
  302. }
  303. if (currentValue == n) {
  304. // Represent delta as a generalized variable-length integer.
  305. let q = delta;
  306. for (let k = base; /* no condition */; k += base) {
  307. const t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
  308. if (q < t) {
  309. break;
  310. }
  311. const qMinusT = q - t;
  312. const baseMinusT = base - t;
  313. output.push(
  314. stringFromCharCode(digitToBasic(t + qMinusT % baseMinusT, 0))
  315. );
  316. q = floor(qMinusT / baseMinusT);
  317. }
  318. output.push(stringFromCharCode(digitToBasic(q, 0)));
  319. bias = adapt(delta, handledCPCountPlusOne, handledCPCount == basicLength);
  320. delta = 0;
  321. ++handledCPCount;
  322. }
  323. }
  324. ++delta;
  325. ++n;
  326. }
  327. return output.join('');
  328. };
  329. /**
  330. * Converts a Punycode string representing a domain name or an email address
  331. * to Unicode. Only the Punycoded parts of the input will be converted, i.e.
  332. * it doesn't matter if you call it on a string that has already been
  333. * converted to Unicode.
  334. * @memberOf punycode
  335. * @param {String} input The Punycoded domain name or email address to
  336. * convert to Unicode.
  337. * @returns {String} The Unicode representation of the given Punycode
  338. * string.
  339. */
  340. const toUnicode = function(input) {
  341. return mapDomain(input, function(string) {
  342. return regexPunycode.test(string)
  343. ? decode(string.slice(4).toLowerCase())
  344. : string;
  345. });
  346. };
  347. /**
  348. * Converts a Unicode string representing a domain name or an email address to
  349. * Punycode. Only the non-ASCII parts of the domain name will be converted,
  350. * i.e. it doesn't matter if you call it with a domain that's already in
  351. * ASCII.
  352. * @memberOf punycode
  353. * @param {String} input The domain name or email address to convert, as a
  354. * Unicode string.
  355. * @returns {String} The Punycode representation of the given domain name or
  356. * email address.
  357. */
  358. const toASCII = function(input) {
  359. return mapDomain(input, function(string) {
  360. return regexNonASCII.test(string)
  361. ? 'xn--' + encode(string)
  362. : string;
  363. });
  364. };
  365. /*--------------------------------------------------------------------------*/
  366. /** Define the public API */
  367. const punycode = {
  368. /**
  369. * A string representing the current Punycode.js version number.
  370. * @memberOf punycode
  371. * @type String
  372. */
  373. 'version': '2.1.0',
  374. /**
  375. * An object of methods to convert from JavaScript's internal character
  376. * representation (UCS-2) to Unicode code points, and back.
  377. * @see <https://mathiasbynens.be/notes/javascript-encoding>
  378. * @memberOf punycode
  379. * @type Object
  380. */
  381. 'ucs2': {
  382. 'decode': ucs2decode,
  383. 'encode': ucs2encode
  384. },
  385. 'decode': decode,
  386. 'encode': encode,
  387. 'toASCII': toASCII,
  388. 'toUnicode': toUnicode
  389. };
  390. module.exports = punycode;
  391. }, function(modId) {var map = {}; return __REQUIRE__(map[modId], modId); })
  392. return __REQUIRE__(1609944441876);
  393. })()
  394. //# sourceMappingURL=index.js.map