Overview
api.storage wraps localStorage with automatic JSON serialization.
Global Storage Methods
storage.get(key)
Retrieve a value. Returns null if not found.
| Parameter | Type | Description |
|---|---|---|
key | string | Storage key |
any | null
storage.set(key, value)
Store a value (auto-serialized to JSON).
| Parameter | Type | Description |
|---|---|---|
key | string | Storage key |
value | any | Value to store (must be JSON-serializable) |
storage.set() emits a storage:change event automatically, so other plugins can react to storage updates.storage.remove(key)
Delete a stored key.
storage.list()
Returns an array of all localStorage keys.
string[]
storage.clear()
Clears all localStorage data. Use with caution.
Plugin-Scoped Storage
These methods automatically prefix keys withplugin:{pluginId}:, preventing collisions between plugins. The current plugin ID is determined automatically.
storage.getForPlugin(pluginId, key)
Retrieve a value scoped to a specific plugin.
| Parameter | Type | Description |
|---|---|---|
pluginId | string | Plugin ID to scope to |
key | string | Storage key (no need to prefix manually) |
any | null
storage.setForPlugin(pluginId, key, value)
Store a value scoped to a specific plugin.
| Parameter | Type | Description |
|---|---|---|
pluginId | string | Plugin ID to scope to |
key | string | Storage key (no need to prefix manually) |
value | any | Value to store |
setForPlugin() emits a storage:change event with the pluginId field set, so listeners can identify which plugin changed.Best Practices
Use plugin-scoped storage
Use plugin-scoped storage
Prefer
getForPlugin/setForPlugin over manual prefixing — it’s safer and cleaner:Use nullish coalescing for defaults
Use nullish coalescing for defaults
See Also
- Storage concept — detailed guide with examples
- Persisting Data guide — real-world patterns