@elasticias/utils 0.0.10
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/README.md +7 -0
- package/fesm2022/elasticias-utils.mjs +145 -0
- package/fesm2022/elasticias-utils.mjs.map +1 -0
- package/package.json +28 -0
- package/types/elasticias-utils.d.ts +34 -0
package/README.md
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configurable prefix-based wrapper for localStorage and sessionStorage.
|
|
3
|
+
* Default prefix is 'Elasticias_'. Override via `StorageUtils.configure()`.
|
|
4
|
+
*/
|
|
5
|
+
class StorageUtils {
|
|
6
|
+
static _prefix = 'Elasticias_';
|
|
7
|
+
static configure(prefix) {
|
|
8
|
+
StorageUtils._prefix = prefix;
|
|
9
|
+
}
|
|
10
|
+
static get prefix() {
|
|
11
|
+
return StorageUtils._prefix;
|
|
12
|
+
}
|
|
13
|
+
static getPrefixedKey(key) {
|
|
14
|
+
return `${StorageUtils._prefix}${key}`;
|
|
15
|
+
}
|
|
16
|
+
static setLocal(key, value) {
|
|
17
|
+
try {
|
|
18
|
+
const localKey = this.getPrefixedKey(key);
|
|
19
|
+
localStorage.setItem(localKey, JSON.stringify(value));
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
console.error('Error storing data in localStorage: ', key, error);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
static getLocal(key, usePrefix = true) {
|
|
26
|
+
const localKey = usePrefix ? this.getPrefixedKey(key) : key;
|
|
27
|
+
const item = localStorage.getItem(localKey);
|
|
28
|
+
try {
|
|
29
|
+
if (item) {
|
|
30
|
+
return JSON.parse(item);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
console.error('Error parsing JSON from localStorage: ', key, error);
|
|
35
|
+
}
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
static removeLocal(key) {
|
|
39
|
+
localStorage.removeItem(this.getPrefixedKey(key));
|
|
40
|
+
}
|
|
41
|
+
static clearLocal() {
|
|
42
|
+
localStorage.clear();
|
|
43
|
+
}
|
|
44
|
+
static setSession(key, value) {
|
|
45
|
+
const sessionKey = this.getPrefixedKey(key);
|
|
46
|
+
sessionStorage.setItem(sessionKey, JSON.stringify(value));
|
|
47
|
+
}
|
|
48
|
+
static getSession(key) {
|
|
49
|
+
const sessionKey = this.getPrefixedKey(key);
|
|
50
|
+
const item = sessionStorage.getItem(sessionKey);
|
|
51
|
+
return item ? JSON.parse(item) : null;
|
|
52
|
+
}
|
|
53
|
+
static removeSession(key) {
|
|
54
|
+
sessionStorage.removeItem(this.getPrefixedKey(key));
|
|
55
|
+
}
|
|
56
|
+
static clearSession() {
|
|
57
|
+
sessionStorage.clear();
|
|
58
|
+
}
|
|
59
|
+
static existsLocal(key) {
|
|
60
|
+
return localStorage.getItem(this.getPrefixedKey(key)) !== null;
|
|
61
|
+
}
|
|
62
|
+
static existsSession(key) {
|
|
63
|
+
return sessionStorage.getItem(this.getPrefixedKey(key)) !== null;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
class AppUtils {
|
|
68
|
+
static toCamelCase(str) {
|
|
69
|
+
if (!str)
|
|
70
|
+
return '';
|
|
71
|
+
const words = str
|
|
72
|
+
.replace(/([a-z])([A-Z])/g, '$1 $2')
|
|
73
|
+
.split(/[\s_]+/)
|
|
74
|
+
.filter(Boolean);
|
|
75
|
+
return words
|
|
76
|
+
.map((word, index) => {
|
|
77
|
+
word = word.toLowerCase();
|
|
78
|
+
return index === 0 ? word : word.charAt(0).toUpperCase() + word.slice(1);
|
|
79
|
+
})
|
|
80
|
+
.join('');
|
|
81
|
+
}
|
|
82
|
+
static toPascalCase(str) {
|
|
83
|
+
const words = str.split(/[\s_]+/).filter(Boolean);
|
|
84
|
+
return words
|
|
85
|
+
.map((word) => {
|
|
86
|
+
word = word.toLowerCase();
|
|
87
|
+
return word.charAt(0).toUpperCase() + word.slice(1);
|
|
88
|
+
})
|
|
89
|
+
.join('');
|
|
90
|
+
}
|
|
91
|
+
static toSnakeCase(str) {
|
|
92
|
+
const words = str.split(/[\s_]+/).filter(Boolean);
|
|
93
|
+
return words.map((word) => word.toLowerCase()).join('_');
|
|
94
|
+
}
|
|
95
|
+
static isNullOrEmpty(value) {
|
|
96
|
+
if (value == null)
|
|
97
|
+
return true;
|
|
98
|
+
if (Array.isArray(value) && value.length === 0)
|
|
99
|
+
return true;
|
|
100
|
+
if (typeof value === 'object' && Object.keys(value).length === 0)
|
|
101
|
+
return true;
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
static truncate(text, maxLength = 50, ellipsis = '...', preserveWords = false) {
|
|
105
|
+
if (!text)
|
|
106
|
+
return '';
|
|
107
|
+
if (text.length <= maxLength)
|
|
108
|
+
return text;
|
|
109
|
+
if (maxLength < ellipsis.length + 2) {
|
|
110
|
+
return text.slice(0, Math.max(0, maxLength - ellipsis.length)) + ellipsis;
|
|
111
|
+
}
|
|
112
|
+
const visibleChars = maxLength - ellipsis.length;
|
|
113
|
+
const startChars = Math.ceil(visibleChars / 2);
|
|
114
|
+
const endChars = Math.floor(visibleChars / 2);
|
|
115
|
+
let start = text.slice(0, startChars);
|
|
116
|
+
let end = text.slice(text.length - endChars);
|
|
117
|
+
if (preserveWords) {
|
|
118
|
+
const lastSpaceInStart = start.lastIndexOf(' ');
|
|
119
|
+
if (lastSpaceInStart > visibleChars * 0.3) {
|
|
120
|
+
start = start.slice(0, lastSpaceInStart);
|
|
121
|
+
}
|
|
122
|
+
const firstSpaceInEnd = end.indexOf(' ');
|
|
123
|
+
if (firstSpaceInEnd !== -1 && firstSpaceInEnd < endChars * 0.7) {
|
|
124
|
+
end = end.slice(firstSpaceInEnd + 1);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return `${start}${ellipsis}${end}`;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
class UuidUtils {
|
|
132
|
+
static randomUUID() {
|
|
133
|
+
if (globalThis.crypto && typeof globalThis.crypto.randomUUID === 'function') {
|
|
134
|
+
return globalThis.crypto.randomUUID();
|
|
135
|
+
}
|
|
136
|
+
return `${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 10)}`;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Generated bundle index. Do not edit.
|
|
142
|
+
*/
|
|
143
|
+
|
|
144
|
+
export { AppUtils, StorageUtils, UuidUtils };
|
|
145
|
+
//# sourceMappingURL=elasticias-utils.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"elasticias-utils.mjs","sources":["../../../../libs/utils/src/lib/storage.utils.ts","../../../../libs/utils/src/lib/app.utils.ts","../../../../libs/utils/src/lib/uuid.utils.ts","../../../../libs/utils/src/elasticias-utils.ts"],"sourcesContent":["/**\n * Configurable prefix-based wrapper for localStorage and sessionStorage.\n * Default prefix is 'Elasticias_'. Override via `StorageUtils.configure()`.\n */\nexport class StorageUtils {\n private static _prefix = 'Elasticias_';\n\n static configure(prefix: string): void {\n StorageUtils._prefix = prefix;\n }\n\n static get prefix(): string {\n return StorageUtils._prefix;\n }\n\n private static getPrefixedKey(key: string): string {\n return `${StorageUtils._prefix}${key}`;\n }\n\n static setLocal(key: string, value: unknown): void {\n try {\n const localKey = this.getPrefixedKey(key);\n localStorage.setItem(localKey, JSON.stringify(value));\n } catch (error) {\n console.error('Error storing data in localStorage: ', key, error);\n }\n }\n\n static getLocal<T>(key: string, usePrefix = true): T | null {\n const localKey = usePrefix ? this.getPrefixedKey(key) : key;\n const item = localStorage.getItem(localKey);\n try {\n if (item) {\n return JSON.parse(item) as T;\n }\n } catch (error) {\n console.error('Error parsing JSON from localStorage: ', key, error);\n }\n return null;\n }\n\n static removeLocal(key: string): void {\n localStorage.removeItem(this.getPrefixedKey(key));\n }\n\n static clearLocal(): void {\n localStorage.clear();\n }\n\n static setSession(key: string, value: unknown): void {\n const sessionKey = this.getPrefixedKey(key);\n sessionStorage.setItem(sessionKey, JSON.stringify(value));\n }\n\n static getSession<T>(key: string): T | null {\n const sessionKey = this.getPrefixedKey(key);\n const item = sessionStorage.getItem(sessionKey);\n return item ? (JSON.parse(item) as T) : null;\n }\n\n static removeSession(key: string): void {\n sessionStorage.removeItem(this.getPrefixedKey(key));\n }\n\n static clearSession(): void {\n sessionStorage.clear();\n }\n\n static existsLocal(key: string): boolean {\n return localStorage.getItem(this.getPrefixedKey(key)) !== null;\n }\n\n static existsSession(key: string): boolean {\n return sessionStorage.getItem(this.getPrefixedKey(key)) !== null;\n }\n}\n","export class AppUtils {\n static toCamelCase(str: string): string {\n if (!str) return '';\n const words = str\n .replace(/([a-z])([A-Z])/g, '$1 $2')\n .split(/[\\s_]+/)\n .filter(Boolean);\n\n return words\n .map((word, index) => {\n word = word.toLowerCase();\n return index === 0 ? word : word.charAt(0).toUpperCase() + word.slice(1);\n })\n .join('');\n }\n\n static toPascalCase(str: string): string {\n const words = str.split(/[\\s_]+/).filter(Boolean);\n return words\n .map((word) => {\n word = word.toLowerCase();\n return word.charAt(0).toUpperCase() + word.slice(1);\n })\n .join('');\n }\n\n static toSnakeCase(str: string): string {\n const words = str.split(/[\\s_]+/).filter(Boolean);\n return words.map((word) => word.toLowerCase()).join('_');\n }\n\n static isNullOrEmpty(value: unknown): boolean {\n if (value == null) return true;\n if (Array.isArray(value) && value.length === 0) return true;\n if (typeof value === 'object' && Object.keys(value).length === 0) return true;\n return false;\n }\n\n static truncate(\n text: string | null | undefined,\n maxLength = 50,\n ellipsis = '...',\n preserveWords = false\n ): string {\n if (!text) return '';\n if (text.length <= maxLength) return text;\n\n if (maxLength < ellipsis.length + 2) {\n return text.slice(0, Math.max(0, maxLength - ellipsis.length)) + ellipsis;\n }\n\n const visibleChars = maxLength - ellipsis.length;\n const startChars = Math.ceil(visibleChars / 2);\n const endChars = Math.floor(visibleChars / 2);\n\n let start = text.slice(0, startChars);\n let end = text.slice(text.length - endChars);\n\n if (preserveWords) {\n const lastSpaceInStart = start.lastIndexOf(' ');\n if (lastSpaceInStart > visibleChars * 0.3) {\n start = start.slice(0, lastSpaceInStart);\n }\n const firstSpaceInEnd = end.indexOf(' ');\n if (firstSpaceInEnd !== -1 && firstSpaceInEnd < endChars * 0.7) {\n end = end.slice(firstSpaceInEnd + 1);\n }\n }\n\n return `${start}${ellipsis}${end}`;\n }\n}\n","export class UuidUtils {\n static randomUUID(): string {\n if (globalThis.crypto && typeof globalThis.crypto.randomUUID === 'function') {\n return globalThis.crypto.randomUUID();\n }\n return `${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 10)}`;\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":"AAAA;;;AAGG;MACU,YAAY,CAAA;AACf,IAAA,OAAO,OAAO,GAAG,aAAa;IAEtC,OAAO,SAAS,CAAC,MAAc,EAAA;AAC7B,QAAA,YAAY,CAAC,OAAO,GAAG,MAAM;IAC/B;AAEA,IAAA,WAAW,MAAM,GAAA;QACf,OAAO,YAAY,CAAC,OAAO;IAC7B;IAEQ,OAAO,cAAc,CAAC,GAAW,EAAA;AACvC,QAAA,OAAO,GAAG,YAAY,CAAC,OAAO,CAAA,EAAG,GAAG,EAAE;IACxC;AAEA,IAAA,OAAO,QAAQ,CAAC,GAAW,EAAE,KAAc,EAAA;AACzC,QAAA,IAAI;YACF,MAAM,QAAQ,GAAG,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC;AACzC,YAAA,YAAY,CAAC,OAAO,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QACvD;QAAE,OAAO,KAAK,EAAE;YACd,OAAO,CAAC,KAAK,CAAC,sCAAsC,EAAE,GAAG,EAAE,KAAK,CAAC;QACnE;IACF;AAEA,IAAA,OAAO,QAAQ,CAAI,GAAW,EAAE,SAAS,GAAG,IAAI,EAAA;AA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+
{
|
|
2
|
+
"name": "@elasticias/utils",
|
|
3
|
+
"version": "0.0.10",
|
|
4
|
+
"sideEffects": false,
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/elasticias/elasticias-framework-ui.git",
|
|
8
|
+
"directory": "libs/utils"
|
|
9
|
+
},
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"registry": "https://registry.npmjs.org",
|
|
12
|
+
"access": "public"
|
|
13
|
+
},
|
|
14
|
+
"module": "fesm2022/elasticias-utils.mjs",
|
|
15
|
+
"typings": "types/elasticias-utils.d.ts",
|
|
16
|
+
"exports": {
|
|
17
|
+
"./package.json": {
|
|
18
|
+
"default": "./package.json"
|
|
19
|
+
},
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./types/elasticias-utils.d.ts",
|
|
22
|
+
"default": "./fesm2022/elasticias-utils.mjs"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"tslib": "^2.3.0"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configurable prefix-based wrapper for localStorage and sessionStorage.
|
|
3
|
+
* Default prefix is 'Elasticias_'. Override via `StorageUtils.configure()`.
|
|
4
|
+
*/
|
|
5
|
+
declare class StorageUtils {
|
|
6
|
+
private static _prefix;
|
|
7
|
+
static configure(prefix: string): void;
|
|
8
|
+
static get prefix(): string;
|
|
9
|
+
private static getPrefixedKey;
|
|
10
|
+
static setLocal(key: string, value: unknown): void;
|
|
11
|
+
static getLocal<T>(key: string, usePrefix?: boolean): T | null;
|
|
12
|
+
static removeLocal(key: string): void;
|
|
13
|
+
static clearLocal(): void;
|
|
14
|
+
static setSession(key: string, value: unknown): void;
|
|
15
|
+
static getSession<T>(key: string): T | null;
|
|
16
|
+
static removeSession(key: string): void;
|
|
17
|
+
static clearSession(): void;
|
|
18
|
+
static existsLocal(key: string): boolean;
|
|
19
|
+
static existsSession(key: string): boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
declare class AppUtils {
|
|
23
|
+
static toCamelCase(str: string): string;
|
|
24
|
+
static toPascalCase(str: string): string;
|
|
25
|
+
static toSnakeCase(str: string): string;
|
|
26
|
+
static isNullOrEmpty(value: unknown): boolean;
|
|
27
|
+
static truncate(text: string | null | undefined, maxLength?: number, ellipsis?: string, preserveWords?: boolean): string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
declare class UuidUtils {
|
|
31
|
+
static randomUUID(): string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export { AppUtils, StorageUtils, UuidUtils };
|