storages - Local storage
Stability: 2 - Stable
The storages module provides persistent storage for simple data and user settings. Stored data remains until the app is uninstalled or deleted explicitly.
It supports types like number, boolean, string, and storing Object / Array via JSON.stringify serialization.
Data stored in storages is shared across scripts. Any script that knows the storage name can access the data, so it must not be used for sensitive secrets. Unlike web localStorage, it cannot provide domain-isolated storage because script paths can change at any time.
storages.create(name)
name{string} Storage name
Create a storage and return a Storage object. Different names are isolated; the same name is shared.
For example, in one script, create a storage named ABC and store a = 123:
var storage = storages.create("ABC");
storage.put("a", 123);Then in another script you can read a from the same storage:
var storage = storages.create("ABC");
log("a = " + storage.get("a"));So the storage name matters. To avoid collisions, use a name containing unique info such as a domain name or author email, for example:
var storage = storages.create("2732014414@qq.com:ABC");storages.remove(name)
name{string} Storage name
Delete a storage and all its data. Returns false if it does not exist; otherwise returns true.
Storages
Storage.get(key[, defaultValue])
key{string} KeydefaultValue{any} Optional default value
Get and return the value for key from storage.
If the key does not exist, returns defaultValue when provided; otherwise returns undefined.
The returned value type depends on what was stored via Storage.put.
Storage.put(key, value)
key{string} Keyvalue{any} Value
Store value to storage under key. value may be any type except undefined. Throws TypeError if value is undefined.
Internally it uses JSON.stringify to convert value to a string, so the value must be JSON-serializable.
Storage.remove(key)
key{string} Key
Remove the value for key. Returns nothing.
Storage.contains(key)
key{string} Key
Returns whether the storage contains the key. true if present, otherwise false.
Storage.clear()
Remove all data in this storage. Returns nothing.
