angular-local-storage
angular-local-storage copied to clipboard
get('nonExistingProperty') should return undefined, not null
I think if a property does not exist, you should not return a value (null is an object in Javascript).
Also, I think it would be convenient to be able to see if a value exists in localStorage by calling a method like has('aProperty') that returns true or false. I know I could call keys() but that sounds like a workaround :-)
Thanks!
Yeah, I second that. For instance, I store a boolean value in the session storage, but in case it isn't set, I'll use a default value. Problem is, I can't distinguish the 'false' value from a missing key. I could get the list of keys and check whether my key is contained in that list, but that seems a bit overkill. A has('aProperty') method would certainly help.
This is actually the proper return for a native localStorage.getItem call when the key is undefined. While I agree that undefined makes more sense, I don't think we should alter expected behaviour.