doipjs/dist/doip.min.js

2 lines
19 KiB
JavaScript
Raw Normal View History

2020-11-06 10:39:06 -07:00
!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).doip=t()}}((function(){return function t(e,r,o){function s(n,a){if(!r[n]){if(!e[n]){var c="function"==typeof require&&require;if(!a&&c)return c(n,!0);if(i)return i(n,!0);var u=new Error("Cannot find module '"+n+"'");throw u.code="MODULE_NOT_FOUND",u}var l=r[n]={exports:{}};e[n][0].call(l.exports,(function(t){return s(e[n][1][t]||t)}),l,l.exports,t,e,r,o)}return r[n].exports}for(var i="function"==typeof require&&require,n=0;n<o.length;n++)s(o[n]);return s}({1:[function(t,e,r){"use strict";const o=t("./core");class s extends Error{constructor(t,...e){let r;super(...e),Error.captureStackTrace&&Error.captureStackTrace(this,s),this.name="StatusError",this.message=t.statusMessage,this.statusCode=t.status,this.res=t,this.json=t.json.bind(t),this.text=t.text.bind(t),this.arrayBuffer=t.arrayBuffer.bind(t);Object.defineProperty(this,"responseBody",{get:()=>(r||(r=this.arrayBuffer()),r)}),this.headers={};for(const[e,r]of t.headers.entries())this.headers[e.toLowerCase()]=r}}e.exports=o(((t,e,r,o,i)=>async(n,a,c={})=>{n=i+(n||"");let u=new URL(n);if(o||(o={}),u.username&&(o.Authorization="Basic "+btoa(u.username+":"+u.password),u=new URL(u.protocol+"//"+u.host+u.pathname+u.search)),"https:"!==u.protocol&&"http:"!==u.protocol)throw new Error("Unknown protocol, "+u.protocol);if(a)if(a instanceof ArrayBuffer||ArrayBuffer.isView(a)||"string"==typeof a);else{if("object"!=typeof a)throw new Error("Unknown body type.");a=JSON.stringify(a),o["Content-Type"]="application/json"}c=new Headers({...o||{},...c});const l=await fetch(u,{method:e,headers:c,body:a});if(l.statusCode=l.status,!t.has(l.status))throw new s(l);return"json"===r?l.json():"buffer"===r?l.arrayBuffer():"string"===r?l.text():l}))},{"./core":2}],2:[function(t,e,r){"use strict";const o=new Set(["json","buffer","string"]);e.exports=t=>(...e)=>{const r=new Set;let s,i,n,a="";return e.forEach((t=>{if("string"==typeof t)if(t.toUpperCase()===t){if(s){throw new Error(`Can't set method to ${t}, already set to ${s}.`)}s=t}else if(t.startsWith("http:")||t.startsWith("https:"))a=t;else{if(!o.has(t))throw new Error("Unknown encoding, "+t);i=t}else if("number"==typeof t)r.add(t);else{if("object"!=typeof t)throw new Error("Unknown type: "+typeof t);if(Array.isArray(t)||t instanceof Set)t.forEach((t=>r.add(t)));else{if(n)throw new Error("Cannot set headers twice.");n=t}}})),s||(s="GET"),0===r.size&&r.add(200),t(r,s,i,n,a)}},{}],3:[function(t,e,r){},{}],4:[function(t,e,r){"use strict";e.exports=t=>{if("[object Object]"!==Object.prototype.toString.call(t))return!1;const e=Object.getPrototypeOf(t);return null===e||e===Object.prototype}},{}],5:[function(t,e,r){"use strict";const o=t("is-plain-obj"),{hasOwnProperty:s}=Object.prototype,{propertyIsEnumerable:i}=Object,n=(t,e,r)=>Object.defineProperty(t,e,{value:r,writable:!0,enumerable:!0,configurable:!0}),a=this,c={concatArrays:!1,ignoreUndefined:!1},u=t=>{const e=[];for(const r in t)s.call(t,r)&&e.push(r);if(Object.getOwnPropertySymbols){const r=Object.getOwnPropertySymbols(t);for(const o of r)i.call(t,o)&&e.push(o)}return e};function l(t){return Array.isArray(t)?function(t){const e=t.slice(0,0);return u(t).forEach((r=>{n(e,r,l(t[r]))})),e}(t):o(t)?function(t){const e=null===Object.getPrototypeOf(t)?Object.create(null):{};return u(t).forEach((r=>{n(e,r,l(t[r]))})),e}(t):t}const p=(t,e,r,o)=>(r.forEach((r=>{void 0===e[r]&&o.ignoreUndefined||(r in t&&t[r]!==Object.getPrototypeOf(t)?n(t,r,h(t[r],e[r],o)):n(t,r,l(e[r])))})),t);function h(t,e,r){return r.concatArrays&&Array.isArray(t)&&Array.isArray(e)?((t,e,r)=>{let o=t.slice(0,0),i=0;return[t,e].forEach((e=>{const a=[];for(let r=0;r<e.length;r++)s.call(e,r)&&(a.push(String(r)),n(o,i++,e===t?e[r]:l(e[r])));o=p(o,e,u(e).filter((t=>!a.includes(t))),r)})),o})(t,e,r):o(e)&&o(t)?p(t,e,u(e),r):l(e)}e.exports=function(...t){const e=h(l(c),this!==a&&this||{}