@tuspe/components 1.7.13 → 1.7.14
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 +6 -2
- package/dist/index.js +17 -10
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -47,10 +47,14 @@ export declare const validateArray: (value: any, items?: number) => boolean;
|
|
|
47
47
|
/**
|
|
48
48
|
* CACHE
|
|
49
49
|
*/
|
|
50
|
+
interface Stored {
|
|
51
|
+
date: number;
|
|
52
|
+
value: any;
|
|
53
|
+
}
|
|
50
54
|
export declare const cacheValues: import("svelte/store").Writable<{
|
|
51
|
-
[key: string]:
|
|
55
|
+
[key: string]: Stored;
|
|
52
56
|
}>;
|
|
53
|
-
export declare const handleCache: (key: string, value?: any) => any;
|
|
57
|
+
export declare const handleCache: (key: string, value?: any, ttl?: number) => any;
|
|
54
58
|
/**
|
|
55
59
|
* PREVENT DEFAULT
|
|
56
60
|
*/
|
package/dist/index.js
CHANGED
|
@@ -75,22 +75,29 @@ export const validateString = (value) => {
|
|
|
75
75
|
export const validateArray = (value, items = 0) => {
|
|
76
76
|
return value && Array.isArray(value) && value.length > items ? true : false;
|
|
77
77
|
};
|
|
78
|
-
/**
|
|
79
|
-
* CACHE
|
|
80
|
-
*/
|
|
81
78
|
export const cacheValues = writable({});
|
|
82
|
-
export const handleCache = (key, value = undefined) => {
|
|
79
|
+
export const handleCache = (key, value = undefined, ttl = 60) => {
|
|
83
80
|
if (!key) {
|
|
84
81
|
return null;
|
|
85
82
|
}
|
|
86
|
-
const newKey = slugify(key);
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
83
|
+
const cache = get(cacheValues), newKey = slugify(key), now = Date.now(), ttlMs = ttl * 1000;
|
|
84
|
+
if (value !== undefined) {
|
|
85
|
+
const newValues = {
|
|
86
|
+
...cache,
|
|
87
|
+
[newKey]: { date: now, value }
|
|
88
|
+
};
|
|
89
|
+
cacheValues.set(newValues);
|
|
91
90
|
}
|
|
92
91
|
else if (cache?.[newKey]) {
|
|
93
|
-
|
|
92
|
+
const cachedItem = cache[newKey];
|
|
93
|
+
if (now - cachedItem.date < ttlMs) {
|
|
94
|
+
return cachedItem.value;
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
// Remove expired cache entry
|
|
98
|
+
const { [newKey]: _, ...rest } = cache;
|
|
99
|
+
cacheValues.set(rest);
|
|
100
|
+
}
|
|
94
101
|
}
|
|
95
102
|
return null;
|
|
96
103
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tuspe/components",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.14",
|
|
4
4
|
"description": "A reusable SvelteKit component library for form elements, breadcrumbs, prices and images.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"svelteKit",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"@sveltejs/package": "^2.3.10",
|
|
68
68
|
"@sveltejs/vite-plugin-svelte": "^5.0.3",
|
|
69
69
|
"eslint-config-prettier": "^10.1.1",
|
|
70
|
-
"eslint-plugin-svelte": "^3.0
|
|
70
|
+
"eslint-plugin-svelte": "^3.1.0",
|
|
71
71
|
"eslint": "^9.22.0",
|
|
72
72
|
"globals": "^16.0.0",
|
|
73
73
|
"prettier-plugin-svelte": "^3.3.3",
|
|
@@ -79,4 +79,4 @@
|
|
|
79
79
|
"typescript": "^5.8.2",
|
|
80
80
|
"vite": "^6.2.1"
|
|
81
81
|
}
|
|
82
|
-
}
|
|
82
|
+
}
|