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

react-fetch-hook

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-fetch-hook - npm Package Compare versions

Comparing version 1.0.6 to 1.0.7

19

dist/useFetch.js

@@ -10,2 +10,6 @@ "use strict";

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
function useFetch(path, options) {

@@ -16,7 +20,16 @@ var defaultFormatter = function defaultFormatter(response) {

var fetchInstance = function fetchInstance(path, options) {
return fetch(path, options).then(options && options.formatter || defaultFormatter);
var fetchInstance = function fetchInstance(formatter) {
return function (path, options) {
return fetch(path, options).then(typeof formatter === "function" && formatter || defaultFormatter);
};
};
return (0, _usePromise.usePromise)(fetchInstance, path, options);
if (options) {
var formatter = options.formatter,
fetchOptions = _objectWithoutProperties(options, ["formatter"]);
return (0, _usePromise.usePromise)(fetchInstance(formatter), path, fetchOptions);
} else {
return (0, _usePromise.usePromise)(fetchInstance(), path);
}
}

@@ -7,2 +7,3 @@ "use strict";

exports.usePromise = usePromise;
exports.flattenInput = void 0;

@@ -19,5 +20,36 @@ var _react = require("react");

function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
var flattenInput = function flattenInput() {
for (var _len = arguments.length, inputs = new Array(_len), _key = 0; _key < _len; _key++) {
inputs[_key] = arguments[_key];
}
return inputs.reduce(function (accumulator, input) {
if (input instanceof Array) {
return [].concat(_toConsumableArray(accumulator), _toConsumableArray(flattenInput.apply(void 0, _toConsumableArray(input))));
}
if (input instanceof Object) {
var keys = Object.keys(input);
return [].concat(_toConsumableArray(accumulator), _toConsumableArray(flattenInput.apply(void 0, _toConsumableArray(keys.reduce(function (a, k) {
return [].concat(_toConsumableArray(a), [k, input[k]]);
}, [])))));
}
return [].concat(_toConsumableArray(accumulator), [input]);
}, []);
};
exports.flattenInput = flattenInput;
function usePromise(callFunction) {
for (var _len = arguments.length, inputs = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
inputs[_key - 1] = arguments[_key];
for (var _len2 = arguments.length, inputs = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
inputs[_key2 - 1] = arguments[_key2];
}

@@ -55,3 +87,3 @@

(0, _react.useEffect)(call, [].concat(inputs));
(0, _react.useEffect)(call, _toConsumableArray(flattenInput(inputs)));
return {

@@ -58,0 +90,0 @@ data: data,

5

package.json
{
"name": "react-fetch-hook",
"version": "1.0.6",
"version": "1.0.7",
"description": "React fetch hook",

@@ -14,3 +14,4 @@ "main": "./dist/index.js",

"build:lib": "cross-env BABEL_ENV=production babel src --out-dir dist --ignore '**/__tests__/**'",
"build:flow": "flow-copy-source -v -i '**/__tests__/**' src dist"
"build:flow": "flow-copy-source -v -i '**/__tests__/**' src dist",
"prepublish": "npm run flow:check && npm run test && npm run build"
},

@@ -17,0 +18,0 @@ "jest": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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