# new store()
Class for mapping accessing the local storage
Members
# (static) prefix :string
The prefix for cache keys (default is meta_)
Type:
- string
Methods
# (static) add(k, v) → {boolean}
Add a key in the local storage (will fail, if key already exsits. for overriding use set())
Parameters:
Name | Type | Description |
---|---|---|
k |
string | the key where to save the object |
v |
any | the value to save |
Returns:
true on success
- Type
- boolean
Example
if(j.store.add("some_var","Hello there!"))
{
// key has been added
}
else
{
// key has NOT been added
}
# (static) clear()
Remove all keys from the localstorage matching the prefix
Example
j.store.clear();
# (static) delete(k)
Remove a key from the local storage
Parameters:
Name | Type | Description |
---|---|---|
k |
string | the key where the object is saved |
Example
j.store.delete("some_var");
# (static) get(k) → {any|null}
Fetch a value from the local storage
Parameters:
Name | Type | Description |
---|---|---|
k |
string | the key to fetch |
Returns:
the fetched value deserialized or null if not found
- Type
- any | null
Example
let some_var = j.store.get("some_var");
# (static) has(k) → {boolean}
Find out, if a key exists in the local storage
Parameters:
Name | Type | Description |
---|---|---|
k |
string | the key to lookup |
Returns:
wether or not the key exists
- Type
- boolean
Example
if(j.store.has("some_var") { ... }
# (static) keys() → {Array.<string>}
Get all keys from the localstorage matching the prefix
Returns:
all the keys, that are currently saved in the local storage
- Type
- Array.<string>
Example
j.store.keys().forEach(k => console.log(k));
# (static) remove(k)
Remove a key from the local storage
Parameters:
Name | Type | Description |
---|---|---|
k |
string | the key where the object is saved |
Example
j.store.remove("some_var");
# (static) set(k, v)
Set a value in the local storage (overrides existing)
Parameters:
Name | Type | Description |
---|---|---|
k |
string | the key where to save the object |
v |
any | the value to save |
Example
j.store.set("some_var","Hello there!");