- * Library that allows you to easily use the localStorage API with more power and flexibility.
+ * Helper library that allows you to use the localStorage API with more power and flexibility.
* @class function LocalStorage
+ * @author Dan Barrett <danb@humaan.com.au>
+ * @copyright Humaan 2016
+ * Copyright (c) 2016 Humaan
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* Fetches the value associated with key from localStorage. If the key/value aren't in localStorage, you can optional provide a callback to run as a fallback getter.
* @param {?function} [optionalCallback=null] - If you want to handle the response in a callback, provide a callback and check the response.
* @returns {*} Returns null if localStorage isn't supported, or the key/value isn't in localStorage, returns anything if it was in localStorage, or returns a callback if key/value was empty in localStorage and callback was provided.
- getItem: function(key, optionalCallback) {
+ getItem: function (key, optionalCallback) {
if (!this.supportsLocalStorage()) {
- var callback = function(data) {
+ var callback = function (data) {
data = typeof data !== 'undefined' ? data : null;
return typeof optionalCallback === 'function' ? optionalCallback(data) : data;
* @param {?int} [expiry=null] - Time in seconds that the localStorage cache should be considered valid.
* @returns {boolean} Returns true if it was stored in localStorage, false otherwise.
- setItem: function(key, value, expiry) {
+ setItem: function (key, value, expiry) {
if (!this.supportsLocalStorage() || typeof value === 'undefined' || key === null || value === null) {
if (typeof expiry === 'number') {
- __expiry: Date.now() + (expiry * 1000)
+ __expiry: Date.now() + (parseInt(expiry) * 1000)
* @param {!string} key - Name of the key in localStorage.
* @returns {void} Remove the key/value combo from the localStorage storage container.
- removeItem: function(key) {
+ removeItem: function (key) {
if (this.supportsLocalStorage()) {
localStorage.removeItem(key);
localStorage.removeItem('_');
// CommonJS module support!
if (typeof module !== 'undefined') {
module.exports = LocalStorage;