node package manager


depot.js is a namespaced localStorage wrapper with a simple API. There are other tools out there but none of them had what I was looking for.

depot.js should work well with CommonJS and AMD loaders. If loaders are not present depot.js will attach itself to the current context (window) when loaded via <script src="depot.min.js"></script>.

depot.js is also a bower component so you should be able to install it by running:

bower install depot

or if you already have a bower based project you can add depot.js to your dependency list in component.json

 "dependencies": {
    "depot": "0.x.x"

depot.js does not depend on any other libraries however if you plan to support older browsers you will need to include ES5-shim.

If you plan to run it on browsers that don't support localStorage you may try to include storage polyfill.

  • save(record)

  • updateAll(hash)

  • update(hash)

  • find(hash | function)

  • all()

  • destroy(id | record)

  • destroyAll(none | hash | function)

  • get(id)

  • size()

var todoStore = depot('todos');

_id property will be generated and attached to each new record:{ title: "todo1" });{ title: "todo2", completed: true });{ title: "todo3", completed: true });
todoStore.updateAll({ completed: false });
todoStore.all(); // [{ id: 1, title "todo1" }, {id: 2, title: todo2 }] 
  • find based on given criteria
todoStore.find({ completed: true }); // [{ id: 2, title: "todo2" }, { id: 3, title: "todo3" }] 
  • find based on given function
todoStore.find(function (record) {
  return record.completed && record.title == "todo3";
}); // [{ id: 3, title: "todo3" }] 
todoStore.get(1); // { id: 1, title: "todo1" } 
  • by record id
  • by record object
  • destroy all
  • destroy by given criteria
todoStore.destroyAll({ completed: true });
  • destroy by given function
todoStore.destroyAll(function (record) {
  return record.completed && record.title == "todo3";

You can pass a second parameter to depot.js with additional options.

var todoStore = depot("todos", options);
  • idAttribute - used to override record id property (default: _id)
var todoStore = depot("todos", { idAttribute: 'id' });
  • storageAdaptor - used to override storage type (default: localStorage)
var todoStore = depot('todos', { storageAdaptor: sessionStorage });
The MIT License