http.min.js

Summary

Maintainability
A
0 mins
Test Coverage
/*! lil-http - v0.1.17 - MIT License - https://github.com/lil-js/http */
(function(e,t){if(typeof define==="function"&&define.amd){define(["exports"],t)}else if(typeof exports==="object"){t(exports);if(typeof module==="object"&&module!==null){module.exports=exports=exports.http}}else{t(e.lil=e.lil||{})}})(this,function(e){"use strict";var t="0.1.17";var n=Object.prototype.toString;var r=Array.prototype.slice;var o=Object.prototype.hasOwnProperty;var a=typeof Function.prototype.bind==="function";var u=location.origin;var i=/^(http[s]?:\/\/[a-z0-9\-\.\:]+)[\/]?/i;var s=/application\/json/;var f=typeof XDomainRequest!=="undefined";var l=function(){};var c={method:"GET",timeout:30*1e3,auth:null,data:null,headers:null,withCredentials:false,responseType:"text"};function p(e){return e&&n.call(e)==="[object Object]"||false}function d(e){var t,n,a,u,i=r.call(arguments).slice(1);for(t=0,n=i.length;t<n;t+=1){u=i[t];for(a in u)if(o.call(u,a))e[a]=u[a]}return e}function y(e){var t=false;return function(){if(t===false){t=true;e.apply(null,arguments)}}}function v(e,t){if(!p(t))return;t["Content-Type"]=t["Content-Type"]||t["content-type"]||L.defaultContent;var n=Object.keys(t).reduce(function(e,n){var r=n.toLowerCase();if(r!==n){if(o.call(t,r)){delete t[r];delete e[r]}}e[n]=t[n];return e},{});Object.keys(n).forEach(function(t){e.setRequestHeader(t,n[t])})}function h(e){var t={},n=e.getAllResponseHeaders().trim().split("\n");n.forEach(function(e){var n=e.trim().split(":");var r=n.shift().trim();var o=n.join(":").trim();t[r]=o});return t}function m(e){return s.test(e.getResponseHeader("Content-Type"))}function g(e){return Object.getOwnPropertyNames(e).filter(function(t){return e[t]!==undefined}).map(function(t){var n=e[t]===null?"":e[t];return encodeURIComponent(t)+(n?"="+encodeURIComponent(n):"")}).join("&").replace(/%20/g,"+")}function T(e){var t=null;if(e.responseType==="text"){t=e.responseText;if(m(e)&&t)t=JSON.parse(t)}else{t=e.response}return t}function C(e){return e===1223?204:e}function x(e){var t={xhr:e,status:C(e.status),statusText:e.statusText,data:null,headers:{}};if(e.readyState===4){t.data=T(e);t.headers=h(e)}return t}function j(e,t){var n=x(e);n.error=t;if(t.stack)n.stack=t.stack;return n}function O(e){e.onreadystatechange=e.onerror=e.ontimeout=null}function b(e){var t=C(e.status);return t>=200&&t<300||t===304}function E(e,t){return y(function(n){t(j(e,n),null)})}function w(e,t,n){return function(e){if(t.readyState===4){O(t);if(b(t)){n(null,x(t))}else{E(t,n)(e)}}}}function R(e){var t=e.match(i);return t&&t[1]===u}function S(e){var t=e.url;if(p(e.params)){t+=(t.indexOf("?")===-1?"?":"&")+g(e.params)}return t}function q(e){if(f&&R(e)){return new XDomainRequest}else{return new XMLHttpRequest}}function H(e){var t=(e.method||"GET").toUpperCase();var n=e.auth;var r=S(e);if(!r||typeof r!=="string"){throw new TypeError("Missing required request URL")}var o=q(r);if(n){o.open(t,r,true,n.user,n.password)}else{o.open(t,r)}o.withCredentials=e.withCredentials;o.responseType=e.responseType;o.timeout=e.timeout;v(o,e.headers);return o}function A(e,t){return function(e){if(e.lengthComputable){t(e,e.loaded/e.total)}else{t(e)}}}function k(e){return e&&p(e.headers)&&(e.headers["content-type"]||e.headers["Content-Type"])||false}function P(e,t){var n=t.data;if(p(t.data)||Array.isArray(t.data)){if(k(t)===false){e.setRequestHeader("Content-Type","application/json")}n=JSON.stringify(t.data)}return n}function U(e,t){return function(){clearTimeout(t);e.apply(null,arguments)}}function D(e,t,n){var r=H(e);var o=P(r,e);var u=E(r,t);if(a){r.ontimeout=u}else{var i=setTimeout(function f(){if(r.readyState!==4){r.abort()}},e.timeout);t=U(t,i);u=E(r,t)}r.onreadystatechange=w(e,r,t);r.onerror=u;if(typeof n==="function"){r.onprogress=A(r,n)}try{r.send(o||null)}catch(s){u(s)}return{xhr:r,config:e}}function G(e){return function(t,n,o,a){var u,i,s=null;var f=d({},c,{method:e});var y=r.call(arguments);for(u=0,i=y.length;u<i;u+=1){s=y[u];if(typeof s==="function"){if(y.length===u+1&&typeof y[u-1]==="function"){a=s}else{o=s}}else if(p(s)){d(f,s)}else if(typeof s==="string"&&!f.url){f.url=s}}return D(f,o||l,a)}}function L(e,t,n,r){return G("GET").apply(null,arguments)}L.VERSION=t;L.defaults=c;L.defaultContent="text/plain";L.get=G("GET");L.post=G("POST");L.put=G("PUT");L.patch=G("PATCH");L.head=G("HEAD");L.delete=L.del=G("DELETE");return e.http=L});
//# sourceMappingURL=http://cdn.rawgit.com/lil-js/http/0.1.17/http.min.js.map