From 32a05db318ede1b2ec053a8760ee38f3bc7f7431 Mon Sep 17 00:00:00 2001 From: Tudor Stanciu Date: Mon, 30 Jan 2023 00:57:47 +0200 Subject: [PATCH] @flare/js-utils update --- package-lock.json | 6 +++--- package.json | 2 +- src/utils/axios.js | 4 +++- src/utils/identity.js | 4 +++- src/utils/localStorage.js | 38 -------------------------------------- 5 files changed, 10 insertions(+), 44 deletions(-) delete mode 100644 src/utils/localStorage.js diff --git a/package-lock.json b/package-lock.json index fc57e03..28c5294 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1325,9 +1325,9 @@ } }, "@flare/js-utils": { - "version": "1.0.1", - "resolved": "https://lab.code-rove.com/public-node-registry/@flare%2fjs-utils/-/js-utils-1.0.1.tgz", - "integrity": "sha512-54zfXBeof4ns9wEGvUeORd6SiAvCcUNEIiamnLtbASVMY6TxrpGp7UL+Dm7iGdC5jmDb5stla6I8aHroQuvvqg==" + "version": "1.0.2", + "resolved": "https://lab.code-rove.com/public-node-registry/@flare%2fjs-utils/-/js-utils-1.0.2.tgz", + "integrity": "sha512-49KjpcRUD6fXPC60bmCsPa8frU6wlQyI5RsjMD70zsuvk8BZFdopsETsjsCembbmzTScIhfMACU4RnimOEwg9Q==" }, "@gar/promisify": { "version": "1.1.3", diff --git a/package.json b/package.json index 032d0d1..42aa272 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "node-fetch": "^2.6.1" }, "dependencies": { - "@flare/js-utils": "^1.0.0", + "@flare/js-utils": "^1.0.2", "@material-ui/core": "^4.11.3", "@material-ui/icons": "^4.11.2", "@material-ui/lab": "^4.0.0-alpha.60", diff --git a/src/utils/axios.js b/src/utils/axios.js index 0f17e8d..7f49586 100644 --- a/src/utils/axios.js +++ b/src/utils/axios.js @@ -1,7 +1,9 @@ import axios from "axios"; import i18next from "i18next"; -import { getItem } from "./localStorage"; import { storageKeys } from "./identity"; +import { localStorage } from "@flare/js-utils"; + +const { getItem } = localStorage; function getHeaders() { const token = getItem(storageKeys.TOKEN); diff --git a/src/utils/identity.js b/src/utils/identity.js index 5755486..c883331 100644 --- a/src/utils/identity.js +++ b/src/utils/identity.js @@ -1,5 +1,7 @@ import { request } from "./axios"; -import { setItem, getItem, removeItem } from "./localStorage"; +import { localStorage } from "@flare/js-utils"; + +const { setItem, getItem, removeItem } = localStorage; const storageKeys = { TOKEN: "AUTHORIZATION_TOKEN", diff --git a/src/utils/localStorage.js b/src/utils/localStorage.js deleted file mode 100644 index 1d4fcdf..0000000 --- a/src/utils/localStorage.js +++ /dev/null @@ -1,38 +0,0 @@ -import { typeValidator } from "@flare/js-utils"; - -const setItem = (key, value) => { - const { isArray, isObject } = typeValidator; - let valueToStore = value; - if (isArray(value) || isObject(value)) { - valueToStore = JSON.stringify(value); - } - - window.localStorage.setItem(key, valueToStore); -}; - -const getItem = (key) => { - var value = window.localStorage.getItem(key); - const { isJson } = typeValidator; - var { data, success } = isJson(value); - - if (success) { - return data; - } else { - return value; - } -}; - -const removeItem = (key) => { - window.localStorage.removeItem(key); -}; - -const clear = () => { - window.localStorage.clear(); -}; - -const key = (index) => { - var keyName = window.localStorage.key(index); - return keyName; -}; - -export { setItem, getItem, removeItem, clear, key };