var angular = require('angular');
require('localforage');
require('../modules');
require('jsUtil');

var module = angular.module('commons.services');
module.factory('localforage', ['$q', function($q){
var promiseFns = ['getItem', 'setItem', 'removeItem', 'clear', 'length', 'key'],
  fns = ['config', 'setDriver'],
  factory = {
    localforage: window.localforage
  };

_.each(promiseFns, function(fn) {
  factory[fn] = function() {
    return $q.when(window.localforage[fn].apply(window.localforage, _.toArray(arguments)));
  };
});

_.each(fns, function(fn) {
  factory[fn] = localforage[fn];
});

return factory;
}]);
