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

ask11-storage

v0.5.0

Published

Functional wrapper around localForage

Downloads

12

Readme

Storage Build Status

Storage is a functional wrapper around localForage. That means it's an asynchronous browser storage with multiple back-ends (IndexedDB, WebSQL, localStorage), which is built for a better offline experience.

The main differences with localForage:

  • batch support
  • error first node-style callbacks, fixes #55
  • simple API inspired by yields/store
  • optional callbacks, return promises
  • development mode

Installation

$ bower install storage
$ component install ask11/storage
$ npm install ask11-storage --save

Standalone build available as storage.js.

<script src="storage.js"></script>
<script>window.storage('key', fn);</script>

Example

// set
storage.set('foo', 'val', fn);
storage.set({ foo: 'val', bar: 'baz' }, fn);

// get
storage.get('foo', fn); // 'val'
storage.get(['foo', 'bar'], fn); // ['val', 'baz']

// delete
storage.del('foo', fn)
storage.del(['foo', 'bar', 'baz'], fn);

API

Each method returns promise, and accepts optional callback.

storage([key, val, fn])

Main function is facade to get/set/del/count methods. It's inspired by yields/store. Setting a key to null is equivalent to deleting the key via storage.del(key).

// set
storage({ key: 'val', key2: 'val2'}, function(err) {});

// get
storage('key', function(err, val) {});
storage(['key', 'key2'], function(err, all) {}); // all.length == 2

// count
storage(function(err, count) {}); // count == 2

// delete
storage('key', null, function(err) {});
storage(['key', 'key2'], null, function(err) {});

storage.get(key, [fn])

Get key value.

storage.get([key1, key2, ..., keyn], [fn])

Get group of values. Callbacks return array of values for each key. If key does not exist, it returns null on this position.

storage.set(key, val, [fn])

Set key to val. You can store any kind of data, including blobs.

storage.del(key, [fn])

Delete key.

storage.set({ key1: val1, key2: val2, key3: val3 }, [fn])

Run a batch operation. Simple way to create, update, remove multiple records. Use null to remove record.

// assume we have 2 records
storage('foo', 7, fn)
storage('bar', ['one', 'two', 'three'], fn);

storage({
  baz: 'val' // create new val
  foo: 1000, // update `foo` value
  bar: null, // remove `bar`
}, function(err) {});

storage.del([key1, key2, ..., keyn], [fn])

Delete a group of keys in one request.

storage.clear()

Clear storage.

storage.count()

Count records.

storage.development

Work with async storage in developer console can be unpleasant. Setup development flag and storage will console.log() results of get or count.

storage.development = true;
storage.set({ foo: 1, bar: 2 });
storage.get(['foo', 'bar']);
// => [1 ,2]
storage.del('bar');
storage.count();
// => 1
// shortcut to: storage.count().then(console.log.bind(console));

storage.forage

It gives you access to the localForage instance. You can use it to configure backend. By default storage setups only name option as storage.

storage.forage.config({ name: 'my-name' });
if (!window.indexedDB) storage.forage.setDriver('localStorageWrapper');

License

Aleksey Kulikov, MIT.