UNPKG

angular-webstorage

Version:

An Angular module that gives you access to the browsers local storage

2 lines 1.46 kB
/*! angular-webstorage 2014-12-13 */ "use strict";var angularWebStorage=angular.module("WebStorageModule",[]);angularWebStorage.provider("webStorageService",function(){this.$get=["$window","$document",function(a,b){var c;b=b?b[0]?b[0]:b:document;var d=function(){var b=a.hasOwnProperty("localStorage")&&null!==a.localStorage;return b},e=function(b,d,e){e="undefined"==typeof e||"boolean"!=typeof e?!1:e;var f=e?"localStorage":"sessionStorage";return angular.isUndefined(d)?d=null:(angular.isObject(d)||angular.isArray(d))&&(d=angular.toJson(d)),c=a[f],c.setItem(b,d),!0},f=function(b,d){var e,f="undefined"==typeof d?!1:!0;return f?(c=a[d],e=c?c.getItem(b):null):(c=a.sessionStorage,e=c?c.getItem(b):null,e&&"null"!==e||(c=a.localStorage,e=c?c.getItem(b):null)),e&&"null"!==e?"{"===e.charAt(0)||"["===e.charAt(0)?angular.fromJson(e):e:null},g=function(b,d){var e="undefined"==typeof d?!1:!0;return e?(c=a[d],c.removeItem(b)):(c=a.sessionStorage,c.removeItem(b),c=a.localStorage,c.removeItem(b)),!0},h=function(b){var d,e="undefined"==typeof b?!1:!0,f=[];if(e){c=a[b];for(d in c)f.push(d)}else{c=a.localStorage;for(d in c)f.push(d);c=a.sessionStorage;for(d in c)-1==f.indexOf(d)&&f.push(d)}return f},i=function(b){var d,e="undefined"==typeof b?!1:!0;if(e){c=a[b];for(d in c)g(d,b)}else{c=a.sessionStorage;for(d in c)g(d,"sessionStorage");c=a.localStorage;for(d in c)g(d,"localStorage")}return!0};return{isSupported:d,set:e,get:f,keys:h,remove:g,clearAll:i}}]});