Summary
Provides an HTML5 style persistent local storage facility for saving and loading simple key, value information. The local storage is saved in a file that matches the current JavaScript file name with the extension '.db' instead of '.js'. The local storage class is represented by a single object called localStorage.
void setItem(key,value)
string getItem(key)
void removeItem(key)
void clear()
Example
while(true) {
key = document.readln("key:");
if(key == "clear")
localStorage.clear();
if(key == "quit")
break;
value = localStorage.getItem(key);
if(value == null) {
value = document.readln("value:");
localStorage.setItem(key,value);
}
else
document.writeln(key + ":" + value);
}
setItem
Set the value for a given key
void setValue(key,value)
Parameters key - string key to set the value for value - string value for the given key
Return Value
none
Notes
If an existing value exists for the key, it is replaced.
getItem
Gets the value for a given key in local storage
string getItem(key)
Parameters
key - string key to get the value for
Return Value
Text representing the value or empty string if key is not found.
Notes
A safe approach would be to check for null or empty strings to check for non-existent values.
removeItem
Remove the item from local storage given a key
void removeItem(key)
Parameters key - string key to remove entry for
Return Value
none
Notes
The method does nothing if the key does not exist
clear
Clear all items from local storage
void clear()
Parameters
none
Return Value
none
Notes
Removes all items from local storage but does not delete the local storage file.