diff --git a/README.md b/README.md index 33c3554..66d8dae 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ http://www.jsdelivr.com/#!angular.locker Simply download the zip file [HERE](https://github.com/tymondesigns/angular-locker/archive/master.zip) and include `dist/angular-locker.min.js` in your project. -1.75 kB Minified & gzipped. +1.76 kB Minified & gzipped.

Usage

diff --git a/bower.json b/bower.json index fd686a5..77d700b 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angular-locker", - "version": "1.1.0", + "version": "1.1.1", "homepage": "https://github.com/tymondesigns/angular-locker", "authors": [ "Sean Tymon " diff --git a/dist/angular-locker.js b/dist/angular-locker.js index f33d848..10e2cfb 100644 --- a/dist/angular-locker.js +++ b/dist/angular-locker.js @@ -579,7 +579,7 @@ * @return {self} */ driver: function (driver) { - return new Locker(driver, this._namespace, this._eventsEnabled); + return new Locker(driver, this._namespace, this._eventsEnabled, this._separator); }, /** @@ -598,7 +598,7 @@ * @return {self} */ namespace: function (namespace) { - return new Locker(this._deriveDriver(this._driver), namespace, this._eventsEnabled); + return new Locker(this._deriveDriver(this._driver), namespace, this._eventsEnabled, this._separator); }, /** diff --git a/dist/angular-locker.min.js b/dist/angular-locker.min.js index 17922b0..04eb97e 100644 --- a/dist/angular-locker.min.js +++ b/dist/angular-locker.min.js @@ -1,3 +1,3 @@ -/*! angular-locker v1.1.0 | (c) 2015 @tymondesigns | https://github.com/tymondesigns/angular-locker */ -!function(e,t){"function"==typeof define&&define.amd?define(function(){return t(e.angular)}):"object"==typeof exports?module.exports=t(e.angular||window&&window.angular):t(e.angular)}(this,function(e){"use strict";e.module("angular-locker",[]).provider("locker",function(){var t=function(t){return e.isFunction(t)?t():t},r=function(e,t){return Object.keys(e).filter(function(r){return e[r]===t})[0]},i=function(e){throw new Error("[angular-locker] "+e)},s={driver:"local",namespace:"locker",eventsEnabled:!0,separator:"."};return{setDefaultDriver:function(e){return s.driver=t(e),this},getDefaultDriver:function(){return s.driver},setDefaultNamespace:function(e){return s.namespace=t(e),this},getDefaultNamespace:function(){return s.namespace},setEventsEnabled:function(e){return s.eventsEnabled=t(e),this},getEventsEnabled:function(){return s.eventsEnabled},setSeparator:function(e){return s.separator=t(e),this},getSeparator:function(){return s.separator},$get:["$window","$rootScope","$parse",function(n,o,a){function h(s,a,h,u){this._registeredDrivers={local:n.localStorage,session:n.sessionStorage},this._resolveDriver=function(e){return this._registeredDrivers.hasOwnProperty(e)||i('The driver "'+e+'" was not found.'),this._registeredDrivers[e]},this._deriveDriver=function(e){return r(this._registeredDrivers,e)},this._driver=this._resolveDriver(s),this._namespace=a,this._eventsEnabled=h,this._separator=u,this._watchers={},this._checkSupport=function(t){if(e.isUndefined(this._supported)){var r="l";try{this._resolveDriver(t||"local").setItem(r,r),this._resolveDriver(t||"local").removeItem(r),this._supported=!0}catch(i){this._supported=!1}}return this._supported},this._getPrefix=function(e){return this._namespace?this._namespace+this._separator+e:e},this._serialize=function(t){try{return e.toJson(t)}catch(r){return t}},this._unserialize=function(t){try{return e.fromJson(t)}catch(r){return t}},this._event=function(t,r){this._eventsEnabled&&o.$emit(t,e.extend(r,{driver:this._deriveDriver(this._driver),namespace:this._namespace}))},this._setItem=function(t,r){if(this._checkSupport())try{var s=this._getItem(t);this._driver.setItem(this._getPrefix(t),this._serialize(r)),this._exists(t)&&!e.equals(s,r)?this._event("locker.item.updated",{key:t,oldValue:s,newValue:r}):this._event("locker.item.added",{key:t,value:r})}catch(n){-1!==["QUOTA_EXCEEDED_ERR","NS_ERROR_DOM_QUOTA_REACHED","QuotaExceededError"].indexOf(n.name)?i("The browser storage quota has been exceeded"):i('Could not add item with key "'+t+'"')}else i("The browser does not support localStorage")},this._getItem=function(e){return this._checkSupport()?this._unserialize(this._driver.getItem(this._getPrefix(e))):(i("The browser does not support localStorage"),void 0)},this._exists=function(e){return this._checkSupport()?this._driver.hasOwnProperty(this._getPrefix(t(e))):(i("The browser does not support localStorage"),void 0)},this._removeItem=function(e){return this._checkSupport()?this._exists(e)?(this._driver.removeItem(this._getPrefix(e)),this._event("locker.item.forgotten",{key:e}),!0):!1:(i("The browser does not support localStorage"),void 0)}}h.prototype={put:function(r,i){if(!r)return!1;if(r=t(r),e.isObject(r))e.forEach(r,function(e,t){this._setItem(t,e)},this);else{if(!e.isDefined(i))return!1;this._setItem(r,t(i))}return this},add:function(e,t){return this.has(e)?!1:(this.put(e,t),!0)},get:function(t,r){if(e.isArray(t)){var i={};return e.forEach(t,function(e){this.has(e)&&(i[e]=this._getItem(e))},this),i}return this.has(t)?this._getItem(t):2===arguments.length?r:void 0},has:function(e){return this._exists(e)},forget:function(r){return r=t(r),e.isArray(r)?e.forEach(r,function(e){this._removeItem(e)},this):this._removeItem(r),this},pull:function(e,t){var r=this.get(e,t);return this.forget(e),r},all:function(){var t={};return e.forEach(this._driver,function(e,r){var i=r.split(this._separator);i.length>1&&i[0]===this._namespace&&(i.splice(0,1),r=i.join(this._separator)),this.has(r)&&(t[r]=this.get(r))},this),t},clean:function(){return this.forget(Object.keys(this.all())),this},empty:function(){return this._driver.clear(),this},count:function(){return Object.keys(this.all()).length},bind:function(t,r,i){e.isUndefined(t.$eval(r))&&(a(r).assign(t,this.get(r,i)),this.has(r)||this.put(r,i));var s=this;return this._watchers[r+t.$id]=t.$watch(r,function(t){e.isDefined(t)&&s.put(r,t)},e.isObject(t[r])),this},unbind:function(e,t){return a(t).assign(e,void 0),this.forget(t),this._watchers[t+e.$id]&&(this._watchers[t+e.$id](),delete this._watchers[t+e.$id]),this},driver:function(e){return new h(e,this._namespace,this._eventsEnabled)},getDriver:function(){return this._driver},namespace:function(e){return new h(this._deriveDriver(this._driver),e,this._eventsEnabled)},getNamespace:function(){return this._namespace},supported:function(e){return this._checkSupport(e)}};var u={local:new h("local",s.namespace,s.eventsEnabled,s.separator),session:new h("session",s.namespace,s.eventsEnabled,s.separator)};return u[s.driver]}]}})}); +/*! angular-locker v1.1.1 | (c) 2015 @tymondesigns | https://github.com/tymondesigns/angular-locker */ +!function(e,t){"function"==typeof define&&define.amd?define(function(){return t(e.angular)}):"object"==typeof exports?module.exports=t(e.angular||window&&window.angular):t(e.angular)}(this,function(e){"use strict";e.module("angular-locker",[]).provider("locker",function(){var t=function(t){return e.isFunction(t)?t():t},r=function(e,t){return Object.keys(e).filter(function(r){return e[r]===t})[0]},i=function(e){throw new Error("[angular-locker] "+e)},s={driver:"local",namespace:"locker",eventsEnabled:!0,separator:"."};return{setDefaultDriver:function(e){return s.driver=t(e),this},getDefaultDriver:function(){return s.driver},setDefaultNamespace:function(e){return s.namespace=t(e),this},getDefaultNamespace:function(){return s.namespace},setEventsEnabled:function(e){return s.eventsEnabled=t(e),this},getEventsEnabled:function(){return s.eventsEnabled},setSeparator:function(e){return s.separator=t(e),this},getSeparator:function(){return s.separator},$get:["$window","$rootScope","$parse",function(n,o,a){function h(s,a,h,u){this._registeredDrivers={local:n.localStorage,session:n.sessionStorage},this._resolveDriver=function(e){return this._registeredDrivers.hasOwnProperty(e)||i('The driver "'+e+'" was not found.'),this._registeredDrivers[e]},this._deriveDriver=function(e){return r(this._registeredDrivers,e)},this._driver=this._resolveDriver(s),this._namespace=a,this._eventsEnabled=h,this._separator=u,this._watchers={},this._checkSupport=function(t){if(e.isUndefined(this._supported)){var r="l";try{this._resolveDriver(t||"local").setItem(r,r),this._resolveDriver(t||"local").removeItem(r),this._supported=!0}catch(i){this._supported=!1}}return this._supported},this._getPrefix=function(e){return this._namespace?this._namespace+this._separator+e:e},this._serialize=function(t){try{return e.toJson(t)}catch(r){return t}},this._unserialize=function(t){try{return e.fromJson(t)}catch(r){return t}},this._event=function(t,r){this._eventsEnabled&&o.$emit(t,e.extend(r,{driver:this._deriveDriver(this._driver),namespace:this._namespace}))},this._setItem=function(t,r){if(this._checkSupport())try{var s=this._getItem(t);this._driver.setItem(this._getPrefix(t),this._serialize(r)),this._exists(t)&&!e.equals(s,r)?this._event("locker.item.updated",{key:t,oldValue:s,newValue:r}):this._event("locker.item.added",{key:t,value:r})}catch(n){-1!==["QUOTA_EXCEEDED_ERR","NS_ERROR_DOM_QUOTA_REACHED","QuotaExceededError"].indexOf(n.name)?i("The browser storage quota has been exceeded"):i('Could not add item with key "'+t+'"')}else i("The browser does not support localStorage")},this._getItem=function(e){return this._checkSupport()?this._unserialize(this._driver.getItem(this._getPrefix(e))):(i("The browser does not support localStorage"),void 0)},this._exists=function(e){return this._checkSupport()?this._driver.hasOwnProperty(this._getPrefix(t(e))):(i("The browser does not support localStorage"),void 0)},this._removeItem=function(e){return this._checkSupport()?this._exists(e)?(this._driver.removeItem(this._getPrefix(e)),this._event("locker.item.forgotten",{key:e}),!0):!1:(i("The browser does not support localStorage"),void 0)}}h.prototype={put:function(r,i){if(!r)return!1;if(r=t(r),e.isObject(r))e.forEach(r,function(e,t){this._setItem(t,e)},this);else{if(!e.isDefined(i))return!1;this._setItem(r,t(i))}return this},add:function(e,t){return this.has(e)?!1:(this.put(e,t),!0)},get:function(t,r){if(e.isArray(t)){var i={};return e.forEach(t,function(e){this.has(e)&&(i[e]=this._getItem(e))},this),i}return this.has(t)?this._getItem(t):2===arguments.length?r:void 0},has:function(e){return this._exists(e)},forget:function(r){return r=t(r),e.isArray(r)?e.forEach(r,function(e){this._removeItem(e)},this):this._removeItem(r),this},pull:function(e,t){var r=this.get(e,t);return this.forget(e),r},all:function(){var t={};return e.forEach(this._driver,function(e,r){var i=r.split(this._separator);i.length>1&&i[0]===this._namespace&&(i.splice(0,1),r=i.join(this._separator)),this.has(r)&&(t[r]=this.get(r))},this),t},clean:function(){return this.forget(Object.keys(this.all())),this},empty:function(){return this._driver.clear(),this},count:function(){return Object.keys(this.all()).length},bind:function(t,r,i){e.isUndefined(t.$eval(r))&&(a(r).assign(t,this.get(r,i)),this.has(r)||this.put(r,i));var s=this;return this._watchers[r+t.$id]=t.$watch(r,function(t){e.isDefined(t)&&s.put(r,t)},e.isObject(t[r])),this},unbind:function(e,t){return a(t).assign(e,void 0),this.forget(t),this._watchers[t+e.$id]&&(this._watchers[t+e.$id](),delete this._watchers[t+e.$id]),this},driver:function(e){return new h(e,this._namespace,this._eventsEnabled,this._separator)},getDriver:function(){return this._driver},namespace:function(e){return new h(this._deriveDriver(this._driver),e,this._eventsEnabled,this._separator)},getNamespace:function(){return this._namespace},supported:function(e){return this._checkSupport(e)}};var u={local:new h("local",s.namespace,s.eventsEnabled,s.separator),session:new h("session",s.namespace,s.eventsEnabled,s.separator)};return u[s.driver]}]}})}); //# sourceMappingURL=angular-locker.min.js.map \ No newline at end of file diff --git a/dist/angular-locker.min.js.map b/dist/angular-locker.min.js.map index e05f314..8184034 100644 --- a/dist/angular-locker.min.js.map +++ b/dist/angular-locker.min.js.map @@ -1,2 +1,2 @@ -/*! angular-locker v1.1.0 | (c) 2015 @tymondesigns | https://github.com/tymondesigns/angular-locker */ -{"version":3,"sources":["angular-locker.min.js"],"names":["root","factory","define","amd","angular","exports","module","window","this","provider","_value","value","isFunction","_keyByVal","object","Object","keys","filter","key","_error","msg","Error","defaults","driver","namespace","eventsEnabled","separator","setDefaultDriver","getDefaultDriver","setDefaultNamespace","getDefaultNamespace","setEventsEnabled","enabled","getEventsEnabled","setSeparator","getSeparator","$get","$window","$rootScope","$parse","Locker","_registeredDrivers","local","localStorage","session","sessionStorage","_resolveDriver","hasOwnProperty","_deriveDriver","_driver","_namespace","_eventsEnabled","_separator","_watchers","_checkSupport","isUndefined","_supported","l","setItem","removeItem","e","_getPrefix","_serialize","toJson","_unserialize","fromJson","_event","name","payload","$emit","extend","_setItem","oldVal","_getItem","_exists","equals","oldValue","newValue","indexOf","getItem","_removeItem","prototype","put","isObject","forEach","isDefined","add","has","get","def","isArray","items","k","arguments","length","forget","pull","all","split","splice","join","clean","empty","clear","count","bind","$scope","$eval","assign","self","$id","$watch","newVal","unbind","getDriver","getNamespace","supported","drivers"],"mappings":"CAUA,SAAWA,EAAMC,GACS,kBAAXC,SAAyBA,OAAOC,IACvCD,OAAO,WACH,MAAOD,GAAQD,EAAKI,WAEE,gBAAZC,S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AAO7F,EAAK,SAAU8F,GACxD5G,EAAQiF,UAAU2B,IAASH,EAAK3B,IAAIhE,EAAK8F,IAC9C5G,EAAQ+E,SAASuB,EAAOxF,KAEpBV,MAUXyG,OAAQ,SAAUP,EAAQxF,GAStB,MARAqB,GAAOrB,GAAK0F,OAAOF,EAAQ,QAC3BlG,KAAKuF,OAAO7E,GACRV,KAAK6C,UAAUnC,EAAMwF,EAAOI,OAE5BtG,KAAK6C,UAAUnC,EAAMwF,EAAOI,aACrBtG,MAAK6C,UAAUnC,EAAMwF,EAAOI,MAGhCtG,MASXe,OAAQ,SAAUA,GACd,MAAO,IAAIiB,GAAOjB,EAAQf,KAAK0C,WAAY1C,KAAK2C,iBAQpD+D,UAAW,WACP,MAAO1G,MAAKyC,SAShBzB,UAAW,SAAUA,GACjB,MAAO,IAAIgB,GAAOhC,KAAKwC,cAAcxC,KAAKyC,SAAUzB,EAAWhB,KAAK2C,iBAQxEgE,aAAc,WACV,MAAO3G,MAAK0C,YAUhBkE,UAAW,SAAU7F,GACjB,MAAOf,MAAK8C,cAAc/B,IASlC,IAAI8F,IACA3E,MAAO,GAAIF,GAAO,QAASlB,EAASE,UAAWF,EAASG,cAAeH,EAASI,WAChFkB,QAAS,GAAIJ,GAAO,UAAWlB,EAASE,UAAWF,EAASG,cAAeH,EAASI,WAGxF,OAAO2F,GAAQ/F,EAASC","file":"angular-locker.min.js","sourcesContent":["/**\n * angular-locker\n *\n * A simple & configurable abstraction for local/session storage in angular projects.\n *\n * @link https://github.com/tymondesigns/angular-locker\n * @author Sean Tymon @tymondesigns\n * @license MIT License, http://www.opensource.org/licenses/MIT\n */\n\n(function (root, factory) {\n if (typeof define === 'function' && define.amd) {\n define(function () {\n return factory(root.angular);\n });\n } else if (typeof exports === 'object') {\n module.exports = factory(root.angular || (window && window.angular));\n } else {\n factory(root.angular);\n }\n})(this, function (angular) {\n\n 'use strict';\n\n angular.module('angular-locker', [])\n\n .provider('locker', function () {\n\n /**\n * If value is a function then execute, otherwise return\n *\n * @param {Mixed} value\n * @return {Mixed}\n */\n var _value = function (value) {\n return angular.isFunction(value) ? value() : value;\n };\n\n /**\n * Get the key of an object by the value\n *\n * @param {Object} object\n * @param {Mixed} value\n * @return {String}\n */\n var _keyByVal = function (object, value) {\n return Object.keys(object).filter(function (key) { return object[key] === value; })[0];\n };\n\n /**\n * Trigger an error\n *\n * @param {String} msg\n * @return {void}\n */\n var _error = function (msg) {\n throw new Error('[angular-locker] ' + msg);\n };\n\n /**\n * Set the default driver and namespace\n *\n * @type {Object}\n */\n var defaults = {\n driver: 'local',\n namespace: 'locker',\n eventsEnabled: true,\n separator: '.'\n };\n\n return {\n\n /**\n * Allow setting of default storage driver via `lockerProvider`\n * e.g. lockerProvider.setDefaultDriver('session');\n *\n * @param {String} driver\n */\n setDefaultDriver: function (driver) {\n defaults.driver = _value(driver);\n\n return this;\n },\n\n /**\n * Get the default driver\n */\n getDefaultDriver: function () {\n return defaults.driver;\n },\n\n /**\n * Allow setting of default namespace via `lockerProvider`\n * e.g. lockerProvider.setDefaultNamespace('myAppName');\n *\n * @param {String} namespace\n */\n setDefaultNamespace: function (namespace) {\n defaults.namespace = _value(namespace);\n\n return this;\n },\n\n /**\n * Get the default namespace\n */\n getDefaultNamespace: function () {\n return defaults.namespace;\n },\n\n /**\n * Set whether the events are enabled\n *\n * @param {Boolean} enabled\n */\n setEventsEnabled: function (enabled) {\n defaults.eventsEnabled = _value(enabled);\n\n return this;\n },\n\n /**\n * Get whether the events are enabled\n */\n getEventsEnabled: function () {\n return defaults.eventsEnabled;\n },\n\n /**\n * Set the separator to use with namespace in keys\n *\n * @param {String} separator\n */\n setSeparator: function (separator) {\n defaults.separator = _value(separator);\n\n return this;\n },\n\n /**\n * Get the separator\n */\n getSeparator: function () {\n return defaults.separator;\n },\n\n /**\n * The locker service\n */\n $get: ['$window', '$rootScope', '$parse', function ($window, $rootScope, $parse) {\n\n /**\n * Define the Locker class\n *\n * @param {Storage} driver\n * @param {String} namespace\n */\n function Locker (driver, namespace, eventsEnabled, separator) {\n\n /**\n * @type {Object}\n */\n this._registeredDrivers = {\n local: $window.localStorage,\n session: $window.sessionStorage\n };\n\n /**\n * Get the Storage instance from the key\n *\n * @param {String} driver\n * @return {Storage}\n */\n this._resolveDriver = function (driver) {\n if (! this._registeredDrivers.hasOwnProperty(driver)) {\n _error('The driver \"' + driver + '\" was not found.');\n }\n\n return this._registeredDrivers[driver];\n };\n\n /**\n * Get the driver key (local/session) by the Storage instance\n *\n * @param {Storage} driver\n * @return {String}\n */\n this._deriveDriver = function (driver) {\n return _keyByVal(this._registeredDrivers, driver);\n };\n\n /**\n * @type {Storage}\n */\n this._driver = this._resolveDriver(driver);\n\n /**\n * @type {String}\n */\n this._namespace = namespace;\n\n /**\n * @type {Boolean}\n */\n this._eventsEnabled = eventsEnabled;\n\n /**\n * @type {String}\n */\n this._separator = separator;\n\n /**\n * @type {Object}\n */\n this._watchers = {};\n\n /**\n * Check browser support\n *\n * @see https://github.com/Modernizr/Modernizr/blob/master/feature-detects/storage/localstorage.js#L38-L47\n * @param {String} driver\n * @return {Boolean}\n */\n this._checkSupport = function (driver) {\n if (angular.isUndefined(this._supported)) {\n var l = 'l';\n try {\n this._resolveDriver(driver || 'local').setItem(l, l);\n this._resolveDriver(driver || 'local').removeItem(l);\n this._supported = true;\n } catch (e) {\n this._supported = false;\n }\n }\n\n return this._supported;\n };\n\n /**\n * Build the storage key from the namspace\n *\n * @param {String} key\n * @return {String}\n */\n this._getPrefix = function (key) {\n if (! this._namespace) return key;\n\n return this._namespace + this._separator + key;\n };\n\n /**\n * Try to encode value as json, or just return the value upon failure\n *\n * @param {Mixed} value\n * @return {Mixed}\n */\n this._serialize = function (value) {\n try {\n return angular.toJson(value);\n } catch (e) {\n return value;\n }\n };\n\n /**\n * Try to parse value as json, if it fails then it probably isn't json so just return it\n *\n * @param {String} value\n * @return {Object|String}\n */\n this._unserialize = function (value) {\n try {\n return angular.fromJson(value);\n } catch (e) {\n return value;\n }\n };\n\n /**\n * Trigger an event\n *\n * @param {String} name\n * @param {Object} payload\n * @return {void}\n */\n this._event = function (name, payload) {\n if (this._eventsEnabled) {\n $rootScope.$emit(name, angular.extend(payload, {\n driver: this._deriveDriver(this._driver),\n namespace: this._namespace,\n }));\n }\n };\n\n /**\n * Add to storage\n *\n * @param {String} key\n * @param {Mixed} value\n */\n this._setItem = function (key, value) {\n if (this._checkSupport()) {\n try {\n var oldVal = this._getItem(key);\n this._driver.setItem(this._getPrefix(key), this._serialize(value));\n if (this._exists(key) && ! angular.equals(oldVal, value)) {\n this._event('locker.item.updated', { key: key, oldValue: oldVal, newValue: value });\n } else {\n this._event('locker.item.added', { key: key, value: value });\n }\n } catch (e) {\n if (['QUOTA_EXCEEDED_ERR', 'NS_ERROR_DOM_QUOTA_REACHED', 'QuotaExceededError'].indexOf(e.name) !== -1) {\n _error('The browser storage quota has been exceeded');\n } else {\n _error('Could not add item with key \"' + key + '\"');\n }\n }\n } else {\n _error('The browser does not support localStorage');\n }\n };\n\n /**\n * Get from storage\n *\n * @param {String} key\n * @return {Mixed}\n */\n this._getItem = function (key) {\n if (this._checkSupport()) {\n return this._unserialize(this._driver.getItem(this._getPrefix(key)));\n } else {\n _error('The browser does not support localStorage');\n }\n };\n\n /**\n * Exists in storage\n *\n * @param {String} key\n * @return {Boolean}\n */\n this._exists = function (key) {\n if (this._checkSupport()) {\n return this._driver.hasOwnProperty(this._getPrefix(_value(key)));\n } else {\n _error('The browser does not support localStorage');\n }\n };\n\n /**\n * Remove from storage\n *\n * @param {String} key\n * @return {Boolean}\n */\n this._removeItem = function (key) {\n if (this._checkSupport()) {\n if (! this._exists(key)) return false;\n this._driver.removeItem(this._getPrefix(key));\n\n this._event('locker.item.forgotten', { key: key });\n\n return true;\n } else {\n _error('The browser does not support localStorage');\n }\n };\n }\n\n /**\n * Define the public api\n *\n * @type {Object}\n */\n Locker.prototype = {\n\n /**\n * Add a new item to storage (even if it already exists)\n *\n * @param {Mixed} key\n * @param {Mixed} value\n * @return {self}\n */\n put: function (key, value) {\n if (! key) return false;\n key = _value(key);\n\n if (angular.isObject(key)) {\n angular.forEach(key, function (value, key) {\n this._setItem(key, value);\n }, this);\n } else {\n if (! angular.isDefined(value)) return false;\n this._setItem(key, _value(value));\n }\n\n return this;\n },\n\n /**\n * Add an item to storage if it doesn't already exist\n *\n * @param {Mixed} key\n * @param {Mixed} value\n * @return {Boolean}\n */\n add: function (key, value) {\n if (! this.has(key)) {\n this.put(key, value);\n return true;\n }\n\n return false;\n },\n\n /**\n * Retrieve the specified item from storage\n *\n * @param {String|Array} key\n * @param {Mixed} def\n * @return {Mixed}\n */\n get: function (key, def) {\n if (angular.isArray(key)) {\n var items = {};\n angular.forEach(key, function (k) {\n if (this.has(k)) items[k] = this._getItem(k);\n }, this);\n\n return items;\n }\n\n if (! this.has(key)) return arguments.length === 2 ? def : void 0;\n\n return this._getItem(key);\n },\n\n /**\n * Determine whether the item exists in storage\n *\n * @param {String|Function} key\n * @return {Boolean}\n */\n has: function (key) {\n return this._exists(key);\n },\n\n /**\n * Remove specified item(s) from storage\n *\n * @param {Mixed} key\n * @return {Object}\n */\n forget: function (key) {\n key = _value(key);\n\n if (angular.isArray(key)) {\n angular.forEach(key, function (key) {\n this._removeItem(key);\n }, this);\n } else {\n this._removeItem(key);\n }\n\n return this;\n },\n\n /**\n * Retrieve the specified item from storage and then remove it\n *\n * @param {String|Array} key\n * @param {Mixed} def\n * @return {Mixed}\n */\n pull: function (key, def) {\n var value = this.get(key, def);\n this.forget(key);\n\n return value;\n },\n\n /**\n * Return all items in storage within the current namespace\n *\n * @return {Object}\n */\n all: function () {\n var items = {};\n angular.forEach(this._driver, function (value, key) {\n var split = key.split(this._separator);\n if (split.length > 1 && split[0] === this._namespace) {\n split.splice(0, 1);\n key = split.join(this._separator);\n }\n if (this.has(key)) items[key] = this.get(key);\n }, this);\n\n return items;\n },\n\n /**\n * Remove all items set within the current namespace\n *\n * @return {self}\n */\n clean: function () {\n this.forget(Object.keys(this.all()));\n\n return this;\n },\n\n /**\n * Empty the current storage driver completely. careful now.\n *\n * @return {self}\n */\n empty: function () {\n this._driver.clear();\n\n return this;\n },\n\n /**\n * Get the total number of items within the current namespace\n *\n * @return {Integer}\n */\n count: function () {\n return Object.keys(this.all()).length;\n },\n\n /**\n * Bind a storage key to a $scope property\n *\n * @param {Object} $scope\n * @param {String} key\n * @param {Mixed} def\n * @return {self}\n */\n bind: function ($scope, key, def) {\n if (angular.isUndefined( $scope.$eval(key) )) {\n $parse(key).assign($scope, this.get(key, def));\n if (! this.has(key)) this.put(key, def);\n }\n\n var self = this;\n this._watchers[key + $scope.$id] = $scope.$watch(key, function (newVal) {\n if (angular.isDefined(newVal)) self.put(key, newVal);\n }, angular.isObject($scope[key]));\n\n return this;\n },\n\n /**\n * Unbind a storage key from a $scope property\n *\n * @param {Object} $scope\n * @param {String} key\n * @return {self}\n */\n unbind: function ($scope, key) {\n $parse(key).assign($scope, void 0);\n this.forget(key);\n if (this._watchers[key + $scope.$id]) {\n // execute the de-registration function\n this._watchers[key + $scope.$id]();\n delete this._watchers[key + $scope.$id];\n }\n\n return this;\n },\n\n /**\n * Set the storage driver on a new instance to enable overriding defaults\n *\n * @param {String} driver\n * @return {self}\n */\n driver: function (driver) {\n return new Locker(driver, this._namespace, this._eventsEnabled);\n },\n\n /**\n * Get the currently set driver\n *\n * @return {Storage}\n */\n getDriver: function () {\n return this._driver;\n },\n\n /**\n * Set the namespace on a new instance to enable overriding defaults\n *\n * @param {String} namespace\n * @return {self}\n */\n namespace: function (namespace) {\n return new Locker(this._deriveDriver(this._driver), namespace, this._eventsEnabled);\n },\n\n /**\n * Get the currently set namespace\n *\n * @return {String}\n */\n getNamespace: function () {\n return this._namespace;\n },\n\n /**\n * Check browser support\n *\n * @see https://github.com/Modernizr/Modernizr/blob/master/feature-detects/storage/localstorage.js#L38-L47\n * @param {String} driver\n * @return {Boolean}\n */\n supported: function (driver) {\n return this._checkSupport(driver);\n }\n };\n\n /**\n * Create the driver instances\n *\n * @type {Object}\n */\n var drivers = {\n local: new Locker('local', defaults.namespace, defaults.eventsEnabled, defaults.separator),\n session: new Locker('session', defaults.namespace, defaults.eventsEnabled, defaults.separator)\n };\n\n return drivers[defaults.driver];\n }]\n };\n\n });\n\n});\n"],"sourceRoot":"/source/"} \ No newline at end of file +/*! angular-locker v1.1.1 | (c) 2015 @tymondesigns | https://github.com/tymondesigns/angular-locker */ +{"version":3,"sources":["angular-locker.min.js"],"names":["root","factory","define","amd","angular","exports","module","window","this","provider","_value","value","isFunction","_keyByVal","object","Object","keys","filter","key","_error","msg","Error","defaults","driver","namespace","eventsEnabled","separator","setDefaultDriver","getDefaultDriver","setDefaultNamespace","getDefaultNamespace","setEventsEnabled","enabled","getEventsEnabled","setSeparator","getSeparator","$get","$window","$rootScope","$parse","Locker","_registeredDrivers","local","localStorage","session","sessionStorage","_resolveDriver","hasOwnProperty","_deriveDriver","_driver","_namespace","_eventsEnabled","_separator","_watchers","_checkSupport","isUndefined","_supported","l","setItem","removeItem","e","_getPrefix","_serialize","toJson","_unserialize","fromJson","_event","name","payload","$emit","extend","_setItem","oldVal","_getItem","_exists","equals","oldValue","newValue","indexOf","getItem","_removeItem","prototype","put","isObject","forEach","isDefined","add","has","get","def","isArray","items","k","arguments","length","forget","pull","all","split","splice","join","clean","empty","clear","count","bind","$scope","$eval","assign","self","$id","$watch","newVal","unbind","getDriver","getNamespace","supported","drivers"],"mappings":"CAUA,SAAWA,EAAMC,GACS,kBAAXC,SAAyBA,OAAOC,IACvCD,OAAO,WACH,MAAOD,GAAQD,EAAKI,WAEE,gBAAZC,SACdC,OAAOD,QAAUJ,EAAQD,EAAKI,SAAYG,QAAUA,OAAOH,SAE3DH,EAAQD,EAAKI,UAElBI,KAAM,SAAUJ,GAEf,YAEAA,GAAQE,OAAO,qBAEdG,SAAS,SAAU,WAQhB,GAAIC,GAAS,SAAUC,GACnB,MAAOP,GAAQQ,WAAWD,GAASA,IAAUA,GAU7CE,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RV,KAAK6C,UAAUnC,EAAMwF,EAAOI,OAE5BtG,KAAK6C,UAAUnC,EAAMwF,EAAOI,aACrBtG,MAAK6C,UAAUnC,EAAMwF,EAAOI,MAGhCtG,MASXe,OAAQ,SAAUA,GACd,MAAO,IAAIiB,GAAOjB,EAAQf,KAAK0C,WAAY1C,KAAK2C,eAAgB3C,KAAK4C,aAQzE8D,UAAW,WACP,MAAO1G,MAAKyC,SAShBzB,UAAW,SAAUA,GACjB,MAAO,IAAIgB,GAAOhC,KAAKwC,cAAcxC,KAAKyC,SAAUzB,EAAWhB,KAAK2C,eAAgB3C,KAAK4C,aAQ7F+D,aAAc,WACV,MAAO3G,MAAK0C,YAUhBkE,UAAW,SAAU7F,GACjB,MAAOf,MAAK8C,cAAc/B,IASlC,IAAI8F,IACA3E,MAAO,GAAIF,GAAO,QAASlB,EAASE,UAAWF,EAASG,cAAeH,EAASI,WAChFkB,QAAS,GAAIJ,GAAO,UAAWlB,EAASE,UAAWF,EAASG,cAAeH,EAASI,WAGxF,OAAO2F,GAAQ/F,EAASC","file":"angular-locker.min.js","sourcesContent":["/**\n * angular-locker\n *\n * A simple & configurable abstraction for local/session storage in angular projects.\n *\n * @link https://github.com/tymondesigns/angular-locker\n * @author Sean Tymon @tymondesigns\n * @license MIT License, http://www.opensource.org/licenses/MIT\n */\n\n(function (root, factory) {\n if (typeof define === 'function' && define.amd) {\n define(function () {\n return factory(root.angular);\n });\n } else if (typeof exports === 'object') {\n module.exports = factory(root.angular || (window && window.angular));\n } else {\n factory(root.angular);\n }\n})(this, function (angular) {\n\n 'use strict';\n\n angular.module('angular-locker', [])\n\n .provider('locker', function () {\n\n /**\n * If value is a function then execute, otherwise return\n *\n * @param {Mixed} value\n * @return {Mixed}\n */\n var _value = function (value) {\n return angular.isFunction(value) ? value() : value;\n };\n\n /**\n * Get the key of an object by the value\n *\n * @param {Object} object\n * @param {Mixed} value\n * @return {String}\n */\n var _keyByVal = function (object, value) {\n return Object.keys(object).filter(function (key) { return object[key] === value; })[0];\n };\n\n /**\n * Trigger an error\n *\n * @param {String} msg\n * @return {void}\n */\n var _error = function (msg) {\n throw new Error('[angular-locker] ' + msg);\n };\n\n /**\n * Set the default driver and namespace\n *\n * @type {Object}\n */\n var defaults = {\n driver: 'local',\n namespace: 'locker',\n eventsEnabled: true,\n separator: '.'\n };\n\n return {\n\n /**\n * Allow setting of default storage driver via `lockerProvider`\n * e.g. lockerProvider.setDefaultDriver('session');\n *\n * @param {String} driver\n */\n setDefaultDriver: function (driver) {\n defaults.driver = _value(driver);\n\n return this;\n },\n\n /**\n * Get the default driver\n */\n getDefaultDriver: function () {\n return defaults.driver;\n },\n\n /**\n * Allow setting of default namespace via `lockerProvider`\n * e.g. lockerProvider.setDefaultNamespace('myAppName');\n *\n * @param {String} namespace\n */\n setDefaultNamespace: function (namespace) {\n defaults.namespace = _value(namespace);\n\n return this;\n },\n\n /**\n * Get the default namespace\n */\n getDefaultNamespace: function () {\n return defaults.namespace;\n },\n\n /**\n * Set whether the events are enabled\n *\n * @param {Boolean} enabled\n */\n setEventsEnabled: function (enabled) {\n defaults.eventsEnabled = _value(enabled);\n\n return this;\n },\n\n /**\n * Get whether the events are enabled\n */\n getEventsEnabled: function () {\n return defaults.eventsEnabled;\n },\n\n /**\n * Set the separator to use with namespace in keys\n *\n * @param {String} separator\n */\n setSeparator: function (separator) {\n defaults.separator = _value(separator);\n\n return this;\n },\n\n /**\n * Get the separator\n */\n getSeparator: function () {\n return defaults.separator;\n },\n\n /**\n * The locker service\n */\n $get: ['$window', '$rootScope', '$parse', function ($window, $rootScope, $parse) {\n\n /**\n * Define the Locker class\n *\n * @param {Storage} driver\n * @param {String} namespace\n */\n function Locker (driver, namespace, eventsEnabled, separator) {\n\n /**\n * @type {Object}\n */\n this._registeredDrivers = {\n local: $window.localStorage,\n session: $window.sessionStorage\n };\n\n /**\n * Get the Storage instance from the key\n *\n * @param {String} driver\n * @return {Storage}\n */\n this._resolveDriver = function (driver) {\n if (! this._registeredDrivers.hasOwnProperty(driver)) {\n _error('The driver \"' + driver + '\" was not found.');\n }\n\n return this._registeredDrivers[driver];\n };\n\n /**\n * Get the driver key (local/session) by the Storage instance\n *\n * @param {Storage} driver\n * @return {String}\n */\n this._deriveDriver = function (driver) {\n return _keyByVal(this._registeredDrivers, driver);\n };\n\n /**\n * @type {Storage}\n */\n this._driver = this._resolveDriver(driver);\n\n /**\n * @type {String}\n */\n this._namespace = namespace;\n\n /**\n * @type {Boolean}\n */\n this._eventsEnabled = eventsEnabled;\n\n /**\n * @type {String}\n */\n this._separator = separator;\n\n /**\n * @type {Object}\n */\n this._watchers = {};\n\n /**\n * Check browser support\n *\n * @see https://github.com/Modernizr/Modernizr/blob/master/feature-detects/storage/localstorage.js#L38-L47\n * @param {String} driver\n * @return {Boolean}\n */\n this._checkSupport = function (driver) {\n if (angular.isUndefined(this._supported)) {\n var l = 'l';\n try {\n this._resolveDriver(driver || 'local').setItem(l, l);\n this._resolveDriver(driver || 'local').removeItem(l);\n this._supported = true;\n } catch (e) {\n this._supported = false;\n }\n }\n\n return this._supported;\n };\n\n /**\n * Build the storage key from the namspace\n *\n * @param {String} key\n * @return {String}\n */\n this._getPrefix = function (key) {\n if (! this._namespace) return key;\n\n return this._namespace + this._separator + key;\n };\n\n /**\n * Try to encode value as json, or just return the value upon failure\n *\n * @param {Mixed} value\n * @return {Mixed}\n */\n this._serialize = function (value) {\n try {\n return angular.toJson(value);\n } catch (e) {\n return value;\n }\n };\n\n /**\n * Try to parse value as json, if it fails then it probably isn't json so just return it\n *\n * @param {String} value\n * @return {Object|String}\n */\n this._unserialize = function (value) {\n try {\n return angular.fromJson(value);\n } catch (e) {\n return value;\n }\n };\n\n /**\n * Trigger an event\n *\n * @param {String} name\n * @param {Object} payload\n * @return {void}\n */\n this._event = function (name, payload) {\n if (this._eventsEnabled) {\n $rootScope.$emit(name, angular.extend(payload, {\n driver: this._deriveDriver(this._driver),\n namespace: this._namespace,\n }));\n }\n };\n\n /**\n * Add to storage\n *\n * @param {String} key\n * @param {Mixed} value\n */\n this._setItem = function (key, value) {\n if (this._checkSupport()) {\n try {\n var oldVal = this._getItem(key);\n this._driver.setItem(this._getPrefix(key), this._serialize(value));\n if (this._exists(key) && ! angular.equals(oldVal, value)) {\n this._event('locker.item.updated', { key: key, oldValue: oldVal, newValue: value });\n } else {\n this._event('locker.item.added', { key: key, value: value });\n }\n } catch (e) {\n if (['QUOTA_EXCEEDED_ERR', 'NS_ERROR_DOM_QUOTA_REACHED', 'QuotaExceededError'].indexOf(e.name) !== -1) {\n _error('The browser storage quota has been exceeded');\n } else {\n _error('Could not add item with key \"' + key + '\"');\n }\n }\n } else {\n _error('The browser does not support localStorage');\n }\n };\n\n /**\n * Get from storage\n *\n * @param {String} key\n * @return {Mixed}\n */\n this._getItem = function (key) {\n if (this._checkSupport()) {\n return this._unserialize(this._driver.getItem(this._getPrefix(key)));\n } else {\n _error('The browser does not support localStorage');\n }\n };\n\n /**\n * Exists in storage\n *\n * @param {String} key\n * @return {Boolean}\n */\n this._exists = function (key) {\n if (this._checkSupport()) {\n return this._driver.hasOwnProperty(this._getPrefix(_value(key)));\n } else {\n _error('The browser does not support localStorage');\n }\n };\n\n /**\n * Remove from storage\n *\n * @param {String} key\n * @return {Boolean}\n */\n this._removeItem = function (key) {\n if (this._checkSupport()) {\n if (! this._exists(key)) return false;\n this._driver.removeItem(this._getPrefix(key));\n\n this._event('locker.item.forgotten', { key: key });\n\n return true;\n } else {\n _error('The browser does not support localStorage');\n }\n };\n }\n\n /**\n * Define the public api\n *\n * @type {Object}\n */\n Locker.prototype = {\n\n /**\n * Add a new item to storage (even if it already exists)\n *\n * @param {Mixed} key\n * @param {Mixed} value\n * @return {self}\n */\n put: function (key, value) {\n if (! key) return false;\n key = _value(key);\n\n if (angular.isObject(key)) {\n angular.forEach(key, function (value, key) {\n this._setItem(key, value);\n }, this);\n } else {\n if (! angular.isDefined(value)) return false;\n this._setItem(key, _value(value));\n }\n\n return this;\n },\n\n /**\n * Add an item to storage if it doesn't already exist\n *\n * @param {Mixed} key\n * @param {Mixed} value\n * @return {Boolean}\n */\n add: function (key, value) {\n if (! this.has(key)) {\n this.put(key, value);\n return true;\n }\n\n return false;\n },\n\n /**\n * Retrieve the specified item from storage\n *\n * @param {String|Array} key\n * @param {Mixed} def\n * @return {Mixed}\n */\n get: function (key, def) {\n if (angular.isArray(key)) {\n var items = {};\n angular.forEach(key, function (k) {\n if (this.has(k)) items[k] = this._getItem(k);\n }, this);\n\n return items;\n }\n\n if (! this.has(key)) return arguments.length === 2 ? def : void 0;\n\n return this._getItem(key);\n },\n\n /**\n * Determine whether the item exists in storage\n *\n * @param {String|Function} key\n * @return {Boolean}\n */\n has: function (key) {\n return this._exists(key);\n },\n\n /**\n * Remove specified item(s) from storage\n *\n * @param {Mixed} key\n * @return {Object}\n */\n forget: function (key) {\n key = _value(key);\n\n if (angular.isArray(key)) {\n angular.forEach(key, function (key) {\n this._removeItem(key);\n }, this);\n } else {\n this._removeItem(key);\n }\n\n return this;\n },\n\n /**\n * Retrieve the specified item from storage and then remove it\n *\n * @param {String|Array} key\n * @param {Mixed} def\n * @return {Mixed}\n */\n pull: function (key, def) {\n var value = this.get(key, def);\n this.forget(key);\n\n return value;\n },\n\n /**\n * Return all items in storage within the current namespace\n *\n * @return {Object}\n */\n all: function () {\n var items = {};\n angular.forEach(this._driver, function (value, key) {\n var split = key.split(this._separator);\n if (split.length > 1 && split[0] === this._namespace) {\n split.splice(0, 1);\n key = split.join(this._separator);\n }\n if (this.has(key)) items[key] = this.get(key);\n }, this);\n\n return items;\n },\n\n /**\n * Remove all items set within the current namespace\n *\n * @return {self}\n */\n clean: function () {\n this.forget(Object.keys(this.all()));\n\n return this;\n },\n\n /**\n * Empty the current storage driver completely. careful now.\n *\n * @return {self}\n */\n empty: function () {\n this._driver.clear();\n\n return this;\n },\n\n /**\n * Get the total number of items within the current namespace\n *\n * @return {Integer}\n */\n count: function () {\n return Object.keys(this.all()).length;\n },\n\n /**\n * Bind a storage key to a $scope property\n *\n * @param {Object} $scope\n * @param {String} key\n * @param {Mixed} def\n * @return {self}\n */\n bind: function ($scope, key, def) {\n if (angular.isUndefined( $scope.$eval(key) )) {\n $parse(key).assign($scope, this.get(key, def));\n if (! this.has(key)) this.put(key, def);\n }\n\n var self = this;\n this._watchers[key + $scope.$id] = $scope.$watch(key, function (newVal) {\n if (angular.isDefined(newVal)) self.put(key, newVal);\n }, angular.isObject($scope[key]));\n\n return this;\n },\n\n /**\n * Unbind a storage key from a $scope property\n *\n * @param {Object} $scope\n * @param {String} key\n * @return {self}\n */\n unbind: function ($scope, key) {\n $parse(key).assign($scope, void 0);\n this.forget(key);\n if (this._watchers[key + $scope.$id]) {\n // execute the de-registration function\n this._watchers[key + $scope.$id]();\n delete this._watchers[key + $scope.$id];\n }\n\n return this;\n },\n\n /**\n * Set the storage driver on a new instance to enable overriding defaults\n *\n * @param {String} driver\n * @return {self}\n */\n driver: function (driver) {\n return new Locker(driver, this._namespace, this._eventsEnabled, this._separator);\n },\n\n /**\n * Get the currently set driver\n *\n * @return {Storage}\n */\n getDriver: function () {\n return this._driver;\n },\n\n /**\n * Set the namespace on a new instance to enable overriding defaults\n *\n * @param {String} namespace\n * @return {self}\n */\n namespace: function (namespace) {\n return new Locker(this._deriveDriver(this._driver), namespace, this._eventsEnabled, this._separator);\n },\n\n /**\n * Get the currently set namespace\n *\n * @return {String}\n */\n getNamespace: function () {\n return this._namespace;\n },\n\n /**\n * Check browser support\n *\n * @see https://github.com/Modernizr/Modernizr/blob/master/feature-detects/storage/localstorage.js#L38-L47\n * @param {String} driver\n * @return {Boolean}\n */\n supported: function (driver) {\n return this._checkSupport(driver);\n }\n };\n\n /**\n * Create the driver instances\n *\n * @type {Object}\n */\n var drivers = {\n local: new Locker('local', defaults.namespace, defaults.eventsEnabled, defaults.separator),\n session: new Locker('session', defaults.namespace, defaults.eventsEnabled, defaults.separator)\n };\n\n return drivers[defaults.driver];\n }]\n };\n\n });\n\n});\n"],"sourceRoot":"/source/"} \ No newline at end of file diff --git a/package.json b/package.json index 997f435..f4d4e97 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular-locker", - "version": "1.1.0", + "version": "1.1.1", "description": "A simple & configurable abstraction for local/session storage in angular projects", "author": "@tymondesigns", "license": "MIT",