Skip to content

Instantly share code, notes, and snippets.

@fatihgvn
Created September 18, 2019 12:49
Show Gist options
  • Save fatihgvn/7687ae9417125d4cfff3789dbc4190f8 to your computer and use it in GitHub Desktop.
Save fatihgvn/7687ae9417125d4cfff3789dbc4190f8 to your computer and use it in GitHub Desktop.
$Storage.set('lang','EN');
var lang = $Storage.get('lang');
$Storage.setJson('user',{
'username':'james bond',
'password':'cbdb7e2b1ed566ceb796af2df07205a3' //bond007
});
var user = $Storage.getJson('user');
$Storage.delete('user'); // remove 'user' data
// OR
$Storage.clear(); // remove all data
$Storage = {};
$Storage.setJson = function (name, value) {
localStorage.setItem(name, JSON.stringify(value));
}
$Storage.set = function (name, value) {
localStorage.setItem(name, value);
}
$Storage.get = function (name) {
return localStorage.getItem(name);
}
$Storage.getJson = function (name) {
return JSON.parse(localStorage.getItem(name));
}
$Storage.delete = function (name) {
localStorage.removeItem(name);
}
$Storage.clear = function () {
localStorage.clear();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment