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

http-client

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

http-client - npm Package Compare versions

Comparing version 3.0.1 to 3.1.0

6

CHANGES.md

@@ -0,1 +1,7 @@

## [HEAD]
- Added the `init` middleware
[HEAD]: https://github.com/mjackson/http-client/compare/latest...HEAD
## [3.0.0]

@@ -2,0 +8,0 @@

23

lib/index.js

@@ -6,3 +6,3 @@ 'use strict';

});
exports.requestInfo = exports.parseJSON = exports.parseText = exports.handleResponse = exports.params = exports.json = exports.body = exports.query = exports.base = exports.accept = exports.auth = exports.header = exports.method = exports.createFetch = exports.createStack = exports.fetch = undefined;
exports.requestInfo = exports.parseJSON = exports.parseText = exports.handleResponse = exports.params = exports.json = exports.body = exports.query = exports.base = exports.accept = exports.auth = exports.header = exports.method = exports.init = exports.createFetch = exports.createStack = exports.fetch = undefined;

@@ -84,14 +84,10 @@ var _queryString = require('query-string');

var setHeader = function setHeader(options, name, value) {
(options.headers || (options.headers = {}))[name] = value;
};
/**
* Sets the request method.
* Sets a property name and value in the options object.
*/
var method = exports.method = function method(verb) {
var init = exports.init = function init(propertyName, value) {
return function (fetch, input) {
var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
options.method = verb;
options[propertyName] = value;
return fetch(input, options);

@@ -102,2 +98,13 @@ };

/**
* Sets the request method.
*/
var method = exports.method = function method(verb) {
return init('method', verb);
};
var setHeader = function setHeader(options, name, value) {
(options.headers || (options.headers = {}))[name] = value;
};
/**
* Adds a header to the request.

@@ -104,0 +111,0 @@ */

{
"name": "http-client",
"version": "3.0.1",
"version": "3.1.0",
"description": "Compose HTTP clients using JavaScript's fetch API",

@@ -5,0 +5,0 @@ "author": "Michael Jackson",

@@ -62,3 +62,3 @@ (function webpackUniversalModuleDefinition(root, factory) {

});
exports.requestInfo = exports.parseJSON = exports.parseText = exports.handleResponse = exports.params = exports.json = exports.body = exports.query = exports.base = exports.accept = exports.auth = exports.header = exports.method = exports.createFetch = exports.createStack = exports.fetch = undefined;
exports.requestInfo = exports.parseJSON = exports.parseText = exports.handleResponse = exports.params = exports.json = exports.body = exports.query = exports.base = exports.accept = exports.auth = exports.header = exports.method = exports.init = exports.createFetch = exports.createStack = exports.fetch = undefined;

@@ -140,14 +140,10 @@ var _queryString = __webpack_require__(1);

var setHeader = function setHeader(options, name, value) {
(options.headers || (options.headers = {}))[name] = value;
};
/**
* Sets the request method.
* Sets a property name and value in the options object.
*/
var method = exports.method = function method(verb) {
var init = exports.init = function init(propertyName, value) {
return function (fetch, input) {
var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
options.method = verb;
options[propertyName] = value;
return fetch(input, options);

@@ -158,2 +154,13 @@ };

/**
* Sets the request method.
*/
var method = exports.method = function method(verb) {
return init('method', verb);
};
var setHeader = function setHeader(options, name, value) {
(options.headers || (options.headers = {}))[name] = value;
};
/**
* Adds a header to the request.

@@ -160,0 +167,0 @@ */

@@ -1,1 +0,1 @@

!function(n,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.HTTPClient=t():n.HTTPClient=t()}(this,function(){return function(n){function t(r){if(e[r])return e[r].exports;var o=e[r]={exports:{},id:r,loaded:!1};return n[r].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var e={};return t.m=n,t.c=e,t.p="",t(0)}([function(n,t,e){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.requestInfo=t.parseJSON=t.parseText=t.handleResponse=t.params=t.json=t.body=t.query=t.base=t.accept=t.auth=t.header=t.method=t.createFetch=t.createStack=t.fetch=void 0;var r=e(1),o=function(n,t){return n.then(function(n){return t(null,n)},t)},u=function(n){return function(t,e,r){"function"!=typeof r&&("function"==typeof e?(r=e,e=void 0):"function"==typeof t&&(r=t,t=void 0));var u=n(t,e);return"function"==typeof r?o(u,r):u}},i=u(fetch),c=function(n){return"string"==typeof n?n:JSON.stringify(n)},f=function(n){return"string"==typeof n?n:(0,r.stringify)(n)},a=function(n,t,e){return n(t,e)};t.fetch=i;var s=t.createStack=function(){for(var n=arguments.length,t=Array(n),e=0;n>e;e++)t[e]=arguments[e];return 0===t.length?a:t.reduceRight(function(n,t){return function(e,r,o){return t(function(t,r){return n(e,t,r)},r,o)}})},p=(t.createFetch=function(){if(0===arguments.length)return i;var n=s.apply(void 0,arguments);return u(function(t,e){return n(fetch,t,e)})},function(n,t,e){(n.headers||(n.headers={}))[t]=e}),d=(t.method=function(n){return function(t,e){var r=arguments.length<=2||void 0===arguments[2]?{}:arguments[2];return r.method=n,t(e,r)}},t.header=function(n,t){return function(e,r){var o=arguments.length<=2||void 0===arguments[2]?{}:arguments[2];return p(o,n,t),e(r,o)}}),h=(t.auth=function(n){return d("Authorization",n)},t.accept=function(n){return d("Accept",n)},t.base=function(n){return function(t,e,r){return t(n+(e||""),r)}},t.query=function(n){var t=f(n);return function(n,e,r){return n(e+(-1===e.indexOf("?")?"?":"&")+t,r)}}),l=t.body=function(n,t){return function(e,r){var o=arguments.length<=2||void 0===arguments[2]?{}:arguments[2];return o.body=n,null!=n.length&&p(o,"Content-Length",n.length),t&&p(o,"Content-Type",t),e(r,o)}},v=(t.json=function(n){return l(c(n),"application/json")},t.params=function(n){var t=f(n);return function(n,e){var r=arguments.length<=2||void 0===arguments[2]?{}:arguments[2],o=(r.method||"GET").toUpperCase(),u="GET"===o||"HEAD"===o?h(t):l(t,"application/x-www-form-urlencoded");return u(n,e,r)}},t.handleResponse=function(n){return function(t,e,r){return t(e,r).then(n)}});t.parseText=function(){var n=arguments.length<=0||void 0===arguments[0]?"textString":arguments[0];return v(function(t){return t.text().then(function(e){return t[n]=e,t})})},t.parseJSON=function(){var n=arguments.length<=0||void 0===arguments[0]?"jsonData":arguments[0];return v(function(t){return t.json().then(function(e){return t[n]=e,t},function(n){throw new Error("Error parsing JSON: "+n.stack)})})},t.requestInfo=function(){return function(n,t,e){return n(t,e).then(function(n){return n.requestInput=t,n.requestOptions=e,n},function(){var n=arguments.length<=0||void 0===arguments[0]?new Error:arguments[0];throw n.requestInput=t,n.requestOptions=e,n})}}},function(n,t,e){"use strict";var r=e(2);t.extract=function(n){return n.split("?")[1]||""},t.parse=function(n){return"string"!=typeof n?{}:(n=n.trim().replace(/^(\?|#|&)/,""),n?n.split("&").reduce(function(n,t){var e=t.replace(/\+/g," ").split("="),r=e.shift(),o=e.length>0?e.join("="):void 0;return r=decodeURIComponent(r),o=void 0===o?null:decodeURIComponent(o),n.hasOwnProperty(r)?Array.isArray(n[r])?n[r].push(o):n[r]=[n[r],o]:n[r]=o,n},{}):{})},t.stringify=function(n){return n?Object.keys(n).sort().map(function(t){var e=n[t];return void 0===e?"":null===e?t:Array.isArray(e)?e.slice().sort().map(function(n){return r(t)+"="+r(n)}).join("&"):r(t)+"="+r(e)}).filter(function(n){return n.length>0}).join("&"):""}},function(n,t){"use strict";n.exports=function(n){return encodeURIComponent(n).replace(/[!'()*]/g,function(n){return"%"+n.charCodeAt(0).toString(16).toUpperCase()})}}])});
!function(n,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.HTTPClient=t():n.HTTPClient=t()}(this,function(){return function(n){function t(r){if(e[r])return e[r].exports;var o=e[r]={exports:{},id:r,loaded:!1};return n[r].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var e={};return t.m=n,t.c=e,t.p="",t(0)}([function(n,t,e){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.requestInfo=t.parseJSON=t.parseText=t.handleResponse=t.params=t.json=t.body=t.query=t.base=t.accept=t.auth=t.header=t.method=t.init=t.createFetch=t.createStack=t.fetch=void 0;var r=e(1),o=function(n,t){return n.then(function(n){return t(null,n)},t)},u=function(n){return function(t,e,r){"function"!=typeof r&&("function"==typeof e?(r=e,e=void 0):"function"==typeof t&&(r=t,t=void 0));var u=n(t,e);return"function"==typeof r?o(u,r):u}},i=u(fetch),c=function(n){return"string"==typeof n?n:JSON.stringify(n)},f=function(n){return"string"==typeof n?n:(0,r.stringify)(n)},a=function(n,t,e){return n(t,e)};t.fetch=i;var s=t.createStack=function(){for(var n=arguments.length,t=Array(n),e=0;n>e;e++)t[e]=arguments[e];return 0===t.length?a:t.reduceRight(function(n,t){return function(e,r,o){return t(function(t,r){return n(e,t,r)},r,o)}})},p=(t.createFetch=function(){if(0===arguments.length)return i;var n=s.apply(void 0,arguments);return u(function(t,e){return n(fetch,t,e)})},t.init=function(n,t){return function(e,r){var o=arguments.length<=2||void 0===arguments[2]?{}:arguments[2];return o[n]=t,e(r,o)}}),d=(t.method=function(n){return p("method",n)},function(n,t,e){(n.headers||(n.headers={}))[t]=e}),h=t.header=function(n,t){return function(e,r){var o=arguments.length<=2||void 0===arguments[2]?{}:arguments[2];return d(o,n,t),e(r,o)}},l=(t.auth=function(n){return h("Authorization",n)},t.accept=function(n){return h("Accept",n)},t.base=function(n){return function(t,e,r){return t(n+(e||""),r)}},t.query=function(n){var t=f(n);return function(n,e,r){return n(e+(-1===e.indexOf("?")?"?":"&")+t,r)}}),v=t.body=function(n,t){return function(e,r){var o=arguments.length<=2||void 0===arguments[2]?{}:arguments[2];return o.body=n,null!=n.length&&d(o,"Content-Length",n.length),t&&d(o,"Content-Type",t),e(r,o)}},y=(t.json=function(n){return v(c(n),"application/json")},t.params=function(n){var t=f(n);return function(n,e){var r=arguments.length<=2||void 0===arguments[2]?{}:arguments[2],o=(r.method||"GET").toUpperCase(),u="GET"===o||"HEAD"===o?l(t):v(t,"application/x-www-form-urlencoded");return u(n,e,r)}},t.handleResponse=function(n){return function(t,e,r){return t(e,r).then(n)}});t.parseText=function(){var n=arguments.length<=0||void 0===arguments[0]?"textString":arguments[0];return y(function(t){return t.text().then(function(e){return t[n]=e,t})})},t.parseJSON=function(){var n=arguments.length<=0||void 0===arguments[0]?"jsonData":arguments[0];return y(function(t){return t.json().then(function(e){return t[n]=e,t},function(n){throw new Error("Error parsing JSON: "+n.stack)})})},t.requestInfo=function(){return function(n,t,e){return n(t,e).then(function(n){return n.requestInput=t,n.requestOptions=e,n},function(){var n=arguments.length<=0||void 0===arguments[0]?new Error:arguments[0];throw n.requestInput=t,n.requestOptions=e,n})}}},function(n,t,e){"use strict";var r=e(2);t.extract=function(n){return n.split("?")[1]||""},t.parse=function(n){return"string"!=typeof n?{}:(n=n.trim().replace(/^(\?|#|&)/,""),n?n.split("&").reduce(function(n,t){var e=t.replace(/\+/g," ").split("="),r=e.shift(),o=e.length>0?e.join("="):void 0;return r=decodeURIComponent(r),o=void 0===o?null:decodeURIComponent(o),n.hasOwnProperty(r)?Array.isArray(n[r])?n[r].push(o):n[r]=[n[r],o]:n[r]=o,n},{}):{})},t.stringify=function(n){return n?Object.keys(n).sort().map(function(t){var e=n[t];return void 0===e?"":null===e?t:Array.isArray(e)?e.slice().sort().map(function(n){return r(t)+"="+r(n)}).join("&"):r(t)+"="+r(e)}).filter(function(n){return n.length>0}).join("&"):""}},function(n,t){"use strict";n.exports=function(n){return encodeURIComponent(n).replace(/[!'()*]/g,function(n){return"%"+n.charCodeAt(0).toString(16).toUpperCase()})}}])});
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