@gjsify/webstorage 0.3.13 → 0.3.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/lib/esm/index.js +69 -56
- package/package.json +3 -3
package/lib/esm/index.js
CHANGED
|
@@ -1,59 +1,72 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
1
|
+
//#region src/index.ts
|
|
2
|
+
/**
|
|
3
|
+
* Storage class implementing the W3C Web Storage API.
|
|
4
|
+
* https://html.spec.whatwg.org/multipage/webstorage.html
|
|
5
|
+
*/
|
|
6
|
+
var Storage = class {
|
|
7
|
+
_data;
|
|
8
|
+
constructor() {
|
|
9
|
+
this._data = new Map();
|
|
10
|
+
}
|
|
11
|
+
/** Returns the number of key/value pairs. */
|
|
12
|
+
get length() {
|
|
13
|
+
return this._data.size;
|
|
14
|
+
}
|
|
15
|
+
/** Returns the name of the nth key, or null if n >= length. */
|
|
16
|
+
key(index) {
|
|
17
|
+
if (index < 0 || index >= this._data.size) return null;
|
|
18
|
+
const keys = Array.from(this._data.keys());
|
|
19
|
+
return keys[index];
|
|
20
|
+
}
|
|
21
|
+
/** Returns the value associated with the given key, or null. */
|
|
22
|
+
getItem(key) {
|
|
23
|
+
return this._data.get(String(key)) ?? null;
|
|
24
|
+
}
|
|
25
|
+
/** Sets the value of the pair identified by key to value. */
|
|
26
|
+
setItem(key, value) {
|
|
27
|
+
this._data.set(String(key), String(value));
|
|
28
|
+
}
|
|
29
|
+
/** Removes the key/value pair with the given key. */
|
|
30
|
+
removeItem(key) {
|
|
31
|
+
this._data.delete(String(key));
|
|
32
|
+
}
|
|
33
|
+
/** Removes all key/value pairs. */
|
|
34
|
+
clear() {
|
|
35
|
+
this._data.clear();
|
|
36
|
+
}
|
|
37
|
+
/** @internal Get all entries (for serialization). */
|
|
38
|
+
_entries() {
|
|
39
|
+
return Array.from(this._data.entries());
|
|
40
|
+
}
|
|
41
|
+
/** @internal Load data from entries (for deserialization). */
|
|
42
|
+
_load(entries) {
|
|
43
|
+
this._data.clear();
|
|
44
|
+
for (const [key, value] of entries) {
|
|
45
|
+
this._data.set(key, value);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
get [Symbol.toStringTag]() {
|
|
49
|
+
return "Storage";
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* localStorage — persistent key/value storage.
|
|
54
|
+
*
|
|
55
|
+
* On GJS, persistence could be achieved via Gio.File to
|
|
56
|
+
* `GLib.get_user_data_dir()/gjsify/localStorage.json`.
|
|
57
|
+
* Currently backed by in-memory storage for cross-platform compatibility.
|
|
58
|
+
*/
|
|
47
59
|
const localStorage = new Storage();
|
|
60
|
+
/**
|
|
61
|
+
* sessionStorage — per-session key/value storage.
|
|
62
|
+
* Data is lost when the process exits.
|
|
63
|
+
*/
|
|
48
64
|
const sessionStorage = new Storage();
|
|
49
|
-
var
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
};
|
|
54
|
-
export {
|
|
55
|
-
Storage,
|
|
56
|
-
index_default as default,
|
|
57
|
-
localStorage,
|
|
58
|
-
sessionStorage
|
|
65
|
+
var src_default = {
|
|
66
|
+
Storage,
|
|
67
|
+
localStorage,
|
|
68
|
+
sessionStorage
|
|
59
69
|
};
|
|
70
|
+
|
|
71
|
+
//#endregion
|
|
72
|
+
export { Storage, src_default as default, localStorage, sessionStorage };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/webstorage",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.14",
|
|
4
4
|
"description": "W3C Web Storage API (localStorage, sessionStorage) for GJS",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "lib/esm/index.js",
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
"localstorage"
|
|
33
33
|
],
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@gjsify/cli": "^0.3.
|
|
36
|
-
"@gjsify/unit": "^0.3.
|
|
35
|
+
"@gjsify/cli": "^0.3.14",
|
|
36
|
+
"@gjsify/unit": "^0.3.14",
|
|
37
37
|
"@types/node": "^25.6.0",
|
|
38
38
|
"typescript": "^6.0.3"
|
|
39
39
|
}
|