index.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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__(1682324647586, function(require, module, exports) {
  8. // Copyright Joyent, Inc. and other Node contributors.
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining a
  11. // copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to permit
  15. // persons to whom the Software is furnished to do so, subject to the
  16. // following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be included
  19. // in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  22. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  24. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  25. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  26. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  27. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. /*<replacement>*/
  29. var Buffer = require('safe-buffer').Buffer;
  30. /*</replacement>*/
  31. var isEncoding = Buffer.isEncoding || function (encoding) {
  32. encoding = '' + encoding;
  33. switch (encoding && encoding.toLowerCase()) {
  34. case 'hex':case 'utf8':case 'utf-8':case 'ascii':case 'binary':case 'base64':case 'ucs2':case 'ucs-2':case 'utf16le':case 'utf-16le':case 'raw':
  35. return true;
  36. default:
  37. return false;
  38. }
  39. };
  40. function _normalizeEncoding(enc) {
  41. if (!enc) return 'utf8';
  42. var retried;
  43. while (true) {
  44. switch (enc) {
  45. case 'utf8':
  46. case 'utf-8':
  47. return 'utf8';
  48. case 'ucs2':
  49. case 'ucs-2':
  50. case 'utf16le':
  51. case 'utf-16le':
  52. return 'utf16le';
  53. case 'latin1':
  54. case 'binary':
  55. return 'latin1';
  56. case 'base64':
  57. case 'ascii':
  58. case 'hex':
  59. return enc;
  60. default:
  61. if (retried) return; // undefined
  62. enc = ('' + enc).toLowerCase();
  63. retried = true;
  64. }
  65. }
  66. };
  67. // Do not cache `Buffer.isEncoding` when checking encoding names as some
  68. // modules monkey-patch it to support additional encodings
  69. function normalizeEncoding(enc) {
  70. var nenc = _normalizeEncoding(enc);
  71. if (typeof nenc !== 'string' && (Buffer.isEncoding === isEncoding || !isEncoding(enc))) throw new Error('Unknown encoding: ' + enc);
  72. return nenc || enc;
  73. }
  74. // StringDecoder provides an interface for efficiently splitting a series of
  75. // buffers into a series of JS strings without breaking apart multi-byte
  76. // characters.
  77. exports.StringDecoder = StringDecoder;
  78. function StringDecoder(encoding) {
  79. this.encoding = normalizeEncoding(encoding);
  80. var nb;
  81. switch (this.encoding) {
  82. case 'utf16le':
  83. this.text = utf16Text;
  84. this.end = utf16End;
  85. nb = 4;
  86. break;
  87. case 'utf8':
  88. this.fillLast = utf8FillLast;
  89. nb = 4;
  90. break;
  91. case 'base64':
  92. this.text = base64Text;
  93. this.end = base64End;
  94. nb = 3;
  95. break;
  96. default:
  97. this.write = simpleWrite;
  98. this.end = simpleEnd;
  99. return;
  100. }
  101. this.lastNeed = 0;
  102. this.lastTotal = 0;
  103. this.lastChar = Buffer.allocUnsafe(nb);
  104. }
  105. StringDecoder.prototype.write = function (buf) {
  106. if (buf.length === 0) return '';
  107. var r;
  108. var i;
  109. if (this.lastNeed) {
  110. r = this.fillLast(buf);
  111. if (r === undefined) return '';
  112. i = this.lastNeed;
  113. this.lastNeed = 0;
  114. } else {
  115. i = 0;
  116. }
  117. if (i < buf.length) return r ? r + this.text(buf, i) : this.text(buf, i);
  118. return r || '';
  119. };
  120. StringDecoder.prototype.end = utf8End;
  121. // Returns only complete characters in a Buffer
  122. StringDecoder.prototype.text = utf8Text;
  123. // Attempts to complete a partial non-UTF-8 character using bytes from a Buffer
  124. StringDecoder.prototype.fillLast = function (buf) {
  125. if (this.lastNeed <= buf.length) {
  126. buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, this.lastNeed);
  127. return this.lastChar.toString(this.encoding, 0, this.lastTotal);
  128. }
  129. buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, buf.length);
  130. this.lastNeed -= buf.length;
  131. };
  132. // Checks the type of a UTF-8 byte, whether it's ASCII, a leading byte, or a
  133. // continuation byte. If an invalid byte is detected, -2 is returned.
  134. function utf8CheckByte(byte) {
  135. if (byte <= 0x7F) return 0;else if (byte >> 5 === 0x06) return 2;else if (byte >> 4 === 0x0E) return 3;else if (byte >> 3 === 0x1E) return 4;
  136. return byte >> 6 === 0x02 ? -1 : -2;
  137. }
  138. // Checks at most 3 bytes at the end of a Buffer in order to detect an
  139. // incomplete multi-byte UTF-8 character. The total number of bytes (2, 3, or 4)
  140. // needed to complete the UTF-8 character (if applicable) are returned.
  141. function utf8CheckIncomplete(self, buf, i) {
  142. var j = buf.length - 1;
  143. if (j < i) return 0;
  144. var nb = utf8CheckByte(buf[j]);
  145. if (nb >= 0) {
  146. if (nb > 0) self.lastNeed = nb - 1;
  147. return nb;
  148. }
  149. if (--j < i || nb === -2) return 0;
  150. nb = utf8CheckByte(buf[j]);
  151. if (nb >= 0) {
  152. if (nb > 0) self.lastNeed = nb - 2;
  153. return nb;
  154. }
  155. if (--j < i || nb === -2) return 0;
  156. nb = utf8CheckByte(buf[j]);
  157. if (nb >= 0) {
  158. if (nb > 0) {
  159. if (nb === 2) nb = 0;else self.lastNeed = nb - 3;
  160. }
  161. return nb;
  162. }
  163. return 0;
  164. }
  165. // Validates as many continuation bytes for a multi-byte UTF-8 character as
  166. // needed or are available. If we see a non-continuation byte where we expect
  167. // one, we "replace" the validated continuation bytes we've seen so far with
  168. // a single UTF-8 replacement character ('\ufffd'), to match v8's UTF-8 decoding
  169. // behavior. The continuation byte check is included three times in the case
  170. // where all of the continuation bytes for a character exist in the same buffer.
  171. // It is also done this way as a slight performance increase instead of using a
  172. // loop.
  173. function utf8CheckExtraBytes(self, buf, p) {
  174. if ((buf[0] & 0xC0) !== 0x80) {
  175. self.lastNeed = 0;
  176. return '\ufffd';
  177. }
  178. if (self.lastNeed > 1 && buf.length > 1) {
  179. if ((buf[1] & 0xC0) !== 0x80) {
  180. self.lastNeed = 1;
  181. return '\ufffd';
  182. }
  183. if (self.lastNeed > 2 && buf.length > 2) {
  184. if ((buf[2] & 0xC0) !== 0x80) {
  185. self.lastNeed = 2;
  186. return '\ufffd';
  187. }
  188. }
  189. }
  190. }
  191. // Attempts to complete a multi-byte UTF-8 character using bytes from a Buffer.
  192. function utf8FillLast(buf) {
  193. var p = this.lastTotal - this.lastNeed;
  194. var r = utf8CheckExtraBytes(this, buf, p);
  195. if (r !== undefined) return r;
  196. if (this.lastNeed <= buf.length) {
  197. buf.copy(this.lastChar, p, 0, this.lastNeed);
  198. return this.lastChar.toString(this.encoding, 0, this.lastTotal);
  199. }
  200. buf.copy(this.lastChar, p, 0, buf.length);
  201. this.lastNeed -= buf.length;
  202. }
  203. // Returns all complete UTF-8 characters in a Buffer. If the Buffer ended on a
  204. // partial character, the character's bytes are buffered until the required
  205. // number of bytes are available.
  206. function utf8Text(buf, i) {
  207. var total = utf8CheckIncomplete(this, buf, i);
  208. if (!this.lastNeed) return buf.toString('utf8', i);
  209. this.lastTotal = total;
  210. var end = buf.length - (total - this.lastNeed);
  211. buf.copy(this.lastChar, 0, end);
  212. return buf.toString('utf8', i, end);
  213. }
  214. // For UTF-8, a replacement character is added when ending on a partial
  215. // character.
  216. function utf8End(buf) {
  217. var r = buf && buf.length ? this.write(buf) : '';
  218. if (this.lastNeed) return r + '\ufffd';
  219. return r;
  220. }
  221. // UTF-16LE typically needs two bytes per character, but even if we have an even
  222. // number of bytes available, we need to check if we end on a leading/high
  223. // surrogate. In that case, we need to wait for the next two bytes in order to
  224. // decode the last character properly.
  225. function utf16Text(buf, i) {
  226. if ((buf.length - i) % 2 === 0) {
  227. var r = buf.toString('utf16le', i);
  228. if (r) {
  229. var c = r.charCodeAt(r.length - 1);
  230. if (c >= 0xD800 && c <= 0xDBFF) {
  231. this.lastNeed = 2;
  232. this.lastTotal = 4;
  233. this.lastChar[0] = buf[buf.length - 2];
  234. this.lastChar[1] = buf[buf.length - 1];
  235. return r.slice(0, -1);
  236. }
  237. }
  238. return r;
  239. }
  240. this.lastNeed = 1;
  241. this.lastTotal = 2;
  242. this.lastChar[0] = buf[buf.length - 1];
  243. return buf.toString('utf16le', i, buf.length - 1);
  244. }
  245. // For UTF-16LE we do not explicitly append special replacement characters if we
  246. // end on a partial character, we simply let v8 handle that.
  247. function utf16End(buf) {
  248. var r = buf && buf.length ? this.write(buf) : '';
  249. if (this.lastNeed) {
  250. var end = this.lastTotal - this.lastNeed;
  251. return r + this.lastChar.toString('utf16le', 0, end);
  252. }
  253. return r;
  254. }
  255. function base64Text(buf, i) {
  256. var n = (buf.length - i) % 3;
  257. if (n === 0) return buf.toString('base64', i);
  258. this.lastNeed = 3 - n;
  259. this.lastTotal = 3;
  260. if (n === 1) {
  261. this.lastChar[0] = buf[buf.length - 1];
  262. } else {
  263. this.lastChar[0] = buf[buf.length - 2];
  264. this.lastChar[1] = buf[buf.length - 1];
  265. }
  266. return buf.toString('base64', i, buf.length - n);
  267. }
  268. function base64End(buf) {
  269. var r = buf && buf.length ? this.write(buf) : '';
  270. if (this.lastNeed) return r + this.lastChar.toString('base64', 0, 3 - this.lastNeed);
  271. return r;
  272. }
  273. // Pass bytes on through for single-byte encodings (e.g. ascii, latin1, hex)
  274. function simpleWrite(buf) {
  275. return buf.toString(this.encoding);
  276. }
  277. function simpleEnd(buf) {
  278. return buf && buf.length ? this.write(buf) : '';
  279. }
  280. }, function(modId) {var map = {}; return __REQUIRE__(map[modId], modId); })
  281. return __REQUIRE__(1682324647586);
  282. })()
  283. //miniprogram-npm-outsideDeps=["safe-buffer"]
  284. //# sourceMappingURL=index.js.map