@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.
Files changed (2) hide show
  1. package/lib/esm/index.js +69 -56
  2. package/package.json +3 -3
package/lib/esm/index.js CHANGED
@@ -1,59 +1,72 @@
1
- class Storage {
2
- _data;
3
- constructor() {
4
- this._data = /* @__PURE__ */ new Map();
5
- }
6
- /** Returns the number of key/value pairs. */
7
- get length() {
8
- return this._data.size;
9
- }
10
- /** Returns the name of the nth key, or null if n >= length. */
11
- key(index) {
12
- if (index < 0 || index >= this._data.size) return null;
13
- const keys = Array.from(this._data.keys());
14
- return keys[index];
15
- }
16
- /** Returns the value associated with the given key, or null. */
17
- getItem(key) {
18
- return this._data.get(String(key)) ?? null;
19
- }
20
- /** Sets the value of the pair identified by key to value. */
21
- setItem(key, value) {
22
- this._data.set(String(key), String(value));
23
- }
24
- /** Removes the key/value pair with the given key. */
25
- removeItem(key) {
26
- this._data.delete(String(key));
27
- }
28
- /** Removes all key/value pairs. */
29
- clear() {
30
- this._data.clear();
31
- }
32
- /** @internal Get all entries (for serialization). */
33
- _entries() {
34
- return Array.from(this._data.entries());
35
- }
36
- /** @internal Load data from entries (for deserialization). */
37
- _load(entries) {
38
- this._data.clear();
39
- for (const [key, value] of entries) {
40
- this._data.set(key, value);
41
- }
42
- }
43
- get [Symbol.toStringTag]() {
44
- return "Storage";
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 index_default = {
50
- Storage,
51
- localStorage,
52
- sessionStorage
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.13",
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.13",
36
- "@gjsify/unit": "^0.3.13",
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
  }