use functions from @flare/js-utils

master
Tudor Stanciu 2023-01-30 00:48:47 +02:00
parent 75f7caf2cc
commit 0907c9cedd
6 changed files with 12 additions and 45 deletions

6
package-lock.json generated
View File

@ -1328,9 +1328,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",

View File

@ -13,7 +13,7 @@
},
"private": true,
"dependencies": {
"@flare/js-utils": "^1.0.0",
"@flare/js-utils": "^1.0.2",
"@material-ui/core": "^4.11.2",
"@material-ui/icons": "^4.11.2",
"@testing-library/jest-dom": "^5.11.6",

View File

@ -1,6 +1,7 @@
import { getItem } from "../utils/localStorage";
import { localStorage } from "@flare/js-utils";
import { storageKeys } from "../utils/identity";
const { getItem } = localStorage;
const token = getItem(storageKeys.TOKEN);
const userName = getItem(storageKeys.USER);

View File

@ -1,8 +1,10 @@
import axios from "axios";
import i18next from "i18next";
import { getItem } from "./localStorage";
import { localStorage } from "@flare/js-utils";
import { storageKeys } from "./identity";
const { getItem } = localStorage;
function getHeaders() {
const token = getItem(storageKeys.TOKEN);
const language = i18next.language;

View File

@ -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",

View File

@ -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 };