angular-storage
Advanced tools
Comparing version 0.0.14 to 0.0.15
@@ -13,3 +13,3 @@ (function() { | ||
angular.module('angular-storage.cookieStorage', ['ngCookies']) | ||
angular.module('angular-storage.cookieStorage', []) | ||
.service('cookieStorage', ["$cookies", function ($cookies) { | ||
@@ -33,4 +33,8 @@ | ||
function InternalStore(namespace, storage, delimiter) { | ||
function InternalStore(namespace, storage, delimiter, useCache) { | ||
this.namespace = namespace || null; | ||
if (angular.isUndefined(useCache) || useCache == null) { | ||
useCache = true; | ||
} | ||
this.useCache = useCache; | ||
this.delimiter = delimiter || '.'; | ||
@@ -50,3 +54,5 @@ this.inMemoryCache = {}; | ||
InternalStore.prototype.set = function(name, elem) { | ||
this.inMemoryCache[name] = elem; | ||
if (this.useCache) { | ||
this.inMemoryCache[name] = elem; | ||
} | ||
this.storage.set(this.getNamespacedKey(name), JSON.stringify(elem)); | ||
@@ -57,3 +63,3 @@ }; | ||
var obj = null; | ||
if (name in this.inMemoryCache) { | ||
if (this.useCache && name in this.inMemoryCache) { | ||
return this.inMemoryCache[name]; | ||
@@ -70,3 +76,5 @@ } | ||
this.inMemoryCache[name] = obj; | ||
if (this.useCache) { | ||
this.inMemoryCache[name] = obj; | ||
} | ||
} catch(e) { | ||
@@ -80,3 +88,5 @@ $log.error('Error parsing saved value', e); | ||
InternalStore.prototype.remove = function(name) { | ||
this.inMemoryCache[name] = null; | ||
if (this.useCache) { | ||
this.inMemoryCache[name] = null; | ||
} | ||
this.storage.remove(this.getNamespacedKey(name)); | ||
@@ -113,2 +123,6 @@ }; | ||
}; | ||
this.clear = function () { | ||
$window.localStorage.clear(); | ||
}; | ||
} else { | ||
@@ -162,2 +176,5 @@ var cookieStorage = $injector.get('cookieStorage'); | ||
//caching is on by default | ||
var _caching = true; | ||
/** | ||
@@ -174,4 +191,13 @@ * Sets the storage. | ||
/** | ||
* Sets the internal cache usage | ||
* | ||
* @param {boolean} useCache Whether to use internal cache | ||
*/ | ||
this.setCaching = function(useCache) { | ||
_caching = !!useCache; | ||
}; | ||
this.$get = ["InternalStore", function(InternalStore) { | ||
var store = new InternalStore(null, _storage); | ||
var store = new InternalStore(null, _storage, null, _caching); | ||
@@ -183,7 +209,8 @@ /** | ||
* @param {String} storage The name of the storage service | ||
* @param {String} key The key | ||
* @param {String} delimiter The key delimiter | ||
* @param {boolean} useCache whether to use the internal caching | ||
* @returns {InternalStore} | ||
*/ | ||
store.getNamespacedStore = function(namespace, storage, key) { | ||
return new InternalStore(namespace, storage, key); | ||
store.getNamespacedStore = function(namespace, storage, delimiter, useCache) { | ||
return new InternalStore(namespace, storage, delimiter, useCache); | ||
}; | ||
@@ -196,2 +223,2 @@ | ||
}()); | ||
}()); |
@@ -1,1 +0,1 @@ | ||
!function(){angular.module("angular-storage",["angular-storage.store"]),angular.module("angular-storage.cookieStorage",[]).service("cookieStorage",["$injector",function(e){var t=e.get("$cookieStore");this.set=function(e,r){return t.put(e,r)},this.get=function(e){return t.get(e)},this.remove=function(e){return t.remove(e)}}]),angular.module("angular-storage.internalStore",["angular-storage.localStorage","angular-storage.sessionStorage"]).factory("InternalStore",["$log","$injector",function(e,t){function r(e,r,o){this.namespace=e||null,this.delimiter=o||".",this.inMemoryCache={},this.storage=t.get(r||"localStorage")}return r.prototype.getNamespacedKey=function(e){return this.namespace?[this.namespace,e].join(this.delimiter):e},r.prototype.set=function(e,t){this.inMemoryCache[e]=t,this.storage.set(this.getNamespacedKey(e),JSON.stringify(t))},r.prototype.get=function(t){var r=null;if(t in this.inMemoryCache)return this.inMemoryCache[t];var o=this.storage.get(this.getNamespacedKey(t));try{r="undefined"==typeof o||"undefined"===o?void 0:JSON.parse(o),this.inMemoryCache[t]=r}catch(a){e.error("Error parsing saved value",a),this.remove(t)}return r},r.prototype.remove=function(e){this.inMemoryCache[e]=null,this.storage.remove(this.getNamespacedKey(e))},r}]),angular.module("angular-storage.localStorage",["angular-storage.cookieStorage"]).service("localStorage",["$window","$injector",function(e,t){var r;try{e.localStorage.setItem("testKey","test"),e.localStorage.removeItem("testKey"),r=!0}catch(o){r=!1}if(r)this.set=function(t,r){return e.localStorage.setItem(t,r)},this.get=function(t){return e.localStorage.getItem(t)},this.remove=function(t){return e.localStorage.removeItem(t)};else{var a=t.get("cookieStorage");this.set=a.set,this.get=a.get,this.remove=a.remove}}]),angular.module("angular-storage.sessionStorage",["angular-storage.cookieStorage"]).service("sessionStorage",["$window","$injector",function(e,t){var r;try{e.sessionStorage.setItem("testKey","test"),e.sessionStorage.removeItem("testKey"),r=!0}catch(o){r=!1}if(r)this.set=function(t,r){return e.sessionStorage.setItem(t,r)},this.get=function(t){return e.sessionStorage.getItem(t)},this.remove=function(t){return e.sessionStorage.removeItem(t)};else{var a=t.get("cookieStorage");this.set=a.set,this.get=a.get,this.remove=a.remove}}]),angular.module("angular-storage.store",["angular-storage.internalStore"]).provider("store",function(){var e="localStorage";this.setStore=function(t){t&&angular.isString(t)&&(e=t)},this.$get=["InternalStore",function(t){var r=new t(null,e);return r.getNamespacedStore=function(e,r,o){return new t(e,r,o)},r}]})}(); | ||
!function(){angular.module("angular-storage",["angular-storage.store"]),angular.module("angular-storage.cookieStorage",[]).service("cookieStorage",["$cookies",function(e){this.set=function(t,r){return e.put(t,r)},this.get=function(t){return e.get(t)},this.remove=function(t){return e.remove(t)}}]),angular.module("angular-storage.internalStore",["angular-storage.localStorage","angular-storage.sessionStorage"]).factory("InternalStore",["$log","$injector",function(e,t){function r(e,r,o,a){this.namespace=e||null,(angular.isUndefined(a)||null==a)&&(a=!0),this.useCache=a,this.delimiter=o||".",this.inMemoryCache={},this.storage=t.get(r||"localStorage")}return r.prototype.getNamespacedKey=function(e){return this.namespace?[this.namespace,e].join(this.delimiter):e},r.prototype.set=function(e,t){this.useCache&&(this.inMemoryCache[e]=t),this.storage.set(this.getNamespacedKey(e),JSON.stringify(t))},r.prototype.get=function(t){var r=null;if(this.useCache&&t in this.inMemoryCache)return this.inMemoryCache[t];var o=this.storage.get(this.getNamespacedKey(t));try{r="undefined"==typeof o||"undefined"===o?void 0:JSON.parse(o),this.useCache&&(this.inMemoryCache[t]=r)}catch(a){e.error("Error parsing saved value",a),this.remove(t)}return r},r.prototype.remove=function(e){this.useCache&&(this.inMemoryCache[e]=null),this.storage.remove(this.getNamespacedKey(e))},r}]),angular.module("angular-storage.localStorage",["angular-storage.cookieStorage"]).service("localStorage",["$window","$injector",function(e,t){var r;try{e.localStorage.setItem("testKey","test"),e.localStorage.removeItem("testKey"),r=!0}catch(o){r=!1}if(r)this.set=function(t,r){return e.localStorage.setItem(t,r)},this.get=function(t){return e.localStorage.getItem(t)},this.remove=function(t){return e.localStorage.removeItem(t)},this.clear=function(){e.localStorage.clear()};else{var a=t.get("cookieStorage");this.set=a.set,this.get=a.get,this.remove=a.remove}}]),angular.module("angular-storage.sessionStorage",["angular-storage.cookieStorage"]).service("sessionStorage",["$window","$injector",function(e,t){var r;try{e.sessionStorage.setItem("testKey","test"),e.sessionStorage.removeItem("testKey"),r=!0}catch(o){r=!1}if(r)this.set=function(t,r){return e.sessionStorage.setItem(t,r)},this.get=function(t){return e.sessionStorage.getItem(t)},this.remove=function(t){return e.sessionStorage.removeItem(t)};else{var a=t.get("cookieStorage");this.set=a.set,this.get=a.get,this.remove=a.remove}}]),angular.module("angular-storage.store",["angular-storage.internalStore"]).provider("store",function(){var e="localStorage",t=!0;this.setStore=function(t){t&&angular.isString(t)&&(e=t)},this.setCaching=function(e){t=!!e},this.$get=["InternalStore",function(r){var o=new r(null,e,null,t);return o.getNamespacedStore=function(e,t,o,a){return new r(e,t,o,a)},o}]})}(); |
{ | ||
"name": "angular-storage", | ||
"version": "0.0.14", | ||
"version": "0.0.15", | ||
"main": "index.js", | ||
@@ -42,3 +42,6 @@ "author": { | ||
"node": ">=0.8.0" | ||
}, | ||
"scripts": { | ||
"test": "gulp test" | ||
} | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
# angular-storage | ||
# angular-storage [![Build Status](https://secure.travis-ci.org/auth0/angular-storage.svg?branch=master)](https://travis-ci.org/auth0/angular-storage) | ||
@@ -65,3 +65,3 @@ A Storage done right for AngularJS. | ||
}; | ||
// This will be saved in localStorage as auth0.obj | ||
@@ -90,3 +90,3 @@ Auth0Store.set('obj', myObj); | ||
}; | ||
// This will be saved in sessionStorage as obj | ||
@@ -105,3 +105,3 @@ store.set('obj', myObj); | ||
### storeProvider.setStore(storageName) | ||
### storeProvider.setStore(storageName) | ||
@@ -138,24 +138,13 @@ Sets the underlying store for the `store` service. It can be `localStorage`, `sessionStorage` or `cookieStorage`. Defaults to `localStorage` | ||
## License | ||
## Author | ||
MIT | ||
[Auth0](auth0.com) | ||
## What is Auth0? | ||
## License | ||
Auth0 helps you to: | ||
This project is licensed under the MIT license. See the [LICENSE](LICENSE) file for more info. | ||
* Add authentication with [multiple authentication sources](https://docs.auth0.com/identityproviders), either social like **Google, Facebook, Microsoft Account, LinkedIn, GitHub, Twitter, Box, Salesforce, amont others**, or enterprise identity systems like **Windows Azure AD, Google Apps, Active Directory, ADFS or any SAML Identity Provider**. | ||
* Add authentication through more traditional **[username/password databases](https://docs.auth0.com/mysql-connection-tutorial)**. | ||
* Add support for **[linking different user accounts](https://docs.auth0.com/link-accounts)** with the same user. | ||
* Support for generating signed [Json Web Tokens](https://docs.auth0.com/jwt) to call your APIs and **flow the user identity** securely. | ||
* Analytics of how, when and where users are logging in. | ||
* Pull data from other sources and add it to the user profile, through [JavaScript rules](https://docs.auth0.com/rules). | ||
## Create a free account in Auth0 | ||
1. Go to [Auth0](https://auth0.com) and click Sign Up. | ||
2. Use Google, GitHub or Microsoft Account to login. | ||
angular.module('angular-storage.internalStore', ['angular-storage.localStorage', 'angular-storage.sessionStorage']) | ||
.factory('InternalStore', function($log, $injector) { | ||
function InternalStore(namespace, storage, delimiter) { | ||
function InternalStore(namespace, storage, delimiter, useCache) { | ||
this.namespace = namespace || null; | ||
if (angular.isUndefined(useCache) || useCache == null) { | ||
useCache = true; | ||
} | ||
this.useCache = useCache; | ||
this.delimiter = delimiter || '.'; | ||
@@ -20,3 +24,5 @@ this.inMemoryCache = {}; | ||
InternalStore.prototype.set = function(name, elem) { | ||
this.inMemoryCache[name] = elem; | ||
if (this.useCache) { | ||
this.inMemoryCache[name] = elem; | ||
} | ||
this.storage.set(this.getNamespacedKey(name), JSON.stringify(elem)); | ||
@@ -27,3 +33,3 @@ }; | ||
var obj = null; | ||
if (name in this.inMemoryCache) { | ||
if (this.useCache && name in this.inMemoryCache) { | ||
return this.inMemoryCache[name]; | ||
@@ -40,3 +46,5 @@ } | ||
this.inMemoryCache[name] = obj; | ||
if (this.useCache) { | ||
this.inMemoryCache[name] = obj; | ||
} | ||
} catch(e) { | ||
@@ -50,3 +58,5 @@ $log.error('Error parsing saved value', e); | ||
InternalStore.prototype.remove = function(name) { | ||
this.inMemoryCache[name] = null; | ||
if (this.useCache) { | ||
this.inMemoryCache[name] = null; | ||
} | ||
this.storage.remove(this.getNamespacedKey(name)); | ||
@@ -53,0 +63,0 @@ }; |
@@ -7,2 +7,5 @@ angular.module('angular-storage.store', ['angular-storage.internalStore']) | ||
//caching is on by default | ||
var _caching = true; | ||
/** | ||
@@ -19,4 +22,13 @@ * Sets the storage. | ||
/** | ||
* Sets the internal cache usage | ||
* | ||
* @param {boolean} useCache Whether to use internal cache | ||
*/ | ||
this.setCaching = function(useCache) { | ||
_caching = !!useCache; | ||
}; | ||
this.$get = function(InternalStore) { | ||
var store = new InternalStore(null, _storage); | ||
var store = new InternalStore(null, _storage, null, _caching); | ||
@@ -28,7 +40,8 @@ /** | ||
* @param {String} storage The name of the storage service | ||
* @param {String} key The key | ||
* @param {String} delimiter The key delimiter | ||
* @param {boolean} useCache whether to use the internal caching | ||
* @returns {InternalStore} | ||
*/ | ||
store.getNamespacedStore = function(namespace, storage, key) { | ||
return new InternalStore(namespace, storage, key); | ||
store.getNamespacedStore = function(namespace, storage, delimiter, useCache) { | ||
return new InternalStore(namespace, storage, delimiter, useCache); | ||
}; | ||
@@ -35,0 +48,0 @@ |
@@ -72,2 +72,50 @@ 'use strict'; | ||
describe('angularStorage storeProvider.setCaching(false)', function () { | ||
var provider; | ||
beforeEach(function() { | ||
module('angular-storage.store', function(storeProvider) { | ||
provider = storeProvider; | ||
provider.setCaching(false); | ||
}); | ||
}); | ||
it('should not store into internal cache', inject(function(store) { | ||
var value1 = 'some value'; | ||
var value2 = 256; | ||
store.set('key1', value1); | ||
store.set('key2', value2); | ||
store.remove('key1'); | ||
expect(store.inMemoryCache).to.be.empty; | ||
expect(store.get('key2')).to.equal(value2); | ||
})); | ||
it('should store into internal cache in namespaced store when default caching', inject(function(store) { | ||
var namespacedStore = store.getNamespacedStore('bb'); | ||
var value1 = 'some value'; | ||
var value2 = 256; | ||
namespacedStore.set('key1', value1); | ||
namespacedStore.set('key2', value2); | ||
expect(namespacedStore.inMemoryCache).not.to.be.empty; | ||
expect(namespacedStore.inMemoryCache).to.have.property('key1'); | ||
expect(namespacedStore.inMemoryCache).to.have.property('key2'); | ||
})); | ||
it('should not store into internal cache in namespaced store when caching=false', inject(function(store) { | ||
var namespacedStore = store.getNamespacedStore('bb', 'localStorage', null, false); | ||
var value1 = 'some value'; | ||
var value2 = 256; | ||
namespacedStore.set('key1', value1); | ||
namespacedStore.set('key2', value2); | ||
expect(namespacedStore.inMemoryCache).to.be.empty; | ||
expect(namespacedStore.get('key1')).to.equal(value1); | ||
expect(namespacedStore.get('key2')).to.equal(value2); | ||
})); | ||
}); | ||
describe('angularStorage storeProvider.setStore("sessionStorage")', function () { | ||
@@ -418,3 +466,3 @@ | ||
var value = 111; | ||
var aStore = store.getNamespacedStore('aa', 'sessionStorage', '-'); | ||
var aStore = store.getNamespacedStore('aa', 'sessionStorage', '-', true); | ||
aStore.set('wayne', value); | ||
@@ -421,0 +469,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
52441
29
1159
0
147