superagent.js 98 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135
  1. (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.superagent = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
  2. },{}],2:[function(require,module,exports){
  3. 'use strict';
  4. var GetIntrinsic = require('get-intrinsic');
  5. var callBind = require('./');
  6. var $indexOf = callBind(GetIntrinsic('String.prototype.indexOf'));
  7. module.exports = function callBoundIntrinsic(name, allowMissing) {
  8. var intrinsic = GetIntrinsic(name, !!allowMissing);
  9. if (typeof intrinsic === 'function' && $indexOf(name, '.prototype.') > -1) {
  10. return callBind(intrinsic);
  11. }
  12. return intrinsic;
  13. };
  14. },{"./":3,"get-intrinsic":8}],3:[function(require,module,exports){
  15. 'use strict';
  16. var bind = require('function-bind');
  17. var GetIntrinsic = require('get-intrinsic');
  18. var $apply = GetIntrinsic('%Function.prototype.apply%');
  19. var $call = GetIntrinsic('%Function.prototype.call%');
  20. var $reflectApply = GetIntrinsic('%Reflect.apply%', true) || bind.call($call, $apply);
  21. var $gOPD = GetIntrinsic('%Object.getOwnPropertyDescriptor%', true);
  22. var $defineProperty = GetIntrinsic('%Object.defineProperty%', true);
  23. var $max = GetIntrinsic('%Math.max%');
  24. if ($defineProperty) {
  25. try {
  26. $defineProperty({}, 'a', {
  27. value: 1
  28. });
  29. } catch (e) {
  30. $defineProperty = null;
  31. }
  32. }
  33. module.exports = function callBind(originalFunction) {
  34. var func = $reflectApply(bind, $call, arguments);
  35. if ($gOPD && $defineProperty) {
  36. var desc = $gOPD(func, 'length');
  37. if (desc.configurable) {
  38. $defineProperty(func, 'length', {
  39. value: 1 + $max(0, originalFunction.length - (arguments.length - 1))
  40. });
  41. }
  42. }
  43. return func;
  44. };
  45. var applyBind = function applyBind() {
  46. return $reflectApply(bind, $apply, arguments);
  47. };
  48. if ($defineProperty) {
  49. $defineProperty(module.exports, 'apply', {
  50. value: applyBind
  51. });
  52. } else {
  53. module.exports.apply = applyBind;
  54. }
  55. },{"function-bind":7,"get-intrinsic":8}],4:[function(require,module,exports){
  56. if (typeof module !== 'undefined') {
  57. module.exports = Emitter;
  58. }
  59. function Emitter(obj) {
  60. if (obj) return mixin(obj);
  61. }
  62. ;
  63. function mixin(obj) {
  64. for (var key in Emitter.prototype) {
  65. obj[key] = Emitter.prototype[key];
  66. }
  67. return obj;
  68. }
  69. Emitter.prototype.on = Emitter.prototype.addEventListener = function (event, fn) {
  70. this._callbacks = this._callbacks || {};
  71. (this._callbacks['$' + event] = this._callbacks['$' + event] || []).push(fn);
  72. return this;
  73. };
  74. Emitter.prototype.once = function (event, fn) {
  75. function on() {
  76. this.off(event, on);
  77. fn.apply(this, arguments);
  78. }
  79. on.fn = fn;
  80. this.on(event, on);
  81. return this;
  82. };
  83. Emitter.prototype.off = Emitter.prototype.removeListener = Emitter.prototype.removeAllListeners = Emitter.prototype.removeEventListener = function (event, fn) {
  84. this._callbacks = this._callbacks || {};
  85. if (0 == arguments.length) {
  86. this._callbacks = {};
  87. return this;
  88. }
  89. var callbacks = this._callbacks['$' + event];
  90. if (!callbacks) return this;
  91. if (1 == arguments.length) {
  92. delete this._callbacks['$' + event];
  93. return this;
  94. }
  95. var cb;
  96. for (var i = 0; i < callbacks.length; i++) {
  97. cb = callbacks[i];
  98. if (cb === fn || cb.fn === fn) {
  99. callbacks.splice(i, 1);
  100. break;
  101. }
  102. }
  103. if (callbacks.length === 0) {
  104. delete this._callbacks['$' + event];
  105. }
  106. return this;
  107. };
  108. Emitter.prototype.emit = function (event) {
  109. this._callbacks = this._callbacks || {};
  110. var args = new Array(arguments.length - 1),
  111. callbacks = this._callbacks['$' + event];
  112. for (var i = 1; i < arguments.length; i++) {
  113. args[i - 1] = arguments[i];
  114. }
  115. if (callbacks) {
  116. callbacks = callbacks.slice(0);
  117. for (var i = 0, len = callbacks.length; i < len; ++i) {
  118. callbacks[i].apply(this, args);
  119. }
  120. }
  121. return this;
  122. };
  123. Emitter.prototype.listeners = function (event) {
  124. this._callbacks = this._callbacks || {};
  125. return this._callbacks['$' + event] || [];
  126. };
  127. Emitter.prototype.hasListeners = function (event) {
  128. return !!this.listeners(event).length;
  129. };
  130. },{}],5:[function(require,module,exports){
  131. module.exports = stringify;
  132. stringify.default = stringify;
  133. stringify.stable = deterministicStringify;
  134. stringify.stableStringify = deterministicStringify;
  135. var LIMIT_REPLACE_NODE = '[...]';
  136. var CIRCULAR_REPLACE_NODE = '[Circular]';
  137. var arr = [];
  138. var replacerStack = [];
  139. function defaultOptions() {
  140. return {
  141. depthLimit: Number.MAX_SAFE_INTEGER,
  142. edgesLimit: Number.MAX_SAFE_INTEGER
  143. };
  144. }
  145. function stringify(obj, replacer, spacer, options) {
  146. if (typeof options === 'undefined') {
  147. options = defaultOptions();
  148. }
  149. decirc(obj, '', 0, [], undefined, 0, options);
  150. var res;
  151. try {
  152. if (replacerStack.length === 0) {
  153. res = JSON.stringify(obj, replacer, spacer);
  154. } else {
  155. res = JSON.stringify(obj, replaceGetterValues(replacer), spacer);
  156. }
  157. } catch (_) {
  158. return JSON.stringify('[unable to serialize, circular reference is too complex to analyze]');
  159. } finally {
  160. while (arr.length !== 0) {
  161. var part = arr.pop();
  162. if (part.length === 4) {
  163. Object.defineProperty(part[0], part[1], part[3]);
  164. } else {
  165. part[0][part[1]] = part[2];
  166. }
  167. }
  168. }
  169. return res;
  170. }
  171. function setReplace(replace, val, k, parent) {
  172. var propertyDescriptor = Object.getOwnPropertyDescriptor(parent, k);
  173. if (propertyDescriptor.get !== undefined) {
  174. if (propertyDescriptor.configurable) {
  175. Object.defineProperty(parent, k, {
  176. value: replace
  177. });
  178. arr.push([parent, k, val, propertyDescriptor]);
  179. } else {
  180. replacerStack.push([val, k, replace]);
  181. }
  182. } else {
  183. parent[k] = replace;
  184. arr.push([parent, k, val]);
  185. }
  186. }
  187. function decirc(val, k, edgeIndex, stack, parent, depth, options) {
  188. depth += 1;
  189. var i;
  190. if (typeof val === 'object' && val !== null) {
  191. for (i = 0; i < stack.length; i++) {
  192. if (stack[i] === val) {
  193. setReplace(CIRCULAR_REPLACE_NODE, val, k, parent);
  194. return;
  195. }
  196. }
  197. if (typeof options.depthLimit !== 'undefined' && depth > options.depthLimit) {
  198. setReplace(LIMIT_REPLACE_NODE, val, k, parent);
  199. return;
  200. }
  201. if (typeof options.edgesLimit !== 'undefined' && edgeIndex + 1 > options.edgesLimit) {
  202. setReplace(LIMIT_REPLACE_NODE, val, k, parent);
  203. return;
  204. }
  205. stack.push(val);
  206. if (Array.isArray(val)) {
  207. for (i = 0; i < val.length; i++) {
  208. decirc(val[i], i, i, stack, val, depth, options);
  209. }
  210. } else {
  211. var keys = Object.keys(val);
  212. for (i = 0; i < keys.length; i++) {
  213. var key = keys[i];
  214. decirc(val[key], key, i, stack, val, depth, options);
  215. }
  216. }
  217. stack.pop();
  218. }
  219. }
  220. function compareFunction(a, b) {
  221. if (a < b) {
  222. return -1;
  223. }
  224. if (a > b) {
  225. return 1;
  226. }
  227. return 0;
  228. }
  229. function deterministicStringify(obj, replacer, spacer, options) {
  230. if (typeof options === 'undefined') {
  231. options = defaultOptions();
  232. }
  233. var tmp = deterministicDecirc(obj, '', 0, [], undefined, 0, options) || obj;
  234. var res;
  235. try {
  236. if (replacerStack.length === 0) {
  237. res = JSON.stringify(tmp, replacer, spacer);
  238. } else {
  239. res = JSON.stringify(tmp, replaceGetterValues(replacer), spacer);
  240. }
  241. } catch (_) {
  242. return JSON.stringify('[unable to serialize, circular reference is too complex to analyze]');
  243. } finally {
  244. while (arr.length !== 0) {
  245. var part = arr.pop();
  246. if (part.length === 4) {
  247. Object.defineProperty(part[0], part[1], part[3]);
  248. } else {
  249. part[0][part[1]] = part[2];
  250. }
  251. }
  252. }
  253. return res;
  254. }
  255. function deterministicDecirc(val, k, edgeIndex, stack, parent, depth, options) {
  256. depth += 1;
  257. var i;
  258. if (typeof val === 'object' && val !== null) {
  259. for (i = 0; i < stack.length; i++) {
  260. if (stack[i] === val) {
  261. setReplace(CIRCULAR_REPLACE_NODE, val, k, parent);
  262. return;
  263. }
  264. }
  265. try {
  266. if (typeof val.toJSON === 'function') {
  267. return;
  268. }
  269. } catch (_) {
  270. return;
  271. }
  272. if (typeof options.depthLimit !== 'undefined' && depth > options.depthLimit) {
  273. setReplace(LIMIT_REPLACE_NODE, val, k, parent);
  274. return;
  275. }
  276. if (typeof options.edgesLimit !== 'undefined' && edgeIndex + 1 > options.edgesLimit) {
  277. setReplace(LIMIT_REPLACE_NODE, val, k, parent);
  278. return;
  279. }
  280. stack.push(val);
  281. if (Array.isArray(val)) {
  282. for (i = 0; i < val.length; i++) {
  283. deterministicDecirc(val[i], i, i, stack, val, depth, options);
  284. }
  285. } else {
  286. var tmp = {};
  287. var keys = Object.keys(val).sort(compareFunction);
  288. for (i = 0; i < keys.length; i++) {
  289. var key = keys[i];
  290. deterministicDecirc(val[key], key, i, stack, val, depth, options);
  291. tmp[key] = val[key];
  292. }
  293. if (typeof parent !== 'undefined') {
  294. arr.push([parent, k, val]);
  295. parent[k] = tmp;
  296. } else {
  297. return tmp;
  298. }
  299. }
  300. stack.pop();
  301. }
  302. }
  303. function replaceGetterValues(replacer) {
  304. replacer = typeof replacer !== 'undefined' ? replacer : function (k, v) {
  305. return v;
  306. };
  307. return function (key, val) {
  308. if (replacerStack.length > 0) {
  309. for (var i = 0; i < replacerStack.length; i++) {
  310. var part = replacerStack[i];
  311. if (part[1] === key && part[0] === val) {
  312. val = part[2];
  313. replacerStack.splice(i, 1);
  314. break;
  315. }
  316. }
  317. }
  318. return replacer.call(this, key, val);
  319. };
  320. }
  321. },{}],6:[function(require,module,exports){
  322. 'use strict';
  323. var ERROR_MESSAGE = 'Function.prototype.bind called on incompatible ';
  324. var slice = Array.prototype.slice;
  325. var toStr = Object.prototype.toString;
  326. var funcType = '[object Function]';
  327. module.exports = function bind(that) {
  328. var target = this;
  329. if (typeof target !== 'function' || toStr.call(target) !== funcType) {
  330. throw new TypeError(ERROR_MESSAGE + target);
  331. }
  332. var args = slice.call(arguments, 1);
  333. var bound;
  334. var binder = function () {
  335. if (this instanceof bound) {
  336. var result = target.apply(this, args.concat(slice.call(arguments)));
  337. if (Object(result) === result) {
  338. return result;
  339. }
  340. return this;
  341. } else {
  342. return target.apply(that, args.concat(slice.call(arguments)));
  343. }
  344. };
  345. var boundLength = Math.max(0, target.length - args.length);
  346. var boundArgs = [];
  347. for (var i = 0; i < boundLength; i++) {
  348. boundArgs.push('$' + i);
  349. }
  350. bound = Function('binder', 'return function (' + boundArgs.join(',') + '){ return binder.apply(this,arguments); }')(binder);
  351. if (target.prototype) {
  352. var Empty = function Empty() {};
  353. Empty.prototype = target.prototype;
  354. bound.prototype = new Empty();
  355. Empty.prototype = null;
  356. }
  357. return bound;
  358. };
  359. },{}],7:[function(require,module,exports){
  360. 'use strict';
  361. var implementation = require('./implementation');
  362. module.exports = Function.prototype.bind || implementation;
  363. },{"./implementation":6}],8:[function(require,module,exports){
  364. 'use strict';
  365. var undefined;
  366. var $SyntaxError = SyntaxError;
  367. var $Function = Function;
  368. var $TypeError = TypeError;
  369. var getEvalledConstructor = function (expressionSyntax) {
  370. try {
  371. return $Function('"use strict"; return (' + expressionSyntax + ').constructor;')();
  372. } catch (e) {}
  373. };
  374. var $gOPD = Object.getOwnPropertyDescriptor;
  375. if ($gOPD) {
  376. try {
  377. $gOPD({}, '');
  378. } catch (e) {
  379. $gOPD = null;
  380. }
  381. }
  382. var throwTypeError = function () {
  383. throw new $TypeError();
  384. };
  385. var ThrowTypeError = $gOPD ? function () {
  386. try {
  387. arguments.callee;
  388. return throwTypeError;
  389. } catch (calleeThrows) {
  390. try {
  391. return $gOPD(arguments, 'callee').get;
  392. } catch (gOPDthrows) {
  393. return throwTypeError;
  394. }
  395. }
  396. }() : throwTypeError;
  397. var hasSymbols = require('has-symbols')();
  398. var hasProto = require('has-proto')();
  399. var getProto = Object.getPrototypeOf || (hasProto ? function (x) {
  400. return x.__proto__;
  401. } : null);
  402. var needsEval = {};
  403. var TypedArray = typeof Uint8Array === 'undefined' || !getProto ? undefined : getProto(Uint8Array);
  404. var INTRINSICS = {
  405. '%AggregateError%': typeof AggregateError === 'undefined' ? undefined : AggregateError,
  406. '%Array%': Array,
  407. '%ArrayBuffer%': typeof ArrayBuffer === 'undefined' ? undefined : ArrayBuffer,
  408. '%ArrayIteratorPrototype%': hasSymbols && getProto ? getProto([][Symbol.iterator]()) : undefined,
  409. '%AsyncFromSyncIteratorPrototype%': undefined,
  410. '%AsyncFunction%': needsEval,
  411. '%AsyncGenerator%': needsEval,
  412. '%AsyncGeneratorFunction%': needsEval,
  413. '%AsyncIteratorPrototype%': needsEval,
  414. '%Atomics%': typeof Atomics === 'undefined' ? undefined : Atomics,
  415. '%BigInt%': typeof BigInt === 'undefined' ? undefined : BigInt,
  416. '%BigInt64Array%': typeof BigInt64Array === 'undefined' ? undefined : BigInt64Array,
  417. '%BigUint64Array%': typeof BigUint64Array === 'undefined' ? undefined : BigUint64Array,
  418. '%Boolean%': Boolean,
  419. '%DataView%': typeof DataView === 'undefined' ? undefined : DataView,
  420. '%Date%': Date,
  421. '%decodeURI%': decodeURI,
  422. '%decodeURIComponent%': decodeURIComponent,
  423. '%encodeURI%': encodeURI,
  424. '%encodeURIComponent%': encodeURIComponent,
  425. '%Error%': Error,
  426. '%eval%': eval,
  427. '%EvalError%': EvalError,
  428. '%Float32Array%': typeof Float32Array === 'undefined' ? undefined : Float32Array,
  429. '%Float64Array%': typeof Float64Array === 'undefined' ? undefined : Float64Array,
  430. '%FinalizationRegistry%': typeof FinalizationRegistry === 'undefined' ? undefined : FinalizationRegistry,
  431. '%Function%': $Function,
  432. '%GeneratorFunction%': needsEval,
  433. '%Int8Array%': typeof Int8Array === 'undefined' ? undefined : Int8Array,
  434. '%Int16Array%': typeof Int16Array === 'undefined' ? undefined : Int16Array,
  435. '%Int32Array%': typeof Int32Array === 'undefined' ? undefined : Int32Array,
  436. '%isFinite%': isFinite,
  437. '%isNaN%': isNaN,
  438. '%IteratorPrototype%': hasSymbols && getProto ? getProto(getProto([][Symbol.iterator]())) : undefined,
  439. '%JSON%': typeof JSON === 'object' ? JSON : undefined,
  440. '%Map%': typeof Map === 'undefined' ? undefined : Map,
  441. '%MapIteratorPrototype%': typeof Map === 'undefined' || !hasSymbols || !getProto ? undefined : getProto(new Map()[Symbol.iterator]()),
  442. '%Math%': Math,
  443. '%Number%': Number,
  444. '%Object%': Object,
  445. '%parseFloat%': parseFloat,
  446. '%parseInt%': parseInt,
  447. '%Promise%': typeof Promise === 'undefined' ? undefined : Promise,
  448. '%Proxy%': typeof Proxy === 'undefined' ? undefined : Proxy,
  449. '%RangeError%': RangeError,
  450. '%ReferenceError%': ReferenceError,
  451. '%Reflect%': typeof Reflect === 'undefined' ? undefined : Reflect,
  452. '%RegExp%': RegExp,
  453. '%Set%': typeof Set === 'undefined' ? undefined : Set,
  454. '%SetIteratorPrototype%': typeof Set === 'undefined' || !hasSymbols || !getProto ? undefined : getProto(new Set()[Symbol.iterator]()),
  455. '%SharedArrayBuffer%': typeof SharedArrayBuffer === 'undefined' ? undefined : SharedArrayBuffer,
  456. '%String%': String,
  457. '%StringIteratorPrototype%': hasSymbols && getProto ? getProto(''[Symbol.iterator]()) : undefined,
  458. '%Symbol%': hasSymbols ? Symbol : undefined,
  459. '%SyntaxError%': $SyntaxError,
  460. '%ThrowTypeError%': ThrowTypeError,
  461. '%TypedArray%': TypedArray,
  462. '%TypeError%': $TypeError,
  463. '%Uint8Array%': typeof Uint8Array === 'undefined' ? undefined : Uint8Array,
  464. '%Uint8ClampedArray%': typeof Uint8ClampedArray === 'undefined' ? undefined : Uint8ClampedArray,
  465. '%Uint16Array%': typeof Uint16Array === 'undefined' ? undefined : Uint16Array,
  466. '%Uint32Array%': typeof Uint32Array === 'undefined' ? undefined : Uint32Array,
  467. '%URIError%': URIError,
  468. '%WeakMap%': typeof WeakMap === 'undefined' ? undefined : WeakMap,
  469. '%WeakRef%': typeof WeakRef === 'undefined' ? undefined : WeakRef,
  470. '%WeakSet%': typeof WeakSet === 'undefined' ? undefined : WeakSet
  471. };
  472. if (getProto) {
  473. try {
  474. null.error;
  475. } catch (e) {
  476. var errorProto = getProto(getProto(e));
  477. INTRINSICS['%Error.prototype%'] = errorProto;
  478. }
  479. }
  480. var doEval = function doEval(name) {
  481. var value;
  482. if (name === '%AsyncFunction%') {
  483. value = getEvalledConstructor('async function () {}');
  484. } else if (name === '%GeneratorFunction%') {
  485. value = getEvalledConstructor('function* () {}');
  486. } else if (name === '%AsyncGeneratorFunction%') {
  487. value = getEvalledConstructor('async function* () {}');
  488. } else if (name === '%AsyncGenerator%') {
  489. var fn = doEval('%AsyncGeneratorFunction%');
  490. if (fn) {
  491. value = fn.prototype;
  492. }
  493. } else if (name === '%AsyncIteratorPrototype%') {
  494. var gen = doEval('%AsyncGenerator%');
  495. if (gen && getProto) {
  496. value = getProto(gen.prototype);
  497. }
  498. }
  499. INTRINSICS[name] = value;
  500. return value;
  501. };
  502. var LEGACY_ALIASES = {
  503. '%ArrayBufferPrototype%': ['ArrayBuffer', 'prototype'],
  504. '%ArrayPrototype%': ['Array', 'prototype'],
  505. '%ArrayProto_entries%': ['Array', 'prototype', 'entries'],
  506. '%ArrayProto_forEach%': ['Array', 'prototype', 'forEach'],
  507. '%ArrayProto_keys%': ['Array', 'prototype', 'keys'],
  508. '%ArrayProto_values%': ['Array', 'prototype', 'values'],
  509. '%AsyncFunctionPrototype%': ['AsyncFunction', 'prototype'],
  510. '%AsyncGenerator%': ['AsyncGeneratorFunction', 'prototype'],
  511. '%AsyncGeneratorPrototype%': ['AsyncGeneratorFunction', 'prototype', 'prototype'],
  512. '%BooleanPrototype%': ['Boolean', 'prototype'],
  513. '%DataViewPrototype%': ['DataView', 'prototype'],
  514. '%DatePrototype%': ['Date', 'prototype'],
  515. '%ErrorPrototype%': ['Error', 'prototype'],
  516. '%EvalErrorPrototype%': ['EvalError', 'prototype'],
  517. '%Float32ArrayPrototype%': ['Float32Array', 'prototype'],
  518. '%Float64ArrayPrototype%': ['Float64Array', 'prototype'],
  519. '%FunctionPrototype%': ['Function', 'prototype'],
  520. '%Generator%': ['GeneratorFunction', 'prototype'],
  521. '%GeneratorPrototype%': ['GeneratorFunction', 'prototype', 'prototype'],
  522. '%Int8ArrayPrototype%': ['Int8Array', 'prototype'],
  523. '%Int16ArrayPrototype%': ['Int16Array', 'prototype'],
  524. '%Int32ArrayPrototype%': ['Int32Array', 'prototype'],
  525. '%JSONParse%': ['JSON', 'parse'],
  526. '%JSONStringify%': ['JSON', 'stringify'],
  527. '%MapPrototype%': ['Map', 'prototype'],
  528. '%NumberPrototype%': ['Number', 'prototype'],
  529. '%ObjectPrototype%': ['Object', 'prototype'],
  530. '%ObjProto_toString%': ['Object', 'prototype', 'toString'],
  531. '%ObjProto_valueOf%': ['Object', 'prototype', 'valueOf'],
  532. '%PromisePrototype%': ['Promise', 'prototype'],
  533. '%PromiseProto_then%': ['Promise', 'prototype', 'then'],
  534. '%Promise_all%': ['Promise', 'all'],
  535. '%Promise_reject%': ['Promise', 'reject'],
  536. '%Promise_resolve%': ['Promise', 'resolve'],
  537. '%RangeErrorPrototype%': ['RangeError', 'prototype'],
  538. '%ReferenceErrorPrototype%': ['ReferenceError', 'prototype'],
  539. '%RegExpPrototype%': ['RegExp', 'prototype'],
  540. '%SetPrototype%': ['Set', 'prototype'],
  541. '%SharedArrayBufferPrototype%': ['SharedArrayBuffer', 'prototype'],
  542. '%StringPrototype%': ['String', 'prototype'],
  543. '%SymbolPrototype%': ['Symbol', 'prototype'],
  544. '%SyntaxErrorPrototype%': ['SyntaxError', 'prototype'],
  545. '%TypedArrayPrototype%': ['TypedArray', 'prototype'],
  546. '%TypeErrorPrototype%': ['TypeError', 'prototype'],
  547. '%Uint8ArrayPrototype%': ['Uint8Array', 'prototype'],
  548. '%Uint8ClampedArrayPrototype%': ['Uint8ClampedArray', 'prototype'],
  549. '%Uint16ArrayPrototype%': ['Uint16Array', 'prototype'],
  550. '%Uint32ArrayPrototype%': ['Uint32Array', 'prototype'],
  551. '%URIErrorPrototype%': ['URIError', 'prototype'],
  552. '%WeakMapPrototype%': ['WeakMap', 'prototype'],
  553. '%WeakSetPrototype%': ['WeakSet', 'prototype']
  554. };
  555. var bind = require('function-bind');
  556. var hasOwn = require('has');
  557. var $concat = bind.call(Function.call, Array.prototype.concat);
  558. var $spliceApply = bind.call(Function.apply, Array.prototype.splice);
  559. var $replace = bind.call(Function.call, String.prototype.replace);
  560. var $strSlice = bind.call(Function.call, String.prototype.slice);
  561. var $exec = bind.call(Function.call, RegExp.prototype.exec);
  562. var rePropName = /[^%.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|%$))/g;
  563. var reEscapeChar = /\\(\\)?/g;
  564. var stringToPath = function stringToPath(string) {
  565. var first = $strSlice(string, 0, 1);
  566. var last = $strSlice(string, -1);
  567. if (first === '%' && last !== '%') {
  568. throw new $SyntaxError('invalid intrinsic syntax, expected closing `%`');
  569. } else if (last === '%' && first !== '%') {
  570. throw new $SyntaxError('invalid intrinsic syntax, expected opening `%`');
  571. }
  572. var result = [];
  573. $replace(string, rePropName, function (match, number, quote, subString) {
  574. result[result.length] = quote ? $replace(subString, reEscapeChar, '$1') : number || match;
  575. });
  576. return result;
  577. };
  578. var getBaseIntrinsic = function getBaseIntrinsic(name, allowMissing) {
  579. var intrinsicName = name;
  580. var alias;
  581. if (hasOwn(LEGACY_ALIASES, intrinsicName)) {
  582. alias = LEGACY_ALIASES[intrinsicName];
  583. intrinsicName = '%' + alias[0] + '%';
  584. }
  585. if (hasOwn(INTRINSICS, intrinsicName)) {
  586. var value = INTRINSICS[intrinsicName];
  587. if (value === needsEval) {
  588. value = doEval(intrinsicName);
  589. }
  590. if (typeof value === 'undefined' && !allowMissing) {
  591. throw new $TypeError('intrinsic ' + name + ' exists, but is not available. Please file an issue!');
  592. }
  593. return {
  594. alias: alias,
  595. name: intrinsicName,
  596. value: value
  597. };
  598. }
  599. throw new $SyntaxError('intrinsic ' + name + ' does not exist!');
  600. };
  601. module.exports = function GetIntrinsic(name, allowMissing) {
  602. if (typeof name !== 'string' || name.length === 0) {
  603. throw new $TypeError('intrinsic name must be a non-empty string');
  604. }
  605. if (arguments.length > 1 && typeof allowMissing !== 'boolean') {
  606. throw new $TypeError('"allowMissing" argument must be a boolean');
  607. }
  608. if ($exec(/^%?[^%]*%?$/, name) === null) {
  609. throw new $SyntaxError('`%` may not be present anywhere but at the beginning and end of the intrinsic name');
  610. }
  611. var parts = stringToPath(name);
  612. var intrinsicBaseName = parts.length > 0 ? parts[0] : '';
  613. var intrinsic = getBaseIntrinsic('%' + intrinsicBaseName + '%', allowMissing);
  614. var intrinsicRealName = intrinsic.name;
  615. var value = intrinsic.value;
  616. var skipFurtherCaching = false;
  617. var alias = intrinsic.alias;
  618. if (alias) {
  619. intrinsicBaseName = alias[0];
  620. $spliceApply(parts, $concat([0, 1], alias));
  621. }
  622. for (var i = 1, isOwn = true; i < parts.length; i += 1) {
  623. var part = parts[i];
  624. var first = $strSlice(part, 0, 1);
  625. var last = $strSlice(part, -1);
  626. if ((first === '"' || first === "'" || first === '`' || last === '"' || last === "'" || last === '`') && first !== last) {
  627. throw new $SyntaxError('property names with quotes must have matching quotes');
  628. }
  629. if (part === 'constructor' || !isOwn) {
  630. skipFurtherCaching = true;
  631. }
  632. intrinsicBaseName += '.' + part;
  633. intrinsicRealName = '%' + intrinsicBaseName + '%';
  634. if (hasOwn(INTRINSICS, intrinsicRealName)) {
  635. value = INTRINSICS[intrinsicRealName];
  636. } else if (value != null) {
  637. if (!(part in value)) {
  638. if (!allowMissing) {
  639. throw new $TypeError('base intrinsic for ' + name + ' exists, but the property is not available.');
  640. }
  641. return void undefined;
  642. }
  643. if ($gOPD && i + 1 >= parts.length) {
  644. var desc = $gOPD(value, part);
  645. isOwn = !!desc;
  646. if (isOwn && 'get' in desc && !('originalValue' in desc.get)) {
  647. value = desc.get;
  648. } else {
  649. value = value[part];
  650. }
  651. } else {
  652. isOwn = hasOwn(value, part);
  653. value = value[part];
  654. }
  655. if (isOwn && !skipFurtherCaching) {
  656. INTRINSICS[intrinsicRealName] = value;
  657. }
  658. }
  659. }
  660. return value;
  661. };
  662. },{"function-bind":7,"has":12,"has-proto":9,"has-symbols":10}],9:[function(require,module,exports){
  663. 'use strict';
  664. var test = {
  665. foo: {}
  666. };
  667. var $Object = Object;
  668. module.exports = function hasProto() {
  669. return {
  670. __proto__: test
  671. }.foo === test.foo && !({
  672. __proto__: null
  673. } instanceof $Object);
  674. };
  675. },{}],10:[function(require,module,exports){
  676. 'use strict';
  677. var origSymbol = typeof Symbol !== 'undefined' && Symbol;
  678. var hasSymbolSham = require('./shams');
  679. module.exports = function hasNativeSymbols() {
  680. if (typeof origSymbol !== 'function') {
  681. return false;
  682. }
  683. if (typeof Symbol !== 'function') {
  684. return false;
  685. }
  686. if (typeof origSymbol('foo') !== 'symbol') {
  687. return false;
  688. }
  689. if (typeof Symbol('bar') !== 'symbol') {
  690. return false;
  691. }
  692. return hasSymbolSham();
  693. };
  694. },{"./shams":11}],11:[function(require,module,exports){
  695. 'use strict';
  696. module.exports = function hasSymbols() {
  697. if (typeof Symbol !== 'function' || typeof Object.getOwnPropertySymbols !== 'function') {
  698. return false;
  699. }
  700. if (typeof Symbol.iterator === 'symbol') {
  701. return true;
  702. }
  703. var obj = {};
  704. var sym = Symbol('test');
  705. var symObj = Object(sym);
  706. if (typeof sym === 'string') {
  707. return false;
  708. }
  709. if (Object.prototype.toString.call(sym) !== '[object Symbol]') {
  710. return false;
  711. }
  712. if (Object.prototype.toString.call(symObj) !== '[object Symbol]') {
  713. return false;
  714. }
  715. var symVal = 42;
  716. obj[sym] = symVal;
  717. for (sym in obj) {
  718. return false;
  719. }
  720. if (typeof Object.keys === 'function' && Object.keys(obj).length !== 0) {
  721. return false;
  722. }
  723. if (typeof Object.getOwnPropertyNames === 'function' && Object.getOwnPropertyNames(obj).length !== 0) {
  724. return false;
  725. }
  726. var syms = Object.getOwnPropertySymbols(obj);
  727. if (syms.length !== 1 || syms[0] !== sym) {
  728. return false;
  729. }
  730. if (!Object.prototype.propertyIsEnumerable.call(obj, sym)) {
  731. return false;
  732. }
  733. if (typeof Object.getOwnPropertyDescriptor === 'function') {
  734. var descriptor = Object.getOwnPropertyDescriptor(obj, sym);
  735. if (descriptor.value !== symVal || descriptor.enumerable !== true) {
  736. return false;
  737. }
  738. }
  739. return true;
  740. };
  741. },{}],12:[function(require,module,exports){
  742. 'use strict';
  743. var bind = require('function-bind');
  744. module.exports = bind.call(Function.call, Object.prototype.hasOwnProperty);
  745. },{"function-bind":7}],13:[function(require,module,exports){
  746. var hasMap = typeof Map === 'function' && Map.prototype;
  747. var mapSizeDescriptor = Object.getOwnPropertyDescriptor && hasMap ? Object.getOwnPropertyDescriptor(Map.prototype, 'size') : null;
  748. var mapSize = hasMap && mapSizeDescriptor && typeof mapSizeDescriptor.get === 'function' ? mapSizeDescriptor.get : null;
  749. var mapForEach = hasMap && Map.prototype.forEach;
  750. var hasSet = typeof Set === 'function' && Set.prototype;
  751. var setSizeDescriptor = Object.getOwnPropertyDescriptor && hasSet ? Object.getOwnPropertyDescriptor(Set.prototype, 'size') : null;
  752. var setSize = hasSet && setSizeDescriptor && typeof setSizeDescriptor.get === 'function' ? setSizeDescriptor.get : null;
  753. var setForEach = hasSet && Set.prototype.forEach;
  754. var hasWeakMap = typeof WeakMap === 'function' && WeakMap.prototype;
  755. var weakMapHas = hasWeakMap ? WeakMap.prototype.has : null;
  756. var hasWeakSet = typeof WeakSet === 'function' && WeakSet.prototype;
  757. var weakSetHas = hasWeakSet ? WeakSet.prototype.has : null;
  758. var hasWeakRef = typeof WeakRef === 'function' && WeakRef.prototype;
  759. var weakRefDeref = hasWeakRef ? WeakRef.prototype.deref : null;
  760. var booleanValueOf = Boolean.prototype.valueOf;
  761. var objectToString = Object.prototype.toString;
  762. var functionToString = Function.prototype.toString;
  763. var $match = String.prototype.match;
  764. var $slice = String.prototype.slice;
  765. var $replace = String.prototype.replace;
  766. var $toUpperCase = String.prototype.toUpperCase;
  767. var $toLowerCase = String.prototype.toLowerCase;
  768. var $test = RegExp.prototype.test;
  769. var $concat = Array.prototype.concat;
  770. var $join = Array.prototype.join;
  771. var $arrSlice = Array.prototype.slice;
  772. var $floor = Math.floor;
  773. var bigIntValueOf = typeof BigInt === 'function' ? BigInt.prototype.valueOf : null;
  774. var gOPS = Object.getOwnPropertySymbols;
  775. var symToString = typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol' ? Symbol.prototype.toString : null;
  776. var hasShammedSymbols = typeof Symbol === 'function' && typeof Symbol.iterator === 'object';
  777. var toStringTag = typeof Symbol === 'function' && Symbol.toStringTag && (typeof Symbol.toStringTag === hasShammedSymbols ? 'object' : 'symbol') ? Symbol.toStringTag : null;
  778. var isEnumerable = Object.prototype.propertyIsEnumerable;
  779. var gPO = (typeof Reflect === 'function' ? Reflect.getPrototypeOf : Object.getPrototypeOf) || ([].__proto__ === Array.prototype ? function (O) {
  780. return O.__proto__;
  781. } : null);
  782. function addNumericSeparator(num, str) {
  783. if (num === Infinity || num === -Infinity || num !== num || num && num > -1000 && num < 1000 || $test.call(/e/, str)) {
  784. return str;
  785. }
  786. var sepRegex = /[0-9](?=(?:[0-9]{3})+(?![0-9]))/g;
  787. if (typeof num === 'number') {
  788. var int = num < 0 ? -$floor(-num) : $floor(num);
  789. if (int !== num) {
  790. var intStr = String(int);
  791. var dec = $slice.call(str, intStr.length + 1);
  792. return $replace.call(intStr, sepRegex, '$&_') + '.' + $replace.call($replace.call(dec, /([0-9]{3})/g, '$&_'), /_$/, '');
  793. }
  794. }
  795. return $replace.call(str, sepRegex, '$&_');
  796. }
  797. var utilInspect = require('./util.inspect');
  798. var inspectCustom = utilInspect.custom;
  799. var inspectSymbol = isSymbol(inspectCustom) ? inspectCustom : null;
  800. module.exports = function inspect_(obj, options, depth, seen) {
  801. var opts = options || {};
  802. if (has(opts, 'quoteStyle') && opts.quoteStyle !== 'single' && opts.quoteStyle !== 'double') {
  803. throw new TypeError('option "quoteStyle" must be "single" or "double"');
  804. }
  805. if (has(opts, 'maxStringLength') && (typeof opts.maxStringLength === 'number' ? opts.maxStringLength < 0 && opts.maxStringLength !== Infinity : opts.maxStringLength !== null)) {
  806. throw new TypeError('option "maxStringLength", if provided, must be a positive integer, Infinity, or `null`');
  807. }
  808. var customInspect = has(opts, 'customInspect') ? opts.customInspect : true;
  809. if (typeof customInspect !== 'boolean' && customInspect !== 'symbol') {
  810. throw new TypeError('option "customInspect", if provided, must be `true`, `false`, or `\'symbol\'`');
  811. }
  812. if (has(opts, 'indent') && opts.indent !== null && opts.indent !== '\t' && !(parseInt(opts.indent, 10) === opts.indent && opts.indent > 0)) {
  813. throw new TypeError('option "indent" must be "\\t", an integer > 0, or `null`');
  814. }
  815. if (has(opts, 'numericSeparator') && typeof opts.numericSeparator !== 'boolean') {
  816. throw new TypeError('option "numericSeparator", if provided, must be `true` or `false`');
  817. }
  818. var numericSeparator = opts.numericSeparator;
  819. if (typeof obj === 'undefined') {
  820. return 'undefined';
  821. }
  822. if (obj === null) {
  823. return 'null';
  824. }
  825. if (typeof obj === 'boolean') {
  826. return obj ? 'true' : 'false';
  827. }
  828. if (typeof obj === 'string') {
  829. return inspectString(obj, opts);
  830. }
  831. if (typeof obj === 'number') {
  832. if (obj === 0) {
  833. return Infinity / obj > 0 ? '0' : '-0';
  834. }
  835. var str = String(obj);
  836. return numericSeparator ? addNumericSeparator(obj, str) : str;
  837. }
  838. if (typeof obj === 'bigint') {
  839. var bigIntStr = String(obj) + 'n';
  840. return numericSeparator ? addNumericSeparator(obj, bigIntStr) : bigIntStr;
  841. }
  842. var maxDepth = typeof opts.depth === 'undefined' ? 5 : opts.depth;
  843. if (typeof depth === 'undefined') {
  844. depth = 0;
  845. }
  846. if (depth >= maxDepth && maxDepth > 0 && typeof obj === 'object') {
  847. return isArray(obj) ? '[Array]' : '[Object]';
  848. }
  849. var indent = getIndent(opts, depth);
  850. if (typeof seen === 'undefined') {
  851. seen = [];
  852. } else if (indexOf(seen, obj) >= 0) {
  853. return '[Circular]';
  854. }
  855. function inspect(value, from, noIndent) {
  856. if (from) {
  857. seen = $arrSlice.call(seen);
  858. seen.push(from);
  859. }
  860. if (noIndent) {
  861. var newOpts = {
  862. depth: opts.depth
  863. };
  864. if (has(opts, 'quoteStyle')) {
  865. newOpts.quoteStyle = opts.quoteStyle;
  866. }
  867. return inspect_(value, newOpts, depth + 1, seen);
  868. }
  869. return inspect_(value, opts, depth + 1, seen);
  870. }
  871. if (typeof obj === 'function' && !isRegExp(obj)) {
  872. var name = nameOf(obj);
  873. var keys = arrObjKeys(obj, inspect);
  874. return '[Function' + (name ? ': ' + name : ' (anonymous)') + ']' + (keys.length > 0 ? ' { ' + $join.call(keys, ', ') + ' }' : '');
  875. }
  876. if (isSymbol(obj)) {
  877. var symString = hasShammedSymbols ? $replace.call(String(obj), /^(Symbol\(.*\))_[^)]*$/, '$1') : symToString.call(obj);
  878. return typeof obj === 'object' && !hasShammedSymbols ? markBoxed(symString) : symString;
  879. }
  880. if (isElement(obj)) {
  881. var s = '<' + $toLowerCase.call(String(obj.nodeName));
  882. var attrs = obj.attributes || [];
  883. for (var i = 0; i < attrs.length; i++) {
  884. s += ' ' + attrs[i].name + '=' + wrapQuotes(quote(attrs[i].value), 'double', opts);
  885. }
  886. s += '>';
  887. if (obj.childNodes && obj.childNodes.length) {
  888. s += '...';
  889. }
  890. s += '</' + $toLowerCase.call(String(obj.nodeName)) + '>';
  891. return s;
  892. }
  893. if (isArray(obj)) {
  894. if (obj.length === 0) {
  895. return '[]';
  896. }
  897. var xs = arrObjKeys(obj, inspect);
  898. if (indent && !singleLineValues(xs)) {
  899. return '[' + indentedJoin(xs, indent) + ']';
  900. }
  901. return '[ ' + $join.call(xs, ', ') + ' ]';
  902. }
  903. if (isError(obj)) {
  904. var parts = arrObjKeys(obj, inspect);
  905. if (!('cause' in Error.prototype) && 'cause' in obj && !isEnumerable.call(obj, 'cause')) {
  906. return '{ [' + String(obj) + '] ' + $join.call($concat.call('[cause]: ' + inspect(obj.cause), parts), ', ') + ' }';
  907. }
  908. if (parts.length === 0) {
  909. return '[' + String(obj) + ']';
  910. }
  911. return '{ [' + String(obj) + '] ' + $join.call(parts, ', ') + ' }';
  912. }
  913. if (typeof obj === 'object' && customInspect) {
  914. if (inspectSymbol && typeof obj[inspectSymbol] === 'function' && utilInspect) {
  915. return utilInspect(obj, {
  916. depth: maxDepth - depth
  917. });
  918. } else if (customInspect !== 'symbol' && typeof obj.inspect === 'function') {
  919. return obj.inspect();
  920. }
  921. }
  922. if (isMap(obj)) {
  923. var mapParts = [];
  924. if (mapForEach) {
  925. mapForEach.call(obj, function (value, key) {
  926. mapParts.push(inspect(key, obj, true) + ' => ' + inspect(value, obj));
  927. });
  928. }
  929. return collectionOf('Map', mapSize.call(obj), mapParts, indent);
  930. }
  931. if (isSet(obj)) {
  932. var setParts = [];
  933. if (setForEach) {
  934. setForEach.call(obj, function (value) {
  935. setParts.push(inspect(value, obj));
  936. });
  937. }
  938. return collectionOf('Set', setSize.call(obj), setParts, indent);
  939. }
  940. if (isWeakMap(obj)) {
  941. return weakCollectionOf('WeakMap');
  942. }
  943. if (isWeakSet(obj)) {
  944. return weakCollectionOf('WeakSet');
  945. }
  946. if (isWeakRef(obj)) {
  947. return weakCollectionOf('WeakRef');
  948. }
  949. if (isNumber(obj)) {
  950. return markBoxed(inspect(Number(obj)));
  951. }
  952. if (isBigInt(obj)) {
  953. return markBoxed(inspect(bigIntValueOf.call(obj)));
  954. }
  955. if (isBoolean(obj)) {
  956. return markBoxed(booleanValueOf.call(obj));
  957. }
  958. if (isString(obj)) {
  959. return markBoxed(inspect(String(obj)));
  960. }
  961. if (!isDate(obj) && !isRegExp(obj)) {
  962. var ys = arrObjKeys(obj, inspect);
  963. var isPlainObject = gPO ? gPO(obj) === Object.prototype : obj instanceof Object || obj.constructor === Object;
  964. var protoTag = obj instanceof Object ? '' : 'null prototype';
  965. var stringTag = !isPlainObject && toStringTag && Object(obj) === obj && toStringTag in obj ? $slice.call(toStr(obj), 8, -1) : protoTag ? 'Object' : '';
  966. var constructorTag = isPlainObject || typeof obj.constructor !== 'function' ? '' : obj.constructor.name ? obj.constructor.name + ' ' : '';
  967. var tag = constructorTag + (stringTag || protoTag ? '[' + $join.call($concat.call([], stringTag || [], protoTag || []), ': ') + '] ' : '');
  968. if (ys.length === 0) {
  969. return tag + '{}';
  970. }
  971. if (indent) {
  972. return tag + '{' + indentedJoin(ys, indent) + '}';
  973. }
  974. return tag + '{ ' + $join.call(ys, ', ') + ' }';
  975. }
  976. return String(obj);
  977. };
  978. function wrapQuotes(s, defaultStyle, opts) {
  979. var quoteChar = (opts.quoteStyle || defaultStyle) === 'double' ? '"' : "'";
  980. return quoteChar + s + quoteChar;
  981. }
  982. function quote(s) {
  983. return $replace.call(String(s), /"/g, '&quot;');
  984. }
  985. function isArray(obj) {
  986. return toStr(obj) === '[object Array]' && (!toStringTag || !(typeof obj === 'object' && toStringTag in obj));
  987. }
  988. function isDate(obj) {
  989. return toStr(obj) === '[object Date]' && (!toStringTag || !(typeof obj === 'object' && toStringTag in obj));
  990. }
  991. function isRegExp(obj) {
  992. return toStr(obj) === '[object RegExp]' && (!toStringTag || !(typeof obj === 'object' && toStringTag in obj));
  993. }
  994. function isError(obj) {
  995. return toStr(obj) === '[object Error]' && (!toStringTag || !(typeof obj === 'object' && toStringTag in obj));
  996. }
  997. function isString(obj) {
  998. return toStr(obj) === '[object String]' && (!toStringTag || !(typeof obj === 'object' && toStringTag in obj));
  999. }
  1000. function isNumber(obj) {
  1001. return toStr(obj) === '[object Number]' && (!toStringTag || !(typeof obj === 'object' && toStringTag in obj));
  1002. }
  1003. function isBoolean(obj) {
  1004. return toStr(obj) === '[object Boolean]' && (!toStringTag || !(typeof obj === 'object' && toStringTag in obj));
  1005. }
  1006. function isSymbol(obj) {
  1007. if (hasShammedSymbols) {
  1008. return obj && typeof obj === 'object' && obj instanceof Symbol;
  1009. }
  1010. if (typeof obj === 'symbol') {
  1011. return true;
  1012. }
  1013. if (!obj || typeof obj !== 'object' || !symToString) {
  1014. return false;
  1015. }
  1016. try {
  1017. symToString.call(obj);
  1018. return true;
  1019. } catch (e) {}
  1020. return false;
  1021. }
  1022. function isBigInt(obj) {
  1023. if (!obj || typeof obj !== 'object' || !bigIntValueOf) {
  1024. return false;
  1025. }
  1026. try {
  1027. bigIntValueOf.call(obj);
  1028. return true;
  1029. } catch (e) {}
  1030. return false;
  1031. }
  1032. var hasOwn = Object.prototype.hasOwnProperty || function (key) {
  1033. return key in this;
  1034. };
  1035. function has(obj, key) {
  1036. return hasOwn.call(obj, key);
  1037. }
  1038. function toStr(obj) {
  1039. return objectToString.call(obj);
  1040. }
  1041. function nameOf(f) {
  1042. if (f.name) {
  1043. return f.name;
  1044. }
  1045. var m = $match.call(functionToString.call(f), /^function\s*([\w$]+)/);
  1046. if (m) {
  1047. return m[1];
  1048. }
  1049. return null;
  1050. }
  1051. function indexOf(xs, x) {
  1052. if (xs.indexOf) {
  1053. return xs.indexOf(x);
  1054. }
  1055. for (var i = 0, l = xs.length; i < l; i++) {
  1056. if (xs[i] === x) {
  1057. return i;
  1058. }
  1059. }
  1060. return -1;
  1061. }
  1062. function isMap(x) {
  1063. if (!mapSize || !x || typeof x !== 'object') {
  1064. return false;
  1065. }
  1066. try {
  1067. mapSize.call(x);
  1068. try {
  1069. setSize.call(x);
  1070. } catch (s) {
  1071. return true;
  1072. }
  1073. return x instanceof Map;
  1074. } catch (e) {}
  1075. return false;
  1076. }
  1077. function isWeakMap(x) {
  1078. if (!weakMapHas || !x || typeof x !== 'object') {
  1079. return false;
  1080. }
  1081. try {
  1082. weakMapHas.call(x, weakMapHas);
  1083. try {
  1084. weakSetHas.call(x, weakSetHas);
  1085. } catch (s) {
  1086. return true;
  1087. }
  1088. return x instanceof WeakMap;
  1089. } catch (e) {}
  1090. return false;
  1091. }
  1092. function isWeakRef(x) {
  1093. if (!weakRefDeref || !x || typeof x !== 'object') {
  1094. return false;
  1095. }
  1096. try {
  1097. weakRefDeref.call(x);
  1098. return true;
  1099. } catch (e) {}
  1100. return false;
  1101. }
  1102. function isSet(x) {
  1103. if (!setSize || !x || typeof x !== 'object') {
  1104. return false;
  1105. }
  1106. try {
  1107. setSize.call(x);
  1108. try {
  1109. mapSize.call(x);
  1110. } catch (m) {
  1111. return true;
  1112. }
  1113. return x instanceof Set;
  1114. } catch (e) {}
  1115. return false;
  1116. }
  1117. function isWeakSet(x) {
  1118. if (!weakSetHas || !x || typeof x !== 'object') {
  1119. return false;
  1120. }
  1121. try {
  1122. weakSetHas.call(x, weakSetHas);
  1123. try {
  1124. weakMapHas.call(x, weakMapHas);
  1125. } catch (s) {
  1126. return true;
  1127. }
  1128. return x instanceof WeakSet;
  1129. } catch (e) {}
  1130. return false;
  1131. }
  1132. function isElement(x) {
  1133. if (!x || typeof x !== 'object') {
  1134. return false;
  1135. }
  1136. if (typeof HTMLElement !== 'undefined' && x instanceof HTMLElement) {
  1137. return true;
  1138. }
  1139. return typeof x.nodeName === 'string' && typeof x.getAttribute === 'function';
  1140. }
  1141. function inspectString(str, opts) {
  1142. if (str.length > opts.maxStringLength) {
  1143. var remaining = str.length - opts.maxStringLength;
  1144. var trailer = '... ' + remaining + ' more character' + (remaining > 1 ? 's' : '');
  1145. return inspectString($slice.call(str, 0, opts.maxStringLength), opts) + trailer;
  1146. }
  1147. var s = $replace.call($replace.call(str, /(['\\])/g, '\\$1'), /[\x00-\x1f]/g, lowbyte);
  1148. return wrapQuotes(s, 'single', opts);
  1149. }
  1150. function lowbyte(c) {
  1151. var n = c.charCodeAt(0);
  1152. var x = {
  1153. 8: 'b',
  1154. 9: 't',
  1155. 10: 'n',
  1156. 12: 'f',
  1157. 13: 'r'
  1158. }[n];
  1159. if (x) {
  1160. return '\\' + x;
  1161. }
  1162. return '\\x' + (n < 0x10 ? '0' : '') + $toUpperCase.call(n.toString(16));
  1163. }
  1164. function markBoxed(str) {
  1165. return 'Object(' + str + ')';
  1166. }
  1167. function weakCollectionOf(type) {
  1168. return type + ' { ? }';
  1169. }
  1170. function collectionOf(type, size, entries, indent) {
  1171. var joinedEntries = indent ? indentedJoin(entries, indent) : $join.call(entries, ', ');
  1172. return type + ' (' + size + ') {' + joinedEntries + '}';
  1173. }
  1174. function singleLineValues(xs) {
  1175. for (var i = 0; i < xs.length; i++) {
  1176. if (indexOf(xs[i], '\n') >= 0) {
  1177. return false;
  1178. }
  1179. }
  1180. return true;
  1181. }
  1182. function getIndent(opts, depth) {
  1183. var baseIndent;
  1184. if (opts.indent === '\t') {
  1185. baseIndent = '\t';
  1186. } else if (typeof opts.indent === 'number' && opts.indent > 0) {
  1187. baseIndent = $join.call(Array(opts.indent + 1), ' ');
  1188. } else {
  1189. return null;
  1190. }
  1191. return {
  1192. base: baseIndent,
  1193. prev: $join.call(Array(depth + 1), baseIndent)
  1194. };
  1195. }
  1196. function indentedJoin(xs, indent) {
  1197. if (xs.length === 0) {
  1198. return '';
  1199. }
  1200. var lineJoiner = '\n' + indent.prev + indent.base;
  1201. return lineJoiner + $join.call(xs, ',' + lineJoiner) + '\n' + indent.prev;
  1202. }
  1203. function arrObjKeys(obj, inspect) {
  1204. var isArr = isArray(obj);
  1205. var xs = [];
  1206. if (isArr) {
  1207. xs.length = obj.length;
  1208. for (var i = 0; i < obj.length; i++) {
  1209. xs[i] = has(obj, i) ? inspect(obj[i], obj) : '';
  1210. }
  1211. }
  1212. var syms = typeof gOPS === 'function' ? gOPS(obj) : [];
  1213. var symMap;
  1214. if (hasShammedSymbols) {
  1215. symMap = {};
  1216. for (var k = 0; k < syms.length; k++) {
  1217. symMap['$' + syms[k]] = syms[k];
  1218. }
  1219. }
  1220. for (var key in obj) {
  1221. if (!has(obj, key)) {
  1222. continue;
  1223. }
  1224. if (isArr && String(Number(key)) === key && key < obj.length) {
  1225. continue;
  1226. }
  1227. if (hasShammedSymbols && symMap['$' + key] instanceof Symbol) {
  1228. continue;
  1229. } else if ($test.call(/[^\w$]/, key)) {
  1230. xs.push(inspect(key, obj) + ': ' + inspect(obj[key], obj));
  1231. } else {
  1232. xs.push(key + ': ' + inspect(obj[key], obj));
  1233. }
  1234. }
  1235. if (typeof gOPS === 'function') {
  1236. for (var j = 0; j < syms.length; j++) {
  1237. if (isEnumerable.call(obj, syms[j])) {
  1238. xs.push('[' + inspect(syms[j]) + ']: ' + inspect(obj[syms[j]], obj));
  1239. }
  1240. }
  1241. }
  1242. return xs;
  1243. }
  1244. },{"./util.inspect":1}],14:[function(require,module,exports){
  1245. var process = module.exports = {};
  1246. var cachedSetTimeout;
  1247. var cachedClearTimeout;
  1248. function defaultSetTimout() {
  1249. throw new Error('setTimeout has not been defined');
  1250. }
  1251. function defaultClearTimeout() {
  1252. throw new Error('clearTimeout has not been defined');
  1253. }
  1254. (function () {
  1255. try {
  1256. if (typeof setTimeout === 'function') {
  1257. cachedSetTimeout = setTimeout;
  1258. } else {
  1259. cachedSetTimeout = defaultSetTimout;
  1260. }
  1261. } catch (e) {
  1262. cachedSetTimeout = defaultSetTimout;
  1263. }
  1264. try {
  1265. if (typeof clearTimeout === 'function') {
  1266. cachedClearTimeout = clearTimeout;
  1267. } else {
  1268. cachedClearTimeout = defaultClearTimeout;
  1269. }
  1270. } catch (e) {
  1271. cachedClearTimeout = defaultClearTimeout;
  1272. }
  1273. })();
  1274. function runTimeout(fun) {
  1275. if (cachedSetTimeout === setTimeout) {
  1276. return setTimeout(fun, 0);
  1277. }
  1278. if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
  1279. cachedSetTimeout = setTimeout;
  1280. return setTimeout(fun, 0);
  1281. }
  1282. try {
  1283. return cachedSetTimeout(fun, 0);
  1284. } catch (e) {
  1285. try {
  1286. return cachedSetTimeout.call(null, fun, 0);
  1287. } catch (e) {
  1288. return cachedSetTimeout.call(this, fun, 0);
  1289. }
  1290. }
  1291. }
  1292. function runClearTimeout(marker) {
  1293. if (cachedClearTimeout === clearTimeout) {
  1294. return clearTimeout(marker);
  1295. }
  1296. if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
  1297. cachedClearTimeout = clearTimeout;
  1298. return clearTimeout(marker);
  1299. }
  1300. try {
  1301. return cachedClearTimeout(marker);
  1302. } catch (e) {
  1303. try {
  1304. return cachedClearTimeout.call(null, marker);
  1305. } catch (e) {
  1306. return cachedClearTimeout.call(this, marker);
  1307. }
  1308. }
  1309. }
  1310. var queue = [];
  1311. var draining = false;
  1312. var currentQueue;
  1313. var queueIndex = -1;
  1314. function cleanUpNextTick() {
  1315. if (!draining || !currentQueue) {
  1316. return;
  1317. }
  1318. draining = false;
  1319. if (currentQueue.length) {
  1320. queue = currentQueue.concat(queue);
  1321. } else {
  1322. queueIndex = -1;
  1323. }
  1324. if (queue.length) {
  1325. drainQueue();
  1326. }
  1327. }
  1328. function drainQueue() {
  1329. if (draining) {
  1330. return;
  1331. }
  1332. var timeout = runTimeout(cleanUpNextTick);
  1333. draining = true;
  1334. var len = queue.length;
  1335. while (len) {
  1336. currentQueue = queue;
  1337. queue = [];
  1338. while (++queueIndex < len) {
  1339. if (currentQueue) {
  1340. currentQueue[queueIndex].run();
  1341. }
  1342. }
  1343. queueIndex = -1;
  1344. len = queue.length;
  1345. }
  1346. currentQueue = null;
  1347. draining = false;
  1348. runClearTimeout(timeout);
  1349. }
  1350. process.nextTick = function (fun) {
  1351. var args = new Array(arguments.length - 1);
  1352. if (arguments.length > 1) {
  1353. for (var i = 1; i < arguments.length; i++) {
  1354. args[i - 1] = arguments[i];
  1355. }
  1356. }
  1357. queue.push(new Item(fun, args));
  1358. if (queue.length === 1 && !draining) {
  1359. runTimeout(drainQueue);
  1360. }
  1361. };
  1362. function Item(fun, array) {
  1363. this.fun = fun;
  1364. this.array = array;
  1365. }
  1366. Item.prototype.run = function () {
  1367. this.fun.apply(null, this.array);
  1368. };
  1369. process.title = 'browser';
  1370. process.browser = true;
  1371. process.env = {};
  1372. process.argv = [];
  1373. process.version = '';
  1374. process.versions = {};
  1375. function noop() {}
  1376. process.on = noop;
  1377. process.addListener = noop;
  1378. process.once = noop;
  1379. process.off = noop;
  1380. process.removeListener = noop;
  1381. process.removeAllListeners = noop;
  1382. process.emit = noop;
  1383. process.prependListener = noop;
  1384. process.prependOnceListener = noop;
  1385. process.listeners = function (name) {
  1386. return [];
  1387. };
  1388. process.binding = function (name) {
  1389. throw new Error('process.binding is not supported');
  1390. };
  1391. process.cwd = function () {
  1392. return '/';
  1393. };
  1394. process.chdir = function (dir) {
  1395. throw new Error('process.chdir is not supported');
  1396. };
  1397. process.umask = function () {
  1398. return 0;
  1399. };
  1400. },{}],15:[function(require,module,exports){
  1401. 'use strict';
  1402. var replace = String.prototype.replace;
  1403. var percentTwenties = /%20/g;
  1404. var Format = {
  1405. RFC1738: 'RFC1738',
  1406. RFC3986: 'RFC3986'
  1407. };
  1408. module.exports = {
  1409. 'default': Format.RFC3986,
  1410. formatters: {
  1411. RFC1738: function (value) {
  1412. return replace.call(value, percentTwenties, '+');
  1413. },
  1414. RFC3986: function (value) {
  1415. return String(value);
  1416. }
  1417. },
  1418. RFC1738: Format.RFC1738,
  1419. RFC3986: Format.RFC3986
  1420. };
  1421. },{}],16:[function(require,module,exports){
  1422. 'use strict';
  1423. var stringify = require('./stringify');
  1424. var parse = require('./parse');
  1425. var formats = require('./formats');
  1426. module.exports = {
  1427. formats: formats,
  1428. parse: parse,
  1429. stringify: stringify
  1430. };
  1431. },{"./formats":15,"./parse":17,"./stringify":18}],17:[function(require,module,exports){
  1432. 'use strict';
  1433. var utils = require('./utils');
  1434. var has = Object.prototype.hasOwnProperty;
  1435. var isArray = Array.isArray;
  1436. var defaults = {
  1437. allowDots: false,
  1438. allowPrototypes: false,
  1439. allowSparse: false,
  1440. arrayLimit: 20,
  1441. charset: 'utf-8',
  1442. charsetSentinel: false,
  1443. comma: false,
  1444. decoder: utils.decode,
  1445. delimiter: '&',
  1446. depth: 5,
  1447. ignoreQueryPrefix: false,
  1448. interpretNumericEntities: false,
  1449. parameterLimit: 1000,
  1450. parseArrays: true,
  1451. plainObjects: false,
  1452. strictNullHandling: false
  1453. };
  1454. var interpretNumericEntities = function (str) {
  1455. return str.replace(/&#(\d+);/g, function ($0, numberStr) {
  1456. return String.fromCharCode(parseInt(numberStr, 10));
  1457. });
  1458. };
  1459. var parseArrayValue = function (val, options) {
  1460. if (val && typeof val === 'string' && options.comma && val.indexOf(',') > -1) {
  1461. return val.split(',');
  1462. }
  1463. return val;
  1464. };
  1465. var isoSentinel = 'utf8=%26%2310003%3B';
  1466. var charsetSentinel = 'utf8=%E2%9C%93';
  1467. var parseValues = function parseQueryStringValues(str, options) {
  1468. var obj = {
  1469. __proto__: null
  1470. };
  1471. var cleanStr = options.ignoreQueryPrefix ? str.replace(/^\?/, '') : str;
  1472. var limit = options.parameterLimit === Infinity ? undefined : options.parameterLimit;
  1473. var parts = cleanStr.split(options.delimiter, limit);
  1474. var skipIndex = -1;
  1475. var i;
  1476. var charset = options.charset;
  1477. if (options.charsetSentinel) {
  1478. for (i = 0; i < parts.length; ++i) {
  1479. if (parts[i].indexOf('utf8=') === 0) {
  1480. if (parts[i] === charsetSentinel) {
  1481. charset = 'utf-8';
  1482. } else if (parts[i] === isoSentinel) {
  1483. charset = 'iso-8859-1';
  1484. }
  1485. skipIndex = i;
  1486. i = parts.length;
  1487. }
  1488. }
  1489. }
  1490. for (i = 0; i < parts.length; ++i) {
  1491. if (i === skipIndex) {
  1492. continue;
  1493. }
  1494. var part = parts[i];
  1495. var bracketEqualsPos = part.indexOf(']=');
  1496. var pos = bracketEqualsPos === -1 ? part.indexOf('=') : bracketEqualsPos + 1;
  1497. var key, val;
  1498. if (pos === -1) {
  1499. key = options.decoder(part, defaults.decoder, charset, 'key');
  1500. val = options.strictNullHandling ? null : '';
  1501. } else {
  1502. key = options.decoder(part.slice(0, pos), defaults.decoder, charset, 'key');
  1503. val = utils.maybeMap(parseArrayValue(part.slice(pos + 1), options), function (encodedVal) {
  1504. return options.decoder(encodedVal, defaults.decoder, charset, 'value');
  1505. });
  1506. }
  1507. if (val && options.interpretNumericEntities && charset === 'iso-8859-1') {
  1508. val = interpretNumericEntities(val);
  1509. }
  1510. if (part.indexOf('[]=') > -1) {
  1511. val = isArray(val) ? [val] : val;
  1512. }
  1513. if (has.call(obj, key)) {
  1514. obj[key] = utils.combine(obj[key], val);
  1515. } else {
  1516. obj[key] = val;
  1517. }
  1518. }
  1519. return obj;
  1520. };
  1521. var parseObject = function (chain, val, options, valuesParsed) {
  1522. var leaf = valuesParsed ? val : parseArrayValue(val, options);
  1523. for (var i = chain.length - 1; i >= 0; --i) {
  1524. var obj;
  1525. var root = chain[i];
  1526. if (root === '[]' && options.parseArrays) {
  1527. obj = [].concat(leaf);
  1528. } else {
  1529. obj = options.plainObjects ? Object.create(null) : {};
  1530. var cleanRoot = root.charAt(0) === '[' && root.charAt(root.length - 1) === ']' ? root.slice(1, -1) : root;
  1531. var index = parseInt(cleanRoot, 10);
  1532. if (!options.parseArrays && cleanRoot === '') {
  1533. obj = {
  1534. 0: leaf
  1535. };
  1536. } else if (!isNaN(index) && root !== cleanRoot && String(index) === cleanRoot && index >= 0 && options.parseArrays && index <= options.arrayLimit) {
  1537. obj = [];
  1538. obj[index] = leaf;
  1539. } else if (cleanRoot !== '__proto__') {
  1540. obj[cleanRoot] = leaf;
  1541. }
  1542. }
  1543. leaf = obj;
  1544. }
  1545. return leaf;
  1546. };
  1547. var parseKeys = function parseQueryStringKeys(givenKey, val, options, valuesParsed) {
  1548. if (!givenKey) {
  1549. return;
  1550. }
  1551. var key = options.allowDots ? givenKey.replace(/\.([^.[]+)/g, '[$1]') : givenKey;
  1552. var brackets = /(\[[^[\]]*])/;
  1553. var child = /(\[[^[\]]*])/g;
  1554. var segment = options.depth > 0 && brackets.exec(key);
  1555. var parent = segment ? key.slice(0, segment.index) : key;
  1556. var keys = [];
  1557. if (parent) {
  1558. if (!options.plainObjects && has.call(Object.prototype, parent)) {
  1559. if (!options.allowPrototypes) {
  1560. return;
  1561. }
  1562. }
  1563. keys.push(parent);
  1564. }
  1565. var i = 0;
  1566. while (options.depth > 0 && (segment = child.exec(key)) !== null && i < options.depth) {
  1567. i += 1;
  1568. if (!options.plainObjects && has.call(Object.prototype, segment[1].slice(1, -1))) {
  1569. if (!options.allowPrototypes) {
  1570. return;
  1571. }
  1572. }
  1573. keys.push(segment[1]);
  1574. }
  1575. if (segment) {
  1576. keys.push('[' + key.slice(segment.index) + ']');
  1577. }
  1578. return parseObject(keys, val, options, valuesParsed);
  1579. };
  1580. var normalizeParseOptions = function normalizeParseOptions(opts) {
  1581. if (!opts) {
  1582. return defaults;
  1583. }
  1584. if (opts.decoder !== null && opts.decoder !== undefined && typeof opts.decoder !== 'function') {
  1585. throw new TypeError('Decoder has to be a function.');
  1586. }
  1587. if (typeof opts.charset !== 'undefined' && opts.charset !== 'utf-8' && opts.charset !== 'iso-8859-1') {
  1588. throw new TypeError('The charset option must be either utf-8, iso-8859-1, or undefined');
  1589. }
  1590. var charset = typeof opts.charset === 'undefined' ? defaults.charset : opts.charset;
  1591. return {
  1592. allowDots: typeof opts.allowDots === 'undefined' ? defaults.allowDots : !!opts.allowDots,
  1593. allowPrototypes: typeof opts.allowPrototypes === 'boolean' ? opts.allowPrototypes : defaults.allowPrototypes,
  1594. allowSparse: typeof opts.allowSparse === 'boolean' ? opts.allowSparse : defaults.allowSparse,
  1595. arrayLimit: typeof opts.arrayLimit === 'number' ? opts.arrayLimit : defaults.arrayLimit,
  1596. charset: charset,
  1597. charsetSentinel: typeof opts.charsetSentinel === 'boolean' ? opts.charsetSentinel : defaults.charsetSentinel,
  1598. comma: typeof opts.comma === 'boolean' ? opts.comma : defaults.comma,
  1599. decoder: typeof opts.decoder === 'function' ? opts.decoder : defaults.decoder,
  1600. delimiter: typeof opts.delimiter === 'string' || utils.isRegExp(opts.delimiter) ? opts.delimiter : defaults.delimiter,
  1601. depth: typeof opts.depth === 'number' || opts.depth === false ? +opts.depth : defaults.depth,
  1602. ignoreQueryPrefix: opts.ignoreQueryPrefix === true,
  1603. interpretNumericEntities: typeof opts.interpretNumericEntities === 'boolean' ? opts.interpretNumericEntities : defaults.interpretNumericEntities,
  1604. parameterLimit: typeof opts.parameterLimit === 'number' ? opts.parameterLimit : defaults.parameterLimit,
  1605. parseArrays: opts.parseArrays !== false,
  1606. plainObjects: typeof opts.plainObjects === 'boolean' ? opts.plainObjects : defaults.plainObjects,
  1607. strictNullHandling: typeof opts.strictNullHandling === 'boolean' ? opts.strictNullHandling : defaults.strictNullHandling
  1608. };
  1609. };
  1610. module.exports = function (str, opts) {
  1611. var options = normalizeParseOptions(opts);
  1612. if (str === '' || str === null || typeof str === 'undefined') {
  1613. return options.plainObjects ? Object.create(null) : {};
  1614. }
  1615. var tempObj = typeof str === 'string' ? parseValues(str, options) : str;
  1616. var obj = options.plainObjects ? Object.create(null) : {};
  1617. var keys = Object.keys(tempObj);
  1618. for (var i = 0; i < keys.length; ++i) {
  1619. var key = keys[i];
  1620. var newObj = parseKeys(key, tempObj[key], options, typeof str === 'string');
  1621. obj = utils.merge(obj, newObj, options);
  1622. }
  1623. if (options.allowSparse === true) {
  1624. return obj;
  1625. }
  1626. return utils.compact(obj);
  1627. };
  1628. },{"./utils":19}],18:[function(require,module,exports){
  1629. 'use strict';
  1630. var getSideChannel = require('side-channel');
  1631. var utils = require('./utils');
  1632. var formats = require('./formats');
  1633. var has = Object.prototype.hasOwnProperty;
  1634. var arrayPrefixGenerators = {
  1635. brackets: function brackets(prefix) {
  1636. return prefix + '[]';
  1637. },
  1638. comma: 'comma',
  1639. indices: function indices(prefix, key) {
  1640. return prefix + '[' + key + ']';
  1641. },
  1642. repeat: function repeat(prefix) {
  1643. return prefix;
  1644. }
  1645. };
  1646. var isArray = Array.isArray;
  1647. var push = Array.prototype.push;
  1648. var pushToArray = function (arr, valueOrArray) {
  1649. push.apply(arr, isArray(valueOrArray) ? valueOrArray : [valueOrArray]);
  1650. };
  1651. var toISO = Date.prototype.toISOString;
  1652. var defaultFormat = formats['default'];
  1653. var defaults = {
  1654. addQueryPrefix: false,
  1655. allowDots: false,
  1656. charset: 'utf-8',
  1657. charsetSentinel: false,
  1658. delimiter: '&',
  1659. encode: true,
  1660. encoder: utils.encode,
  1661. encodeValuesOnly: false,
  1662. format: defaultFormat,
  1663. formatter: formats.formatters[defaultFormat],
  1664. indices: false,
  1665. serializeDate: function serializeDate(date) {
  1666. return toISO.call(date);
  1667. },
  1668. skipNulls: false,
  1669. strictNullHandling: false
  1670. };
  1671. var isNonNullishPrimitive = function isNonNullishPrimitive(v) {
  1672. return typeof v === 'string' || typeof v === 'number' || typeof v === 'boolean' || typeof v === 'symbol' || typeof v === 'bigint';
  1673. };
  1674. var sentinel = {};
  1675. var stringify = function stringify(object, prefix, generateArrayPrefix, commaRoundTrip, strictNullHandling, skipNulls, encoder, filter, sort, allowDots, serializeDate, format, formatter, encodeValuesOnly, charset, sideChannel) {
  1676. var obj = object;
  1677. var tmpSc = sideChannel;
  1678. var step = 0;
  1679. var findFlag = false;
  1680. while ((tmpSc = tmpSc.get(sentinel)) !== void undefined && !findFlag) {
  1681. var pos = tmpSc.get(object);
  1682. step += 1;
  1683. if (typeof pos !== 'undefined') {
  1684. if (pos === step) {
  1685. throw new RangeError('Cyclic object value');
  1686. } else {
  1687. findFlag = true;
  1688. }
  1689. }
  1690. if (typeof tmpSc.get(sentinel) === 'undefined') {
  1691. step = 0;
  1692. }
  1693. }
  1694. if (typeof filter === 'function') {
  1695. obj = filter(prefix, obj);
  1696. } else if (obj instanceof Date) {
  1697. obj = serializeDate(obj);
  1698. } else if (generateArrayPrefix === 'comma' && isArray(obj)) {
  1699. obj = utils.maybeMap(obj, function (value) {
  1700. if (value instanceof Date) {
  1701. return serializeDate(value);
  1702. }
  1703. return value;
  1704. });
  1705. }
  1706. if (obj === null) {
  1707. if (strictNullHandling) {
  1708. return encoder && !encodeValuesOnly ? encoder(prefix, defaults.encoder, charset, 'key', format) : prefix;
  1709. }
  1710. obj = '';
  1711. }
  1712. if (isNonNullishPrimitive(obj) || utils.isBuffer(obj)) {
  1713. if (encoder) {
  1714. var keyValue = encodeValuesOnly ? prefix : encoder(prefix, defaults.encoder, charset, 'key', format);
  1715. return [formatter(keyValue) + '=' + formatter(encoder(obj, defaults.encoder, charset, 'value', format))];
  1716. }
  1717. return [formatter(prefix) + '=' + formatter(String(obj))];
  1718. }
  1719. var values = [];
  1720. if (typeof obj === 'undefined') {
  1721. return values;
  1722. }
  1723. var objKeys;
  1724. if (generateArrayPrefix === 'comma' && isArray(obj)) {
  1725. if (encodeValuesOnly && encoder) {
  1726. obj = utils.maybeMap(obj, encoder);
  1727. }
  1728. objKeys = [{
  1729. value: obj.length > 0 ? obj.join(',') || null : void undefined
  1730. }];
  1731. } else if (isArray(filter)) {
  1732. objKeys = filter;
  1733. } else {
  1734. var keys = Object.keys(obj);
  1735. objKeys = sort ? keys.sort(sort) : keys;
  1736. }
  1737. var adjustedPrefix = commaRoundTrip && isArray(obj) && obj.length === 1 ? prefix + '[]' : prefix;
  1738. for (var j = 0; j < objKeys.length; ++j) {
  1739. var key = objKeys[j];
  1740. var value = typeof key === 'object' && typeof key.value !== 'undefined' ? key.value : obj[key];
  1741. if (skipNulls && value === null) {
  1742. continue;
  1743. }
  1744. var keyPrefix = isArray(obj) ? typeof generateArrayPrefix === 'function' ? generateArrayPrefix(adjustedPrefix, key) : adjustedPrefix : adjustedPrefix + (allowDots ? '.' + key : '[' + key + ']');
  1745. sideChannel.set(object, step);
  1746. var valueSideChannel = getSideChannel();
  1747. valueSideChannel.set(sentinel, sideChannel);
  1748. pushToArray(values, stringify(value, keyPrefix, generateArrayPrefix, commaRoundTrip, strictNullHandling, skipNulls, generateArrayPrefix === 'comma' && encodeValuesOnly && isArray(obj) ? null : encoder, filter, sort, allowDots, serializeDate, format, formatter, encodeValuesOnly, charset, valueSideChannel));
  1749. }
  1750. return values;
  1751. };
  1752. var normalizeStringifyOptions = function normalizeStringifyOptions(opts) {
  1753. if (!opts) {
  1754. return defaults;
  1755. }
  1756. if (opts.encoder !== null && typeof opts.encoder !== 'undefined' && typeof opts.encoder !== 'function') {
  1757. throw new TypeError('Encoder has to be a function.');
  1758. }
  1759. var charset = opts.charset || defaults.charset;
  1760. if (typeof opts.charset !== 'undefined' && opts.charset !== 'utf-8' && opts.charset !== 'iso-8859-1') {
  1761. throw new TypeError('The charset option must be either utf-8, iso-8859-1, or undefined');
  1762. }
  1763. var format = formats['default'];
  1764. if (typeof opts.format !== 'undefined') {
  1765. if (!has.call(formats.formatters, opts.format)) {
  1766. throw new TypeError('Unknown format option provided.');
  1767. }
  1768. format = opts.format;
  1769. }
  1770. var formatter = formats.formatters[format];
  1771. var filter = defaults.filter;
  1772. if (typeof opts.filter === 'function' || isArray(opts.filter)) {
  1773. filter = opts.filter;
  1774. }
  1775. return {
  1776. addQueryPrefix: typeof opts.addQueryPrefix === 'boolean' ? opts.addQueryPrefix : defaults.addQueryPrefix,
  1777. allowDots: typeof opts.allowDots === 'undefined' ? defaults.allowDots : !!opts.allowDots,
  1778. charset: charset,
  1779. charsetSentinel: typeof opts.charsetSentinel === 'boolean' ? opts.charsetSentinel : defaults.charsetSentinel,
  1780. delimiter: typeof opts.delimiter === 'undefined' ? defaults.delimiter : opts.delimiter,
  1781. encode: typeof opts.encode === 'boolean' ? opts.encode : defaults.encode,
  1782. encoder: typeof opts.encoder === 'function' ? opts.encoder : defaults.encoder,
  1783. encodeValuesOnly: typeof opts.encodeValuesOnly === 'boolean' ? opts.encodeValuesOnly : defaults.encodeValuesOnly,
  1784. filter: filter,
  1785. format: format,
  1786. formatter: formatter,
  1787. serializeDate: typeof opts.serializeDate === 'function' ? opts.serializeDate : defaults.serializeDate,
  1788. skipNulls: typeof opts.skipNulls === 'boolean' ? opts.skipNulls : defaults.skipNulls,
  1789. sort: typeof opts.sort === 'function' ? opts.sort : null,
  1790. strictNullHandling: typeof opts.strictNullHandling === 'boolean' ? opts.strictNullHandling : defaults.strictNullHandling
  1791. };
  1792. };
  1793. module.exports = function (object, opts) {
  1794. var obj = object;
  1795. var options = normalizeStringifyOptions(opts);
  1796. var objKeys;
  1797. var filter;
  1798. if (typeof options.filter === 'function') {
  1799. filter = options.filter;
  1800. obj = filter('', obj);
  1801. } else if (isArray(options.filter)) {
  1802. filter = options.filter;
  1803. objKeys = filter;
  1804. }
  1805. var keys = [];
  1806. if (typeof obj !== 'object' || obj === null) {
  1807. return '';
  1808. }
  1809. var arrayFormat;
  1810. if (opts && opts.arrayFormat in arrayPrefixGenerators) {
  1811. arrayFormat = opts.arrayFormat;
  1812. } else if (opts && 'indices' in opts) {
  1813. arrayFormat = opts.indices ? 'indices' : 'repeat';
  1814. } else {
  1815. arrayFormat = 'indices';
  1816. }
  1817. var generateArrayPrefix = arrayPrefixGenerators[arrayFormat];
  1818. if (opts && 'commaRoundTrip' in opts && typeof opts.commaRoundTrip !== 'boolean') {
  1819. throw new TypeError('`commaRoundTrip` must be a boolean, or absent');
  1820. }
  1821. var commaRoundTrip = generateArrayPrefix === 'comma' && opts && opts.commaRoundTrip;
  1822. if (!objKeys) {
  1823. objKeys = Object.keys(obj);
  1824. }
  1825. if (options.sort) {
  1826. objKeys.sort(options.sort);
  1827. }
  1828. var sideChannel = getSideChannel();
  1829. for (var i = 0; i < objKeys.length; ++i) {
  1830. var key = objKeys[i];
  1831. if (options.skipNulls && obj[key] === null) {
  1832. continue;
  1833. }
  1834. pushToArray(keys, stringify(obj[key], key, generateArrayPrefix, commaRoundTrip, options.strictNullHandling, options.skipNulls, options.encode ? options.encoder : null, options.filter, options.sort, options.allowDots, options.serializeDate, options.format, options.formatter, options.encodeValuesOnly, options.charset, sideChannel));
  1835. }
  1836. var joined = keys.join(options.delimiter);
  1837. var prefix = options.addQueryPrefix === true ? '?' : '';
  1838. if (options.charsetSentinel) {
  1839. if (options.charset === 'iso-8859-1') {
  1840. prefix += 'utf8=%26%2310003%3B&';
  1841. } else {
  1842. prefix += 'utf8=%E2%9C%93&';
  1843. }
  1844. }
  1845. return joined.length > 0 ? prefix + joined : '';
  1846. };
  1847. },{"./formats":15,"./utils":19,"side-channel":20}],19:[function(require,module,exports){
  1848. 'use strict';
  1849. var formats = require('./formats');
  1850. var has = Object.prototype.hasOwnProperty;
  1851. var isArray = Array.isArray;
  1852. var hexTable = function () {
  1853. var array = [];
  1854. for (var i = 0; i < 256; ++i) {
  1855. array.push('%' + ((i < 16 ? '0' : '') + i.toString(16)).toUpperCase());
  1856. }
  1857. return array;
  1858. }();
  1859. var compactQueue = function compactQueue(queue) {
  1860. while (queue.length > 1) {
  1861. var item = queue.pop();
  1862. var obj = item.obj[item.prop];
  1863. if (isArray(obj)) {
  1864. var compacted = [];
  1865. for (var j = 0; j < obj.length; ++j) {
  1866. if (typeof obj[j] !== 'undefined') {
  1867. compacted.push(obj[j]);
  1868. }
  1869. }
  1870. item.obj[item.prop] = compacted;
  1871. }
  1872. }
  1873. };
  1874. var arrayToObject = function arrayToObject(source, options) {
  1875. var obj = options && options.plainObjects ? Object.create(null) : {};
  1876. for (var i = 0; i < source.length; ++i) {
  1877. if (typeof source[i] !== 'undefined') {
  1878. obj[i] = source[i];
  1879. }
  1880. }
  1881. return obj;
  1882. };
  1883. var merge = function merge(target, source, options) {
  1884. if (!source) {
  1885. return target;
  1886. }
  1887. if (typeof source !== 'object') {
  1888. if (isArray(target)) {
  1889. target.push(source);
  1890. } else if (target && typeof target === 'object') {
  1891. if (options && (options.plainObjects || options.allowPrototypes) || !has.call(Object.prototype, source)) {
  1892. target[source] = true;
  1893. }
  1894. } else {
  1895. return [target, source];
  1896. }
  1897. return target;
  1898. }
  1899. if (!target || typeof target !== 'object') {
  1900. return [target].concat(source);
  1901. }
  1902. var mergeTarget = target;
  1903. if (isArray(target) && !isArray(source)) {
  1904. mergeTarget = arrayToObject(target, options);
  1905. }
  1906. if (isArray(target) && isArray(source)) {
  1907. source.forEach(function (item, i) {
  1908. if (has.call(target, i)) {
  1909. var targetItem = target[i];
  1910. if (targetItem && typeof targetItem === 'object' && item && typeof item === 'object') {
  1911. target[i] = merge(targetItem, item, options);
  1912. } else {
  1913. target.push(item);
  1914. }
  1915. } else {
  1916. target[i] = item;
  1917. }
  1918. });
  1919. return target;
  1920. }
  1921. return Object.keys(source).reduce(function (acc, key) {
  1922. var value = source[key];
  1923. if (has.call(acc, key)) {
  1924. acc[key] = merge(acc[key], value, options);
  1925. } else {
  1926. acc[key] = value;
  1927. }
  1928. return acc;
  1929. }, mergeTarget);
  1930. };
  1931. var assign = function assignSingleSource(target, source) {
  1932. return Object.keys(source).reduce(function (acc, key) {
  1933. acc[key] = source[key];
  1934. return acc;
  1935. }, target);
  1936. };
  1937. var decode = function (str, decoder, charset) {
  1938. var strWithoutPlus = str.replace(/\+/g, ' ');
  1939. if (charset === 'iso-8859-1') {
  1940. return strWithoutPlus.replace(/%[0-9a-f]{2}/gi, unescape);
  1941. }
  1942. try {
  1943. return decodeURIComponent(strWithoutPlus);
  1944. } catch (e) {
  1945. return strWithoutPlus;
  1946. }
  1947. };
  1948. var encode = function encode(str, defaultEncoder, charset, kind, format) {
  1949. if (str.length === 0) {
  1950. return str;
  1951. }
  1952. var string = str;
  1953. if (typeof str === 'symbol') {
  1954. string = Symbol.prototype.toString.call(str);
  1955. } else if (typeof str !== 'string') {
  1956. string = String(str);
  1957. }
  1958. if (charset === 'iso-8859-1') {
  1959. return escape(string).replace(/%u[0-9a-f]{4}/gi, function ($0) {
  1960. return '%26%23' + parseInt($0.slice(2), 16) + '%3B';
  1961. });
  1962. }
  1963. var out = '';
  1964. for (var i = 0; i < string.length; ++i) {
  1965. var c = string.charCodeAt(i);
  1966. if (c === 0x2D || c === 0x2E || c === 0x5F || c === 0x7E || c >= 0x30 && c <= 0x39 || c >= 0x41 && c <= 0x5A || c >= 0x61 && c <= 0x7A || format === formats.RFC1738 && (c === 0x28 || c === 0x29)) {
  1967. out += string.charAt(i);
  1968. continue;
  1969. }
  1970. if (c < 0x80) {
  1971. out = out + hexTable[c];
  1972. continue;
  1973. }
  1974. if (c < 0x800) {
  1975. out = out + (hexTable[0xC0 | c >> 6] + hexTable[0x80 | c & 0x3F]);
  1976. continue;
  1977. }
  1978. if (c < 0xD800 || c >= 0xE000) {
  1979. out = out + (hexTable[0xE0 | c >> 12] + hexTable[0x80 | c >> 6 & 0x3F] + hexTable[0x80 | c & 0x3F]);
  1980. continue;
  1981. }
  1982. i += 1;
  1983. c = 0x10000 + ((c & 0x3FF) << 10 | string.charCodeAt(i) & 0x3FF);
  1984. out += hexTable[0xF0 | c >> 18] + hexTable[0x80 | c >> 12 & 0x3F] + hexTable[0x80 | c >> 6 & 0x3F] + hexTable[0x80 | c & 0x3F];
  1985. }
  1986. return out;
  1987. };
  1988. var compact = function compact(value) {
  1989. var queue = [{
  1990. obj: {
  1991. o: value
  1992. },
  1993. prop: 'o'
  1994. }];
  1995. var refs = [];
  1996. for (var i = 0; i < queue.length; ++i) {
  1997. var item = queue[i];
  1998. var obj = item.obj[item.prop];
  1999. var keys = Object.keys(obj);
  2000. for (var j = 0; j < keys.length; ++j) {
  2001. var key = keys[j];
  2002. var val = obj[key];
  2003. if (typeof val === 'object' && val !== null && refs.indexOf(val) === -1) {
  2004. queue.push({
  2005. obj: obj,
  2006. prop: key
  2007. });
  2008. refs.push(val);
  2009. }
  2010. }
  2011. }
  2012. compactQueue(queue);
  2013. return value;
  2014. };
  2015. var isRegExp = function isRegExp(obj) {
  2016. return Object.prototype.toString.call(obj) === '[object RegExp]';
  2017. };
  2018. var isBuffer = function isBuffer(obj) {
  2019. if (!obj || typeof obj !== 'object') {
  2020. return false;
  2021. }
  2022. return !!(obj.constructor && obj.constructor.isBuffer && obj.constructor.isBuffer(obj));
  2023. };
  2024. var combine = function combine(a, b) {
  2025. return [].concat(a, b);
  2026. };
  2027. var maybeMap = function maybeMap(val, fn) {
  2028. if (isArray(val)) {
  2029. var mapped = [];
  2030. for (var i = 0; i < val.length; i += 1) {
  2031. mapped.push(fn(val[i]));
  2032. }
  2033. return mapped;
  2034. }
  2035. return fn(val);
  2036. };
  2037. module.exports = {
  2038. arrayToObject: arrayToObject,
  2039. assign: assign,
  2040. combine: combine,
  2041. compact: compact,
  2042. decode: decode,
  2043. encode: encode,
  2044. isBuffer: isBuffer,
  2045. isRegExp: isRegExp,
  2046. maybeMap: maybeMap,
  2047. merge: merge
  2048. };
  2049. },{"./formats":15}],20:[function(require,module,exports){
  2050. 'use strict';
  2051. var GetIntrinsic = require('get-intrinsic');
  2052. var callBound = require('call-bind/callBound');
  2053. var inspect = require('object-inspect');
  2054. var $TypeError = GetIntrinsic('%TypeError%');
  2055. var $WeakMap = GetIntrinsic('%WeakMap%', true);
  2056. var $Map = GetIntrinsic('%Map%', true);
  2057. var $weakMapGet = callBound('WeakMap.prototype.get', true);
  2058. var $weakMapSet = callBound('WeakMap.prototype.set', true);
  2059. var $weakMapHas = callBound('WeakMap.prototype.has', true);
  2060. var $mapGet = callBound('Map.prototype.get', true);
  2061. var $mapSet = callBound('Map.prototype.set', true);
  2062. var $mapHas = callBound('Map.prototype.has', true);
  2063. var listGetNode = function (list, key) {
  2064. for (var prev = list, curr; (curr = prev.next) !== null; prev = curr) {
  2065. if (curr.key === key) {
  2066. prev.next = curr.next;
  2067. curr.next = list.next;
  2068. list.next = curr;
  2069. return curr;
  2070. }
  2071. }
  2072. };
  2073. var listGet = function (objects, key) {
  2074. var node = listGetNode(objects, key);
  2075. return node && node.value;
  2076. };
  2077. var listSet = function (objects, key, value) {
  2078. var node = listGetNode(objects, key);
  2079. if (node) {
  2080. node.value = value;
  2081. } else {
  2082. objects.next = {
  2083. key: key,
  2084. next: objects.next,
  2085. value: value
  2086. };
  2087. }
  2088. };
  2089. var listHas = function (objects, key) {
  2090. return !!listGetNode(objects, key);
  2091. };
  2092. module.exports = function getSideChannel() {
  2093. var $wm;
  2094. var $m;
  2095. var $o;
  2096. var channel = {
  2097. assert: function (key) {
  2098. if (!channel.has(key)) {
  2099. throw new $TypeError('Side channel does not contain ' + inspect(key));
  2100. }
  2101. },
  2102. get: function (key) {
  2103. if ($WeakMap && key && (typeof key === 'object' || typeof key === 'function')) {
  2104. if ($wm) {
  2105. return $weakMapGet($wm, key);
  2106. }
  2107. } else if ($Map) {
  2108. if ($m) {
  2109. return $mapGet($m, key);
  2110. }
  2111. } else {
  2112. if ($o) {
  2113. return listGet($o, key);
  2114. }
  2115. }
  2116. },
  2117. has: function (key) {
  2118. if ($WeakMap && key && (typeof key === 'object' || typeof key === 'function')) {
  2119. if ($wm) {
  2120. return $weakMapHas($wm, key);
  2121. }
  2122. } else if ($Map) {
  2123. if ($m) {
  2124. return $mapHas($m, key);
  2125. }
  2126. } else {
  2127. if ($o) {
  2128. return listHas($o, key);
  2129. }
  2130. }
  2131. return false;
  2132. },
  2133. set: function (key, value) {
  2134. if ($WeakMap && key && (typeof key === 'object' || typeof key === 'function')) {
  2135. if (!$wm) {
  2136. $wm = new $WeakMap();
  2137. }
  2138. $weakMapSet($wm, key, value);
  2139. } else if ($Map) {
  2140. if (!$m) {
  2141. $m = new $Map();
  2142. }
  2143. $mapSet($m, key, value);
  2144. } else {
  2145. if (!$o) {
  2146. $o = {
  2147. key: {},
  2148. next: null
  2149. };
  2150. }
  2151. listSet($o, key, value);
  2152. }
  2153. }
  2154. };
  2155. return channel;
  2156. };
  2157. },{"call-bind/callBound":2,"get-intrinsic":8,"object-inspect":13}],21:[function(require,module,exports){
  2158. function Agent() {
  2159. this._defaults = [];
  2160. }
  2161. for (const fn of ['use', 'on', 'once', 'set', 'query', 'type', 'accept', 'auth', 'withCredentials', 'sortQuery', 'retry', 'ok', 'redirects', 'timeout', 'buffer', 'serialize', 'parse', 'ca', 'key', 'pfx', 'cert', 'disableTLSCerts']) {
  2162. Agent.prototype[fn] = function () {
  2163. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  2164. args[_key] = arguments[_key];
  2165. }
  2166. this._defaults.push({
  2167. fn,
  2168. args
  2169. });
  2170. return this;
  2171. };
  2172. }
  2173. Agent.prototype._setDefaults = function (request) {
  2174. for (const def of this._defaults) {
  2175. request[def.fn](...def.args);
  2176. }
  2177. };
  2178. module.exports = Agent;
  2179. },{}],22:[function(require,module,exports){
  2180. let root;
  2181. if (typeof window !== 'undefined') {
  2182. root = window;
  2183. } else if (typeof self === 'undefined') {
  2184. console.warn('Using browser-only version of superagent in non-browser environment');
  2185. root = this;
  2186. } else {
  2187. root = self;
  2188. }
  2189. const Emitter = require('component-emitter');
  2190. const safeStringify = require('fast-safe-stringify');
  2191. const qs = require('qs');
  2192. const RequestBase = require('./request-base');
  2193. const {
  2194. isObject,
  2195. mixin,
  2196. hasOwn
  2197. } = require('./utils');
  2198. const ResponseBase = require('./response-base');
  2199. const Agent = require('./agent-base');
  2200. function noop() {}
  2201. module.exports = function (method, url) {
  2202. if (typeof url === 'function') {
  2203. return new exports.Request('GET', method).end(url);
  2204. }
  2205. if (arguments.length === 1) {
  2206. return new exports.Request('GET', method);
  2207. }
  2208. return new exports.Request(method, url);
  2209. };
  2210. exports = module.exports;
  2211. const request = exports;
  2212. exports.Request = Request;
  2213. request.getXHR = () => {
  2214. if (root.XMLHttpRequest) {
  2215. return new root.XMLHttpRequest();
  2216. }
  2217. throw new Error('Browser-only version of superagent could not find XHR');
  2218. };
  2219. const trim = ''.trim ? s => s.trim() : s => s.replace(/(^\s*|\s*$)/g, '');
  2220. function serialize(object) {
  2221. if (!isObject(object)) return object;
  2222. const pairs = [];
  2223. for (const key in object) {
  2224. if (hasOwn(object, key)) pushEncodedKeyValuePair(pairs, key, object[key]);
  2225. }
  2226. return pairs.join('&');
  2227. }
  2228. function pushEncodedKeyValuePair(pairs, key, value) {
  2229. if (value === undefined) return;
  2230. if (value === null) {
  2231. pairs.push(encodeURI(key));
  2232. return;
  2233. }
  2234. if (Array.isArray(value)) {
  2235. for (const v of value) {
  2236. pushEncodedKeyValuePair(pairs, key, v);
  2237. }
  2238. } else if (isObject(value)) {
  2239. for (const subkey in value) {
  2240. if (hasOwn(value, subkey)) pushEncodedKeyValuePair(pairs, `${key}[${subkey}]`, value[subkey]);
  2241. }
  2242. } else {
  2243. pairs.push(encodeURI(key) + '=' + encodeURIComponent(value));
  2244. }
  2245. }
  2246. request.serializeObject = serialize;
  2247. function parseString(string_) {
  2248. const object = {};
  2249. const pairs = string_.split('&');
  2250. let pair;
  2251. let pos;
  2252. for (let i = 0, length_ = pairs.length; i < length_; ++i) {
  2253. pair = pairs[i];
  2254. pos = pair.indexOf('=');
  2255. if (pos === -1) {
  2256. object[decodeURIComponent(pair)] = '';
  2257. } else {
  2258. object[decodeURIComponent(pair.slice(0, pos))] = decodeURIComponent(pair.slice(pos + 1));
  2259. }
  2260. }
  2261. return object;
  2262. }
  2263. request.parseString = parseString;
  2264. request.types = {
  2265. html: 'text/html',
  2266. json: 'application/json',
  2267. xml: 'text/xml',
  2268. urlencoded: 'application/x-www-form-urlencoded',
  2269. form: 'application/x-www-form-urlencoded',
  2270. 'form-data': 'application/x-www-form-urlencoded'
  2271. };
  2272. request.serialize = {
  2273. 'application/x-www-form-urlencoded': qs.stringify,
  2274. 'application/json': safeStringify
  2275. };
  2276. request.parse = {
  2277. 'application/x-www-form-urlencoded': parseString,
  2278. 'application/json': JSON.parse
  2279. };
  2280. function parseHeader(string_) {
  2281. const lines = string_.split(/\r?\n/);
  2282. const fields = {};
  2283. let index;
  2284. let line;
  2285. let field;
  2286. let value;
  2287. for (let i = 0, length_ = lines.length; i < length_; ++i) {
  2288. line = lines[i];
  2289. index = line.indexOf(':');
  2290. if (index === -1) {
  2291. continue;
  2292. }
  2293. field = line.slice(0, index).toLowerCase();
  2294. value = trim(line.slice(index + 1));
  2295. fields[field] = value;
  2296. }
  2297. return fields;
  2298. }
  2299. function isJSON(mime) {
  2300. return /[/+]json($|[^-\w])/i.test(mime);
  2301. }
  2302. function Response(request_) {
  2303. this.req = request_;
  2304. this.xhr = this.req.xhr;
  2305. this.text = this.req.method !== 'HEAD' && (this.xhr.responseType === '' || this.xhr.responseType === 'text') || typeof this.xhr.responseType === 'undefined' ? this.xhr.responseText : null;
  2306. this.statusText = this.req.xhr.statusText;
  2307. let {
  2308. status
  2309. } = this.xhr;
  2310. if (status === 1223) {
  2311. status = 204;
  2312. }
  2313. this._setStatusProperties(status);
  2314. this.headers = parseHeader(this.xhr.getAllResponseHeaders());
  2315. this.header = this.headers;
  2316. this.header['content-type'] = this.xhr.getResponseHeader('content-type');
  2317. this._setHeaderProperties(this.header);
  2318. if (this.text === null && request_._responseType) {
  2319. this.body = this.xhr.response;
  2320. } else {
  2321. this.body = this.req.method === 'HEAD' ? null : this._parseBody(this.text ? this.text : this.xhr.response);
  2322. }
  2323. }
  2324. mixin(Response.prototype, ResponseBase.prototype);
  2325. Response.prototype._parseBody = function (string_) {
  2326. let parse = request.parse[this.type];
  2327. if (this.req._parser) {
  2328. return this.req._parser(this, string_);
  2329. }
  2330. if (!parse && isJSON(this.type)) {
  2331. parse = request.parse['application/json'];
  2332. }
  2333. return parse && string_ && (string_.length > 0 || string_ instanceof Object) ? parse(string_) : null;
  2334. };
  2335. Response.prototype.toError = function () {
  2336. const {
  2337. req
  2338. } = this;
  2339. const {
  2340. method
  2341. } = req;
  2342. const {
  2343. url
  2344. } = req;
  2345. const message = `cannot ${method} ${url} (${this.status})`;
  2346. const error = new Error(message);
  2347. error.status = this.status;
  2348. error.method = method;
  2349. error.url = url;
  2350. return error;
  2351. };
  2352. request.Response = Response;
  2353. function Request(method, url) {
  2354. const self = this;
  2355. this._query = this._query || [];
  2356. this.method = method;
  2357. this.url = url;
  2358. this.header = {};
  2359. this._header = {};
  2360. this.on('end', () => {
  2361. let error = null;
  2362. let res = null;
  2363. try {
  2364. res = new Response(self);
  2365. } catch (err) {
  2366. error = new Error('Parser is unable to parse the response');
  2367. error.parse = true;
  2368. error.original = err;
  2369. if (self.xhr) {
  2370. error.rawResponse = typeof self.xhr.responseType === 'undefined' ? self.xhr.responseText : self.xhr.response;
  2371. error.status = self.xhr.status ? self.xhr.status : null;
  2372. error.statusCode = error.status;
  2373. } else {
  2374. error.rawResponse = null;
  2375. error.status = null;
  2376. }
  2377. return self.callback(error);
  2378. }
  2379. self.emit('response', res);
  2380. let new_error;
  2381. try {
  2382. if (!self._isResponseOK(res)) {
  2383. new_error = new Error(res.statusText || res.text || 'Unsuccessful HTTP response');
  2384. }
  2385. } catch (err) {
  2386. new_error = err;
  2387. }
  2388. if (new_error) {
  2389. new_error.original = error;
  2390. new_error.response = res;
  2391. new_error.status = new_error.status || res.status;
  2392. self.callback(new_error, res);
  2393. } else {
  2394. self.callback(null, res);
  2395. }
  2396. });
  2397. }
  2398. Emitter(Request.prototype);
  2399. mixin(Request.prototype, RequestBase.prototype);
  2400. Request.prototype.type = function (type) {
  2401. this.set('Content-Type', request.types[type] || type);
  2402. return this;
  2403. };
  2404. Request.prototype.accept = function (type) {
  2405. this.set('Accept', request.types[type] || type);
  2406. return this;
  2407. };
  2408. Request.prototype.auth = function (user, pass, options) {
  2409. if (arguments.length === 1) pass = '';
  2410. if (typeof pass === 'object' && pass !== null) {
  2411. options = pass;
  2412. pass = '';
  2413. }
  2414. if (!options) {
  2415. options = {
  2416. type: typeof btoa === 'function' ? 'basic' : 'auto'
  2417. };
  2418. }
  2419. const encoder = options.encoder ? options.encoder : string => {
  2420. if (typeof btoa === 'function') {
  2421. return btoa(string);
  2422. }
  2423. throw new Error('Cannot use basic auth, btoa is not a function');
  2424. };
  2425. return this._auth(user, pass, options, encoder);
  2426. };
  2427. Request.prototype.query = function (value) {
  2428. if (typeof value !== 'string') value = serialize(value);
  2429. if (value) this._query.push(value);
  2430. return this;
  2431. };
  2432. Request.prototype.attach = function (field, file, options) {
  2433. if (file) {
  2434. if (this._data) {
  2435. throw new Error("superagent can't mix .send() and .attach()");
  2436. }
  2437. this._getFormData().append(field, file, options || file.name);
  2438. }
  2439. return this;
  2440. };
  2441. Request.prototype._getFormData = function () {
  2442. if (!this._formData) {
  2443. this._formData = new root.FormData();
  2444. }
  2445. return this._formData;
  2446. };
  2447. Request.prototype.callback = function (error, res) {
  2448. if (this._shouldRetry(error, res)) {
  2449. return this._retry();
  2450. }
  2451. const fn = this._callback;
  2452. this.clearTimeout();
  2453. if (error) {
  2454. if (this._maxRetries) error.retries = this._retries - 1;
  2455. this.emit('error', error);
  2456. }
  2457. fn(error, res);
  2458. };
  2459. Request.prototype.crossDomainError = function () {
  2460. const error = new Error('Request has been terminated\nPossible causes: the network is offline, Origin is not allowed by Access-Control-Allow-Origin, the page is being unloaded, etc.');
  2461. error.crossDomain = true;
  2462. error.status = this.status;
  2463. error.method = this.method;
  2464. error.url = this.url;
  2465. this.callback(error);
  2466. };
  2467. Request.prototype.agent = function () {
  2468. console.warn('This is not supported in browser version of superagent');
  2469. return this;
  2470. };
  2471. Request.prototype.ca = Request.prototype.agent;
  2472. Request.prototype.buffer = Request.prototype.ca;
  2473. Request.prototype.write = () => {
  2474. throw new Error('Streaming is not supported in browser version of superagent');
  2475. };
  2476. Request.prototype.pipe = Request.prototype.write;
  2477. Request.prototype._isHost = function (object) {
  2478. return object && typeof object === 'object' && !Array.isArray(object) && Object.prototype.toString.call(object) !== '[object Object]';
  2479. };
  2480. Request.prototype.end = function (fn) {
  2481. if (this._endCalled) {
  2482. console.warn('Warning: .end() was called twice. This is not supported in superagent');
  2483. }
  2484. this._endCalled = true;
  2485. this._callback = fn || noop;
  2486. this._finalizeQueryString();
  2487. this._end();
  2488. };
  2489. Request.prototype._setUploadTimeout = function () {
  2490. const self = this;
  2491. if (this._uploadTimeout && !this._uploadTimeoutTimer) {
  2492. this._uploadTimeoutTimer = setTimeout(() => {
  2493. self._timeoutError('Upload timeout of ', self._uploadTimeout, 'ETIMEDOUT');
  2494. }, this._uploadTimeout);
  2495. }
  2496. };
  2497. Request.prototype._end = function () {
  2498. if (this._aborted) return this.callback(new Error('The request has been aborted even before .end() was called'));
  2499. const self = this;
  2500. this.xhr = request.getXHR();
  2501. const {
  2502. xhr
  2503. } = this;
  2504. let data = this._formData || this._data;
  2505. this._setTimeouts();
  2506. xhr.addEventListener('readystatechange', () => {
  2507. const {
  2508. readyState
  2509. } = xhr;
  2510. if (readyState >= 2 && self._responseTimeoutTimer) {
  2511. clearTimeout(self._responseTimeoutTimer);
  2512. }
  2513. if (readyState !== 4) {
  2514. return;
  2515. }
  2516. let status;
  2517. try {
  2518. status = xhr.status;
  2519. } catch (err) {
  2520. status = 0;
  2521. }
  2522. if (!status) {
  2523. if (self.timedout || self._aborted) return;
  2524. return self.crossDomainError();
  2525. }
  2526. self.emit('end');
  2527. });
  2528. const handleProgress = (direction, e) => {
  2529. if (e.total > 0) {
  2530. e.percent = e.loaded / e.total * 100;
  2531. if (e.percent === 100) {
  2532. clearTimeout(self._uploadTimeoutTimer);
  2533. }
  2534. }
  2535. e.direction = direction;
  2536. self.emit('progress', e);
  2537. };
  2538. if (this.hasListeners('progress')) {
  2539. try {
  2540. xhr.addEventListener('progress', handleProgress.bind(null, 'download'));
  2541. if (xhr.upload) {
  2542. xhr.upload.addEventListener('progress', handleProgress.bind(null, 'upload'));
  2543. }
  2544. } catch (err) {}
  2545. }
  2546. if (xhr.upload) {
  2547. this._setUploadTimeout();
  2548. }
  2549. try {
  2550. if (this.username && this.password) {
  2551. xhr.open(this.method, this.url, true, this.username, this.password);
  2552. } else {
  2553. xhr.open(this.method, this.url, true);
  2554. }
  2555. } catch (err) {
  2556. return this.callback(err);
  2557. }
  2558. if (this._withCredentials) xhr.withCredentials = true;
  2559. if (!this._formData && this.method !== 'GET' && this.method !== 'HEAD' && typeof data !== 'string' && !this._isHost(data)) {
  2560. const contentType = this._header['content-type'];
  2561. let serialize = this._serializer || request.serialize[contentType ? contentType.split(';')[0] : ''];
  2562. if (!serialize && isJSON(contentType)) {
  2563. serialize = request.serialize['application/json'];
  2564. }
  2565. if (serialize) data = serialize(data);
  2566. }
  2567. for (const field in this.header) {
  2568. if (this.header[field] === null) continue;
  2569. if (hasOwn(this.header, field)) xhr.setRequestHeader(field, this.header[field]);
  2570. }
  2571. if (this._responseType) {
  2572. xhr.responseType = this._responseType;
  2573. }
  2574. this.emit('request', this);
  2575. xhr.send(typeof data === 'undefined' ? null : data);
  2576. };
  2577. request.agent = () => new Agent();
  2578. for (const method of ['GET', 'POST', 'OPTIONS', 'PATCH', 'PUT', 'DELETE']) {
  2579. Agent.prototype[method.toLowerCase()] = function (url, fn) {
  2580. const request_ = new request.Request(method, url);
  2581. this._setDefaults(request_);
  2582. if (fn) {
  2583. request_.end(fn);
  2584. }
  2585. return request_;
  2586. };
  2587. }
  2588. Agent.prototype.del = Agent.prototype.delete;
  2589. request.get = (url, data, fn) => {
  2590. const request_ = request('GET', url);
  2591. if (typeof data === 'function') {
  2592. fn = data;
  2593. data = null;
  2594. }
  2595. if (data) request_.query(data);
  2596. if (fn) request_.end(fn);
  2597. return request_;
  2598. };
  2599. request.head = (url, data, fn) => {
  2600. const request_ = request('HEAD', url);
  2601. if (typeof data === 'function') {
  2602. fn = data;
  2603. data = null;
  2604. }
  2605. if (data) request_.query(data);
  2606. if (fn) request_.end(fn);
  2607. return request_;
  2608. };
  2609. request.options = (url, data, fn) => {
  2610. const request_ = request('OPTIONS', url);
  2611. if (typeof data === 'function') {
  2612. fn = data;
  2613. data = null;
  2614. }
  2615. if (data) request_.send(data);
  2616. if (fn) request_.end(fn);
  2617. return request_;
  2618. };
  2619. function del(url, data, fn) {
  2620. const request_ = request('DELETE', url);
  2621. if (typeof data === 'function') {
  2622. fn = data;
  2623. data = null;
  2624. }
  2625. if (data) request_.send(data);
  2626. if (fn) request_.end(fn);
  2627. return request_;
  2628. }
  2629. request.del = del;
  2630. request.delete = del;
  2631. request.patch = (url, data, fn) => {
  2632. const request_ = request('PATCH', url);
  2633. if (typeof data === 'function') {
  2634. fn = data;
  2635. data = null;
  2636. }
  2637. if (data) request_.send(data);
  2638. if (fn) request_.end(fn);
  2639. return request_;
  2640. };
  2641. request.post = (url, data, fn) => {
  2642. const request_ = request('POST', url);
  2643. if (typeof data === 'function') {
  2644. fn = data;
  2645. data = null;
  2646. }
  2647. if (data) request_.send(data);
  2648. if (fn) request_.end(fn);
  2649. return request_;
  2650. };
  2651. request.put = (url, data, fn) => {
  2652. const request_ = request('PUT', url);
  2653. if (typeof data === 'function') {
  2654. fn = data;
  2655. data = null;
  2656. }
  2657. if (data) request_.send(data);
  2658. if (fn) request_.end(fn);
  2659. return request_;
  2660. };
  2661. },{"./agent-base":21,"./request-base":23,"./response-base":24,"./utils":25,"component-emitter":4,"fast-safe-stringify":5,"qs":16}],23:[function(require,module,exports){
  2662. (function (process){(function (){
  2663. const semver = require('semver');
  2664. const {
  2665. isObject,
  2666. hasOwn
  2667. } = require('./utils');
  2668. module.exports = RequestBase;
  2669. function RequestBase() {}
  2670. RequestBase.prototype.clearTimeout = function () {
  2671. clearTimeout(this._timer);
  2672. clearTimeout(this._responseTimeoutTimer);
  2673. clearTimeout(this._uploadTimeoutTimer);
  2674. delete this._timer;
  2675. delete this._responseTimeoutTimer;
  2676. delete this._uploadTimeoutTimer;
  2677. return this;
  2678. };
  2679. RequestBase.prototype.parse = function (fn) {
  2680. this._parser = fn;
  2681. return this;
  2682. };
  2683. RequestBase.prototype.responseType = function (value) {
  2684. this._responseType = value;
  2685. return this;
  2686. };
  2687. RequestBase.prototype.serialize = function (fn) {
  2688. this._serializer = fn;
  2689. return this;
  2690. };
  2691. RequestBase.prototype.timeout = function (options) {
  2692. if (!options || typeof options !== 'object') {
  2693. this._timeout = options;
  2694. this._responseTimeout = 0;
  2695. this._uploadTimeout = 0;
  2696. return this;
  2697. }
  2698. for (const option in options) {
  2699. if (hasOwn(options, option)) {
  2700. switch (option) {
  2701. case 'deadline':
  2702. this._timeout = options.deadline;
  2703. break;
  2704. case 'response':
  2705. this._responseTimeout = options.response;
  2706. break;
  2707. case 'upload':
  2708. this._uploadTimeout = options.upload;
  2709. break;
  2710. default:
  2711. console.warn('Unknown timeout option', option);
  2712. }
  2713. }
  2714. }
  2715. return this;
  2716. };
  2717. RequestBase.prototype.retry = function (count, fn) {
  2718. if (arguments.length === 0 || count === true) count = 1;
  2719. if (count <= 0) count = 0;
  2720. this._maxRetries = count;
  2721. this._retries = 0;
  2722. this._retryCallback = fn;
  2723. return this;
  2724. };
  2725. const ERROR_CODES = new Set(['ETIMEDOUT', 'ECONNRESET', 'EADDRINUSE', 'ECONNREFUSED', 'EPIPE', 'ENOTFOUND', 'ENETUNREACH', 'EAI_AGAIN']);
  2726. const STATUS_CODES = new Set([408, 413, 429, 500, 502, 503, 504, 521, 522, 524]);
  2727. RequestBase.prototype._shouldRetry = function (error, res) {
  2728. if (!this._maxRetries || this._retries++ >= this._maxRetries) {
  2729. return false;
  2730. }
  2731. if (this._retryCallback) {
  2732. try {
  2733. const override = this._retryCallback(error, res);
  2734. if (override === true) return true;
  2735. if (override === false) return false;
  2736. } catch (err) {
  2737. console.error(err);
  2738. }
  2739. }
  2740. if (res && res.status && STATUS_CODES.has(res.status)) return true;
  2741. if (error) {
  2742. if (error.code && ERROR_CODES.has(error.code)) return true;
  2743. if (error.timeout && error.code === 'ECONNABORTED') return true;
  2744. if (error.crossDomain) return true;
  2745. }
  2746. return false;
  2747. };
  2748. RequestBase.prototype._retry = function () {
  2749. this.clearTimeout();
  2750. if (this.req) {
  2751. this.req = null;
  2752. this.req = this.request();
  2753. }
  2754. this._aborted = false;
  2755. this.timedout = false;
  2756. this.timedoutError = null;
  2757. return this._end();
  2758. };
  2759. RequestBase.prototype.then = function (resolve, reject) {
  2760. if (!this._fullfilledPromise) {
  2761. const self = this;
  2762. if (this._endCalled) {
  2763. console.warn('Warning: superagent request was sent twice, because both .end() and .then() were called. Never call .end() if you use promises');
  2764. }
  2765. this._fullfilledPromise = new Promise((resolve, reject) => {
  2766. self.on('abort', () => {
  2767. if (this._maxRetries && this._maxRetries > this._retries) {
  2768. return;
  2769. }
  2770. if (this.timedout && this.timedoutError) {
  2771. reject(this.timedoutError);
  2772. return;
  2773. }
  2774. const error = new Error('Aborted');
  2775. error.code = 'ABORTED';
  2776. error.status = this.status;
  2777. error.method = this.method;
  2778. error.url = this.url;
  2779. reject(error);
  2780. });
  2781. self.end((error, res) => {
  2782. if (error) reject(error);else resolve(res);
  2783. });
  2784. });
  2785. }
  2786. return this._fullfilledPromise.then(resolve, reject);
  2787. };
  2788. RequestBase.prototype.catch = function (callback) {
  2789. return this.then(undefined, callback);
  2790. };
  2791. RequestBase.prototype.use = function (fn) {
  2792. fn(this);
  2793. return this;
  2794. };
  2795. RequestBase.prototype.ok = function (callback) {
  2796. if (typeof callback !== 'function') throw new Error('Callback required');
  2797. this._okCallback = callback;
  2798. return this;
  2799. };
  2800. RequestBase.prototype._isResponseOK = function (res) {
  2801. if (!res) {
  2802. return false;
  2803. }
  2804. if (this._okCallback) {
  2805. return this._okCallback(res);
  2806. }
  2807. return res.status >= 200 && res.status < 300;
  2808. };
  2809. RequestBase.prototype.get = function (field) {
  2810. return this._header[field.toLowerCase()];
  2811. };
  2812. RequestBase.prototype.getHeader = RequestBase.prototype.get;
  2813. RequestBase.prototype.set = function (field, value) {
  2814. if (isObject(field)) {
  2815. for (const key in field) {
  2816. if (hasOwn(field, key)) this.set(key, field[key]);
  2817. }
  2818. return this;
  2819. }
  2820. this._header[field.toLowerCase()] = value;
  2821. this.header[field] = value;
  2822. return this;
  2823. };
  2824. RequestBase.prototype.unset = function (field) {
  2825. delete this._header[field.toLowerCase()];
  2826. delete this.header[field];
  2827. return this;
  2828. };
  2829. RequestBase.prototype.field = function (name, value, options) {
  2830. if (name === null || undefined === name) {
  2831. throw new Error('.field(name, val) name can not be empty');
  2832. }
  2833. if (this._data) {
  2834. throw new Error(".field() can't be used if .send() is used. Please use only .send() or only .field() & .attach()");
  2835. }
  2836. if (isObject(name)) {
  2837. for (const key in name) {
  2838. if (hasOwn(name, key)) this.field(key, name[key]);
  2839. }
  2840. return this;
  2841. }
  2842. if (Array.isArray(value)) {
  2843. for (const i in value) {
  2844. if (hasOwn(value, i)) this.field(name, value[i]);
  2845. }
  2846. return this;
  2847. }
  2848. if (value === null || undefined === value) {
  2849. throw new Error('.field(name, val) val can not be empty');
  2850. }
  2851. if (typeof value === 'boolean') {
  2852. value = String(value);
  2853. }
  2854. if (options) this._getFormData().append(name, value, options);else this._getFormData().append(name, value);
  2855. return this;
  2856. };
  2857. RequestBase.prototype.abort = function () {
  2858. if (this._aborted) {
  2859. return this;
  2860. }
  2861. this._aborted = true;
  2862. if (this.xhr) this.xhr.abort();
  2863. if (this.req) {
  2864. if (semver.gte(process.version, 'v13.0.0') && semver.lt(process.version, 'v14.0.0')) {
  2865. throw new Error('Superagent does not work in v13 properly with abort() due to Node.js core changes');
  2866. }
  2867. this.req.abort();
  2868. }
  2869. this.clearTimeout();
  2870. this.emit('abort');
  2871. return this;
  2872. };
  2873. RequestBase.prototype._auth = function (user, pass, options, base64Encoder) {
  2874. switch (options.type) {
  2875. case 'basic':
  2876. this.set('Authorization', `Basic ${base64Encoder(`${user}:${pass}`)}`);
  2877. break;
  2878. case 'auto':
  2879. this.username = user;
  2880. this.password = pass;
  2881. break;
  2882. case 'bearer':
  2883. this.set('Authorization', `Bearer ${user}`);
  2884. break;
  2885. default:
  2886. break;
  2887. }
  2888. return this;
  2889. };
  2890. RequestBase.prototype.withCredentials = function (on) {
  2891. if (on === undefined) on = true;
  2892. this._withCredentials = on;
  2893. return this;
  2894. };
  2895. RequestBase.prototype.redirects = function (n) {
  2896. this._maxRedirects = n;
  2897. return this;
  2898. };
  2899. RequestBase.prototype.maxResponseSize = function (n) {
  2900. if (typeof n !== 'number') {
  2901. throw new TypeError('Invalid argument');
  2902. }
  2903. this._maxResponseSize = n;
  2904. return this;
  2905. };
  2906. RequestBase.prototype.toJSON = function () {
  2907. return {
  2908. method: this.method,
  2909. url: this.url,
  2910. data: this._data,
  2911. headers: this._header
  2912. };
  2913. };
  2914. RequestBase.prototype.send = function (data) {
  2915. const isObject_ = isObject(data);
  2916. let type = this._header['content-type'];
  2917. if (this._formData) {
  2918. throw new Error(".send() can't be used if .attach() or .field() is used. Please use only .send() or only .field() & .attach()");
  2919. }
  2920. if (isObject_ && !this._data) {
  2921. if (Array.isArray(data)) {
  2922. this._data = [];
  2923. } else if (!this._isHost(data)) {
  2924. this._data = {};
  2925. }
  2926. } else if (data && this._data && this._isHost(this._data)) {
  2927. throw new Error("Can't merge these send calls");
  2928. }
  2929. if (isObject_ && isObject(this._data)) {
  2930. for (const key in data) {
  2931. if (typeof data[key] == 'bigint' && !data[key].toJSON) throw new Error('Cannot serialize BigInt value to json');
  2932. if (hasOwn(data, key)) this._data[key] = data[key];
  2933. }
  2934. } else if (typeof data === 'bigint') throw new Error("Cannot send value of type BigInt");else if (typeof data === 'string') {
  2935. if (!type) this.type('form');
  2936. type = this._header['content-type'];
  2937. if (type) type = type.toLowerCase().trim();
  2938. if (type === 'application/x-www-form-urlencoded') {
  2939. this._data = this._data ? `${this._data}&${data}` : data;
  2940. } else {
  2941. this._data = (this._data || '') + data;
  2942. }
  2943. } else {
  2944. this._data = data;
  2945. }
  2946. if (!isObject_ || this._isHost(data)) {
  2947. return this;
  2948. }
  2949. if (!type) this.type('json');
  2950. return this;
  2951. };
  2952. RequestBase.prototype.sortQuery = function (sort) {
  2953. this._sort = typeof sort === 'undefined' ? true : sort;
  2954. return this;
  2955. };
  2956. RequestBase.prototype._finalizeQueryString = function () {
  2957. const query = this._query.join('&');
  2958. if (query) {
  2959. this.url += (this.url.includes('?') ? '&' : '?') + query;
  2960. }
  2961. this._query.length = 0;
  2962. if (this._sort) {
  2963. const index = this.url.indexOf('?');
  2964. if (index >= 0) {
  2965. const queryArray = this.url.slice(index + 1).split('&');
  2966. if (typeof this._sort === 'function') {
  2967. queryArray.sort(this._sort);
  2968. } else {
  2969. queryArray.sort();
  2970. }
  2971. this.url = this.url.slice(0, index) + '?' + queryArray.join('&');
  2972. }
  2973. }
  2974. };
  2975. RequestBase.prototype._appendQueryString = () => {
  2976. console.warn('Unsupported');
  2977. };
  2978. RequestBase.prototype._timeoutError = function (reason, timeout, errno) {
  2979. if (this._aborted) {
  2980. return;
  2981. }
  2982. const error = new Error(`${reason + timeout}ms exceeded`);
  2983. error.timeout = timeout;
  2984. error.code = 'ECONNABORTED';
  2985. error.errno = errno;
  2986. this.timedout = true;
  2987. this.timedoutError = error;
  2988. this.abort();
  2989. this.callback(error);
  2990. };
  2991. RequestBase.prototype._setTimeouts = function () {
  2992. const self = this;
  2993. if (this._timeout && !this._timer) {
  2994. this._timer = setTimeout(() => {
  2995. self._timeoutError('Timeout of ', self._timeout, 'ETIME');
  2996. }, this._timeout);
  2997. }
  2998. if (this._responseTimeout && !this._responseTimeoutTimer) {
  2999. this._responseTimeoutTimer = setTimeout(() => {
  3000. self._timeoutError('Response timeout of ', self._responseTimeout, 'ETIMEDOUT');
  3001. }, this._responseTimeout);
  3002. }
  3003. };
  3004. }).call(this)}).call(this,require('_process'))
  3005. },{"./utils":25,"_process":14,"semver":1}],24:[function(require,module,exports){
  3006. const utils = require('./utils');
  3007. module.exports = ResponseBase;
  3008. function ResponseBase() {}
  3009. ResponseBase.prototype.get = function (field) {
  3010. return this.header[field.toLowerCase()];
  3011. };
  3012. ResponseBase.prototype._setHeaderProperties = function (header) {
  3013. const ct = header['content-type'] || '';
  3014. this.type = utils.type(ct);
  3015. const parameters = utils.params(ct);
  3016. for (const key in parameters) {
  3017. if (Object.prototype.hasOwnProperty.call(parameters, key)) this[key] = parameters[key];
  3018. }
  3019. this.links = {};
  3020. try {
  3021. if (header.link) {
  3022. this.links = utils.parseLinks(header.link);
  3023. }
  3024. } catch (err) {}
  3025. };
  3026. ResponseBase.prototype._setStatusProperties = function (status) {
  3027. const type = Math.trunc(status / 100);
  3028. this.statusCode = status;
  3029. this.status = this.statusCode;
  3030. this.statusType = type;
  3031. this.info = type === 1;
  3032. this.ok = type === 2;
  3033. this.redirect = type === 3;
  3034. this.clientError = type === 4;
  3035. this.serverError = type === 5;
  3036. this.error = type === 4 || type === 5 ? this.toError() : false;
  3037. this.created = status === 201;
  3038. this.accepted = status === 202;
  3039. this.noContent = status === 204;
  3040. this.badRequest = status === 400;
  3041. this.unauthorized = status === 401;
  3042. this.notAcceptable = status === 406;
  3043. this.forbidden = status === 403;
  3044. this.notFound = status === 404;
  3045. this.unprocessableEntity = status === 422;
  3046. };
  3047. },{"./utils":25}],25:[function(require,module,exports){
  3048. exports.type = string_ => string_.split(/ *; */).shift();
  3049. exports.params = value => {
  3050. const object = {};
  3051. for (const string_ of value.split(/ *; */)) {
  3052. const parts = string_.split(/ *= */);
  3053. const key = parts.shift();
  3054. const value = parts.shift();
  3055. if (key && value) object[key] = value;
  3056. }
  3057. return object;
  3058. };
  3059. exports.parseLinks = value => {
  3060. const object = {};
  3061. for (const string_ of value.split(/ *, */)) {
  3062. const parts = string_.split(/ *; */);
  3063. const url = parts[0].slice(1, -1);
  3064. const rel = parts[1].split(/ *= */)[1].slice(1, -1);
  3065. object[rel] = url;
  3066. }
  3067. return object;
  3068. };
  3069. exports.cleanHeader = (header, changesOrigin) => {
  3070. delete header['content-type'];
  3071. delete header['content-length'];
  3072. delete header['transfer-encoding'];
  3073. delete header.host;
  3074. if (changesOrigin) {
  3075. delete header.authorization;
  3076. delete header.cookie;
  3077. }
  3078. return header;
  3079. };
  3080. exports.isObject = object => {
  3081. return object !== null && typeof object === 'object';
  3082. };
  3083. exports.hasOwn = Object.hasOwn || function (object, property) {
  3084. if (object == null) {
  3085. throw new TypeError('Cannot convert undefined or null to object');
  3086. }
  3087. return Object.prototype.hasOwnProperty.call(new Object(object), property);
  3088. };
  3089. exports.mixin = (target, source) => {
  3090. for (const key in source) {
  3091. if (exports.hasOwn(source, key)) {
  3092. target[key] = source[key];
  3093. }
  3094. }
  3095. };
  3096. },{}]},{},[22])(22)
  3097. });