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 🙏

© 2026 – Pkg Stats / Ryan Hefner

vault.js

v1.0.3

Published

Key-Value Storage of true data types for the browser and node

Readme

vault.js

Key-Value Storage of true data types for the browser and node

Vault is an API to store Key-Value pairs as true data types. It can utilize localStorage, sessionStorage, and cookies in the Browser. In node, it uses a file at the root of the project (redis support coming soon).

It handles JSON objects, arrays, booleans, numbers, and even returns undefined and null accurately.

npm install vault.js
bower install vault.js
<script src="//cdnjs.cloudflare.com/ajax/libs/vault.js/1.0.0/vault.min.js"></script>

What's new!

  • [1.0.0] Memory Storage. Automatic cleanup (expired items removed in the background). Moves data from one storage to another if the same var is set with different config.
  • [0.1.4] Support for use server-side added- writes data to .vault.json at the root level
  • [0.1.0] localStorage and sessionStorage support the path param

What's next?

  • [ ] add redis as a storage option
  • [ ] handle storage limit errors
  • [ ] add support to request more storage
  • [ ] handle storage events
  • [x] add server-side storage for node- save data to a json file

Run/Develop locally

git clone [email protected]:jimmybyrum/vault.js.git
cd vault.js
npm install
npm run build

Usage

Local, Session, Cookie, File, Memory

Vault.set(String key, Mixed value, Object optional_config)
Vault.set(String key, Mixed value, Object optional_config);
rules for which storage to use
if node
  if config.expires exists and equals "session"
    use Memory
  else
    use File
else if config.expires exists and localStorage is supported, then
  use localStorage
else if sessionStorage is supported, then
  use sessionStorage
else
  use cookies

or, if you want to specify which storage to use:

// client side
Vault.Cookie.set(...);
Vault.Session.set(...);
Vault.Local.set(...);

// server side
Vault.File.set(...);
Vault.Memory.set(...);
optional_config
{
  // Cookie options.
  domain: ".jimmybyrum.com",
  secure: true,

  // Cookie and Local options
  path: "/",
  expires: "2014-09-25 8:24:32 pm", // or anything that can be parsed by new Date(...)
  expires: "+3 days", // works for all time increments from milliseconds to years.

  // File and Memory options
  expires

  // domain and local/session storage
  local/session is natively tied to the domain. Subdomain keys can only be set from that subdomain.
}

examples

Vault.set("year", 1999); // saves in localStorage (browser) or to a file (server)

Vault.set("year", 1999, { expires: 'session' }); // saves in sessionStorage (browser) or in Memory (server)

Vault.set("year", 1999, { expires: '1999-12-31 11:59:59 pm' }); // saves in localStorage until 11:59:59 on December 31, 1999

Vault.Session.set('foo', 'bar');
Vault.Session.set('foo', 'bar', {
  expires: '+6 months',
  path: '/examples'
});
Vault.Local.set('my_array', [1,2,3,4]);
Vault.Cookie.set('my_object', {
  foo: 'bar',
  an_array: [1,2,3],
  year: 2012
});
Vault.Local.set('age', 33);
Vault.get(String key)

Will check storage in this order: Memory, File (if node), Session, Local, Cookie

To specify which storage to get from, use:

Vault.Cookie.get(String key);
Vault.Local.get(String key);
Vault.Session.get(String key);
Vault.File.get(String key);
Vault.Memory.get(String key);

examples

Vault.get('foo'); returns from Memory, else File (if node), else Session, else Local, else Cookie, else undefined

Vault.Session.get('foo');
// returns 'bar'
Vault.Local.get('my_array');
// [1,2,3,4]
Vault.Cookie.get('my_object');
// {
//   foo: 'bar',
//   an_array: [1,2,3],
//   year: 2012
// }
Vault.Local.get('age');
// returns the number 33
remove

removes an item

Vault.remove('my_object'); // removes from all storage types
Vault.Session.remove('my_object');
Vault.Local.remove('my_array');
Vault.Cookie.remove('my_array');
Vault.File.remove('my_array');
Vault.Memory.remove('my_array');
clear

clears all items

Vault.clear(); // clears all storage types
Vault.Session.clear();
Vault.Local.clear();
Vault.Cookie.clear();
Vault.File.clear();
Vault.Memory.clear();
list

lists all items in Vault in the console

Vault.list(); // lists all storage types
Vault.Session.list();
Vault.Local.list();
Vault.Cookie.list();
Vault.File.list();
Vault.Memory.list();

Webpack

To use Vault.js with webpack you'll need to use json-loader.

npm i --save json-loader

Then in webpack config:

  module: {
    loaders: [
      {test: /\.json$/, loader: "json-loader" }
    ]
  },

You may also want to set up an alias so your require statements are a bit cleaner:

  resolve: {
    alias: {
      'vault.js': 'vault.js/browser.js'
    }
  }