@bennetgallein/mande
Version:
Some awesome description
7 lines (6 loc) • 1.83 kB
JavaScript
/*!
* @bennetgallein/mande v3.0.0-rc5
* (c) 2024 Eduardo San Martin Morote
* @license MIT
*/
var BennetgalleinMande=function(e){"use strict";let n=/\/+$/,t=/^\/+/;const s={responseAs:"json",headers:{Accept:"application/json","Content-Type":"application/json"}};return e.defaults=s,e.mande=function(e,r={},o){function c(r,o,c,i={}){let u,p;"object"==typeof o?(u="",p=o,i=c||{}):(u=o,p=c);let d=Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},s),l),{method:r}),i),{headers:(b=Object.assign(Object.assign(Object.assign({},s.headers),l.headers),i.headers),Object.keys(b).reduce(((e,n)=>(null!=b[n]&&(e[n]=b[n]),e)),{}))});var b;let f=Object.assign(Object.assign(Object.assign({},s.query),l.query),i.query),{responseAs:j}=d;return u=function(e,s){return e.replace(n,"")+"/"+s.replace(t,"")}(e,"number"==typeof u?""+u:u||""),u+=function(e){let n=Object.keys(e).map((n=>[n,e[n]].map(encodeURIComponent).join("="))).join("&");return n?"?"+n:""}(f),p&&(d.body=JSON.stringify(p)),a(u,d).then((e=>Promise.all([e,"response"===j?e:e[j]().catch((()=>null))]))).then((([e,n])=>{if(e.status>=200&&e.status<300)return"response"!==j&&204==e.status?null:n;let t=new Error(e.statusText);throw t.response=e,t.body=n,t}))}const a="undefined"!=typeof fetch?fetch:o;if(!a)throw new Error("No fetch function exists. Make sure to include a polyfill on Node.js.");const l=Object.assign({query:{},headers:{}},r);return{options:l,post:c.bind(null,"POST"),put:c.bind(null,"PUT"),patch:c.bind(null,"PATCH"),get:(e,n)=>c("GET",e,null,n),delete:(e,n)=>c("DELETE",e,null,n)}},e.nuxtWrap=function(e,n){const t=n.length;return function(){let s=e,r=Array.from(arguments);if(arguments.length===t){s=Object.assign({},e);const[n]=r.splice(0,1);n(s)}return n.call(null,s,...r)}},Object.defineProperty(e,"__esModule",{value:!0}),e}({});