client-side-storage
Advanced tools
Comparing version 1.0.8 to 1.1.0
{ | ||
"name": "client-side-storage", | ||
"version": "1.0.8", | ||
"version": "1.1.0", | ||
"description": "Simple, extensible, client-side key/value pair storage for winners, like you.", | ||
"main": "src/storage-methods.js", | ||
"main": "dist/storage-methods.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"prebuild": "rm -rf dist && mkdir dist", | ||
"build": "babel src/storage-methods.js -o dist/storage-methods.js", | ||
"commit": "./node_modules/commitizen/bin/git-cz", | ||
"start": "npm run test", | ||
"test": "mocha tests/tests.js -w --compilers js:babel/register", | ||
"test:single": "./node_modules/istanbul/lib/cli.js cover -x *test* _mocha -- -R spec tests/tests.js --compilers js:babel/register", | ||
"semantic-release": "semantic-release pre && npm publish && semantic-release post", | ||
"check-coverage": "./node_modules/istanbul/lib/cli.js check-coverage --statements 80 --branches 80 --lines 80 --functions 80", | ||
"report-coverage": "cat ./coverage/lcov.info | codecov" | ||
}, | ||
@@ -12,8 +20,32 @@ "author": { | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/heydemo/client-side-storage" | ||
}, | ||
"license": "ISC", | ||
"devDependencies": {}, | ||
"devDependencies": { | ||
"babel": "5.8.21", | ||
"chai": "3.4.0", | ||
"chai-as-promised": "5.1.0", | ||
"codecov.io": "0.1.6", | ||
"commitizen": "1.0.5", | ||
"cz-conventional-changelog": "1.1.2", | ||
"ghooks": "0.3.2", | ||
"istanbul": "0.4.0", | ||
"mocha": "1.21.5", | ||
"semantic-release": "4.3.5" | ||
}, | ||
"dependencies": { | ||
"localStorage": "^1.0.3", | ||
"node-aop": "0.1.0", | ||
"q": "^1.4.1" | ||
}, | ||
"czConfig": { | ||
"path": "node_modules/cz-conventional-changelog" | ||
}, | ||
"config": { | ||
"ghooks": { | ||
"pre-commit": "npm run test:single && npm run check-coverage" | ||
} | ||
} | ||
} | ||
} |
@@ -1,1 +0,4 @@ | ||
BROKEN. DON'T USE | ||
[![travis build](https://img.shields.io/travis/heydemo/client-side-storage.svg)](https://travis-ci.org/heydemo/client-side-storage) | ||
[![codecov coverage](https://codecov.io/github/heydemo/client-side-storage.svg)](https://codecov.io/github/heydemo/client-side-storage) | ||
var StorageAPI = require('./StorageAPI'); | ||
StorageAPI.registerStorageMethod('localStorage', require('./Storage.localStorage')); | ||
//StorageAPI.registerStorageMethod('phonegap', require('./Storage.phonegap')); | ||
module.exports = StorageAPI; |
@@ -13,14 +13,10 @@ var Q = require('q'); | ||
get: function(variable) { | ||
var deferred = Q.defer(); | ||
var value = localStorage.getItem(variable); | ||
value = (value == null) ? undefined : JSON.parse(value); | ||
deferred.resolve(value); | ||
return deferred.promise; | ||
return value; | ||
}, | ||
set: function(variable, value) { | ||
value = JSON.stringify(value); | ||
var deferred = Q.defer(); | ||
localStorage.setItem(variable, value); | ||
deferred.resolve(); | ||
return deferred.promise; | ||
return true; | ||
}, | ||
@@ -31,7 +27,7 @@ setMultiple: function(obj) { | ||
value = obj[key]; | ||
Storage.set(key, value); | ||
localStorage.setItem(key, JSON.stringify(value)); | ||
} | ||
return true; | ||
}, | ||
getMultiple: function(keys) { | ||
var deferred = Q.defer(); | ||
var values = {}; | ||
@@ -43,4 +39,3 @@ keys.forEach(function(key) { | ||
}) | ||
deferred.resolve(values); | ||
return deferred.promise; | ||
return values; | ||
}, | ||
@@ -54,6 +49,3 @@ remove: function(variable) { | ||
clear: function(variable) { | ||
var deferred = Q.defer(); | ||
localStorage.clear(); | ||
deferred.resolve(); | ||
return deferred.promise; | ||
} | ||
@@ -60,0 +52,0 @@ } |
@@ -5,6 +5,6 @@ var Q = require('q'); | ||
var dbInitialize = function(tx) { | ||
tx.executeSql('CREATE TABLE IF NOT EXISTS bliss_storage (key, value, dataType)'); | ||
tx.executeSql('CREATE TABLE IF NOT EXISTS client_side_storage (key, value, dataType)'); | ||
}; | ||
var dbError: function(err) { | ||
var dbError = function(err) { | ||
console.log("SQL Error: " + err.message); | ||
@@ -17,3 +17,3 @@ } | ||
_db.transaction(Storage.dbInitialize, Storage.dbError); | ||
} | ||
}, | ||
isSupported: function() { | ||
@@ -20,0 +20,0 @@ return false; |
@@ -14,4 +14,10 @@ /* | ||
Storage = { | ||
registerStorageMethod: function(name, method) { | ||
class Storage { | ||
constructor() { | ||
this.wrapMethod(this, 'get'); | ||
this.wrapMethod(this, 'set'); | ||
this.wrapMethod(this, 'remove'); | ||
this.wrapMethod(this, 'clear'); | ||
} | ||
registerStorageMethod(name, method) { | ||
if (typeof(name) !== 'string') { | ||
@@ -24,9 +30,5 @@ throw new Error('First argument to registerStorageMethod should be name - a string'); | ||
_storage_methods[name] = method; | ||
}, | ||
_selectCorrectStorageMethod: function() { | ||
} | ||
_selectCorrectStorageMethod() { | ||
for (var name in _storage_methods) { | ||
console.log('NAME'); | ||
console.log(name); | ||
console.log('END NAME'); | ||
console.log(_storage_methods); | ||
var storage_method = _storage_methods[name]; | ||
@@ -40,61 +42,98 @@ if (storage_method.isSupported()) { | ||
} | ||
}, | ||
_getCurrentMethod: function() { | ||
} | ||
getCurrentMethod() { | ||
return _storage_methods[_current_method] | ||
}, | ||
ensureInit: function() { | ||
if (!_init) { | ||
throw new Error('You must call Storage.init before using Storage'); | ||
} | ||
/* | ||
* Wrapper function which ensures we always return a promise | ||
*/ | ||
returnPromise(value) { | ||
if (this._isPromise(value)) { | ||
return value; | ||
} | ||
}, | ||
init: function() { | ||
Storage._selectCorrectStorageMethod(); | ||
else { | ||
var deferred = Q.defer(); | ||
deferred.resolve(value); | ||
return deferred.promise; | ||
} | ||
} | ||
_isPromise(value) { | ||
return (typeof(value) == 'object' && typeof(value.then) === 'function'); | ||
} | ||
init() { | ||
var deferred = Q.defer(); | ||
this._selectCorrectStorageMethod(); | ||
var promise; | ||
var method = Storage._getCurrentMethod(); | ||
var args = Array.prototype.slice.apply(arguments); | ||
var method = this.getCurrentMethod(); | ||
var args = Array.from(arguments); | ||
if (method.init) { | ||
promise = method.init.apply(null, args); | ||
if (typeof(method.init) === 'function') { | ||
this.returnPromise(method.init.apply(null, args)) | ||
.then((value) => { | ||
_init = true; | ||
deferred.resolve(value); | ||
}); | ||
} | ||
else { | ||
_init = true; | ||
deferred.resolve(true); | ||
} | ||
_init = true; | ||
return deferred.promise; | ||
if (promise) { | ||
return promise; | ||
} | ||
ensureInit() { | ||
if (!_init) { | ||
return this.init(); | ||
} | ||
else { | ||
return this.returnPromise(true); | ||
} | ||
} | ||
wrapMethod(obj, method_name) { | ||
var original_method = obj[method_name]; | ||
var that = this; | ||
obj[method_name] = function() { | ||
var deferred = Q.defer(); | ||
deferred.resolve(); | ||
var args = Array.from(arguments); | ||
obj.ensureInit() | ||
.then(function() { | ||
try { | ||
var return_value = original_method.apply(obj, args); | ||
return obj.returnPromise(return_value); | ||
} | ||
catch(error) { | ||
console.log('Error in StorageMethod.'+ method_name +' : ' + error); | ||
} | ||
}) | ||
.then(function(resolved_value) { | ||
deferred.resolve(resolved_value); | ||
}); | ||
return deferred.promise; | ||
} | ||
}, | ||
get: function(key) { | ||
Storage.ensureInit(); | ||
} | ||
get(key) { | ||
var getType = (typeof(key) == 'object') ? 'getMultiple' : 'get'; | ||
var method = Storage._getCurrentMethod(); | ||
var args = Array.prototype.slice.apply(arguments); | ||
return method[getType].apply(null, args); | ||
}, | ||
set: function(key, value) { | ||
Storage.ensureInit(); | ||
var method = this.getCurrentMethod(); | ||
var args = Array.from(arguments); | ||
return method[getType].apply(this, args); | ||
} | ||
set(key, value) { | ||
var setType = (typeof(key) == 'object') ? 'setMultiple' : 'set'; | ||
var method = Storage._getCurrentMethod(); | ||
var args = Array.prototype.slice.apply(arguments); | ||
return method[setType].apply(null, args); | ||
}, | ||
remove: function() { | ||
Storage.ensureInit(); | ||
var method = Storage._getCurrentMethod(); | ||
var args = Array.prototype.slice.apply(arguments); | ||
return method.remove.apply(null, args); | ||
}, | ||
clear: function() { | ||
Storage.ensureInit(); | ||
var method = Storage._getCurrentMethod(); | ||
var args = Array.prototype.slice.apply(arguments); | ||
var method = this.getCurrentMethod(); | ||
var args = Array.from(arguments); | ||
return method[setType].apply(this, args); | ||
} | ||
remove() { | ||
var method = this.getCurrentMethod(); | ||
var args = Array.from(arguments); | ||
return method.remove.apply(this, args); | ||
} | ||
clear() { | ||
var method = this.getCurrentMethod(); | ||
var args = Array.from(arguments); | ||
return method.clear(); | ||
@@ -104,2 +143,2 @@ } | ||
module.exports = Storage; //asdfasdfasdfsd | ||
module.exports = new Storage(); |
Sorry, the diff of this file is too big to display
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
1
5
0
17636
3
10
534
1
+ Addednode-aop@0.1.0
+ Addednode-aop@0.1.0(transitive)