Comparing version 0.0.1 to 1.0.0
80
index.js
@@ -7,34 +7,54 @@ 'use strict'; | ||
var attic = function(prefix) { | ||
this.prefix = prefix; | ||
var attic = function() {}; | ||
var supported = function() { | ||
var test = 'test'; | ||
try { | ||
localStorage.setItem(test, test); | ||
localStorage.removeItem(test); | ||
return true; | ||
} catch (e) { | ||
return false; | ||
} | ||
}; | ||
attic.prototype = { | ||
supported: function(){ | ||
var test = 'test'; | ||
try { | ||
localStorage.setItem(test, test); | ||
localStorage.removeItem(test); | ||
return true; | ||
} catch (e) { | ||
return false; | ||
} | ||
}, | ||
get_key: function(key) { | ||
// get a key from storage | ||
str: function(val) { | ||
return JSON.stringify(val); | ||
}, | ||
get_value: function(key, value) { | ||
// find a value in the key | ||
parseVal: function(val) { | ||
return JSON.parse(val); | ||
}, | ||
store_key: function(key, value) { | ||
// store a key value pair | ||
hasKey: function(key) { | ||
return !_.isUndefined(localStorage.getItem(key)) && !_.isEmpty(localStorage.getItem(key)); | ||
}, | ||
remove_value: function(key, value) { | ||
// remove a value from the key | ||
find: function(key) { | ||
if (this.hasKey(key)) { | ||
return this.parseVal(localStorage.getItem(key)); | ||
} else { | ||
return null; | ||
} | ||
}, | ||
remove_key: function(key) { | ||
// remove a key from localstorage | ||
hasValue: function(key, value) { | ||
return _.contains(this.find(key), this.str(value)); | ||
}, | ||
empty: function() { | ||
// remove all keys with the set prefix | ||
store: function(value, key) { | ||
if (this.hasKey(key)) { | ||
if (!this.hasValue(key, value)) { | ||
var arr = this.find(key); | ||
arr.push(this.str(value)); | ||
localStorage.setItem(key, this.str(arr)); | ||
} | ||
} else { | ||
localStorage.setItem(key, this.str([this.str(value)])); | ||
} | ||
return localStorage.getItem(key); | ||
}, | ||
clean: function(value, key) { | ||
var result = _.without(this.find(key), this.str(value)); | ||
localStorage.setItem(key, JSON.stringify(result)); | ||
return result; | ||
}, | ||
cleanKey: function(key) { | ||
localStorage.removeItem(key); | ||
} | ||
@@ -44,9 +64,9 @@ | ||
if(attic.supported()){ | ||
return attic; | ||
}else{ | ||
console.log('localstorage not supported'); | ||
return false; | ||
} | ||
if (supported()) { | ||
return attic; | ||
} else { | ||
console.log('localstorage not supported'); | ||
return false; | ||
} | ||
}()); |
{ | ||
"name": "atticjs", | ||
"version": "0.0.1", | ||
"version": "1.0.0", | ||
"description": "Small localstorage wrapper with prefixing", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
atticjs | ||
======= | ||
Small localstorage wrapper with prefixing | ||
Small localstorage wrapper for storing arrays of strings, objects and arrays | ||
@@ -10,2 +10,2 @@ | ||
Thanks to [Emma Chee](https://github.com/echee) for naming the project :) | ||
Thanks to [Emma Chee](https://github.com/echee) for naming the project :) |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
3902
61
1
11