better-localstorage - v1.1.1
Table of content
Installation
This module is published through the NPM registry. You can easly install it with the following command:
npm i better-localstorage
Usage
This module allow to interact with client's localstorage and store JSON-parsed data, so each entry can contains JSON-like data.
get(key[, options])
Get an element from the local storage.
Returns
Object
- Entry's content if it exists and its content as been parsed.
undefined
- If the entry doesn't exists.
Parameters
key | string | | Entry's name |
options | GetOptions | :white_check_mark: | Getter's options |
Throw
RangeError
- If key
is not provided.
TypeError
- If the entry's value cannot be parsed as JSON.
Examples
get("test");
get("something");
get("test");
set(key, value)
Set an element to the local storage.
Returns
Parameters
key | string | | Entry's name |
value | Object | | Content to set in the localstorage |
Throw
RangeError
- If key
or value
is not provided.
TypeError
if the value cannot be strigified as JSON.
Examples
set("test", true);
set("something", { hi: "everyone" });
exists(key)
Check if an entry exists in the local storage.
Returns
boolean
- true
if the entry exists, false
otherwise.
Parameters
Throw
RangeError
- If key
is not provided.
Examples
exists("test");
exists("something");
destroy(key)
Remove an entry from the local storage.
Returns
boolean
- true
if the entry has been removed by the function's call, false
otherwise.
Parameters
Throw
RangeError
- If key
is not provided.
Examples
destroy("test");
destroy("something");
clear()
Clear all entries from the local storage.
Returns
boolean
- true
if the entries have been removed by the function's call, false
otherwise.
Examples
clear();
clear();
GetOptions
get()
options.
Content
destroy | boolean | :white_check_mark: | If true , will destroy the entry after calling this function (even if an error occured) |
destroyOnError | boolean | :white_check_mark: | If true , will destroy the entry only if an error occured |
Contributing
Feel free to open an issue if you want to report bugs or discuss about suggestions!
License
MIT