Last active
December 12, 2015 03:09
-
-
Save honbin/4704712 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var LocalStorage = LocalStorage || (function() { | |
var LOCAL_STORAGE_KEY = "key"; | |
var connect = function() { | |
if (!localStorage.hasOwnProperty(LOCAL_STORAGE_KEY) ) { | |
var item = {}; | |
localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(item)); | |
} | |
}; | |
var getList = function() { | |
var item = JSON.parse(localStorage.getItem(LOCAL_STORAGE_KEY)); | |
return item[LOCAL_STORAGE_KEY]; | |
}; | |
var isValueKey = function(key) { | |
var item = JSON.parse(localStorage.getItem(LOCAL_STORAGE_KEY)); | |
return item.hasOwnProperty(key); | |
}; | |
var getValue = function(key) { | |
var item = JSON.parse(localStorage.getItem(LOCAL_STORAGE_KEY)); | |
return item[key]; | |
}; | |
var setValue = function(key, val) { | |
var item = {}; | |
item = JSON.parse(localStorage.getItem(LOCAL_STORAGE_KEY)); | |
item[key] = val; | |
return localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(item)); | |
}; | |
var deleteValue = function(key) { | |
var item = JSON.parse(localStorage.getItem(LOCAL_STORAGE_KEY)); | |
delete(item[key]); | |
return localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(item)); | |
}; | |
return { | |
connect : connect, | |
getList : getList, | |
isValueKey : isValueKey, | |
getValue : getValue, | |
setValue : setValue, | |
deleteValue : deleteValue | |
}; | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment