Socket
Socket
Sign inDemoInstall

angular-localforage

Package Overview
Dependencies
27
Maintainers
2
Versions
18
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.3.7 to 1.3.8

index.html

10

CHANGELOG.md

@@ -0,1 +1,11 @@

<a name="1.3.8"></a>
# 1.3.8 (2018-02-16)
## Documentation
- update travis link/shield
([63f97d8d](https://github.com/ocombe/angular-localForage/commit/63f97d8d2bd589aca7e5be64ce7f69e3b5c88e82))
<a name="1.3.7"></a>

@@ -2,0 +12,0 @@ # 1.3.7 (2017-05-12)

138

dist/angular-localForage.js
/**
* angular-localforage - Angular service & directive for https://github.com/mozilla/localForage (Offline storage, improved.)
* @version v1.3.7
* @version v1.3.8
* @link https://github.com/ocombe/angular-localForage

@@ -117,2 +117,4 @@ * @license MIT

var self = this;
var args = arguments;
var localCopy;

@@ -127,25 +129,21 @@ if(angular.isArray(key)) {

}));
} else {
var deferred = $q.defer(),
args = arguments,
localCopy = stripMeta(value);
}
self._localforage.setItem(self.prefix() + key, localCopy)
.then(function success() {
if(notify.setItem) {
$rootScope.$broadcast('LocalForageModule.setItem', {
key: key,
newvalue: localCopy,
driver: self.driver()
});
}
deferred.resolve(localCopy);
})
.catch(function withError(error) {
self.onError(error, args, self.setItem, deferred);
});
localCopy = stripMeta(value);
return deferred.promise;
}
return self._localforage
.setItem(self.prefix() + key, localCopy)
.then(function success() {
if(notify.setItem) {
$rootScope.$broadcast('LocalForageModule.setItem', {
key: key,
newvalue: localCopy,
driver: self.driver()
});
}
return localCopy;
})
.catch(onError(args, self.setItem));
function stripMeta(value) {

@@ -182,3 +180,3 @@ var copy;

self = this,
promise;
promise;
if(angular.isArray(key)) {

@@ -282,3 +280,5 @@ var res = [],

LocalForageInstance.prototype.pull = function pull(key) {
// throw error on undefined key
var self = this;
var itemValue;
if(angular.isUndefined(key)) {

@@ -288,15 +288,11 @@ throw new Error("You must define a key to pull");

var self = this,
deferred = $q.defer(),
onError = function error(err) {
deferred.reject(err);
};
self.getItem(key).then(function success(value) {
self.removeItem(key).then(function success() {
deferred.resolve(value);
}, onError);
}, onError);
return deferred.promise;
return self
.getItem(key)
.then(function (value) {
itemValue = value;
return self.removeItem(key);
})
.then(function () {
return itemValue;
});
};

@@ -316,2 +312,11 @@

return deferred.promise;
// return $q(function (resolve, reject) {
// self._localforage
// .clear()
// .then(function (keys) {
// resolve();
// })
// .catch(onError(arguments, self.clear));
// });
};

@@ -347,3 +352,5 @@

for(var i = 0, len = keyList.length; i < len; i++) {
tempKeyList.push(keyList[i].substr(self.prefix().length, keyList[i].length));
tempKeyList.push(
keyList[i].substr(self.prefix().length, keyList[i].length)
);
}

@@ -394,3 +401,3 @@ keyList = tempKeyList;

key: opts
}
};
} else if(!angular.isObject(opts) || angular.isUndefined(opts.key)) {

@@ -419,23 +426,25 @@ throw new Error("You must define a key to bind");

return self.getItem(opts.key).then(function(item) {
if (item !== null) { // If it does exist assign it to the $scope value
return self
.getItem(opts.key, true)
.then(function(item) {
model.assign($scope, item);
} else if(!angular.isUndefined(opts.defaultValue)) { // If a value doesn't already exist store it as is
return item;
})
.catch(function () {
model.assign($scope, opts.defaultValue);
self.setItem(opts.key, opts.defaultValue);
}
return self.setItem(opts.key, opts.defaultValue);
})
.then(function (item) {
if(angular.isDefined(watchers[opts.key])) {
watchers[opts.key]();
}
// Register a listener for changes on the $scope value
// to update the localForage value
if(angular.isDefined(watchers[opts.key])) {
watchers[opts.key]();
}
watchers[opts.key] = $scope.$watch(scopeKey, function(val) {
if(angular.isDefined(val)) {
self.setItem(opts.key, val);
}
}, true);
watchers[opts.key] = $scope.$watch(scopeKey, function(val) {
if(angular.isDefined(val)) {
self.setItem(opts.key, val);
}
}, true);
return item;
});
return item;
});
};

@@ -508,4 +517,22 @@

function onError(args, fct) {
return function(err) {
if(((angular.isObject(err) && err.name ? err.name === 'InvalidStateError' : (angular.isString(err) && err === 'InvalidStateError')) && this.driver() === 'asyncStorage')
|| (angular.isObject(err) && err.code && err.code === 5)) {
var self = this;
return self
.setDriver('localStorageWrapper')
.then(function () {
return fct.apply(self, args);
});
}
return $q.reject(err);
};
}
lfInstances[defaultConfig.name] = new LocalForageInstance();
return lfInstances[defaultConfig.name];
}]

@@ -530,2 +557,1 @@ });

});
/**
* angular-localforage - Angular service & directive for https://github.com/mozilla/localForage (Offline storage, improved.)
* @version v1.3.7
* @version v1.3.8
* @link https://github.com/ocombe/angular-localForage

@@ -8,2 +8,2 @@ * @license MIT

*/
!function(e,r){"use strict";var t=e&&e.angular||window&&window.angular;if("function"==typeof define&&define.amd)define(["localforage"],function(e){return r(t,e)});else{if("object"!=typeof exports&&"object"!=typeof global)return r(t,e.localforage);"undefined"==typeof module?global.module.exports=r(t,require("localforage")):module.exports=r(t,require("localforage"))}}(this,function(e,r,t){"use strict";var n=e.module("LocalForageModule",["ng"]);return n.provider("$localForage",function(){var t={},n={name:"lf"},o={setItem:!1,removeItem:!1},i={};this.setNotify=function(e,r){o={setItem:e,removeItem:r}},this.config=function(r){if(!e.isObject(r))throw new Error("The config parameter should be an object");e.extend(n,r)},this.$get=["$rootScope","$q","$parse",function(a,f,s){var u=function(t){e.isDefined(t)?this._localforage=r.createInstance(t):(this._localforage=r,r.config(n))};u.prototype.createInstance=function(r){if(e.isObject(r)){if(r=e.extend({},n,r),e.isDefined(t[r.name]))throw new Error("A localForage instance with the name "+r.name+" is already defined.");return t[r.name]=new u(r),t[r.name]}throw new Error("The parameter should be a config object.")},u.prototype.instance=function(r){if(e.isUndefined(r))return t[n.name];if(e.isString(r)){if(e.isDefined(t[r]))return t[r];throw new Error("No localForage instance of that name exists.")}throw new Error("The parameter should be a string.")},u.prototype.setDriver=function(e){return this._localforage.setDriver(e)},u.prototype.driver=function(){return this._localforage.driver()},u.prototype.defineDriver=function(e){return this._localforage.defineDriver(e)},u.prototype.setItem=function(r,t){function n(r){var t;return e.isArray(r)?r.map(n):e.isObject(r)&&r.constructor===Object?(t=e.extend({},r),e.isDefined(t.$promise)&&delete t.$promise,e.isDefined(t.$$hashKey)&&delete t.$$hashKey,Object.keys(t).reduce(function(e,r){return e[r]=n(t[r]),e},{})):r}if(e.isUndefined(r))throw new Error("You must define a key to set");var i=this;if(e.isArray(r)){if(!e.isArray(t))throw new Error("If you set an array of keys, the values should be an array too");return f.all(r.map(function(e,r){return i.setItem(e,t[r])}))}var s=f.defer(),u=arguments,c=n(t);return i._localforage.setItem(i.prefix()+r,c).then(function(){o.setItem&&a.$broadcast("LocalForageModule.setItem",{key:r,newvalue:c,driver:i.driver()}),s.resolve(c)})["catch"](function(e){i.onError(e,u,i.setItem,s)}),s.promise},u.prototype.getItem=function(r,t){if(e.isUndefined(r))throw new Error("You must define a key to get");var n,o=f.defer(),i=arguments,a=this;if(e.isArray(r)){var s=[],u=0;n=a._localforage.iterate(function(e,t){var n=r.indexOf(a.prefix()+t);return n>-1&&(s[n]=e,u++),u===r.length?s:void 0}).then(function(){for(var n=!0,i=0;i<r.length;i++)e.isUndefined(s[i])&&(s[i]=null,n=!1);n||!t?o.resolve(s):o.reject(s)})}else n=a._localforage.getItem(a.prefix()+r).then(function(e){t&&null===e?o.reject(e):o.resolve(e)});return n.then(null,function(e){a.onError(e,i,a.getItem,o)}),o.promise},u.prototype.iterate=function(r){if(e.isUndefined(r))throw new Error("You must define a callback to iterate");var t=f.defer(),n=arguments,o=this;return o._localforage.iterate(r).then(function(e){t.resolve(e)},function(e){o.onError(e,n,o.iterate,t)}),t.promise},u.prototype.removeItem=function(r){if(e.isUndefined(r))throw new Error("You must define a key to remove");var t=this;if(e.isArray(r)){var n=[];return e.forEach(r,function(e,r){n.push(t.removeItem(e))}),f.all(n)}var i=f.defer(),s=arguments;return t._localforage.removeItem(t.prefix()+r).then(function(){o.removeItem&&a.$broadcast("LocalForageModule.removeItem",{key:r,driver:t.driver()}),i.resolve()},function(e){t.onError(e,s,t.removeItem,i)}),i.promise},u.prototype.pull=function(r){if(e.isUndefined(r))throw new Error("You must define a key to pull");var t=this,n=f.defer(),o=function(e){n.reject(e)};return t.getItem(r).then(function(e){t.removeItem(r).then(function(){n.resolve(e)},o)},o),n.promise},u.prototype.clear=function(){var e=f.defer(),r=arguments,t=this;return t._localforage.clear().then(function(r){e.resolve()},function(n){t.onError(n,r,t.clear,e)}),e.promise},u.prototype.key=function(r){if(e.isUndefined(r))throw new Error("You must define a position to get for the key function");var t=f.defer(),n=arguments,o=this;return o._localforage.key(r).then(function(e){t.resolve(e)},function(e){o.onError(e,n,o.key,t)}),t.promise};var c=function(){var e=f.defer(),r=arguments,t=this;return t._localforage.keys().then(function(r){if(n.oldPrefix&&"localStorageWrapper"===t.driver()){for(var o=[],i=0,a=r.length;a>i;i++)o.push(r[i].substr(t.prefix().length,r[i].length));r=o}e.resolve(r)},function(n){t.onError(n,r,t.keys,e)}),e.promise};return u.prototype.keys=c,u.prototype.getKeys=c,u.prototype.length=function(){var e=f.defer(),r=arguments,t=this;return t._localforage.length().then(function(r){e.resolve(r)},function(n){t.onError(n,r,length,e)}),e.promise},u.prototype.bind=function(r,o){if(e.isString(o))o={key:o};else if(!e.isObject(o)||e.isUndefined(o.key))throw new Error("You must define a key to bind");var a={defaultValue:"",name:n.name};o=e.extend({},a,o);var f=t[o.name];if(e.isUndefined(f))throw new Error("You must use the name of an existing instance");var u=o.scopeKey||o.key,c=s(u);return f.getItem(o.key).then(function(t){return null!==t?c.assign(r,t):e.isUndefined(o.defaultValue)||(c.assign(r,o.defaultValue),f.setItem(o.key,o.defaultValue)),e.isDefined(i[o.key])&&i[o.key](),i[o.key]=r.$watch(u,function(r){e.isDefined(r)&&f.setItem(o.key,r)},!0),t})},u.prototype.unbind=function(r,o){if(e.isString(o))o={key:o};else if(!e.isObject(o)||e.isUndefined(o.key))throw new Error("You must define a key to unbind");var a={scopeKey:o.key,name:n.name};o=e.extend({},a,o);var f=t[o.name];if(e.isUndefined(f))throw new Error("You must use the name of an existing instance");return s(o.scopeKey).assign(r,null),e.isDefined(i[o.key])&&(i[o.key](),delete i[o.key]),f.removeItem(o.key)},u.prototype.prefix=function(){return"localStorageWrapper"===this.driver()&&n.oldPrefix?this._localforage.config().name+".":""},u.prototype.onError=function(r,t,n,o){if((e.isObject(r)&&r.name?"InvalidStateError"===r.name:e.isString(r)&&"InvalidStateError"===r)&&"asyncStorage"===this.driver()||e.isObject(r)&&r.code&&5===r.code){var i=this;i.setDriver("localStorageWrapper").then(function(){n.apply(i,t).then(function(e){o.resolve(e)},function(e){o.reject(e)})},function(){o.reject(r)})}else o.reject(r)},t[n.name]=new u,t[n.name]}]}),n.directive("localForage",["$localForage",function(r){return{restrict:"A",link:function(t,n,o){var i=t.$eval(o.localForage);e.isObject(i)&&e.isDefined(i.key)?r.bind(t,i):r.bind(t,o.localForage)}}}]),n.name});
!function(e,r){"use strict";var t=e&&e.angular||window&&window.angular;if("function"==typeof define&&define.amd)define(["localforage"],function(e){return r(t,e)});else{if("object"!=typeof exports&&"object"!=typeof global)return r(t,e.localforage);"undefined"==typeof module?global.module.exports=r(t,require("localforage")):module.exports=r(t,require("localforage"))}}(this,function(e,r,t){"use strict";var n=e.module("LocalForageModule",["ng"]);return n.provider("$localForage",function(){var t={},n={name:"lf"},o={setItem:!1,removeItem:!1},i={};this.setNotify=function(e,r){o={setItem:e,removeItem:r}},this.config=function(r){if(!e.isObject(r))throw new Error("The config parameter should be an object");e.extend(n,r)},this.$get=["$rootScope","$q","$parse",function(a,f,s){function u(r,t){return function(n){if((e.isObject(n)&&n.name?"InvalidStateError"===n.name:e.isString(n)&&"InvalidStateError"===n)&&"asyncStorage"===this.driver()||e.isObject(n)&&n.code&&5===n.code){var o=this;return o.setDriver("localStorageWrapper").then(function(){return t.apply(o,r)})}return f.reject(n)}}var c=function(t){e.isDefined(t)?this._localforage=r.createInstance(t):(this._localforage=r,r.config(n))};c.prototype.createInstance=function(r){if(e.isObject(r)){if(r=e.extend({},n,r),e.isDefined(t[r.name]))throw new Error("A localForage instance with the name "+r.name+" is already defined.");return t[r.name]=new c(r),t[r.name]}throw new Error("The parameter should be a config object.")},c.prototype.instance=function(r){if(e.isUndefined(r))return t[n.name];if(e.isString(r)){if(e.isDefined(t[r]))return t[r];throw new Error("No localForage instance of that name exists.")}throw new Error("The parameter should be a string.")},c.prototype.setDriver=function(e){return this._localforage.setDriver(e)},c.prototype.driver=function(){return this._localforage.driver()},c.prototype.defineDriver=function(e){return this._localforage.defineDriver(e)},c.prototype.setItem=function(r,t){function n(r){var t;return e.isArray(r)?r.map(n):e.isObject(r)&&r.constructor===Object?(t=e.extend({},r),e.isDefined(t.$promise)&&delete t.$promise,e.isDefined(t.$$hashKey)&&delete t.$$hashKey,Object.keys(t).reduce(function(e,r){return e[r]=n(t[r]),e},{})):r}if(e.isUndefined(r))throw new Error("You must define a key to set");var i,s=this,c=arguments;if(e.isArray(r)){if(!e.isArray(t))throw new Error("If you set an array of keys, the values should be an array too");return f.all(r.map(function(e,r){return s.setItem(e,t[r])}))}return i=n(t),s._localforage.setItem(s.prefix()+r,i).then(function(){return o.setItem&&a.$broadcast("LocalForageModule.setItem",{key:r,newvalue:i,driver:s.driver()}),i})["catch"](u(c,s.setItem))},c.prototype.getItem=function(r,t){if(e.isUndefined(r))throw new Error("You must define a key to get");var n,o=f.defer(),i=arguments,a=this;if(e.isArray(r)){var s=[],u=0;n=a._localforage.iterate(function(e,t){var n=r.indexOf(a.prefix()+t);return n>-1&&(s[n]=e,u++),u===r.length?s:void 0}).then(function(){for(var n=!0,i=0;i<r.length;i++)e.isUndefined(s[i])&&(s[i]=null,n=!1);n||!t?o.resolve(s):o.reject(s)})}else n=a._localforage.getItem(a.prefix()+r).then(function(e){t&&null===e?o.reject(e):o.resolve(e)});return n.then(null,function(e){a.onError(e,i,a.getItem,o)}),o.promise},c.prototype.iterate=function(r){if(e.isUndefined(r))throw new Error("You must define a callback to iterate");var t=f.defer(),n=arguments,o=this;return o._localforage.iterate(r).then(function(e){t.resolve(e)},function(e){o.onError(e,n,o.iterate,t)}),t.promise},c.prototype.removeItem=function(r){if(e.isUndefined(r))throw new Error("You must define a key to remove");var t=this;if(e.isArray(r)){var n=[];return e.forEach(r,function(e,r){n.push(t.removeItem(e))}),f.all(n)}var i=f.defer(),s=arguments;return t._localforage.removeItem(t.prefix()+r).then(function(){o.removeItem&&a.$broadcast("LocalForageModule.removeItem",{key:r,driver:t.driver()}),i.resolve()},function(e){t.onError(e,s,t.removeItem,i)}),i.promise},c.prototype.pull=function(r){var t,n=this;if(e.isUndefined(r))throw new Error("You must define a key to pull");return n.getItem(r).then(function(e){return t=e,n.removeItem(r)}).then(function(){return t})},c.prototype.clear=function(){var e=f.defer(),r=arguments,t=this;return t._localforage.clear().then(function(r){e.resolve()},function(n){t.onError(n,r,t.clear,e)}),e.promise},c.prototype.key=function(r){if(e.isUndefined(r))throw new Error("You must define a position to get for the key function");var t=f.defer(),n=arguments,o=this;return o._localforage.key(r).then(function(e){t.resolve(e)},function(e){o.onError(e,n,o.key,t)}),t.promise};var l=function(){var e=f.defer(),r=arguments,t=this;return t._localforage.keys().then(function(r){if(n.oldPrefix&&"localStorageWrapper"===t.driver()){for(var o=[],i=0,a=r.length;a>i;i++)o.push(r[i].substr(t.prefix().length,r[i].length));r=o}e.resolve(r)},function(n){t.onError(n,r,t.keys,e)}),e.promise};return c.prototype.keys=l,c.prototype.getKeys=l,c.prototype.length=function(){var e=f.defer(),r=arguments,t=this;return t._localforage.length().then(function(r){e.resolve(r)},function(n){t.onError(n,r,length,e)}),e.promise},c.prototype.bind=function(r,o){if(e.isString(o))o={key:o};else if(!e.isObject(o)||e.isUndefined(o.key))throw new Error("You must define a key to bind");var a={defaultValue:"",name:n.name};o=e.extend({},a,o);var f=t[o.name];if(e.isUndefined(f))throw new Error("You must use the name of an existing instance");var u=o.scopeKey||o.key,c=s(u);return f.getItem(o.key,!0).then(function(e){return c.assign(r,e),e})["catch"](function(){return c.assign(r,o.defaultValue),f.setItem(o.key,o.defaultValue)}).then(function(t){return e.isDefined(i[o.key])&&i[o.key](),i[o.key]=r.$watch(u,function(r){e.isDefined(r)&&f.setItem(o.key,r)},!0),t})},c.prototype.unbind=function(r,o){if(e.isString(o))o={key:o};else if(!e.isObject(o)||e.isUndefined(o.key))throw new Error("You must define a key to unbind");var a={scopeKey:o.key,name:n.name};o=e.extend({},a,o);var f=t[o.name];if(e.isUndefined(f))throw new Error("You must use the name of an existing instance");return s(o.scopeKey).assign(r,null),e.isDefined(i[o.key])&&(i[o.key](),delete i[o.key]),f.removeItem(o.key)},c.prototype.prefix=function(){return"localStorageWrapper"===this.driver()&&n.oldPrefix?this._localforage.config().name+".":""},c.prototype.onError=function(r,t,n,o){if((e.isObject(r)&&r.name?"InvalidStateError"===r.name:e.isString(r)&&"InvalidStateError"===r)&&"asyncStorage"===this.driver()||e.isObject(r)&&r.code&&5===r.code){var i=this;i.setDriver("localStorageWrapper").then(function(){n.apply(i,t).then(function(e){o.resolve(e)},function(e){o.reject(e)})},function(){o.reject(r)})}else o.reject(r)},t[n.name]=new c,t[n.name]}]}),n.directive("localForage",["$localForage",function(r){return{restrict:"A",link:function(t,n,o){var i=t.$eval(o.localForage);e.isObject(i)&&e.isDefined(i.key)?r.bind(t,i):r.bind(t,o.localForage)}}}]),n.name});
{
"name": "angular-localforage",
"version": "1.3.7",
"version": "1.3.8",
"description": "Angular service & directive for https://github.com/mozilla/localForage (Offline storage, improved.)",

@@ -45,9 +45,8 @@ "license": "MIT",

"gulp-uglify": "~1.2.0",
"jasmine-core": "~2.3.4",
"karma": "~0.12.37",
"karma-chrome-launcher": "~0.2.0",
"karma-cli": "~0.1.0",
"karma-firefox-launcher": "~0.1.6",
"karma-jasmine": "~0.3.6",
"karma-sauce-launcher": "^0.2.14",
"jasmine-core": "^2.6.0",
"karma": "^1.6.0",
"karma-chrome-launcher": "^2.0.0",
"karma-cli": "^1.0.1",
"karma-firefox-launcher": "^1.0.1",
"karma-jasmine": "^1.1.0",
"qq": "~0.3.5",

@@ -54,0 +53,0 @@ "run-sequence": "~1.1.1",

@@ -1,2 +0,2 @@

angular-localForage [![Build Status](https://travis-ci.org/ocombe/angular-localForage.svg)](https://travis-ci.org/ocombe/angular-localForage)
angular-localForage [![Build Status](https://travis-ci.org/scotttrinh/angular-localForage.svg)](https://travis-ci.org/scotttrinh/angular-localForage)
===================

@@ -3,0 +3,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc