angular-marshall.storage
Advanced tools
Comparing version 0.1.2 to 0.1.3
@@ -6,4 +6,4 @@ /*! | ||
* @author Jacob Marshall <hello@jacobmarshall.co> | ||
* @version v0.1.1 | ||
* @version v0.1.3 | ||
*/ | ||
!function(t){"use strict";function e(e){function r(t){return function(){var r=this,n=arguments;return e.$apply(function(){t.apply(r,n)})}}function n(e){this.prefix=t.isDefined(e)?e:""}var i=n.prototype,a=function(){try{return window.localStorage}catch(t){}}(),o={},s=[],c={};return i.get=function(t){return o.safeStorage.call(this,"getItem",this.prefix+t)},i.set=function(t,e){o.safeStorage.call(this,"setItem",this.prefix+t,e)},i.has=function(t){return-1!==this.keys().indexOf(t)},i.remove=function(t){o.safeStorage.call(this,"removeItem",this.prefix+t)},i.clear=function(){this.keys().forEach(this.remove.bind(this))},i.json=function(e,r){var n;if(t.isDefined(r))try{this.set(e,JSON.stringify(r))}catch(i){}else if(this.has(e))try{n=JSON.parse(this.get(e))}catch(i){}return n},i.watch=function(t,e,n){var i=o.regex.call(this,t,!0),a=o.updateEvent.bind(this,i,e),c=r(a);if(s.push(a),window.addEventListener("storage",c,!1),n===!0){var u=o.match.call(this,t);Object.keys(u).forEach(function(t){e(t,u[t],u[t])},this)}return function(){s.splice(s.indexOf(a),1),window.removeEventListener("storage",c,!1),i=a=c=null}},i.keys=function(){var t=[];if(a)for(var e=0;e<a.length;e++){var r=o.safeStorage.call(this,"key",e);0===r.indexOf(this.prefix)&&(r=r.substring(this.prefix.length),t.push(r))}return t},i.sub=function(t){return new n(this.prefix+t)},o.updateEvent=function(t,e,r){var n,i=t.test(r.key);i?(n=r.key.substring(this.prefix.length),e(n,r.newValue,r.oldValue)):null===r.key&&o.triggerBefore(c),o.updateData()},o.match=function(t){var e=o.regex.call(this,t,!1),r={};return this.keys().forEach(function(t){e.test(t)&&(r[t]=this.get(t))},this),r},o.regex=function(t,e){return new RegExp("^"+(e?this.prefix:"")+t.replace("*","(.*)")+"$")},o.triggerUpdate=function(e,r,n){var i={key:e,newValue:r,oldValue:n};t.forEach(s,function(t){try{t(i)}catch(e){window.console&&window.console.error&&window.console.error(e)}})},o.updateData=function(){a&&(c=JSON.parse(JSON.stringify(a)))},o.triggerBefore=function(e){t.forEach(Object.keys(e),function(t){o.triggerUpdate(t,null,e[t])})},o.safeStorage=function(t){if(a){var e=[].slice.call(arguments,1);try{return a[t].apply(a,e)}catch(r){}}},a&&(t.forEach(["setItem","removeItem"],function(t){try{var r=window.Storage.prototype[t];window.Storage.prototype[t]=function(t){var n,i=this.getItem(t);r.apply(this,arguments),n=this.getItem(t),n!==i&&(o.triggerUpdate(t,n,i),e.$$phase||e.$apply()),o.updateData()}}catch(n){}}),function(){try{var t=window.Storage.prototype.clear;window.Storage.prototype.clear=function(){var r=JSON.parse(JSON.stringify(this));t.call(this),o.triggerBefore(r),e.$$phase||e.$apply(),o.updateData()}}catch(r){}}()),o.updateData(),function(t){return new n(t)}}t.module("marshall.storage",[]).factory("storageService",e),e.$inject=["$rootScope"]}(window.angular); |
{ | ||
"name": "angular-marshall.storage", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "A simple localStorage service for angular.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -6,3 +6,3 @@ /*! | ||
* @author Jacob Marshall <hello@jacobmarshall.co> | ||
* @version v0.1.1 | ||
* @version v0.1.3 | ||
*/ | ||
@@ -9,0 +9,0 @@ (function (angular) { |
Sorry, the diff of this file is not supported yet
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
48413