@vorlefan/react-hooks
Advanced tools
Comparing version 1.0.5 to 1.0.6
@@ -289,3 +289,3 @@ import { useState, useMemo, useCallback, useEffect } from 'react'; | ||
var hasDOM = !!(typeof window !== "undefined" && window.document && window.document.createElement); | ||
var hasDOM = !!(typeof window !== 'undefined' && window.document && window.document.createElement); | ||
/** | ||
@@ -304,3 +304,3 @@ * @description Check out if he website is on 'server-side' or 'client-side' | ||
inClient.set(hasDOM); | ||
if (!!onChange && typeof onChange === "function") onChange(inClient.state); | ||
if (!!onChange && typeof onChange === 'function') onChange(inClient.state); | ||
return function () { | ||
@@ -331,3 +331,3 @@ return inClient.off(); | ||
function useObject(data, assign) { | ||
var _useState = useState(_typeof(assign) === "object" ? Object.assign(data, assign) : data), | ||
var _useState = useState(_typeof(assign) === 'object' ? Object.assign(data, assign) : data), | ||
_useState2 = _slicedToArray(_useState, 2), | ||
@@ -361,3 +361,3 @@ state = _useState2[0], | ||
isValid: function isValid() { | ||
return _typeof(state) === "object" && Object.keys(state).length > 0; | ||
return _typeof(state) === 'object' && Object.keys(state).length > 0; | ||
}, | ||
@@ -418,3 +418,3 @@ empty: function empty() { | ||
generalOptions = _ref$generalOptions === void 0 ? {} : _ref$generalOptions; | ||
var methodHTTP = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "GET"; | ||
var methodHTTP = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'GET'; | ||
var fetch = arguments.length > 2 ? arguments[2] : undefined; | ||
@@ -450,6 +450,6 @@ | ||
var header = useObject(config || {}, !!token ? { | ||
"x-user-token": token | ||
'x-user-token': token | ||
} : {}); | ||
var serializer = useCallback(function (setup) { | ||
return typeof format === "function" ? format(setup) : JSON.stringify(setup); | ||
return typeof format === 'function' ? format(setup) : JSON.stringify(setup); | ||
}, []); | ||
@@ -473,3 +473,3 @@ useEffect(function () { | ||
if (_typeof(generalOptions) === "object") { | ||
if (_typeof(generalOptions) === 'object') { | ||
Object.assign(options, generalOptions); | ||
@@ -482,3 +482,3 @@ } | ||
var queryUrl = ""; | ||
var queryUrl = ''; | ||
@@ -491,7 +491,7 @@ if (queries.isValid()) { | ||
queryUrl += "".concat(key, "=").concat(value); | ||
if (index !== queries.length() - 1) queryUrl += "&"; | ||
if (index !== queries.length() - 1) queryUrl += '&'; | ||
}); | ||
} | ||
fetch("".concat(uri).concat(queryUrl.length > 0 ? "?" + queryUrl : queryUrl), _objectSpread2({}, options)).then( /*#__PURE__*/function () { | ||
fetch("".concat(uri).concat(queryUrl.length > 0 ? '?' + queryUrl : queryUrl), _objectSpread2({}, options)).then( /*#__PURE__*/function () { | ||
var _ref4 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(response) { | ||
@@ -503,3 +503,3 @@ var dataResponse; | ||
case 0: | ||
if (!(typeof onData === "function")) { | ||
if (!(typeof onData === 'function')) { | ||
_context.next = 6; | ||
@@ -528,3 +528,3 @@ break; | ||
success.on(); | ||
if (typeof onSuccess === "function") onSuccess(data); | ||
if (typeof onSuccess === 'function') onSuccess(dataResponse); | ||
loading.off(); | ||
@@ -546,3 +546,3 @@ | ||
success.off(); | ||
if (typeof onSuccess === "function") onError(err); | ||
if (typeof onSuccess === 'function') onError(err); | ||
loading.off(); | ||
@@ -614,3 +614,3 @@ }); | ||
var handleFormat = useCallback(function (value) { | ||
return typeof setup.state.format === "function" ? setup.state.format(value) : value; | ||
return typeof setup.state.format === 'function' ? setup.state.format(value) : value; | ||
}, [setup.state.format]); | ||
@@ -623,9 +623,9 @@ return useMemo(function () { | ||
next: function next() { | ||
return setup.set("value", handleFormat(setup.state.value) >= setup.state.max ? setup.state.reverse ? setup.state.min : setup.state.max : setup.state.value + setup.state.step); | ||
return setup.set('value', handleFormat(setup.state.value) >= setup.state.max ? setup.state.reverse ? setup.state.min : setup.state.max : setup.state.value + setup.state.step); | ||
}, | ||
pred: function pred() { | ||
return setup.set("value", handleFormat(setup.state.value) <= setup.state.min ? setup.state.reverse ? setup.state.max : setup.state.min : setup.state.value - setup.state.step); | ||
return setup.set('value', handleFormat(setup.state.value) <= setup.state.min ? setup.state.reverse ? setup.state.max : setup.state.min : setup.state.value - setup.state.step); | ||
}, | ||
set: function set(state) { | ||
return setup.set("value", state); | ||
return setup.set('value', state); | ||
}, | ||
@@ -646,6 +646,6 @@ is: function is(index) { | ||
start: function start() { | ||
return setup.set("value", setup.state.min); | ||
return setup.set('value', setup.state.min); | ||
}, | ||
end: function end() { | ||
return setup.set("value", setup.state.max); | ||
return setup.set('value', setup.state.max); | ||
}, | ||
@@ -741,5 +741,5 @@ list: function list(value) { | ||
useEffect(function () { | ||
window.addEventListener("click", handleClick); | ||
window.addEventListener('click', handleClick); | ||
return function () { | ||
return window.removeEventListener("click", handleClick); | ||
return window.removeEventListener('click', handleClick); | ||
}; | ||
@@ -767,5 +767,5 @@ }); | ||
useEffect(function () { | ||
window.addEventListener("click", handleClick); | ||
window.addEventListener('click', handleClick); | ||
return function () { | ||
return window.removeEventListener("click", handleClick); | ||
return window.removeEventListener('click', handleClick); | ||
}; | ||
@@ -813,3 +813,3 @@ }); | ||
useEffect(function () { | ||
target.addEventListener("wheel", function (event) { | ||
target.addEventListener('wheel', function (event) { | ||
return handleDirection({ | ||
@@ -822,3 +822,3 @@ event: event, | ||
return function () { | ||
target.removeEventListener("wheel", function (event) { | ||
target.removeEventListener('wheel', function (event) { | ||
return handleDirection({ | ||
@@ -841,3 +841,3 @@ event: event, | ||
function getSize(screenSize, config, aspect) { | ||
if (typeof window === "undefined") { | ||
if (typeof window === 'undefined') { | ||
return config; | ||
@@ -853,3 +853,3 @@ } | ||
innerHeight *= aspect[1] || 1; | ||
var orientation = innerWidth > innerHeight ? "landscape" : "portrait"; | ||
var orientation = innerWidth > innerHeight ? 'landscape' : 'portrait'; | ||
var ratio = +parseFloat(innerHeight / innerWidth).toFixed(2); | ||
@@ -883,3 +883,3 @@ var difference = 0; | ||
ratio: 0.47, | ||
orientation: "landscape", | ||
orientation: 'landscape', | ||
difference: 1 | ||
@@ -898,7 +898,7 @@ }; | ||
useEffect(function () { | ||
window.addEventListener("resize", function () { | ||
window.addEventListener('resize', function () { | ||
handleResize(); | ||
}); | ||
return function () { | ||
window.removeEventListener("resize", handleResize); | ||
window.removeEventListener('resize', handleResize); | ||
}; | ||
@@ -968,5 +968,5 @@ }, []); | ||
if (!!inClient) { | ||
window.addEventListener("scroll", listener); | ||
window.addEventListener('scroll', listener); | ||
return function () { | ||
return window.removeEventListener("scroll", listener); | ||
return window.removeEventListener('scroll', listener); | ||
}; | ||
@@ -973,0 +973,0 @@ } |
@@ -293,3 +293,3 @@ 'use strict'; | ||
var hasDOM = !!(typeof window !== "undefined" && window.document && window.document.createElement); | ||
var hasDOM = !!(typeof window !== 'undefined' && window.document && window.document.createElement); | ||
/** | ||
@@ -308,3 +308,3 @@ * @description Check out if he website is on 'server-side' or 'client-side' | ||
inClient.set(hasDOM); | ||
if (!!onChange && typeof onChange === "function") onChange(inClient.state); | ||
if (!!onChange && typeof onChange === 'function') onChange(inClient.state); | ||
return function () { | ||
@@ -335,3 +335,3 @@ return inClient.off(); | ||
function useObject(data, assign) { | ||
var _useState = react.useState(_typeof(assign) === "object" ? Object.assign(data, assign) : data), | ||
var _useState = react.useState(_typeof(assign) === 'object' ? Object.assign(data, assign) : data), | ||
_useState2 = _slicedToArray(_useState, 2), | ||
@@ -365,3 +365,3 @@ state = _useState2[0], | ||
isValid: function isValid() { | ||
return _typeof(state) === "object" && Object.keys(state).length > 0; | ||
return _typeof(state) === 'object' && Object.keys(state).length > 0; | ||
}, | ||
@@ -422,3 +422,3 @@ empty: function empty() { | ||
generalOptions = _ref$generalOptions === void 0 ? {} : _ref$generalOptions; | ||
var methodHTTP = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "GET"; | ||
var methodHTTP = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'GET'; | ||
var fetch = arguments.length > 2 ? arguments[2] : undefined; | ||
@@ -454,6 +454,6 @@ | ||
var header = useObject(config || {}, !!token ? { | ||
"x-user-token": token | ||
'x-user-token': token | ||
} : {}); | ||
var serializer = react.useCallback(function (setup) { | ||
return typeof format === "function" ? format(setup) : JSON.stringify(setup); | ||
return typeof format === 'function' ? format(setup) : JSON.stringify(setup); | ||
}, []); | ||
@@ -477,3 +477,3 @@ react.useEffect(function () { | ||
if (_typeof(generalOptions) === "object") { | ||
if (_typeof(generalOptions) === 'object') { | ||
Object.assign(options, generalOptions); | ||
@@ -486,3 +486,3 @@ } | ||
var queryUrl = ""; | ||
var queryUrl = ''; | ||
@@ -495,7 +495,7 @@ if (queries.isValid()) { | ||
queryUrl += "".concat(key, "=").concat(value); | ||
if (index !== queries.length() - 1) queryUrl += "&"; | ||
if (index !== queries.length() - 1) queryUrl += '&'; | ||
}); | ||
} | ||
fetch("".concat(uri).concat(queryUrl.length > 0 ? "?" + queryUrl : queryUrl), _objectSpread2({}, options)).then( /*#__PURE__*/function () { | ||
fetch("".concat(uri).concat(queryUrl.length > 0 ? '?' + queryUrl : queryUrl), _objectSpread2({}, options)).then( /*#__PURE__*/function () { | ||
var _ref4 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(response) { | ||
@@ -507,3 +507,3 @@ var dataResponse; | ||
case 0: | ||
if (!(typeof onData === "function")) { | ||
if (!(typeof onData === 'function')) { | ||
_context.next = 6; | ||
@@ -532,3 +532,3 @@ break; | ||
success.on(); | ||
if (typeof onSuccess === "function") onSuccess(data); | ||
if (typeof onSuccess === 'function') onSuccess(dataResponse); | ||
loading.off(); | ||
@@ -550,3 +550,3 @@ | ||
success.off(); | ||
if (typeof onSuccess === "function") onError(err); | ||
if (typeof onSuccess === 'function') onError(err); | ||
loading.off(); | ||
@@ -618,3 +618,3 @@ }); | ||
var handleFormat = react.useCallback(function (value) { | ||
return typeof setup.state.format === "function" ? setup.state.format(value) : value; | ||
return typeof setup.state.format === 'function' ? setup.state.format(value) : value; | ||
}, [setup.state.format]); | ||
@@ -627,9 +627,9 @@ return react.useMemo(function () { | ||
next: function next() { | ||
return setup.set("value", handleFormat(setup.state.value) >= setup.state.max ? setup.state.reverse ? setup.state.min : setup.state.max : setup.state.value + setup.state.step); | ||
return setup.set('value', handleFormat(setup.state.value) >= setup.state.max ? setup.state.reverse ? setup.state.min : setup.state.max : setup.state.value + setup.state.step); | ||
}, | ||
pred: function pred() { | ||
return setup.set("value", handleFormat(setup.state.value) <= setup.state.min ? setup.state.reverse ? setup.state.max : setup.state.min : setup.state.value - setup.state.step); | ||
return setup.set('value', handleFormat(setup.state.value) <= setup.state.min ? setup.state.reverse ? setup.state.max : setup.state.min : setup.state.value - setup.state.step); | ||
}, | ||
set: function set(state) { | ||
return setup.set("value", state); | ||
return setup.set('value', state); | ||
}, | ||
@@ -650,6 +650,6 @@ is: function is(index) { | ||
start: function start() { | ||
return setup.set("value", setup.state.min); | ||
return setup.set('value', setup.state.min); | ||
}, | ||
end: function end() { | ||
return setup.set("value", setup.state.max); | ||
return setup.set('value', setup.state.max); | ||
}, | ||
@@ -745,5 +745,5 @@ list: function list(value) { | ||
react.useEffect(function () { | ||
window.addEventListener("click", handleClick); | ||
window.addEventListener('click', handleClick); | ||
return function () { | ||
return window.removeEventListener("click", handleClick); | ||
return window.removeEventListener('click', handleClick); | ||
}; | ||
@@ -771,5 +771,5 @@ }); | ||
react.useEffect(function () { | ||
window.addEventListener("click", handleClick); | ||
window.addEventListener('click', handleClick); | ||
return function () { | ||
return window.removeEventListener("click", handleClick); | ||
return window.removeEventListener('click', handleClick); | ||
}; | ||
@@ -817,3 +817,3 @@ }); | ||
react.useEffect(function () { | ||
target.addEventListener("wheel", function (event) { | ||
target.addEventListener('wheel', function (event) { | ||
return handleDirection({ | ||
@@ -826,3 +826,3 @@ event: event, | ||
return function () { | ||
target.removeEventListener("wheel", function (event) { | ||
target.removeEventListener('wheel', function (event) { | ||
return handleDirection({ | ||
@@ -845,3 +845,3 @@ event: event, | ||
function getSize(screenSize, config, aspect) { | ||
if (typeof window === "undefined") { | ||
if (typeof window === 'undefined') { | ||
return config; | ||
@@ -857,3 +857,3 @@ } | ||
innerHeight *= aspect[1] || 1; | ||
var orientation = innerWidth > innerHeight ? "landscape" : "portrait"; | ||
var orientation = innerWidth > innerHeight ? 'landscape' : 'portrait'; | ||
var ratio = +parseFloat(innerHeight / innerWidth).toFixed(2); | ||
@@ -887,3 +887,3 @@ var difference = 0; | ||
ratio: 0.47, | ||
orientation: "landscape", | ||
orientation: 'landscape', | ||
difference: 1 | ||
@@ -902,7 +902,7 @@ }; | ||
react.useEffect(function () { | ||
window.addEventListener("resize", function () { | ||
window.addEventListener('resize', function () { | ||
handleResize(); | ||
}); | ||
return function () { | ||
window.removeEventListener("resize", handleResize); | ||
window.removeEventListener('resize', handleResize); | ||
}; | ||
@@ -972,5 +972,5 @@ }, []); | ||
if (!!inClient) { | ||
window.addEventListener("scroll", listener); | ||
window.addEventListener('scroll', listener); | ||
return function () { | ||
return window.removeEventListener("scroll", listener); | ||
return window.removeEventListener('scroll', listener); | ||
}; | ||
@@ -977,0 +977,0 @@ } |
{ | ||
"name": "@vorlefan/react-hooks", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "Useful react hooks for React & Next.js app", | ||
@@ -5,0 +5,0 @@ "author": "DaxSoft", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
161140
2