Created
September 18, 2019 12:49
-
-
Save fatihgvn/7687ae9417125d4cfff3789dbc4190f8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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