/
localeStorager.js
38 lines (34 loc) · 1.1 KB
/
localeStorager.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
* Locale Storager
* A little script that helps in managing the localeStorage of the browser.
* v 0.9 - January 11th 2012
* By Gaya Kessler - http://www.gayadesign.com
*
* Usage:
* The script stores strings and arrays (objects) in the browser's localeStorage. Also an easy way to parse the
* values and get the logical representation in Javascript variables.
*
* localeStorager.store(key, variable)
* Store a variable in the localeStorage using a key.
*
* localeStorager.get(key)
* Get the Javascript representation of the value using the key.
*
* localeStorager.remove(key)
* Remove the value from the localeStorage.
*/
var localeStorager = {
store: function (key, variable) {
//check the kind of variable that has been put in.
localStorage.setItem(key, JSON.stringify(variable));
},
get: function (key) {
//get the value of the key.
return JSON.parse(localStorage.getItem(key));
},
remove: function (key) {
//empty a localeStorage value
localStorage.removeItem(key);
return true;
}
};