@fixefy/fixefy-ui-utils 0.2.47 → 0.2.48
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -19,6 +19,7 @@ _export_star(require("./json"), exports);
|
|
|
19
19
|
_export_star(require("./makeStyles"), exports);
|
|
20
20
|
const _page_context = /*#__PURE__*/ _interop_require_default(_export_star(require("./page_context"), exports));
|
|
21
21
|
_export_star(require("./redirect"), exports);
|
|
22
|
+
_export_star(require("./storage"), exports);
|
|
22
23
|
_export_star(require("./transform"), exports);
|
|
23
24
|
_export_star(require("./types"), exports);
|
|
24
25
|
_export_star(require("./validate"), exports);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
type StorageType = 'localStorage' | 'sessionStorage';
|
|
2
|
+
export declare const useStorage: () => {
|
|
3
|
+
getItem: ({ key, type }: {
|
|
4
|
+
key: string;
|
|
5
|
+
type: StorageType;
|
|
6
|
+
}) => any;
|
|
7
|
+
setItem: ({ key, value, type }: {
|
|
8
|
+
key: string;
|
|
9
|
+
value: unknown;
|
|
10
|
+
type: StorageType;
|
|
11
|
+
}) => void;
|
|
12
|
+
removeItem: ({ key, type }: {
|
|
13
|
+
key: string;
|
|
14
|
+
type: StorageType;
|
|
15
|
+
}) => void;
|
|
16
|
+
clear: ({ type }: {
|
|
17
|
+
type: StorageType;
|
|
18
|
+
}) => void;
|
|
19
|
+
getStorageLength: ({ type }: {
|
|
20
|
+
type: StorageType;
|
|
21
|
+
}) => number | null;
|
|
22
|
+
};
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "useStorage", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return useStorage;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const isWindow = typeof window !== 'undefined';
|
|
12
|
+
const useStorage = ()=>{
|
|
13
|
+
const isStorageTypeProvided = (type)=>{
|
|
14
|
+
if (!type) {
|
|
15
|
+
throw new Error('Provide type of storage: localStorage or sessionStorage.');
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
const getItem = ({ key, type })=>{
|
|
19
|
+
try {
|
|
20
|
+
if (isWindow) {
|
|
21
|
+
isStorageTypeProvided(type);
|
|
22
|
+
//@ts-ignore
|
|
23
|
+
const item = JSON.parse(window[type].getItem(key));
|
|
24
|
+
if (!item) return null;
|
|
25
|
+
return item;
|
|
26
|
+
}
|
|
27
|
+
} catch (error) {
|
|
28
|
+
// console.log(error)
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
const setItem = ({ key, value, type })=>{
|
|
32
|
+
try {
|
|
33
|
+
if (isWindow) {
|
|
34
|
+
isStorageTypeProvided(type);
|
|
35
|
+
window[type].setItem(key, JSON.stringify(value));
|
|
36
|
+
}
|
|
37
|
+
} catch (error) {
|
|
38
|
+
// console.log(error)
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
const removeItem = ({ key, type })=>{
|
|
42
|
+
try {
|
|
43
|
+
if (isWindow) {
|
|
44
|
+
isStorageTypeProvided(type);
|
|
45
|
+
window[type].removeItem(key);
|
|
46
|
+
}
|
|
47
|
+
} catch (error) {
|
|
48
|
+
// console.log(error)
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
const clear = ({ type })=>{
|
|
52
|
+
try {
|
|
53
|
+
if (isWindow) {
|
|
54
|
+
isStorageTypeProvided(type);
|
|
55
|
+
window[type].clear();
|
|
56
|
+
}
|
|
57
|
+
} catch (error) {
|
|
58
|
+
// console.log(error)
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
const getStorageLength = ({ type })=>{
|
|
62
|
+
try {
|
|
63
|
+
if (isWindow) {
|
|
64
|
+
isStorageTypeProvided(type);
|
|
65
|
+
return window[type].length;
|
|
66
|
+
}
|
|
67
|
+
} catch (error) {
|
|
68
|
+
// console.log(error)
|
|
69
|
+
}
|
|
70
|
+
return null;
|
|
71
|
+
};
|
|
72
|
+
return {
|
|
73
|
+
getItem,
|
|
74
|
+
setItem,
|
|
75
|
+
removeItem,
|
|
76
|
+
clear,
|
|
77
|
+
getStorageLength
|
|
78
|
+
};
|
|
79
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useStorage } from './hooks/use-storage';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "useStorage", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return _usestorage.useStorage;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _usestorage = require("./hooks/use-storage");
|
package/package.json
CHANGED