Default value in get() function
Closed this issue · 2 comments
maverick42 commented
Hi,
I like Simplestorage.But the [defaultValue] in get() function is missing ...
I must copy the jstorage code (one line ...) on every new version
if you can add this little but "required" option :)
Regards
Frédérik
andris9 commented
I'm not changing the API – it is meant to be minimal – but you can easily create your own wrapper function:
function storageGet(key, defaultValue){
var value = simpleStorage.get(key);
return typeof value == 'undefined' ? defaultValue : value;
}
And then use storageGet()
instead of simpleStorage.get()
.
will-e-yams commented
the defaultValue
is null
; that makes the most sense.