Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
axios.cjs4355 linesDownload Raw Back to node
1// Axios v1.6.8 Copyright (c) 2024 Matt Zabriskie and contributors2'use strict';3 4const FormData$1 = require('form-data');5const url = require('url');6const proxyFromEnv = require('proxy-from-env');7const http = require('http');8const https = require('https');9const util = require('util');10const followRedirects = require('follow-redirects');11const zlib = require('zlib');12const stream = require('stream');13const events = require('events');14 15function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }16 17const FormData__default = /*#__PURE__*/_interopDefaultLegacy(FormData$1);18const url__default = /*#__PURE__*/_interopDefaultLegacy(url);19const http__default = /*#__PURE__*/_interopDefaultLegacy(http);20const https__default = /*#__PURE__*/_interopDefaultLegacy(https);21const util__default = /*#__PURE__*/_interopDefaultLegacy(util);22const followRedirects__default = /*#__PURE__*/_interopDefaultLegacy(followRedirects);23const zlib__default = /*#__PURE__*/_interopDefaultLegacy(zlib);24const stream__default = /*#__PURE__*/_interopDefaultLegacy(stream);25 26function bind(fn, thisArg) {27  return function wrap() {28    return fn.apply(thisArg, arguments);29  };30}31 32// utils is a library of generic helper functions non-specific to axios33 34const {toString} = Object.prototype;35const {getPrototypeOf} = Object;36 37const kindOf = (cache => thing => {38    const str = toString.call(thing);39    return cache[str] || (cache[str] = str.slice(8, -1).toLowerCase());40})(Object.create(null));41 42const kindOfTest = (type) => {43  type = type.toLowerCase();44  return (thing) => kindOf(thing) === type45};46 47const typeOfTest = type => thing => typeof thing === type;48 49/**50 * Determine if a value is an Array51 *52 * @param {Object} val The value to test53 *54 * @returns {boolean} True if value is an Array, otherwise false55 */56const {isArray} = Array;57 58/**59 * Determine if a value is undefined60 *61 * @param {*} val The value to test62 *63 * @returns {boolean} True if the value is undefined, otherwise false64 */65const isUndefined = typeOfTest('undefined');66 67/**68 * Determine if a value is a Buffer69 *70 * @param {*} val The value to test71 *72 * @returns {boolean} True if value is a Buffer, otherwise false73 */74function isBuffer(val) {75  return val !== null && !isUndefined(val) && val.constructor !== null && !isUndefined(val.constructor)76    && isFunction(val.constructor.isBuffer) && val.constructor.isBuffer(val);77}78 79/**80 * Determine if a value is an ArrayBuffer81 *82 * @param {*} val The value to test83 *84 * @returns {boolean} True if value is an ArrayBuffer, otherwise false85 */86const isArrayBuffer = kindOfTest('ArrayBuffer');87 88 89/**90 * Determine if a value is a view on an ArrayBuffer91 *92 * @param {*} val The value to test93 *94 * @returns {boolean} True if value is a view on an ArrayBuffer, otherwise false95 */96function isArrayBufferView(val) {97  let result;98  if ((typeof ArrayBuffer !== 'undefined') && (ArrayBuffer.isView)) {99    result = ArrayBuffer.isView(val);100  } else {101    result = (val) && (val.buffer) && (isArrayBuffer(val.buffer));102  }103  return result;104}105 106/**107 * Determine if a value is a String108 *109 * @param {*} val The value to test110 *111 * @returns {boolean} True if value is a String, otherwise false112 */113const isString = typeOfTest('string');114 115/**116 * Determine if a value is a Function117 *118 * @param {*} val The value to test119 * @returns {boolean} True if value is a Function, otherwise false120 */121const isFunction = typeOfTest('function');122 123/**124 * Determine if a value is a Number125 *126 * @param {*} val The value to test127 *128 * @returns {boolean} True if value is a Number, otherwise false129 */130const isNumber = typeOfTest('number');131 132/**133 * Determine if a value is an Object134 *135 * @param {*} thing The value to test136 *137 * @returns {boolean} True if value is an Object, otherwise false138 */139const isObject = (thing) => thing !== null && typeof thing === 'object';140 141/**142 * Determine if a value is a Boolean143 *144 * @param {*} thing The value to test145 * @returns {boolean} True if value is a Boolean, otherwise false146 */147const isBoolean = thing => thing === true || thing === false;148 149/**150 * Determine if a value is a plain Object151 *152 * @param {*} val The value to test153 *154 * @returns {boolean} True if value is a plain Object, otherwise false155 */156const isPlainObject = (val) => {157  if (kindOf(val) !== 'object') {158    return false;159  }160 161  const prototype = getPrototypeOf(val);162  return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in val) && !(Symbol.iterator in val);163};164 165/**166 * Determine if a value is a Date167 *168 * @param {*} val The value to test169 *170 * @returns {boolean} True if value is a Date, otherwise false171 */172const isDate = kindOfTest('Date');173 174/**175 * Determine if a value is a File176 *177 * @param {*} val The value to test178 *179 * @returns {boolean} True if value is a File, otherwise false180 */181const isFile = kindOfTest('File');182 183/**184 * Determine if a value is a Blob185 *186 * @param {*} val The value to test187 *188 * @returns {boolean} True if value is a Blob, otherwise false189 */190const isBlob = kindOfTest('Blob');191 192/**193 * Determine if a value is a FileList194 *195 * @param {*} val The value to test196 *197 * @returns {boolean} True if value is a File, otherwise false198 */199const isFileList = kindOfTest('FileList');200 201/**202 * Determine if a value is a Stream203 *204 * @param {*} val The value to test205 *206 * @returns {boolean} True if value is a Stream, otherwise false207 */208const isStream = (val) => isObject(val) && isFunction(val.pipe);209 210/**211 * Determine if a value is a FormData212 *213 * @param {*} thing The value to test214 *215 * @returns {boolean} True if value is an FormData, otherwise false216 */217const isFormData = (thing) => {218  let kind;219  return thing && (220    (typeof FormData === 'function' && thing instanceof FormData) || (221      isFunction(thing.append) && (222        (kind = kindOf(thing)) === 'formdata' ||223        // detect form-data instance224        (kind === 'object' && isFunction(thing.toString) && thing.toString() === '[object FormData]')225      )226    )227  )228};229 230/**231 * Determine if a value is a URLSearchParams object232 *233 * @param {*} val The value to test234 *235 * @returns {boolean} True if value is a URLSearchParams object, otherwise false236 */237const isURLSearchParams = kindOfTest('URLSearchParams');238 239/**240 * Trim excess whitespace off the beginning and end of a string241 *242 * @param {String} str The String to trim243 *244 * @returns {String} The String freed of excess whitespace245 */246const trim = (str) => str.trim ?247  str.trim() : str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');248 249/**250 * Iterate over an Array or an Object invoking a function for each item.251 *252 * If `obj` is an Array callback will be called passing253 * the value, index, and complete array for each item.254 *255 * If 'obj' is an Object callback will be called passing256 * the value, key, and complete object for each property.257 *258 * @param {Object|Array} obj The object to iterate259 * @param {Function} fn The callback to invoke for each item260 *261 * @param {Boolean} [allOwnKeys = false]262 * @returns {any}263 */264function forEach(obj, fn, {allOwnKeys = false} = {}) {265  // Don't bother if no value provided266  if (obj === null || typeof obj === 'undefined') {267    return;268  }269 270  let i;271  let l;272 273  // Force an array if not already something iterable274  if (typeof obj !== 'object') {275    /*eslint no-param-reassign:0*/276    obj = [obj];277  }278 279  if (isArray(obj)) {280    // Iterate over array values281    for (i = 0, l = obj.length; i < l; i++) {282      fn.call(null, obj[i], i, obj);283    }284  } else {285    // Iterate over object keys286    const keys = allOwnKeys ? Object.getOwnPropertyNames(obj) : Object.keys(obj);287    const len = keys.length;288    let key;289 290    for (i = 0; i < len; i++) {291      key = keys[i];292      fn.call(null, obj[key], key, obj);293    }294  }295}296 297function findKey(obj, key) {298  key = key.toLowerCase();299  const keys = Object.keys(obj);300  let i = keys.length;301  let _key;302  while (i-- > 0) {303    _key = keys[i];304    if (key === _key.toLowerCase()) {305      return _key;306    }307  }308  return null;309}310 311const _global = (() => {312  /*eslint no-undef:0*/313  if (typeof globalThis !== "undefined") return globalThis;314  return typeof self !== "undefined" ? self : (typeof window !== 'undefined' ? window : global)315})();316 317const isContextDefined = (context) => !isUndefined(context) && context !== _global;318 319/**320 * Accepts varargs expecting each argument to be an object, then321 * immutably merges the properties of each object and returns result.322 *323 * When multiple objects contain the same key the later object in324 * the arguments list will take precedence.325 *326 * Example:327 *328 * ```js329 * var result = merge({foo: 123}, {foo: 456});330 * console.log(result.foo); // outputs 456331 * ```332 *333 * @param {Object} obj1 Object to merge334 *335 * @returns {Object} Result of all merge properties336 */337function merge(/* obj1, obj2, obj3, ... */) {338  const {caseless} = isContextDefined(this) && this || {};339  const result = {};340  const assignValue = (val, key) => {341    const targetKey = caseless && findKey(result, key) || key;342    if (isPlainObject(result[targetKey]) && isPlainObject(val)) {343      result[targetKey] = merge(result[targetKey], val);344    } else if (isPlainObject(val)) {345      result[targetKey] = merge({}, val);346    } else if (isArray(val)) {347      result[targetKey] = val.slice();348    } else {349      result[targetKey] = val;350    }351  };352 353  for (let i = 0, l = arguments.length; i < l; i++) {354    arguments[i] && forEach(arguments[i], assignValue);355  }356  return result;357}358 359/**360 * Extends object a by mutably adding to it the properties of object b.361 *362 * @param {Object} a The object to be extended363 * @param {Object} b The object to copy properties from364 * @param {Object} thisArg The object to bind function to365 *366 * @param {Boolean} [allOwnKeys]367 * @returns {Object} The resulting value of object a368 */369const extend = (a, b, thisArg, {allOwnKeys}= {}) => {370  forEach(b, (val, key) => {371    if (thisArg && isFunction(val)) {372      a[key] = bind(val, thisArg);373    } else {374      a[key] = val;375    }376  }, {allOwnKeys});377  return a;378};379 380/**381 * Remove byte order marker. This catches EF BB BF (the UTF-8 BOM)382 *383 * @param {string} content with BOM384 *385 * @returns {string} content value without BOM386 */387const stripBOM = (content) => {388  if (content.charCodeAt(0) === 0xFEFF) {389    content = content.slice(1);390  }391  return content;392};393 394/**395 * Inherit the prototype methods from one constructor into another396 * @param {function} constructor397 * @param {function} superConstructor398 * @param {object} [props]399 * @param {object} [descriptors]400 *401 * @returns {void}402 */403const inherits = (constructor, superConstructor, props, descriptors) => {404  constructor.prototype = Object.create(superConstructor.prototype, descriptors);405  constructor.prototype.constructor = constructor;406  Object.defineProperty(constructor, 'super', {407    value: superConstructor.prototype408  });409  props && Object.assign(constructor.prototype, props);410};411 412/**413 * Resolve object with deep prototype chain to a flat object414 * @param {Object} sourceObj source object415 * @param {Object} [destObj]416 * @param {Function|Boolean} [filter]417 * @param {Function} [propFilter]418 *419 * @returns {Object}420 */421const toFlatObject = (sourceObj, destObj, filter, propFilter) => {422  let props;423  let i;424  let prop;425  const merged = {};426 427  destObj = destObj || {};428  // eslint-disable-next-line no-eq-null,eqeqeq429  if (sourceObj == null) return destObj;430 431  do {432    props = Object.getOwnPropertyNames(sourceObj);433    i = props.length;434    while (i-- > 0) {435      prop = props[i];436      if ((!propFilter || propFilter(prop, sourceObj, destObj)) && !merged[prop]) {437        destObj[prop] = sourceObj[prop];438        merged[prop] = true;439      }440    }441    sourceObj = filter !== false && getPrototypeOf(sourceObj);442  } while (sourceObj && (!filter || filter(sourceObj, destObj)) && sourceObj !== Object.prototype);443 444  return destObj;445};446 447/**448 * Determines whether a string ends with the characters of a specified string449 *450 * @param {String} str451 * @param {String} searchString452 * @param {Number} [position= 0]453 *454 * @returns {boolean}455 */456const endsWith = (str, searchString, position) => {457  str = String(str);458  if (position === undefined || position > str.length) {459    position = str.length;460  }461  position -= searchString.length;462  const lastIndex = str.indexOf(searchString, position);463  return lastIndex !== -1 && lastIndex === position;464};465 466 467/**468 * Returns new array from array like object or null if failed469 *470 * @param {*} [thing]471 *472 * @returns {?Array}473 */474const toArray = (thing) => {475  if (!thing) return null;476  if (isArray(thing)) return thing;477  let i = thing.length;478  if (!isNumber(i)) return null;479  const arr = new Array(i);480  while (i-- > 0) {481    arr[i] = thing[i];482  }483  return arr;484};485 486/**487 * Checking if the Uint8Array exists and if it does, it returns a function that checks if the488 * thing passed in is an instance of Uint8Array489 *490 * @param {TypedArray}491 *492 * @returns {Array}493 */494// eslint-disable-next-line func-names495const isTypedArray = (TypedArray => {496  // eslint-disable-next-line func-names497  return thing => {498    return TypedArray && thing instanceof TypedArray;499  };500})(typeof Uint8Array !== 'undefined' && getPrototypeOf(Uint8Array));501 502/**503 * For each entry in the object, call the function with the key and value.504 *505 * @param {Object<any, any>} obj - The object to iterate over.506 * @param {Function} fn - The function to call for each entry.507 *508 * @returns {void}509 */510const forEachEntry = (obj, fn) => {511  const generator = obj && obj[Symbol.iterator];512 513  const iterator = generator.call(obj);514 515  let result;516 517  while ((result = iterator.next()) && !result.done) {518    const pair = result.value;519    fn.call(obj, pair[0], pair[1]);520  }521};522 523/**524 * It takes a regular expression and a string, and returns an array of all the matches525 *526 * @param {string} regExp - The regular expression to match against.527 * @param {string} str - The string to search.528 *529 * @returns {Array<boolean>}530 */531const matchAll = (regExp, str) => {532  let matches;533  const arr = [];534 535  while ((matches = regExp.exec(str)) !== null) {536    arr.push(matches);537  }538 539  return arr;540};541 542/* Checking if the kindOfTest function returns true when passed an HTMLFormElement. */543const isHTMLForm = kindOfTest('HTMLFormElement');544 545const toCamelCase = str => {546  return str.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,547    function replacer(m, p1, p2) {548      return p1.toUpperCase() + p2;549    }550  );551};552 553/* Creating a function that will check if an object has a property. */554const hasOwnProperty = (({hasOwnProperty}) => (obj, prop) => hasOwnProperty.call(obj, prop))(Object.prototype);555 556/**557 * Determine if a value is a RegExp object558 *559 * @param {*} val The value to test560 *561 * @returns {boolean} True if value is a RegExp object, otherwise false562 */563const isRegExp = kindOfTest('RegExp');564 565const reduceDescriptors = (obj, reducer) => {566  const descriptors = Object.getOwnPropertyDescriptors(obj);567  const reducedDescriptors = {};568 569  forEach(descriptors, (descriptor, name) => {570    let ret;571    if ((ret = reducer(descriptor, name, obj)) !== false) {572      reducedDescriptors[name] = ret || descriptor;573    }574  });575 576  Object.defineProperties(obj, reducedDescriptors);577};578 579/**580 * Makes all methods read-only581 * @param {Object} obj582 */583 584const freezeMethods = (obj) => {585  reduceDescriptors(obj, (descriptor, name) => {586    // skip restricted props in strict mode587    if (isFunction(obj) && ['arguments', 'caller', 'callee'].indexOf(name) !== -1) {588      return false;589    }590 591    const value = obj[name];592 593    if (!isFunction(value)) return;594 595    descriptor.enumerable = false;596 597    if ('writable' in descriptor) {598      descriptor.writable = false;599      return;600    }601 602    if (!descriptor.set) {603      descriptor.set = () => {604        throw Error('Can not rewrite read-only method \'' + name + '\'');605      };606    }607  });608};609 610const toObjectSet = (arrayOrString, delimiter) => {611  const obj = {};612 613  const define = (arr) => {614    arr.forEach(value => {615      obj[value] = true;616    });617  };618 619  isArray(arrayOrString) ? define(arrayOrString) : define(String(arrayOrString).split(delimiter));620 621  return obj;622};623 624const noop = () => {};625 626const toFiniteNumber = (value, defaultValue) => {627  value = +value;628  return Number.isFinite(value) ? value : defaultValue;629};630 631const ALPHA = 'abcdefghijklmnopqrstuvwxyz';632 633const DIGIT = '0123456789';634 635const ALPHABET = {636  DIGIT,637  ALPHA,638  ALPHA_DIGIT: ALPHA + ALPHA.toUpperCase() + DIGIT639};640 641const generateString = (size = 16, alphabet = ALPHABET.ALPHA_DIGIT) => {642  let str = '';643  const {length} = alphabet;644  while (size--) {645    str += alphabet[Math.random() * length|0];646  }647 648  return str;649};650 651/**652 * If the thing is a FormData object, return true, otherwise return false.653 *654 * @param {unknown} thing - The thing to check.655 *656 * @returns {boolean}657 */658function isSpecCompliantForm(thing) {659  return !!(thing && isFunction(thing.append) && thing[Symbol.toStringTag] === 'FormData' && thing[Symbol.iterator]);660}661 662const toJSONObject = (obj) => {663  const stack = new Array(10);664 665  const visit = (source, i) => {666 667    if (isObject(source)) {668      if (stack.indexOf(source) >= 0) {669        return;670      }671 672      if(!('toJSON' in source)) {673        stack[i] = source;674        const target = isArray(source) ? [] : {};675 676        forEach(source, (value, key) => {677          const reducedValue = visit(value, i + 1);678          !isUndefined(reducedValue) && (target[key] = reducedValue);679        });680 681        stack[i] = undefined;682 683        return target;684      }685    }686 687    return source;688  };689 690  return visit(obj, 0);691};692 693const isAsyncFn = kindOfTest('AsyncFunction');694 695const isThenable = (thing) =>696  thing && (isObject(thing) || isFunction(thing)) && isFunction(thing.then) && isFunction(thing.catch);697 698const utils$1 = {699  isArray,700  isArrayBuffer,701  isBuffer,702  isFormData,703  isArrayBufferView,704  isString,705  isNumber,706  isBoolean,707  isObject,708  isPlainObject,709  isUndefined,710  isDate,711  isFile,712  isBlob,713  isRegExp,714  isFunction,715  isStream,716  isURLSearchParams,717  isTypedArray,718  isFileList,719  forEach,720  merge,721  extend,722  trim,723  stripBOM,724  inherits,725  toFlatObject,726  kindOf,727  kindOfTest,728  endsWith,729  toArray,730  forEachEntry,731  matchAll,732  isHTMLForm,733  hasOwnProperty,734  hasOwnProp: hasOwnProperty, // an alias to avoid ESLint no-prototype-builtins detection735  reduceDescriptors,736  freezeMethods,737  toObjectSet,738  toCamelCase,739  noop,740  toFiniteNumber,741  findKey,742  global: _global,743  isContextDefined,744  ALPHABET,745  generateString,746  isSpecCompliantForm,747  toJSONObject,748  isAsyncFn,749  isThenable750};751 752/**753 * Create an Error with the specified message, config, error code, request and response.754 *755 * @param {string} message The error message.756 * @param {string} [code] The error code (for example, 'ECONNABORTED').757 * @param {Object} [config] The config.758 * @param {Object} [request] The request.759 * @param {Object} [response] The response.760 *761 * @returns {Error} The created error.762 */763function AxiosError(message, code, config, request, response) {764  Error.call(this);765 766  if (Error.captureStackTrace) {767    Error.captureStackTrace(this, this.constructor);768  } else {769    this.stack = (new Error()).stack;770  }771 772  this.message = message;773  this.name = 'AxiosError';774  code && (this.code = code);775  config && (this.config = config);776  request && (this.request = request);777  response && (this.response = response);778}779 780utils$1.inherits(AxiosError, Error, {781  toJSON: function toJSON() {782    return {783      // Standard784      message: this.message,785      name: this.name,786      // Microsoft787      description: this.description,788      number: this.number,789      // Mozilla790      fileName: this.fileName,791      lineNumber: this.lineNumber,792      columnNumber: this.columnNumber,793      stack: this.stack,794      // Axios795      config: utils$1.toJSONObject(this.config),796      code: this.code,797      status: this.response && this.response.status ? this.response.status : null798    };799  }800});801 802const prototype$1 = AxiosError.prototype;803const descriptors = {};804 805[806  'ERR_BAD_OPTION_VALUE',807  'ERR_BAD_OPTION',808  'ECONNABORTED',809  'ETIMEDOUT',810  'ERR_NETWORK',811  'ERR_FR_TOO_MANY_REDIRECTS',812  'ERR_DEPRECATED',813  'ERR_BAD_RESPONSE',814  'ERR_BAD_REQUEST',815  'ERR_CANCELED',816  'ERR_NOT_SUPPORT',817  'ERR_INVALID_URL'818// eslint-disable-next-line func-names819].forEach(code => {820  descriptors[code] = {value: code};821});822 823Object.defineProperties(AxiosError, descriptors);824Object.defineProperty(prototype$1, 'isAxiosError', {value: true});825 826// eslint-disable-next-line func-names827AxiosError.from = (error, code, config, request, response, customProps) => {828  const axiosError = Object.create(prototype$1);829 830  utils$1.toFlatObject(error, axiosError, function filter(obj) {831    return obj !== Error.prototype;832  }, prop => {833    return prop !== 'isAxiosError';834  });835 836  AxiosError.call(axiosError, error.message, code, config, request, response);837 838  axiosError.cause = error;839 840  axiosError.name = error.name;841 842  customProps && Object.assign(axiosError, customProps);843 844  return axiosError;845};846 847/**848 * Determines if the given thing is a array or js object.849 *850 * @param {string} thing - The object or array to be visited.851 *852 * @returns {boolean}853 */854function isVisitable(thing) {855  return utils$1.isPlainObject(thing) || utils$1.isArray(thing);856}857 858/**859 * It removes the brackets from the end of a string860 *861 * @param {string} key - The key of the parameter.862 *863 * @returns {string} the key without the brackets.864 */865function removeBrackets(key) {866  return utils$1.endsWith(key, '[]') ? key.slice(0, -2) : key;867}868 869/**870 * It takes a path, a key, and a boolean, and returns a string871 *872 * @param {string} path - The path to the current key.873 * @param {string} key - The key of the current object being iterated over.874 * @param {string} dots - If true, the key will be rendered with dots instead of brackets.875 *876 * @returns {string} The path to the current key.877 */878function renderKey(path, key, dots) {879  if (!path) return key;880  return path.concat(key).map(function each(token, i) {881    // eslint-disable-next-line no-param-reassign882    token = removeBrackets(token);883    return !dots && i ? '[' + token + ']' : token;884  }).join(dots ? '.' : '');885}886 887/**888 * If the array is an array and none of its elements are visitable, then it's a flat array.889 *890 * @param {Array<any>} arr - The array to check891 *892 * @returns {boolean}893 */894function isFlatArray(arr) {895  return utils$1.isArray(arr) && !arr.some(isVisitable);896}897 898const predicates = utils$1.toFlatObject(utils$1, {}, null, function filter(prop) {899  return /^is[A-Z]/.test(prop);900});901 902/**903 * Convert a data object to FormData904 *905 * @param {Object} obj906 * @param {?Object} [formData]907 * @param {?Object} [options]908 * @param {Function} [options.visitor]909 * @param {Boolean} [options.metaTokens = true]910 * @param {Boolean} [options.dots = false]911 * @param {?Boolean} [options.indexes = false]912 *913 * @returns {Object}914 **/915 916/**917 * It converts an object into a FormData object918 *919 * @param {Object<any, any>} obj - The object to convert to form data.920 * @param {string} formData - The FormData object to append to.921 * @param {Object<string, any>} options922 *923 * @returns924 */925function toFormData(obj, formData, options) {926  if (!utils$1.isObject(obj)) {927    throw new TypeError('target must be an object');928  }929 930  // eslint-disable-next-line no-param-reassign931  formData = formData || new (FormData__default["default"] || FormData)();932 933  // eslint-disable-next-line no-param-reassign934  options = utils$1.toFlatObject(options, {935    metaTokens: true,936    dots: false,937    indexes: false938  }, false, function defined(option, source) {939    // eslint-disable-next-line no-eq-null,eqeqeq940    return !utils$1.isUndefined(source[option]);941  });942 943  const metaTokens = options.metaTokens;944  // eslint-disable-next-line no-use-before-define945  const visitor = options.visitor || defaultVisitor;946  const dots = options.dots;947  const indexes = options.indexes;948  const _Blob = options.Blob || typeof Blob !== 'undefined' && Blob;949  const useBlob = _Blob && utils$1.isSpecCompliantForm(formData);950 951  if (!utils$1.isFunction(visitor)) {952    throw new TypeError('visitor must be a function');953  }954 955  function convertValue(value) {956    if (value === null) return '';957 958    if (utils$1.isDate(value)) {959      return value.toISOString();960    }961 962    if (!useBlob && utils$1.isBlob(value)) {963      throw new AxiosError('Blob is not supported. Use a Buffer instead.');964    }965 966    if (utils$1.isArrayBuffer(value) || utils$1.isTypedArray(value)) {967      return useBlob && typeof Blob === 'function' ? new Blob([value]) : Buffer.from(value);968    }969 970    return value;971  }972 973  /**974   * Default visitor.975   *976   * @param {*} value977   * @param {String|Number} key978   * @param {Array<String|Number>} path979   * @this {FormData}980   *981   * @returns {boolean} return true to visit the each prop of the value recursively982   */983  function defaultVisitor(value, key, path) {984    let arr = value;985 986    if (value && !path && typeof value === 'object') {987      if (utils$1.endsWith(key, '{}')) {988        // eslint-disable-next-line no-param-reassign989        key = metaTokens ? key : key.slice(0, -2);990        // eslint-disable-next-line no-param-reassign991        value = JSON.stringify(value);992      } else if (993        (utils$1.isArray(value) && isFlatArray(value)) ||994        ((utils$1.isFileList(value) || utils$1.endsWith(key, '[]')) && (arr = utils$1.toArray(value))995        )) {996        // eslint-disable-next-line no-param-reassign997        key = removeBrackets(key);998 999        arr.forEach(function each(el, index) {1000          !(utils$1.isUndefined(el) || el === null) && formData.append(1001            // eslint-disable-next-line no-nested-ternary1002            indexes === true ? renderKey([key], index, dots) : (indexes === null ? key : key + '[]'),1003            convertValue(el)1004          );1005        });1006        return false;1007      }1008    }1009 1010    if (isVisitable(value)) {1011      return true;1012    }1013 1014    formData.append(renderKey(path, key, dots), convertValue(value));1015 1016    return false;1017  }1018 1019  const stack = [];1020 1021  const exposedHelpers = Object.assign(predicates, {1022    defaultVisitor,1023    convertValue,1024    isVisitable1025  });1026 1027  function build(value, path) {1028    if (utils$1.isUndefined(value)) return;1029 1030    if (stack.indexOf(value) !== -1) {1031      throw Error('Circular reference detected in ' + path.join('.'));1032    }1033 1034    stack.push(value);1035 1036    utils$1.forEach(value, function each(el, key) {1037      const result = !(utils$1.isUndefined(el) || el === null) && visitor.call(1038        formData, el, utils$1.isString(key) ? key.trim() : key, path, exposedHelpers1039      );1040 1041      if (result === true) {1042        build(el, path ? path.concat(key) : [key]);1043      }1044    });1045 1046    stack.pop();1047  }1048 1049  if (!utils$1.isObject(obj)) {1050    throw new TypeError('data must be an object');1051  }1052 1053  build(obj);1054 1055  return formData;1056}1057 1058/**1059 * It encodes a string by replacing all characters that are not in the unreserved set with1060 * their percent-encoded equivalents1061 *1062 * @param {string} str - The string to encode.1063 *1064 * @returns {string} The encoded string.1065 */1066function encode$1(str) {1067  const charMap = {1068    '!': '%21',1069    "'": '%27',1070    '(': '%28',1071    ')': '%29',1072    '~': '%7E',1073    '%20': '+',1074    '%00': '\x00'1075  };1076  return encodeURIComponent(str).replace(/[!'()~]|%20|%00/g, function replacer(match) {1077    return charMap[match];1078  });1079}1080 1081/**1082 * It takes a params object and converts it to a FormData object1083 *1084 * @param {Object<string, any>} params - The parameters to be converted to a FormData object.1085 * @param {Object<string, any>} options - The options object passed to the Axios constructor.1086 *1087 * @returns {void}1088 */1089function AxiosURLSearchParams(params, options) {1090  this._pairs = [];1091 1092  params && toFormData(params, this, options);1093}1094 1095const prototype = AxiosURLSearchParams.prototype;1096 1097prototype.append = function append(name, value) {1098  this._pairs.push([name, value]);1099};1100 1101prototype.toString = function toString(encoder) {1102  const _encode = encoder ? function(value) {1103    return encoder.call(this, value, encode$1);1104  } : encode$1;1105 1106  return this._pairs.map(function each(pair) {1107    return _encode(pair[0]) + '=' + _encode(pair[1]);1108  }, '').join('&');1109};1110 1111/**1112 * It replaces all instances of the characters `:`, `$`, `,`, `+`, `[`, and `]` with their1113 * URI encoded counterparts1114 *1115 * @param {string} val The value to be encoded.1116 *1117 * @returns {string} The encoded value.1118 */1119function encode(val) {1120  return encodeURIComponent(val).1121    replace(/%3A/gi, ':').1122    replace(/%24/g, '$').1123    replace(/%2C/gi, ',').1124    replace(/%20/g, '+').1125    replace(/%5B/gi, '[').1126    replace(/%5D/gi, ']');1127}1128 1129/**1130 * Build a URL by appending params to the end1131 *1132 * @param {string} url The base of the url (e.g., http://www.google.com)1133 * @param {object} [params] The params to be appended1134 * @param {?object} options1135 *1136 * @returns {string} The formatted url1137 */1138function buildURL(url, params, options) {1139  /*eslint no-param-reassign:0*/1140  if (!params) {1141    return url;1142  }1143  1144  const _encode = options && options.encode || encode;1145 1146  const serializeFn = options && options.serialize;1147 1148  let serializedParams;1149 1150  if (serializeFn) {1151    serializedParams = serializeFn(params, options);1152  } else {1153    serializedParams = utils$1.isURLSearchParams(params) ?1154      params.toString() :1155      new AxiosURLSearchParams(params, options).toString(_encode);1156  }1157 1158  if (serializedParams) {1159    const hashmarkIndex = url.indexOf("#");1160 1161    if (hashmarkIndex !== -1) {1162      url = url.slice(0, hashmarkIndex);1163    }1164    url += (url.indexOf('?') === -1 ? '?' : '&') + serializedParams;1165  }1166 1167  return url;1168}1169 1170class InterceptorManager {1171  constructor() {1172    this.handlers = [];1173  }1174 1175  /**1176   * Add a new interceptor to the stack1177   *1178   * @param {Function} fulfilled The function to handle `then` for a `Promise`1179   * @param {Function} rejected The function to handle `reject` for a `Promise`1180   *1181   * @return {Number} An ID used to remove interceptor later1182   */1183  use(fulfilled, rejected, options) {1184    this.handlers.push({1185      fulfilled,1186      rejected,1187      synchronous: options ? options.synchronous : false,1188      runWhen: options ? options.runWhen : null1189    });1190    return this.handlers.length - 1;1191  }1192 1193  /**1194   * Remove an interceptor from the stack1195   *1196   * @param {Number} id The ID that was returned by `use`1197   *1198   * @returns {Boolean} `true` if the interceptor was removed, `false` otherwise1199   */1200  eject(id) {

Showing the first 1,200 of 4355 lines. Download the file for the rest.

codekingpro/portable-devtools · Team Ai