#angular-datastorage
Simple configurable storage service using localStorage or sessionStorage key/value system. Include multiple objects setter and expiration timestamp management
To start using the storage service, simply copy it in your actual AngularJS project and include
angular-datastorage in your main module.
angular-datastorage exposes one config methods over its service DataStorage:
DataStorage.setStorageType(<string>newType)
Used to choose storage system used in the service ('localStorage' or 'sessionStorage'). Default set on localStorage.
angular-datastorage has one universal getter and two setter methods :
DataStorage.get(<string>key)
DataStorage.set(<string>key, <string|object>value, [<string|Date>expirationDate])
DataStorage.setMultiple({key: <string>myKey, value: <string|object>myValue}, [...])
- Get method work with the key. Return the value if found else return
null. If an expirationDate exists and is expired, will returnnull. - Set method accept any type for the value, it will be encapsulated in a JSON object. expirationDate can be a string timestamp or a Date variable. Return
trueif execution went right else returnnull. - setMultiple accept 0 to n parameters. Only thing is that objects need to be encapsulated in a key/value/[expirationDate] object to be set. If setter fails on one of the parameters, stop the execution and return
null. Else returntrueat the end.
angular-datastorage also has complementary methods to update, remove and clear stored data :
DataStorage.update(<string>key, <string|object>value, [<string|Date>expirationDate])
DataStorage.remove(<string>key)
DataStorage.clear()
- Update method modify value and/or expirationDate of a specific key. Return
truein case of success elsenull. If expirationDate expired for the key, will call theremovemethod and returnnull. - Remove delete the entry at the key specified and return
true. Returnnullif the entry doesn't exist. - Clear method wipe the whole storage.
- Abstract calls to the primary methods (setItem, etc.) to be able to extend the service to any key/value storage system
- Create a deleteMultiple method to delete n objects stored
- Include the possibility to bind a logger through an optional object and provide explicit messages