@sydsoft/base 1.37.0 → 1.39.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/dist/esm/_lib/storage/encData.d.ts +2 -0
- package/dist/esm/_lib/storage/encData.js +38 -0
- package/dist/esm/_lib/storage/localStorage.d.ts +6 -0
- package/dist/esm/_lib/storage/localStorage.js +69 -0
- package/dist/esm/_lib/storage/sessionStorage.d.ts +6 -0
- package/dist/esm/_lib/storage/sessionStorage.js +69 -0
- package/dist/esm/index.d.ts +3 -0
- package/dist/esm/index.js +3 -0
- package/package.json +1 -1
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { isDev } from '../baseFunctions';
|
|
2
|
+
var keys = [3, 5, 8, 11, 15, 22];
|
|
3
|
+
export var encData = function (data) {
|
|
4
|
+
try {
|
|
5
|
+
var utf8Data = unescape(encodeURIComponent(JSON.stringify(data))); // Dizeyi UTF-8'e dönüştür
|
|
6
|
+
var newData_1 = btoa(utf8Data);
|
|
7
|
+
keys.map(function (value) {
|
|
8
|
+
var randomChar = String.fromCharCode(Math.floor(Math.random() * (122 - 97 + 1)) + 97);
|
|
9
|
+
newData_1 = newData_1.slice(0, value) + randomChar + newData_1.slice(value);
|
|
10
|
+
});
|
|
11
|
+
return newData_1;
|
|
12
|
+
}
|
|
13
|
+
catch (e) {
|
|
14
|
+
isDev && console.log('ERROR => encData =>', e);
|
|
15
|
+
return '';
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
export var decData = function (data) {
|
|
19
|
+
try {
|
|
20
|
+
var decode_1 = data;
|
|
21
|
+
keys.map(function (value, index) {
|
|
22
|
+
var prevValue = keys[index - 1];
|
|
23
|
+
if (!prevValue) {
|
|
24
|
+
decode_1 = decode_1.slice(0, value) + decode_1.slice(value + 1);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
decode_1 = decode_1.slice(0, value - index) + decode_1.slice(value - index + 1);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
var decodedString = atob(decode_1);
|
|
31
|
+
var utf8DecodedString = decodeURIComponent(escape(decodedString));
|
|
32
|
+
return JSON.parse(utf8DecodedString);
|
|
33
|
+
}
|
|
34
|
+
catch (e) {
|
|
35
|
+
isDev && console.log('ERROR => decData =>', e);
|
|
36
|
+
return '';
|
|
37
|
+
}
|
|
38
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const setLocalStorage: (key: string, value: any) => boolean;
|
|
2
|
+
export declare const getLocalStorage: (key: string) => any;
|
|
3
|
+
export declare const removeLocalStorage: (key: string) => boolean;
|
|
4
|
+
export declare const clearLocalStorage: () => boolean;
|
|
5
|
+
export declare const getLocalStorageAllKeys: () => string[];
|
|
6
|
+
export declare const getLocalStorageSize: () => number;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { decData, encData } from "./encData";
|
|
2
|
+
import { isDev } from "../baseFunctions";
|
|
3
|
+
var storageAvailable = typeof Storage === "undefined" || !window.localStorage ? false : true;
|
|
4
|
+
export var setLocalStorage = function (key, value) {
|
|
5
|
+
if (!storageAvailable)
|
|
6
|
+
return false;
|
|
7
|
+
try {
|
|
8
|
+
localStorage.setItem(key, encData(value));
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
catch (e) {
|
|
12
|
+
isDev && console.log("ERROR => localStorage =>", e);
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
export var getLocalStorage = function (key) {
|
|
17
|
+
if (!storageAvailable)
|
|
18
|
+
return false;
|
|
19
|
+
try {
|
|
20
|
+
var saved = localStorage.getItem(key);
|
|
21
|
+
return saved ? decData(saved) : null;
|
|
22
|
+
}
|
|
23
|
+
catch (e) {
|
|
24
|
+
isDev && console.log("ERROR => localStorage =>", e);
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
export var removeLocalStorage = function (key) {
|
|
29
|
+
if (!storageAvailable)
|
|
30
|
+
return false;
|
|
31
|
+
try {
|
|
32
|
+
localStorage.removeItem(key);
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
catch (e) {
|
|
36
|
+
isDev && console.log("ERROR => localStorage =>", e);
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
export var clearLocalStorage = function () {
|
|
41
|
+
if (!storageAvailable)
|
|
42
|
+
return false;
|
|
43
|
+
try {
|
|
44
|
+
localStorage.clear();
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
catch (e) {
|
|
48
|
+
isDev && console.log("ERROR => localStorage =>", e);
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
// Tüm localStorage anahtarlarını getir
|
|
53
|
+
export var getLocalStorageAllKeys = function () {
|
|
54
|
+
if (!storageAvailable)
|
|
55
|
+
return [];
|
|
56
|
+
return Object.keys(localStorage);
|
|
57
|
+
};
|
|
58
|
+
// Tüm localStorage boyutunu getir
|
|
59
|
+
export var getLocalStorageSize = function () {
|
|
60
|
+
if (!storageAvailable)
|
|
61
|
+
return 0;
|
|
62
|
+
var total = 0;
|
|
63
|
+
for (var key in localStorage) {
|
|
64
|
+
if (localStorage.hasOwnProperty(key)) {
|
|
65
|
+
total += localStorage[key].length + key.length;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return total;
|
|
69
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const setSessionStorage: (key: string, value: any) => boolean;
|
|
2
|
+
export declare const getSessionStorage: (key: string) => any;
|
|
3
|
+
export declare const removeSessionStorage: (key: string) => boolean;
|
|
4
|
+
export declare const clearSessionStorage: () => boolean;
|
|
5
|
+
export declare const getSessionStorageAllKeys: () => string[];
|
|
6
|
+
export declare const getSessionStorageSize: () => number;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { decData, encData } from "./encData";
|
|
2
|
+
import { isDev } from "../baseFunctions";
|
|
3
|
+
var storageAvailable = typeof Storage === "undefined" || !window.sessionStorage ? false : true;
|
|
4
|
+
export var setSessionStorage = function (key, value) {
|
|
5
|
+
if (!storageAvailable)
|
|
6
|
+
return false;
|
|
7
|
+
try {
|
|
8
|
+
sessionStorage.setItem(key, encData(value));
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
catch (e) {
|
|
12
|
+
isDev && console.log("ERROR => SessionStorage =>", e);
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
export var getSessionStorage = function (key) {
|
|
17
|
+
if (!storageAvailable)
|
|
18
|
+
return false;
|
|
19
|
+
try {
|
|
20
|
+
var saved = sessionStorage.getItem(key);
|
|
21
|
+
return saved ? decData(saved) : null;
|
|
22
|
+
}
|
|
23
|
+
catch (e) {
|
|
24
|
+
isDev && console.log("ERROR => SessionStorage =>", e);
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
export var removeSessionStorage = function (key) {
|
|
29
|
+
if (!storageAvailable)
|
|
30
|
+
return false;
|
|
31
|
+
try {
|
|
32
|
+
sessionStorage.removeItem(key);
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
catch (e) {
|
|
36
|
+
isDev && console.log("ERROR => SessionStorage =>", e);
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
export var clearSessionStorage = function () {
|
|
41
|
+
if (!storageAvailable)
|
|
42
|
+
return false;
|
|
43
|
+
try {
|
|
44
|
+
sessionStorage.clear();
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
catch (e) {
|
|
48
|
+
isDev && console.log("ERROR => SessionStorage =>", e);
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
// Tüm SessionStorage anahtarlarını getir
|
|
53
|
+
export var getSessionStorageAllKeys = function () {
|
|
54
|
+
if (!storageAvailable)
|
|
55
|
+
return [];
|
|
56
|
+
return Object.keys(sessionStorage);
|
|
57
|
+
};
|
|
58
|
+
// Tüm SessionStorage boyutunu getir
|
|
59
|
+
export var getSessionStorageSize = function () {
|
|
60
|
+
if (!storageAvailable)
|
|
61
|
+
return 0;
|
|
62
|
+
var total = 0;
|
|
63
|
+
for (var key in sessionStorage) {
|
|
64
|
+
if (sessionStorage.hasOwnProperty(key)) {
|
|
65
|
+
total += sessionStorage[key].length + key.length;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return total;
|
|
69
|
+
};
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
export * from './_lib/baseFunctions';
|
|
2
2
|
export * from './_lib/inputMask';
|
|
3
3
|
export * from './_lib/storage/cookies';
|
|
4
|
+
export * from './_lib/storage/encData';
|
|
5
|
+
export * from './_lib/storage/localStorage';
|
|
6
|
+
export * from './_lib/storage/sessionStorage';
|
|
4
7
|
export * from './_lib/useInterval';
|
|
5
8
|
export * from './alert';
|
|
6
9
|
export * from './box';
|
package/dist/esm/index.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
export * from './_lib/baseFunctions';
|
|
2
2
|
export * from './_lib/inputMask';
|
|
3
3
|
export * from './_lib/storage/cookies';
|
|
4
|
+
export * from './_lib/storage/encData';
|
|
5
|
+
export * from './_lib/storage/localStorage';
|
|
6
|
+
export * from './_lib/storage/sessionStorage';
|
|
4
7
|
export * from './_lib/useInterval';
|
|
5
8
|
export * from './alert';
|
|
6
9
|
export * from './box';
|