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

cabinet-storage

v0.4.1

Published

A simple interface for accessing local and session storage

Readme

cabinet.js

A simple interface for accessing local and session storage.

Installation

npm install cabinet-storage

Implementation Example

// import the Cabinet module
import Cabinet from "cabinet-storage"

Methods

Cabinet uses local storage by default. Access session storage under the Cabinet.session namespace.


Cabinet.set(key, val[, metadata])

Creates an item inside local storage

Parameters

  1. key (String | Number)
  2. val (Any)
  3. metadata (Object: optional)

Examples


Cabinet.set("dog", "Scooby") // returns "Scooby"
Cabinet.set("total", 50/(10-5)) // 10
Cabinet.set("person", {name: "Michael", age: 26, gender: "Male"}); // storing objects
Cabinet.set("animals", ["lion", "tiger", "bear"]); // storing arrays
Cabinet.set("friends", [{name: "Stan"}, {name: "Wendy"}]); // storing collection
Cabinet.set("check", true); // true
Cabinet.set("reminder", new Date(Date.now() + 1000)); // Mon Feb 26 2018 21:47:15 GMT-0800 (Pacific Standard Time)

Working with expirations


// set an expiration using a new Date instance
Cabinet.set("reminder", "Thanks a ton", {
  expires: new Date(Date.now() + 300000000)
})

// set an expiration to 30 days from now
Cabinet.set("partyime", "It's time to party", {
 expires: {value: 30, unit: "day"} // returns "It's time to party"
})

Cabinet.set("dueDate", "Project due", {
 expires: {value: 3, unit: "hour"}
})

// time units: "day", "hour", "minute", "second"

Cabinet.get(key[, defaultVal])

Retrieves an item from local storage if it exists

Parameters

  1. key (String | Number)
  2. defaultVal (Any: optional)

Examples


Cabinet.get("friends") // returns [{name: "Stan"}, {name: "Wendy"}]

// items that don't exist return null
Cabinet.get("doesntExist") // null

// iterating through a collection
Cabinet.get("friends").map(item => {
 let name = item.name
})

Default Values


// If the item doesn't exist in local storage and a default value is provided, Cabinet will call the set method
Cabinet.get("todos", []) // returns []
Cabinet.get("nameField", "Enter Your Name") // "Enter Your Name"

Cabinet.getAll()

Retrieves all items from local storage

Examples


// returns an array containing all of the values in local storage
Cabinet.getAll() // ["reminder", 123, [], {name: "Stan"}]

// filter out numbers
Cabinet.getAll().filter(val => typeof val === "number") // filtered array

Cabinet.remove(key)

Removes an item from local storage if it exists

Parameters

  1. key (String | Number)

Examples

// returns true if the item was successfully removed
Cabinet.remove("reminder") // true

// returns null if the item doesn't exist
Cabinet.remove("doesntExist") // null

Cabinet.removeAll()

Removes all items from local storage

Examples


Cabinet.removeAll() // returns true

Cabinet.getMetadata(key)

Retrieves a set of attributes that Cabinet stores with an item inside local storage

Parameters

  1. key (String | Number)

Examples

// readable properties

const friends = Cabinet.getMetadata("friends") // returns the metadata object {}

friends.dateCreated // date string
friends.expires // date string or null (if not provided)
friends.source // "CABINET_STORAGE"
friends.type // datatype (string)
friends.val // the stored value

// retrieve the expiration date
let expires = new Date(Cabinet.getMetadata("reminder").expires) // Thu Mar 08 2018 21:40:24 GMT-0800 (Pacific Standard Time)

// check if the item came from Cabinet
if (Cabinet.getMetadata("reminder").source === "CABINET_STORAGE") {
 // do stuff...
}

Cabinet.removeExpired()

Removes all expired items from local storage

Examples

// returns an array containing the keys of the removed items
Cabinet.removeExpired() // ["key1", "key2", "key3"]

// no expired items
Cabinet.removeExpired() // null

Cabinet.count()

Returns a count of the number of items saved in local storage

Examples

Cabinet.count() // 3

Cabinet.keys()

Returns an array containing all of the keys in local storage

Examples

Cabinet.keys() // ["key1", "key2", "key3"]

Session Storage Usage

Cabinet.session.methodName()

Access session storage under the Cabinet.session namespace.

Cabinet.session.get(key)
Cabinet.session.set(key, val)
Cabinet.session.getAll()
Cabinet.session.remove(key)
Cabinet.session.removeAll()
Cabinet.session.getMetadata()
Cabinet.session.removeExpired()
Cabinet.session.keys()
Cabinet.session.count()

Development Build

# install dependencies
npm install --save-dev

# run demo build
npm run demo

Next, open /demo/dist/index.html in your browser. Interact with the module from /demo/src/demo.js. You can log output to the console or render output to the examples index page.

Production Build

npm run build

production build is output to /dist/main.js