@flare/js-utils using

master
Tudor Stanciu 2022-05-09 01:24:52 +03:00
parent 49b529e671
commit 74754e6ba8
3 changed files with 12 additions and 24 deletions

9
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,9 @@
{
"javascript.validate.enable": false,
"javascript.format.enable": true,
"typescript.format.enable": false,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
}

View File

@ -1,23 +0,0 @@
const isArray = parameter => {
const _isArray = parameter.constructor === Array;
// parameter instanceof Array;
// Array.isArray(parameter);
return _isArray;
};
const isObject = parameter => {
const _isObject = typeof parameter === "object" && parameter !== null;
return _isObject;
};
function isJson(str) {
try {
const data = JSON.parse(str);
return { data, success: true };
} catch (e) {
return { data: null, success: false };
}
}
export { isArray, isObject, isJson };

View File

@ -1,6 +1,7 @@
import { isArray, isObject, isJson } from "./dataType";
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);
@ -11,6 +12,7 @@ const setItem = (key, value) => {
const getItem = key => {
var value = window.localStorage.getItem(key);
const { isJson } = typeValidator;
var { data, success } = isJson(value);
if (success) {