Comparing version 0.3.8 to 0.3.9
@@ -81,3 +81,3 @@ (function (root, factory) { | ||
this.set = function (key, value) { | ||
return window[storageType].setItem(key, serializer(value)); | ||
return window[storageType].setItem(storageKeyPrefix + key, serializer(value)); | ||
}; | ||
@@ -167,5 +167,6 @@ | ||
angular.forEach($storage, function(v, k) { | ||
angular.isDefined(v) && '$' !== k[0] && webStorage.setItem(storageKeyPrefix + k, serializer(v)); | ||
delete temp$storage[k]; | ||
if (angular.isDefined(v) && '$' !== k[0]) { | ||
webStorage.setItem(storageKeyPrefix + k, serializer(v)) | ||
delete temp$storage[k]; | ||
} | ||
}); | ||
@@ -204,3 +205,3 @@ | ||
$window.addEventListener && $window.addEventListener('beforeunload', function() { | ||
$storage.$sync(); | ||
$storage.$apply(); | ||
}); | ||
@@ -207,0 +208,0 @@ |
@@ -1,1 +0,1 @@ | ||
/*! ngstorage 0.3.8 | Copyright (c) 2015 Gias Kay Lee | MIT License */!function(a,b){"use strict";"function"==typeof define&&define.amd?define(["angular"],b):"object"==typeof exports?module.exports=b(require("angular")):b(a.angular)}(this,function(a){"use strict";function b(b){return function(){var c="ngStorage-";this.setKeyPrefix=function(a){if("string"!=typeof a)throw new TypeError("[ngStorage] - "+b+"Provider.setKeyPrefix() expects a String.");c=a};var d=a.toJson,e=a.fromJson;this.setSerializer=function(a){if("function"!=typeof a)throw new TypeError("[ngStorage] - "+b+"Provider.setSerializer expects a function.");d=a},this.setDeserializer=function(a){if("function"!=typeof a)throw new TypeError("[ngStorage] - "+b+"Provider.setDeserializer expects a function.");e=a},this.get=function(a){return e(window[b].getItem(c+a))},this.set=function(a,c){return window[b].setItem(a,d(c))},this.$get=["$rootScope","$window","$log","$timeout",function(f,g,h,i){function j(a){var b;try{b=g[a]}catch(c){b=!1}if(b&&"localStorage"===a){var d="__"+Math.round(1e7*Math.random());try{localStorage.setItem(d,d),localStorage.removeItem(d)}catch(c){b=!1}}return b}var k,l,m=c.length,n=j(b)||(h.warn("This browser does not support Web Storage!"),{setItem:a.noop,getItem:a.noop}),o={$default:function(b){for(var c in b)a.isDefined(o[c])||(o[c]=b[c]);return o.$sync(),o},$reset:function(a){for(var b in o)"$"===b[0]||delete o[b]&&n.removeItem(c+b);return o.$default(a)},$sync:function(){for(var a,b=0,d=n.length;d>b;b++)(a=n.key(b))&&c===a.slice(0,m)&&(o[a.slice(m)]=e(n.getItem(a)))},$apply:function(){var b;if(l=null,!a.equals(o,k)){b=a.copy(k),a.forEach(o,function(e,f){a.isDefined(e)&&"$"!==f[0]&&n.setItem(c+f,d(e)),delete b[f]});for(var e in b)n.removeItem(c+e);k=a.copy(o)}}};return o.$sync(),k=a.copy(o),f.$watch(function(){l||(l=i(o.$apply,100,!1))}),g.addEventListener&&g.addEventListener("storage",function(b){c===b.key.slice(0,m)&&(b.newValue?o[b.key.slice(m)]=e(b.newValue):delete o[b.key.slice(m)],k=a.copy(o),f.$apply())}),g.addEventListener&&g.addEventListener("beforeunload",function(){o.$sync()}),o}]}}return a=a&&a.module?a:window.angular,a.module("ngStorage",[]).provider("$localStorage",b("localStorage")).provider("$sessionStorage",b("sessionStorage"))}); | ||
/*! ngstorage 0.3.9 | Copyright (c) 2015 Gias Kay Lee | MIT License */!function(a,b){"use strict";"function"==typeof define&&define.amd?define(["angular"],b):"object"==typeof exports?module.exports=b(require("angular")):b(a.angular)}(this,function(a){"use strict";function b(b){return function(){var c="ngStorage-";this.setKeyPrefix=function(a){if("string"!=typeof a)throw new TypeError("[ngStorage] - "+b+"Provider.setKeyPrefix() expects a String.");c=a};var d=a.toJson,e=a.fromJson;this.setSerializer=function(a){if("function"!=typeof a)throw new TypeError("[ngStorage] - "+b+"Provider.setSerializer expects a function.");d=a},this.setDeserializer=function(a){if("function"!=typeof a)throw new TypeError("[ngStorage] - "+b+"Provider.setDeserializer expects a function.");e=a},this.get=function(a){return e(window[b].getItem(c+a))},this.set=function(a,e){return window[b].setItem(c+a,d(e))},this.$get=["$rootScope","$window","$log","$timeout",function(f,g,h,i){function j(a){var b;try{b=g[a]}catch(c){b=!1}if(b&&"localStorage"===a){var d="__"+Math.round(1e7*Math.random());try{localStorage.setItem(d,d),localStorage.removeItem(d)}catch(c){b=!1}}return b}var k,l,m=c.length,n=j(b)||(h.warn("This browser does not support Web Storage!"),{setItem:a.noop,getItem:a.noop}),o={$default:function(b){for(var c in b)a.isDefined(o[c])||(o[c]=b[c]);return o.$sync(),o},$reset:function(a){for(var b in o)"$"===b[0]||delete o[b]&&n.removeItem(c+b);return o.$default(a)},$sync:function(){for(var a,b=0,d=n.length;d>b;b++)(a=n.key(b))&&c===a.slice(0,m)&&(o[a.slice(m)]=e(n.getItem(a)))},$apply:function(){var b;if(l=null,!a.equals(o,k)){b=a.copy(k),a.forEach(o,function(e,f){a.isDefined(e)&&"$"!==f[0]&&(n.setItem(c+f,d(e)),delete b[f])});for(var e in b)n.removeItem(c+e);k=a.copy(o)}}};return o.$sync(),k=a.copy(o),f.$watch(function(){l||(l=i(o.$apply,100,!1))}),g.addEventListener&&g.addEventListener("storage",function(b){c===b.key.slice(0,m)&&(b.newValue?o[b.key.slice(m)]=e(b.newValue):delete o[b.key.slice(m)],k=a.copy(o),f.$apply())}),g.addEventListener&&g.addEventListener("beforeunload",function(){o.$apply()}),o}]}}return a=a&&a.module?a:window.angular,a.module("ngStorage",[]).provider("$localStorage",b("localStorage")).provider("$sessionStorage",b("sessionStorage"))}); |
{ | ||
"name": "ngstorage", | ||
"version": "0.3.8", | ||
"version": "0.3.9", | ||
"author": "Gias Kay Lee", | ||
@@ -5,0 +5,0 @@ "licenses": [ |
@@ -184,2 +184,24 @@ ngStorage | ||
### Custom serialization | ||
To change how ngStorage serializes and deserializes values (uses JSON by default) you can use your own functions. | ||
```javascript | ||
angular.module('app', ['ngStorage']) | ||
.config(['$localStorageProvider', | ||
function ($localStorageProvider) { | ||
var mySerializer = function (value) { | ||
// Do what you want with the value. | ||
return value; | ||
}; | ||
var myDeserializer = function (value) { | ||
return value; | ||
}; | ||
$localStorageProvider.setSerializer(mySerializer); | ||
$localStorageProvider.setDeserializer(myDeserializer); | ||
}];) | ||
``` | ||
### Minification | ||
@@ -186,0 +208,0 @@ Just run `$ npm install` to install dependencies. Then run `$ grunt` for minification. |
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
21435
171
245