@sunmi/request
Advanced tools
| import fetch from 'isomorphic-fetch'; | ||
| /*! ***************************************************************************** | ||
| Copyright (c) Microsoft Corporation. | ||
| Permission to use, copy, modify, and/or distribute this software for any | ||
| purpose with or without fee is hereby granted. | ||
| THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
| REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | ||
| AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
| INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | ||
| LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR | ||
| OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | ||
| PERFORMANCE OF THIS SOFTWARE. | ||
| ***************************************************************************** */ | ||
| function __rest(s, e) { | ||
| var t = {}; | ||
| for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
| t[p] = s[p]; | ||
| if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
| for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { | ||
| if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) | ||
| t[p[i]] = s[p[i]]; | ||
| } | ||
| return t; | ||
| } | ||
| function buildURL(url, params, paramsSerializer) { | ||
| if (params) { | ||
| return url + (url.indexOf('?') > -1 ? '&' : '?') + paramsSerializer(params); | ||
| } | ||
| else { | ||
| return url; | ||
| } | ||
| } | ||
| function isAbsoluteURL(url) { | ||
| return /^([a-z][a-z\d\+\-\.]*:)?\/\//i.test(url); | ||
| } | ||
| function combineURL(baseURL, relativeURL) { | ||
| return isAbsoluteURL(relativeURL) | ||
| ? relativeURL | ||
| : `${baseURL.replace(/\/+$/, '')}/${relativeURL.replace(/^\/+/, '')}`; | ||
| } | ||
| const isArray = (value) => Array.isArray(value); | ||
| const isObject = (value) => { | ||
| const type = typeof value; | ||
| return value != null && (type === 'object' || type === 'function'); | ||
| }; | ||
| function paramsSerializer(params) { | ||
| const result = []; | ||
| function flatten(path, source, target) { | ||
| if (isArray(source)) { | ||
| source.map(item => { | ||
| flatten(path + `[]`, item, target); | ||
| }); | ||
| } | ||
| else if (isObject(source)) { | ||
| Object.keys(source).map(key => { | ||
| flatten(path + `[${key}]`, source[key], target); | ||
| }); | ||
| } | ||
| else { | ||
| target.push([path, source]); | ||
| } | ||
| } | ||
| if (!params) | ||
| return ''; | ||
| Object.keys(params).map(key => { | ||
| flatten(key, params[key], result); | ||
| }); | ||
| return result.map(item => item.join('=')).join('&'); | ||
| } | ||
| function transformData(data) { | ||
| const searchParams = new URLSearchParams(); | ||
| Object.keys(data).map(key => { | ||
| searchParams.append(key, data[key]); | ||
| }); | ||
| return searchParams; | ||
| } | ||
| function dispatchRequest(config) { | ||
| const { url = '', baseURL = '', params = null, paramsSerializer: paramsSerializer$1 = paramsSerializer, data = null, transformData: transformData$1 = transformData, beforeRequest = [], afterResponse = [], timeout = 0, responseType = 'json' } = config, init = __rest(config, ["url", "baseURL", "params", "paramsSerializer", "data", "transformData", "beforeRequest", "afterResponse", "timeout", "responseType"]); | ||
| const requestURL = buildURL(combineURL(baseURL, url), params, paramsSerializer$1); | ||
| const requestInit = Object.assign(Object.assign({}, init), { method: init.method || 'GET' }); | ||
| if (['POST', 'PUT', 'PATCH'].indexOf(requestInit.method) > -1) { | ||
| if (data && requestInit.body === undefined) { | ||
| requestInit.body = transformData$1(data); | ||
| } | ||
| if (beforeRequest.length) { | ||
| beforeRequest.map(fn => { | ||
| requestInit.body = fn(requestInit.body); | ||
| }); | ||
| } | ||
| } | ||
| return fetch(requestURL, requestInit).then(function (response) { | ||
| if (afterResponse.length) { | ||
| afterResponse.map(fn => { | ||
| response = fn(response); | ||
| }); | ||
| } | ||
| if (responseType === 'json') { | ||
| return response.json(); | ||
| } | ||
| else if (responseType === 'text') { | ||
| return response.text(); | ||
| } | ||
| else if (responseType === 'blob') { | ||
| return response.blob(); | ||
| } | ||
| else if (responseType === 'arraybuffer') { | ||
| return response.arrayBuffer(); | ||
| } | ||
| return response; | ||
| }, function (reason) { | ||
| return reason; | ||
| }); | ||
| } | ||
| class InterceptorManager { | ||
| constructor() { | ||
| this.handlers = []; | ||
| } | ||
| use(resolve, reject) { | ||
| this.handlers.push({ | ||
| resolve, | ||
| reject | ||
| }); | ||
| return this.handlers.length - 1; | ||
| } | ||
| eject(id) { | ||
| if (this.handlers[id]) { | ||
| this.handlers[id] = null; | ||
| } | ||
| } | ||
| forEach(fn) { | ||
| this.handlers.map(handler => { | ||
| if (handler) { | ||
| fn(handler); | ||
| } | ||
| }); | ||
| } | ||
| } | ||
| function mergeConfig(config1, config2 = {}) { | ||
| const defaults = {}; | ||
| [ | ||
| 'method', | ||
| 'body', | ||
| 'headers', | ||
| 'mode', | ||
| 'credentials', | ||
| 'cache', | ||
| 'redirect', | ||
| 'referrer', | ||
| 'referrerPolicy', | ||
| 'integrity', | ||
| 'keepalive', | ||
| 'url', | ||
| 'baseURL', | ||
| 'params', | ||
| 'paramsSerializer', | ||
| 'data', | ||
| 'transformData', | ||
| 'beforeRequest', | ||
| 'afterResponse', | ||
| 'timeout', | ||
| 'responseType' | ||
| ].map(key => { | ||
| if (typeof config2[key] !== 'undefined') { | ||
| defaults[key] = config2[key]; | ||
| } | ||
| else if (typeof config1[key] !== 'undefined') { | ||
| defaults[key] = config1[key]; | ||
| } | ||
| }); | ||
| return defaults; | ||
| } | ||
| class Request { | ||
| constructor(config) { | ||
| this.defaults = config; | ||
| this.interceptors = { | ||
| request: new InterceptorManager(), | ||
| response: new InterceptorManager() | ||
| }; | ||
| } | ||
| request(_) { | ||
| let config; | ||
| if (typeof arguments[0] === 'string') { | ||
| config = arguments[1] || {}; | ||
| config.url = arguments[0]; | ||
| } | ||
| else { | ||
| config = arguments[0] || {}; | ||
| } | ||
| const finalConfig = mergeConfig(this.defaults, config); | ||
| let chain = [dispatchRequest, undefined]; | ||
| let promise = Promise.resolve(finalConfig); | ||
| this.interceptors.request.forEach(interceptor => { | ||
| chain.unshift(interceptor.resolve, interceptor.reject); | ||
| }); | ||
| this.interceptors.response.forEach(interceptor => { | ||
| chain.push(interceptor.resolve, interceptor.reject); | ||
| }); | ||
| while (chain.length) { | ||
| promise = promise.then(chain.shift(), chain.shift()); | ||
| } | ||
| return promise; | ||
| } | ||
| get(url, params = null, config) { | ||
| return this.request(Object.assign({ method: 'GET', url, | ||
| params }, (config || {}))); | ||
| } | ||
| head(url, params = null, config) { | ||
| return this.request(Object.assign({ method: 'HEAD', url, | ||
| params }, (config || {}))); | ||
| } | ||
| delete(url, params = null, config) { | ||
| return this.request(Object.assign({ method: 'DELETE', url, | ||
| params }, (config || {}))); | ||
| } | ||
| post(url, data = null, config) { | ||
| return this.request(Object.assign({ method: 'POST', url, | ||
| data }, (config || {}))); | ||
| } | ||
| put(url, data = null, config) { | ||
| return this.request(Object.assign({ method: 'PUT', url, | ||
| data }, (config || {}))); | ||
| } | ||
| patch(url, data = null, config) { | ||
| return this.request(Object.assign({ method: 'PATCH', url, | ||
| data }, (config || {}))); | ||
| } | ||
| } | ||
| const defaults = { | ||
| method: 'GET', | ||
| timeout: 0, | ||
| responseType: 'json', | ||
| paramsSerializer, | ||
| transformData | ||
| }; | ||
| function bind(fn, thisArg) { | ||
| return function () { | ||
| return fn.apply(thisArg, Array.from(arguments)); | ||
| }; | ||
| } | ||
| function extend(target, source, thisArg) { | ||
| Object.getOwnPropertyNames(source).map(key => { | ||
| if (typeof source[key] === 'function' && thisArg) { | ||
| target[key] = bind(source[key], thisArg); | ||
| } | ||
| else { | ||
| target[key] = source[key]; | ||
| } | ||
| }); | ||
| return target; | ||
| } | ||
| function createInstance(config) { | ||
| const ctx = new Request(config); | ||
| let instance = bind(Request.prototype.request, ctx); | ||
| extend(instance, Request.prototype, ctx); | ||
| extend(instance, ctx); | ||
| return instance; | ||
| } | ||
| const instance = createInstance(defaults); | ||
| instance.create = config => { | ||
| return createInstance(mergeConfig(instance.defaults, config)); | ||
| }; | ||
| export default instance; |
+309
| (function (global, factory) { | ||
| typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('isomorphic-fetch')) : | ||
| typeof define === 'function' && define.amd ? define(['isomorphic-fetch'], factory) : | ||
| (global = global || self, global.request = factory(global.fetch)); | ||
| }(this, (function (fetch) { 'use strict'; | ||
| fetch = fetch && Object.prototype.hasOwnProperty.call(fetch, 'default') ? fetch['default'] : fetch; | ||
| /*! ***************************************************************************** | ||
| Copyright (c) Microsoft Corporation. | ||
| Permission to use, copy, modify, and/or distribute this software for any | ||
| purpose with or without fee is hereby granted. | ||
| THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
| REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | ||
| AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
| INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | ||
| LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR | ||
| OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | ||
| PERFORMANCE OF THIS SOFTWARE. | ||
| ***************************************************************************** */ | ||
| var __assign = function() { | ||
| __assign = Object.assign || function __assign(t) { | ||
| for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
| s = arguments[i]; | ||
| for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; | ||
| } | ||
| return t; | ||
| }; | ||
| return __assign.apply(this, arguments); | ||
| }; | ||
| function __rest(s, e) { | ||
| var t = {}; | ||
| for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
| t[p] = s[p]; | ||
| if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
| for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { | ||
| if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) | ||
| t[p[i]] = s[p[i]]; | ||
| } | ||
| return t; | ||
| } | ||
| function buildURL(url, params, paramsSerializer) { | ||
| if (params) { | ||
| return url + (url.indexOf('?') > -1 ? '&' : '?') + paramsSerializer(params); | ||
| } | ||
| else { | ||
| return url; | ||
| } | ||
| } | ||
| function isAbsoluteURL(url) { | ||
| return /^([a-z][a-z\d\+\-\.]*:)?\/\//i.test(url); | ||
| } | ||
| function combineURL(baseURL, relativeURL) { | ||
| return isAbsoluteURL(relativeURL) | ||
| ? relativeURL | ||
| : baseURL.replace(/\/+$/, '') + "/" + relativeURL.replace(/^\/+/, ''); | ||
| } | ||
| var isArray = function (value) { return Array.isArray(value); }; | ||
| var isObject = function (value) { | ||
| var type = typeof value; | ||
| return value != null && (type === 'object' || type === 'function'); | ||
| }; | ||
| function paramsSerializer(params) { | ||
| var result = []; | ||
| function flatten(path, source, target) { | ||
| if (isArray(source)) { | ||
| source.map(function (item) { | ||
| flatten(path + "[]", item, target); | ||
| }); | ||
| } | ||
| else if (isObject(source)) { | ||
| Object.keys(source).map(function (key) { | ||
| flatten(path + ("[" + key + "]"), source[key], target); | ||
| }); | ||
| } | ||
| else { | ||
| target.push([path, source]); | ||
| } | ||
| } | ||
| if (!params) | ||
| return ''; | ||
| Object.keys(params).map(function (key) { | ||
| flatten(key, params[key], result); | ||
| }); | ||
| return result.map(function (item) { return item.join('='); }).join('&'); | ||
| } | ||
| function transformData(data) { | ||
| var searchParams = new URLSearchParams(); | ||
| Object.keys(data).map(function (key) { | ||
| searchParams.append(key, data[key]); | ||
| }); | ||
| return searchParams; | ||
| } | ||
| function dispatchRequest(config) { | ||
| var _a = config.url, url = _a === void 0 ? '' : _a, _b = config.baseURL, baseURL = _b === void 0 ? '' : _b, _c = config.params, params = _c === void 0 ? null : _c, _d = config.paramsSerializer, paramsSerializer$1 = _d === void 0 ? paramsSerializer : _d, _e = config.data, data = _e === void 0 ? null : _e, _f = config.transformData, transformData$1 = _f === void 0 ? transformData : _f, _g = config.beforeRequest, beforeRequest = _g === void 0 ? [] : _g, _h = config.afterResponse, afterResponse = _h === void 0 ? [] : _h, _j = config.timeout, _k = config.responseType, responseType = _k === void 0 ? 'json' : _k, init = __rest(config, ["url", "baseURL", "params", "paramsSerializer", "data", "transformData", "beforeRequest", "afterResponse", "timeout", "responseType"]); | ||
| var requestURL = buildURL(combineURL(baseURL, url), params, paramsSerializer$1); | ||
| var requestInit = __assign(__assign({}, init), { method: init.method || 'GET' }); | ||
| if (['POST', 'PUT', 'PATCH'].indexOf(requestInit.method) > -1) { | ||
| if (data && requestInit.body === undefined) { | ||
| requestInit.body = transformData$1(data); | ||
| } | ||
| if (beforeRequest.length) { | ||
| beforeRequest.map(function (fn) { | ||
| requestInit.body = fn(requestInit.body); | ||
| }); | ||
| } | ||
| } | ||
| return fetch(requestURL, requestInit).then(function (response) { | ||
| if (afterResponse.length) { | ||
| afterResponse.map(function (fn) { | ||
| response = fn(response); | ||
| }); | ||
| } | ||
| if (responseType === 'json') { | ||
| return response.json(); | ||
| } | ||
| else if (responseType === 'text') { | ||
| return response.text(); | ||
| } | ||
| else if (responseType === 'blob') { | ||
| return response.blob(); | ||
| } | ||
| else if (responseType === 'arraybuffer') { | ||
| return response.arrayBuffer(); | ||
| } | ||
| return response; | ||
| }, function (reason) { | ||
| return reason; | ||
| }); | ||
| } | ||
| var InterceptorManager = (function () { | ||
| function InterceptorManager() { | ||
| this.handlers = []; | ||
| } | ||
| InterceptorManager.prototype.use = function (resolve, reject) { | ||
| this.handlers.push({ | ||
| resolve: resolve, | ||
| reject: reject | ||
| }); | ||
| return this.handlers.length - 1; | ||
| }; | ||
| InterceptorManager.prototype.eject = function (id) { | ||
| if (this.handlers[id]) { | ||
| this.handlers[id] = null; | ||
| } | ||
| }; | ||
| InterceptorManager.prototype.forEach = function (fn) { | ||
| this.handlers.map(function (handler) { | ||
| if (handler) { | ||
| fn(handler); | ||
| } | ||
| }); | ||
| }; | ||
| return InterceptorManager; | ||
| }()); | ||
| function mergeConfig(config1, config2) { | ||
| if (config2 === void 0) { config2 = {}; } | ||
| var defaults = {}; | ||
| [ | ||
| 'method', | ||
| 'body', | ||
| 'headers', | ||
| 'mode', | ||
| 'credentials', | ||
| 'cache', | ||
| 'redirect', | ||
| 'referrer', | ||
| 'referrerPolicy', | ||
| 'integrity', | ||
| 'keepalive', | ||
| 'url', | ||
| 'baseURL', | ||
| 'params', | ||
| 'paramsSerializer', | ||
| 'data', | ||
| 'transformData', | ||
| 'beforeRequest', | ||
| 'afterResponse', | ||
| 'timeout', | ||
| 'responseType' | ||
| ].map(function (key) { | ||
| if (typeof config2[key] !== 'undefined') { | ||
| defaults[key] = config2[key]; | ||
| } | ||
| else if (typeof config1[key] !== 'undefined') { | ||
| defaults[key] = config1[key]; | ||
| } | ||
| }); | ||
| return defaults; | ||
| } | ||
| var Request = (function () { | ||
| function Request(config) { | ||
| this.defaults = config; | ||
| this.interceptors = { | ||
| request: new InterceptorManager(), | ||
| response: new InterceptorManager() | ||
| }; | ||
| } | ||
| Request.prototype.request = function (_) { | ||
| var config; | ||
| if (typeof arguments[0] === 'string') { | ||
| config = arguments[1] || {}; | ||
| config.url = arguments[0]; | ||
| } | ||
| else { | ||
| config = arguments[0] || {}; | ||
| } | ||
| var finalConfig = mergeConfig(this.defaults, config); | ||
| var chain = [dispatchRequest, undefined]; | ||
| var promise = Promise.resolve(finalConfig); | ||
| this.interceptors.request.forEach(function (interceptor) { | ||
| chain.unshift(interceptor.resolve, interceptor.reject); | ||
| }); | ||
| this.interceptors.response.forEach(function (interceptor) { | ||
| chain.push(interceptor.resolve, interceptor.reject); | ||
| }); | ||
| while (chain.length) { | ||
| promise = promise.then(chain.shift(), chain.shift()); | ||
| } | ||
| return promise; | ||
| }; | ||
| Request.prototype.get = function (url, params, config) { | ||
| if (params === void 0) { params = null; } | ||
| return this.request(__assign({ method: 'GET', url: url, | ||
| params: params }, (config || {}))); | ||
| }; | ||
| Request.prototype.head = function (url, params, config) { | ||
| if (params === void 0) { params = null; } | ||
| return this.request(__assign({ method: 'HEAD', url: url, | ||
| params: params }, (config || {}))); | ||
| }; | ||
| Request.prototype.delete = function (url, params, config) { | ||
| if (params === void 0) { params = null; } | ||
| return this.request(__assign({ method: 'DELETE', url: url, | ||
| params: params }, (config || {}))); | ||
| }; | ||
| Request.prototype.post = function (url, data, config) { | ||
| if (data === void 0) { data = null; } | ||
| return this.request(__assign({ method: 'POST', url: url, | ||
| data: data }, (config || {}))); | ||
| }; | ||
| Request.prototype.put = function (url, data, config) { | ||
| if (data === void 0) { data = null; } | ||
| return this.request(__assign({ method: 'PUT', url: url, | ||
| data: data }, (config || {}))); | ||
| }; | ||
| Request.prototype.patch = function (url, data, config) { | ||
| if (data === void 0) { data = null; } | ||
| return this.request(__assign({ method: 'PATCH', url: url, | ||
| data: data }, (config || {}))); | ||
| }; | ||
| return Request; | ||
| }()); | ||
| var defaults = { | ||
| method: 'GET', | ||
| timeout: 0, | ||
| responseType: 'json', | ||
| paramsSerializer: paramsSerializer, | ||
| transformData: transformData | ||
| }; | ||
| function bind(fn, thisArg) { | ||
| return function () { | ||
| return fn.apply(thisArg, Array.from(arguments)); | ||
| }; | ||
| } | ||
| function extend(target, source, thisArg) { | ||
| Object.getOwnPropertyNames(source).map(function (key) { | ||
| if (typeof source[key] === 'function' && thisArg) { | ||
| target[key] = bind(source[key], thisArg); | ||
| } | ||
| else { | ||
| target[key] = source[key]; | ||
| } | ||
| }); | ||
| return target; | ||
| } | ||
| function createInstance(config) { | ||
| var ctx = new Request(config); | ||
| var instance = bind(Request.prototype.request, ctx); | ||
| extend(instance, Request.prototype, ctx); | ||
| extend(instance, ctx); | ||
| return instance; | ||
| } | ||
| var instance = createInstance(defaults); | ||
| instance.create = function (config) { | ||
| return createInstance(mergeConfig(instance.defaults, config)); | ||
| }; | ||
| return instance; | ||
| }))); |
| !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("isomorphic-fetch")):"function"==typeof define&&define.amd?define(["isomorphic-fetch"],t):(e=e||self).request=t(e.fetch)}(this,function(l){"use strict";l=l&&Object.prototype.hasOwnProperty.call(l,"default")?l.default:l;var d=function(){return(d=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};var i=function(e){return Array.isArray(e)},u=function(e){var t=typeof e;return null!=e&&("object"==t||"function"==t)};function h(t){var r=[];return t?(Object.keys(t).map(function(e){!function t(r,n,o){i(n)?n.map(function(e){t(r+"[]",e,o)}):u(n)?Object.keys(n).map(function(e){t(r+"["+e+"]",n[e],o)}):o.push([r,n])}(e,t[e],r)}),r.map(function(e){return e.join("=")}).join("&")):""}function y(t){var r=new URLSearchParams;return Object.keys(t).map(function(e){r.append(e,t[e])}),r}function o(e){var t=e.url,t=void 0===t?"":t,r=e.baseURL,r=void 0===r?"":r,n=e.params,n=void 0===n?null:n,o=e.paramsSerializer,o=void 0===o?h:o,i=e.data,i=void 0===i?null:i,u=e.transformData,u=void 0===u?y:u,a=e.beforeRequest,a=void 0===a?[]:a,s=e.afterResponse,p=void 0===s?[]:s,s=(e.timeout,e.responseType),f=void 0===s?"json":s,s=function(e,t){var r={};for(o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(r[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols)for(var n=0,o=Object.getOwnPropertySymbols(e);n<o.length;n++)t.indexOf(o[n])<0&&Object.prototype.propertyIsEnumerable.call(e,o[n])&&(r[o[n]]=e[o[n]]);return r}(e,["url","baseURL","params","paramsSerializer","data","transformData","beforeRequest","afterResponse","timeout","responseType"]),o=(e=r,t=/^([a-z][a-z\d\+\-\.]*:)?\/\//i.test(r=t)?r:e.replace(/\/+$/,"")+"/"+r.replace(/^\/+/,""),e=o,(r=n)?t+(-1<t.indexOf("?")?"&":"?")+e(r):t),c=d(d({},s),{method:s.method||"GET"});return-1<["POST","PUT","PATCH"].indexOf(c.method)&&(i&&void 0===c.body&&(c.body=u(i)),a.length&&a.map(function(e){c.body=e(c.body)})),l(o,c).then(function(t){return p.length&&p.map(function(e){t=e(t)}),"json"===f?t.json():"text"===f?t.text():"blob"===f?t.blob():"arraybuffer"===f?t.arrayBuffer():t},function(e){return e})}e.prototype.use=function(e,t){return this.handlers.push({resolve:e,reject:t}),this.handlers.length-1},e.prototype.eject=function(e){this.handlers[e]&&(this.handlers[e]=null)},e.prototype.forEach=function(t){this.handlers.map(function(e){e&&t(e)})};var t=e;function e(){this.handlers=[]}function a(t,r){void 0===r&&(r={});var n={};return["method","body","headers","mode","credentials","cache","redirect","referrer","referrerPolicy","integrity","keepalive","url","baseURL","params","paramsSerializer","data","transformData","beforeRequest","afterResponse","timeout","responseType"].map(function(e){void 0!==r[e]?n[e]=r[e]:void 0!==t[e]&&(n[e]=t[e])}),n}n.prototype.request=function(e){"string"==typeof e?(t=arguments[1]||{}).url=e:t=e||{};var t,e=a(this.defaults,t),r=[o,void 0],n=Promise.resolve(e);for(this.interceptors.request.forEach(function(e){r.unshift(e.resolve,e.reject)}),this.interceptors.response.forEach(function(e){r.push(e.resolve,e.reject)});r.length;)n=n.then(r.shift(),r.shift());return n},n.prototype.get=function(e,t,r){return this.request(d({method:"GET",url:e,params:t=void 0===t?null:t},r||{}))},n.prototype.head=function(e,t,r){return this.request(d({method:"HEAD",url:e,params:t=void 0===t?null:t},r||{}))},n.prototype.delete=function(e,t,r){return this.request(d({method:"DELETE",url:e,params:t=void 0===t?null:t},r||{}))},n.prototype.post=function(e,t,r){return this.request(d({method:"POST",url:e,data:t=void 0===t?null:t},r||{}))},n.prototype.put=function(e,t,r){return this.request(d({method:"PUT",url:e,data:t=void 0===t?null:t},r||{}))},n.prototype.patch=function(e,t,r){return this.request(d({method:"PATCH",url:e,data:t=void 0===t?null:t},r||{}))};var r=n;function n(e){this.defaults=e,this.interceptors={request:new t,response:new t}}function s(e,t){return function(){return e.apply(t,Array.from(arguments))}}function p(t,r,n){Object.getOwnPropertyNames(r).map(function(e){"function"==typeof r[e]&&n?t[e]=s(r[e],n):t[e]=r[e]})}function f(e){var e=new r(e),t=s(r.prototype.request,e);return p(t,r.prototype,e),p(t,e),t}var c=f({method:"GET",timeout:0,responseType:"json",paramsSerializer:h,transformData:y});return c.create=function(e){return f(a(c.defaults,e))},c}); |
+2
-2
| { | ||
| "name": "@sunmi/request", | ||
| "version": "1.0.6-beta.0", | ||
| "version": "1.0.6-beta.1", | ||
| "description": "wrapped fetch method", | ||
@@ -24,3 +24,3 @@ "keywords": [ | ||
| }, | ||
| "gitHead": "e2d7cdb2582a6c0bcb420342168f539afef203f3" | ||
| "gitHead": "33e114d49975fb11400bcf64a7153af7349655fa" | ||
| } |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Network access
Supply chain riskThis module accesses the network.
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
37209
204.54%6
100%649
721.52%3
50%12
1100%