Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

wrape

Package Overview
Dependencies
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wrape - npm Package Compare versions

Comparing version 1.2.63 to 1.2.64

2

package.json
{
"name": "wrape",
"version": "1.2.63",
"version": "1.2.64",
"description": "Easily generate API client's SDK — organize and simplify API Requests — OOP-ish way.",

@@ -5,0 +5,0 @@ "main": "wrape.min.js",

/*!
* Wrape v1.2.63
* Wrape v1.2.64
* Author: Elis <contact@elis.cc>
* License: MIT
*/
function Wrape(e,t,n,r){n=n||{};r=Object.assign({base:"",headers:{},params:{},values:{},sender:!1,request_middleware:null,response_middleware:null,fetch_parse:!0,fetch_agent:!1,fetch_error_handler:!1},r);const a={form:"multipart/form-data",url:"application/x-www-form-urlencoded",json:"application/json",text:"text/plain"},o=Object.values(a),i=["headers","body","query","path"],s={POST:"body",GET:"query"},u={"multipart/form-data":function(){var e=new t;return e.toString=function(){return this},e},"application/x-www-form-urlencoded":function(){return new URLSearchParams},"application/json":function(){return{append:function(e,t){this.data=this.data||{},this.data[e]=t},toString:function(){return JSON.stringify(this.data)},isEmpty:function(){return!this.data||0==Object.keys(this.data).length}}},"text/plain":function(){return{append:function(e,t){return this.data=this.data||[],this.data.push(t)},toString:function(){return this.data.join("")},isEmpty:function(){return!this.data||0==this.data.length}}}};function c(e){return null==e}function f(e){for(var t of e)return!1;return!0}function d(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function p(t,n,r,a){return"function"==typeof r.sender?r.sender(t,n,a,r):e(t,n).then((async function(e){var o={},i=r.fetch_parse,s="function"==typeof a?a:null,u="function"==typeof r.fetch_error_handler?r.fetch_error_handler:null;try{if(i){var c=e.headers.get("Content-Type");o={status_code:e.status,status:e.status,statusText:e.statusText,headers:e.headers},c&&new RegExp("application/json").test(c)?o.json=await e.json():o.text=await e.text();var f=e.ok?"Success.":"Something went wrong.";o.message=o.json&&o.json.message?o.json.message:f}else o=e;if(!e.ok)throw new Error("Request failed.")}catch(e){return u?u(e,{url:t,options:n},o):Promise.reject(e)}return s?s(o):o}))}function l(e,t,n){var a={[t=t||"Wrape"]:function(o){if(!(this instanceof a[t]))throw new Error("You must initalize this object using 'new' command.");Object.assign(this,e);const i=function(e){if(this instanceof i)throw new Error("This object is already initialized.");this.$options=Object.assign({},r,n,e)}.bind(this);return this.set=i,this.set(o),this}};return a[t]}function h(e,n){return e.method="string"==typeof e.method?e.method.toUpperCase():"GET",e.enctype=a[e.enctype]||(o.includes(e.enctype)?e.enctype:o[0]),e.params=e.params||{},n&&(n=Object.assign({},r,n)),async function(a){var l=this.$options||n||r,h=`${l.base}${e.path}`,m={method:e.method,headers:l.headers,agent:l.fetch_agent},y=Object.assign({},l.params,e.params),w=Object.keys(y),g=Array.from(arguments),v=e.request||l.request_middleware,b=e.response||l.response_middleware,j=u[e.enctype](),_=new URLSearchParams;for(var x in g.length>1?a=g.reduce((function(e,t,n){return w[n]?(e[w[n]]=t,e):e}),{}):g[0]instanceof t?(a={},g[0].forEach((function(e,t){a[t]=e}))):a=1!=g.length||1!=w.length||!g[0]||g[0][w[0]]||g[0]instanceof t?a||{}:{[w[0]]:g[0]},y){var E=y[x],S=a[x]||E.default||l.values[x],$=E.name||x;if(E.required&&c(S))throw(q=new Error(E.help||`The '${x}' field is required.`)).field=q.param=x,q;if(!c(S)){if("function"==typeof E.formatter||"function"==typeof E.format){var O=E.format||E.formatter;S=O(S)}if(E.validate){var q,k="function"==typeof E.validate?E.validate(S):new RegExp(E.validate).test(S);if(!k)throw(q=new Error(E.help||`The '${x}' field is invalid.`)).field=q.param=x,q}var T="string"==typeof E.location?E.location.toLowerCase():s[m.method];if(!T||!i.includes(T))throw new Error(`Invalid location for '${x}' field.`);"headers"!=T?"body"!=T?"query"!=T?"path"==T&&(h=h.replace(new RegExp(":"+d($)),S)):_.append($,S):j.append($,S):(m.headers=m.headers||{},m.headers[$]=S)}}var P=_.toString();P&&(h=`${h}?${P}`);var R=j.keys&&f(j.keys())||j.getLengthSync&&0==j.getLengthSync()||j.isEmpty&&j.isEmpty();if(R||(m.body=j.toString()),m.body&&e.enctype!==o[0]&&(m.headers=m.headers||{},m.headers["Content-Type"]=e.enctype),"function"==typeof v){var L=await Promise.resolve(v(h,m,_,j));if(!1===L)return!1;L&&L.url&&(h=L.url),L&&L.options&&(m=returns.options)}return p(h,m,l,b)}}return function e(t,n,r,a){for(var o in n){var i=n[o];if(i&&"object"==typeof i)if(i.hasOwnProperty("path")){var s=i;if(t._ne=!0,void 0!==t[o]){console.warn(`Skipping ${o} as it confilicts with another key in the object, avoid using keys like ('set') because they are reserved constructor words.`);continue}t[o]=h(s,a)}else"$options"===o&&(a=i),t[o]="$"===o.substr(0,1)?i:e({},i,o,a)}return t=t._ne?Object.assign(t,{set:l(t,r,a)}):t}({},n,!0)}!function(e,t){"function"==typeof define&&define.amd?define("wrape",[],t):"object"==typeof module&&module.exports?module.exports=t():e.Wrape=t()}("undefined"!=typeof self?self:this,(function(){const e="object"==typeof module&&module.exports?require("node-fetch"):window.fetch,t="object"==typeof module&&module.exports?require("form-data"):window.FormData;return e?t?Wrape.bind(null,e,t):(console.warn("FormData is not installed. If you are using Node please install form-data."),!1):(console.warn("Fetch API is not installed. If you are using Node please install node-fetch."),!1)}));
function Wrape(e,t,n,r){n=n||{};r=Object.assign({base:"",headers:{},params:{},values:{},sender:!1,request_middleware:null,response_middleware:null,fetch_parse:!0,fetch_agent:!1,fetch_error_handler:!1},r);const a={form:"multipart/form-data",url:"application/x-www-form-urlencoded",json:"application/json",text:"text/plain"},o=Object.values(a),i=["headers","body","query","path"],s={POST:"body",GET:"query"},u={"multipart/form-data":function(){var e=new t;return e.toString=function(){return this},e},"application/x-www-form-urlencoded":function(){return new URLSearchParams},"application/json":function(){return{append:function(e,t){this.data=this.data||{},this.data[e]=t},toString:function(){return JSON.stringify(this.data)},isEmpty:function(){return!this.data||0==Object.keys(this.data).length}}},"text/plain":function(){return{append:function(e,t){return this.data=this.data||[],this.data.push(t)},toString:function(){return this.data.join("")},isEmpty:function(){return!this.data||0==this.data.length}}}};function f(e){return null==e}function c(e){for(var t of e)return!1;return!0}function d(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function p(t,n,r,a){return"function"==typeof r.sender?r.sender(t,n,a,r):e(t,n).then((async function(e){var o={},i=r.fetch_parse,s="function"==typeof a?a:null,u="function"==typeof r.fetch_error_handler?r.fetch_error_handler:null;try{if(i){var f=e.headers.get("Content-Type");o={status_code:e.status,status:e.status,statusText:e.statusText,headers:e.headers},f&&new RegExp("application/json").test(f)?o.json=await e.json():o.text=await e.text();var c=e.ok?"Success.":"Something went wrong.";o.message=o.json&&o.json.message?o.json.message:c}else o=e;if(!e.ok)throw new Error("Request failed.")}catch(e){return u?u(e,{url:t,options:n},o):Promise.reject(e)}return s?s(o):o}))}function l(e,t,n){var a={[t=t||"Wrape"]:function(o){if(!(this instanceof a[t]))throw new Error("You must initalize this object using 'new' command.");Object.assign(this,e);const i=function(e){if(this instanceof i)throw new Error("This object is already initialized.");this.$options=Object.assign({},r,n,e)}.bind(this);return this.set=i,this.set(o),this}};return a[t]}function h(e,n){return e.method="string"==typeof e.method?e.method.toUpperCase():"GET",e.enctype=a[e.enctype]||(o.includes(e.enctype)?e.enctype:o[0]),e.params=e.params||{},n&&(n=Object.assign({},r,n)),async function(a){var l=this.$options||n||r,h=`${l.base}${e.path}`,m={method:e.method,headers:l.headers,agent:l.fetch_agent},y=Object.assign({},l.params,e.params),w=Object.keys(y),g=Array.from(arguments),v=e.request||l.request_middleware,b=e.response||l.response_middleware,j=u[e.enctype](),_=new URLSearchParams;for(var x in g.length>1?a=g.reduce((function(e,t,n){return w[n]?(e[w[n]]=t,e):e}),{}):g[0]instanceof t?(a={},g[0].forEach((function(e,t){a[t]=e}))):a=1!=g.length||1!=w.length||!g[0]||g[0][w[0]]||g[0]instanceof t?a||{}:{[w[0]]:g[0]},y){var E=y[x],S=a[x]||(E.hasOwnProperty("default")?E.default:l.values[x]),$=E.name||x;if(E.required&&f(S))throw(q=new Error(E.help||`The '${x}' field is required.`)).field=q.param=x,q;if(!f(S)){if("function"==typeof E.formatter||"function"==typeof E.format){var O=E.format||E.formatter;S=O(S)}if(E.validate){var q,k="function"==typeof E.validate?E.validate(S):new RegExp(E.validate).test(S);if(!k)throw(q=new Error(E.help||`The '${x}' field is invalid.`)).field=q.param=x,q}var T="string"==typeof E.location?E.location.toLowerCase():s[m.method];if(!T||!i.includes(T))throw new Error(`Invalid location for '${x}' field.`);"headers"!=T?"body"!=T?"query"!=T?"path"==T&&(h=h.replace(new RegExp(":"+d($)),S)):_.append($,S):j.append($,S):(m.headers=m.headers||{},m.headers[$]=S)}}var P=_.toString();P&&(h=`${h}?${P}`);var R=j.keys&&c(j.keys())||j.getLengthSync&&0==j.getLengthSync()||j.isEmpty&&j.isEmpty();if(R||(m.body=j.toString()),m.body&&e.enctype!==o[0]&&(m.headers=m.headers||{},m.headers["Content-Type"]=e.enctype),"function"==typeof v){var L=await Promise.resolve(v(h,m,_,j));if(!1===L)return!1;L&&L.url&&(h=L.url),L&&L.options&&(m=returns.options)}return p(h,m,l,b)}}return function e(t,n,r,a){for(var o in n){var i=n[o];if(i&&"object"==typeof i)if(i.hasOwnProperty("path")){var s=i;if(t._ne=!0,void 0!==t[o]){console.warn(`Skipping ${o} as it confilicts with another key in the object, avoid using keys like ('set') because they are reserved constructor words.`);continue}t[o]=h(s,a)}else{if("$options"===o&&(a=i),"$"===o.substr(0,1))continue;t[o]=e({},i,o,a)}}return t=t._ne?Object.assign(t,{set:l(t,r,a)}):t}({},n,!0)}!function(e,t){"function"==typeof define&&define.amd?define("wrape",[],t):"object"==typeof module&&module.exports?module.exports=t():e.Wrape=t()}("undefined"!=typeof self?self:this,(function(){const e="object"==typeof module&&module.exports?require("node-fetch"):window.fetch,t="object"==typeof module&&module.exports?require("form-data"):window.FormData;return e?t?Wrape.bind(null,e,t):(console.warn("FormData is not installed. If you are using Node please install form-data."),!1):(console.warn("Fetch API is not installed. If you are using Node please install node-fetch."),!1)}));
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc