diff --git a/.gitignore b/.gitignore index 394c46f..dd1053e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ .grunt node_modules _SpecRunner.html +package-lock.json +lockr.min.js \ No newline at end of file diff --git a/lockr.js b/lockr.js index 846fc33..9552ed5 100644 --- a/lockr.js +++ b/lockr.js @@ -73,12 +73,12 @@ value = null; } } - if(value === null) { + + if(!value) { return missing; - } else if (typeof value === 'object' && typeof value.data !== 'undefined') { + } + else if (typeof value === 'object' && typeof value.data !== 'undefined') { return value.data; - } else { - return missing; } }; @@ -111,11 +111,8 @@ } catch (e) { value = null; } - - if (value === null) - return []; - else - return (value.data || []); + + return (value && value.data) ? value.data : []; }; Lockr.sismember = function(key, value, options) { diff --git a/lockr.min.js b/lockr.min.js deleted file mode 100644 index 47eba50..0000000 --- a/lockr.min.js +++ /dev/null @@ -1 +0,0 @@ -!function(root,factory){"undefined"!=typeof exports?"undefined"!=typeof module&&module.exports&&(exports=module.exports=factory(root,exports)):"function"==typeof define&&define.amd?define(["exports"],function(exports){root.Lockr=factory(root,exports)}):root.Lockr=factory(root,{})}(this,function(root,Lockr){"use strict";return Array.prototype.indexOf||(Array.prototype.indexOf=function(elt){var len=this.length>>>0,from=Number(arguments[1])||0;for(from=from<0?Math.ceil(from):Math.floor(from),from<0&&(from+=len);from-1)return null;try{values.push(value),json=JSON.stringify({data:values}),localStorage.setItem(query_key,json)}catch(e){console.log(e),console&&console.warn("Lockr didn't successfully add the "+value+" to "+key+" set, because the localStorage is full.")}},Lockr.smembers=function(key,options){var value,query_key=this._getPrefixedKey(key,options);try{value=JSON.parse(localStorage.getItem(query_key))}catch(e){value=null}return null===value?[]:value.data||[]},Lockr.sismember=function(key,value,options){return Lockr.smembers(key).indexOf(value)>-1},Lockr.keys=function(){var keys=[],allKeys=Object.keys(localStorage);return 0===Lockr.prefix.length?allKeys:(allKeys.forEach(function(key){key.indexOf(Lockr.prefix)!==-1&&keys.push(key.replace(Lockr.prefix,""))}),keys)},Lockr.getAll=function(includeKeys){var keys=Lockr.keys();return includeKeys?keys.reduce(function(accum,key){var tempObj={};return tempObj[key]=Lockr.get(key),accum.push(tempObj),accum},[]):keys.map(function(key){return Lockr.get(key)})},Lockr.srem=function(key,value,options){var json,index,query_key=this._getPrefixedKey(key,options),values=Lockr.smembers(key,value);index=values.indexOf(value),index>-1&&values.splice(index,1),json=JSON.stringify({data:values});try{localStorage.setItem(query_key,json)}catch(e){console&&console.warn("Lockr couldn't remove the "+value+" from the set "+key)}},Lockr.rm=function(key){localStorage.removeItem(key)},Lockr.flush=function(){Lockr.prefix.length?Lockr.keys().forEach(function(key){localStorage.removeItem(Lockr._getPrefixedKey(key))}):localStorage.clear()},Lockr}); \ No newline at end of file