npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

depot

v0.1.6

Published

[![build status](https://secure.travis-ci.org/mkuklis/depot.js.png)](http://travis-ci.org/mkuklis/depot.js)

Downloads

24

Readme

depot.js

build status

depot.js

Description

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.

Setup

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"
    ...
  }

Dependencies

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.

API

  • save(record)

  • updateAll(hash)

  • update(hash)

  • find(hash | function)

  • all()

  • destroy(id | record)

  • destroyAll(none | hash | function)

  • get(id)

  • size()

##Usage

####Define new store

var todoStore = depot('todos');

####Add new records

_id property will be generated and attached to each new record:

todoStore.save({ title: "todo1" });
todoStore.save({ title: "todo2", completed: true });
todoStore.save({ title: "todo3", completed: true });

####Update all records

todoStore.updateAll({ completed: false });

####Return all records

todoStore.all(); // [{ id: 1, title "todo1" }, {id: 2, title: todo2 }]

####Find records

  • 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" }]

####Return single record by id

todoStore.get(1); // { id: 1, title: "todo1" }

####Destroy single record

  • by record id
todoStore.destroy(1);
  • by record object
todoStore.destroy(todo);

####Destroy all records

  • destroy all
todoStore.destroyAll();
  • destroy by given criteria
todoStore.destroyAll({ completed: true });
  • destroy by given function
todoStore.destroyAll(function (record) {
  return record.completed && record.title == "todo3";
});

##Options

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

var todoStore = depot("todos", options);

Available 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 });

##Contributors:

##License: