box-cat
Version:
对暴露get,post之类接口的实例(例如axios、fly.io)二度封装
17 lines (14 loc) • 3.49 kB
JavaScript
// * Released under the MIT License.
;function e(e){var t=function(e,t){return void 0===t&&(t="param"),e.split(new RegExp(t)).slice(0,2)}(e);t[0]=function(e){return["$","(",")","*","+",".","[","]","?","\\","^","{","}","|"].some((function(t){return t===e}))?"\\"+e:e}(t[0]);var n,r,o=(n=t[0],r=t[1],new RegExp("\\/"+n+"([^"+r+"]+)"+r));return t[1]=function(e){return""===e?e:"[^"+e+"]"}(t[1]),{paramsRegExp:o,sliceRegExp:function(e,t){return new RegExp("\\/"+e+t+"[^/]+","g")}(t[0],t[1])}}function t(t){void 0===t&&(t={});var n=function(e){var t={methods:{get:["get"],post:["post"],put:["put"],delete:["delete"],options:["options"],head:["head"],trace:["trace"],connect:["connect"],patch:["patch"]},rule:":param",methodsRule:"startsWith"};if(e.mergeMethods){var n=e.mergeMethods;delete e.mergeMethods,Object.assign(t.methods,n)}return Object.assign({},t,e)}(t),r=e(n.rule);return{processOptions:n,paramsRegExp:r.paramsRegExp,sliceRegExp:r.sliceRegExp}}
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */function n(){for(var e=0,t=0,n=arguments.length;t<n;t++)e+=arguments[t].length;var r=Array(e),o=0;for(t=0;t<n;t++)for(var c=arguments[t],i=0,u=c.length;i<u;i++,o++)r[o]=c[i];return r}function r(e,t,n,r,o,c){if(1===e.length)return[e[0],n,Object.assign({},c,r)];var i=void 0;if("object"==typeof n){var u=[],a=void 0,s=function(e){-1!==(a=t.findIndex((function(t){return t===e})))&&(u[a]="/"+n[e])};for(var f in n)s(f);i=u.reduce((function(t,n,r){return""+t+n+e[r+1]}),e[0])}else i=e[0]+"/"+n+e[1];return[i,r,Object.assign({},c,o)]}function o(e,o,c){void 0===c&&(c={});var i,u=t(c),a=u.processOptions,s=u.paramsRegExp,f=u.sliceRegExp;return function(t){var c,u,p;if(c=t,u=a.methodsRule,p=a.methods,function(e,t,n){return!(!t||!n[t])||(n[t]?console.warn("BoxCat:engine\u6ca1\u6709"+t+"\u65b9\u6cd5"):console.warn("BoxCat:\u6ca1\u6709\u5339\u914d\u5230"+e+"\u6240\u9700\u7684\u8bf7\u6c42\u65b9\u5f0f"),!1)}(t,i=Object.keys(p).find((function(e){return!!p[e].find((function(e){return c.toLocaleLowerCase()[u](e.toLocaleLowerCase())}))})),o))return function(e,t,o,c,i,u){var a=t.split(c),s=t.match(c),f=[];return s&&(f=s.map((function(e){return e.replace(i,"$1")}))),function(t,c,i){for(var s=[],p=3;p<arguments.length;p++)s[p-3]=arguments[p];return o[e].apply(o,n(r(a,f,t,c,i,u),s))}}(i,e[t],o,f,s,a.config)}}function c(e,t,n){void 0===n&&(n={});var r=o(e,t,n),c={};return Object.keys(e).forEach((function(e){c[e]=r(e)})),c}Object.defineProperty(exports,"__esModule",{value:!0});var i=c;exports.createAll=i,exports.createApis=c,exports.createProxy=function(e,t,n){return void 0===n&&(n={}),"undefined"!=typeof Proxy?(r=o(e,t,n),new Proxy({},{get:function(e,t,n){return e[t]||(e[t]=r(t)),Reflect.get(e,t,n)}})):c(e,t,n);var r};