@gateweb/react-utils 1.16.0 → 1.17.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gateweb/react-utils",
3
- "version": "1.16.0",
3
+ "version": "1.17.0",
4
4
  "description": "React Utils for GateWeb",
5
5
  "homepage": "https://github.com/GatewebSolutions/react-utils",
6
6
  "files": [
@@ -1,53 +0,0 @@
1
- 'use client';
2
- /**
3
- * 從 localStorage 取得資料,支援槽狀取值
4
- *
5
- * @param key 鍵值
6
- * @param deCode 是否解碼
7
- * @returns 取得的資料
8
- * @example
9
- * const data = getLocalStorage('key');
10
- *
11
- * const data = getLocalStorage('key.subKey');
12
- */ const getLocalStorage = (key, deCode = true)=>{
13
- const keys = key.split('.');
14
- const storage = localStorage.getItem(keys[0]);
15
- if (!storage) return undefined;
16
- let currentObject;
17
- try {
18
- if (deCode) {
19
- currentObject = JSON.parse(window.atob(storage));
20
- } else {
21
- currentObject = JSON.parse(storage);
22
- }
23
- } catch (_error) {
24
- return undefined;
25
- }
26
- // let currentObject = JSON.parse(storage);
27
- if (keys.length === 1) {
28
- return currentObject;
29
- }
30
- keys.shift();
31
- while(keys.length > 0){
32
- const currentKey = keys.shift();
33
- if (!currentKey) break;
34
- currentObject = currentObject[currentKey];
35
- if (!currentObject) break;
36
- }
37
- return currentObject;
38
- };
39
- /**
40
- * 將資料存入 localStorage
41
- * @param key 鍵值
42
- * @param value 可序列化的資料
43
- * @param enCode 是否編碼
44
- */ const setLocalStorage = (key, value, enCode = true)=>{
45
- if (enCode) {
46
- localStorage.setItem(key, window.btoa(JSON.stringify(value)));
47
- } else {
48
- localStorage.setItem(key, JSON.stringify(value));
49
- }
50
- };
51
-
52
- exports.getLocalStorage = getLocalStorage;
53
- exports.setLocalStorage = setLocalStorage;
@@ -1,52 +0,0 @@
1
- 'use client';
2
- /**
3
- * 從 localStorage 取得資料,支援槽狀取值
4
- *
5
- * @param key 鍵值
6
- * @param deCode 是否解碼
7
- * @returns 取得的資料
8
- * @example
9
- * const data = getLocalStorage('key');
10
- *
11
- * const data = getLocalStorage('key.subKey');
12
- */ const getLocalStorage = (key, deCode = true)=>{
13
- const keys = key.split('.');
14
- const storage = localStorage.getItem(keys[0]);
15
- if (!storage) return undefined;
16
- let currentObject;
17
- try {
18
- if (deCode) {
19
- currentObject = JSON.parse(window.atob(storage));
20
- } else {
21
- currentObject = JSON.parse(storage);
22
- }
23
- } catch (_error) {
24
- return undefined;
25
- }
26
- // let currentObject = JSON.parse(storage);
27
- if (keys.length === 1) {
28
- return currentObject;
29
- }
30
- keys.shift();
31
- while(keys.length > 0){
32
- const currentKey = keys.shift();
33
- if (!currentKey) break;
34
- currentObject = currentObject[currentKey];
35
- if (!currentObject) break;
36
- }
37
- return currentObject;
38
- };
39
- /**
40
- * 將資料存入 localStorage
41
- * @param key 鍵值
42
- * @param value 可序列化的資料
43
- * @param enCode 是否編碼
44
- */ const setLocalStorage = (key, value, enCode = true)=>{
45
- if (enCode) {
46
- localStorage.setItem(key, window.btoa(JSON.stringify(value)));
47
- } else {
48
- localStorage.setItem(key, JSON.stringify(value));
49
- }
50
- };
51
-
52
- export { getLocalStorage as g, setLocalStorage as s };