hook-use-url
Advanced tools
Comparing version 1.0.8 to 1.0.9
29
index.js
@@ -1,21 +0,21 @@ | ||
import {push, replace} from 'connected-react-router'; | ||
import {useSelector} from 'react-redux'; | ||
import {useDispatch} from 'react-redux'; | ||
import {push, replace} from "connected-react-router"; | ||
import {useSelector} from "react-redux"; | ||
import {useDispatch} from "react-redux"; | ||
const queryString = require('query-string'); | ||
const queryString = require("query-string"); | ||
function pushNewState({dispatch, routerState, allVariables, doReturnUrl, path, doReplaceInsteadPush}) { | ||
const replaceOrPush = doReplaceInsteadPush ? 'replace' : 'push'; | ||
const replaceOrPush = doReplaceInsteadPush ? "replace" : "push"; | ||
const pathname = typeof path === 'string' ? path | ||
const pathname = typeof path === "string" ? path | ||
: routerState && routerState.location && routerState.location.pathname | ||
? routerState.location.pathname | ||
: ''; | ||
: ""; | ||
const hash = routerState && routerState.location && routerState.location.hash | ||
? routerState.location.hash | ||
: ''; | ||
: ""; | ||
const search = queryString.stringify(allVariables); | ||
const url = `${pathname}${search ? `?${search}` : ''}${hash}`; | ||
const url = `${pathname}${search ? `?${search}` : ""}${hash}`; | ||
@@ -25,6 +25,6 @@ if (doReturnUrl === true) { | ||
} | ||
if (replaceOrPush === 'push') { | ||
if (replaceOrPush === "push") { | ||
return dispatch(push(url)); | ||
} | ||
if (replaceOrPush === 'replace') { | ||
if (replaceOrPush === "replace") { | ||
return dispatch(replace(url)); | ||
@@ -40,3 +40,3 @@ } | ||
? routerState.location.search | ||
: ''; | ||
: ""; | ||
const allVariables = queryString.parse(search); | ||
@@ -47,3 +47,3 @@ const url = { | ||
let values = url.get({variable}) || []; | ||
if (typeof values === 'string') { | ||
if (typeof values === "string") { | ||
if (values) { | ||
@@ -97,6 +97,6 @@ values = [values]; | ||
let newVariables = {...allVariables}; | ||
let values = url.arrayGet({variable: pair.variable}); | ||
if (arrayAddPairs && arrayAddPairs.length > 0) { | ||
arrayAddPairs.forEach((pair) => { | ||
let values = url.arrayGet({variable: pair.variable}); | ||
if (values.includes(pair.value) === false) { | ||
@@ -112,3 +112,2 @@ values.push(pair.value); | ||
arrayRemovePairs.forEach((pair) => { | ||
let values = url.arrayGet({variable: pair.variable}); | ||
if (values.includes(pair.value)) { | ||
@@ -115,0 +114,0 @@ values = values.filter((x) => x !== pair.value); |
{ | ||
"name": "hook-use-url", | ||
"version": "1.0.8", | ||
"version": "1.0.9", | ||
"description": "useUrl hook for easier URL reading & writing within ReactJS app", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
7736
220