ZaDarkSide/simpleStorage

Default value in get() function

Closed this issue · 2 comments

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

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().

the defaultValue is null; that makes the most sense.