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

all-localstorage

v1.0.2

Published

Easy interact with localstorage in browser or node environment

Readme

All-LocalStorage

Interact with Browser localStorage and NodeJS in-Memory with more additional features.

npm version Rate on Openbase

Features

  • Set, Get, Clear data: Already the case with the native APIs.
  • Single and concise API to interact with all type of storage.
  • Support all Javascript Types of data: String, Number, Object, Array, ... No need to JSON.stringify() before to store object, neither to parse the data when retreived.
  • Auto-select the Storage depending on the environment.
  • Encrypt and Decrypt data stored in the localstorage.
  • Save flash data: Temporary hold data and delete after retreived.
  • Map stored data by prefixing attributes/keys for grouping fetch and targeted flush delete.

Installation

Install using npm:

$ npm install all-localstorage

then import it into your code

const Storage = require('all-localstorage');

// or 

import Storage from 'all-localstorage';

Via HTML <script> tag with the CDN source:

<script src="https://cdn.jsdelivr.net/npm/[email protected]/all-localstorage.min.js" type="text/javascript"></script>

Or download localstorage.js or localstorage.min.js files from the repository into your project.

<script src="/localstorage.min.js" type="text/javascript"></script>

Usage

Create new instance.

const options = {
    prefix: 'my_',
    storage: 'in-memory',
    encrypt: true,
    // ...
}

const store = new Storage( options );

Options

  • prefix: String Prefix of attributes in the store. Important during flush data process.

  • storage: String Targeted storage: localStorage, in-memory, ... Default: localStorage

  • encrypt: Boolean Define whether data should be encrypted before to be stored. Default: false

  • token: String Specify a unique token to use to encrypt the data

Methods

set(attribute, data)

Insert data to the storage

const data = "hello";

store.set('greeting', data );

get(attribute)

Retreive stored data. Return false when the attribute of data specify does not exist.

const data = store.get('greeting');

console.log( data ); // Hello

flash(attribute, data)

Insert temporary a data to the storage. The stored data get deleted immediately when get() method is called to retreive the data. Useful for saving flash data. To not confund with flush() described below.

const data = { foo: 'bar' };
store.flash('attr', data);

const data2 = store.get('attr');
console.log( data2 ); // { foo: 'bar' }

// Data stored calling `flash` method can only be `get` once
console.log( store.get('attr') ); // undefined

update(attribute, data, [action])

Update stored. This method is useful to make changes on Array or Object data without re-inserting the whole data set like we normally do with the conventional localstorage APIs. It accepts three arguments, the attribute, data, and action (Optional)

  • When the stored data is an array, use the action argument to specify what to do: push, shift, pop ...
  • When the stored data is an Object, the only use of the action argument is to delete a field. If action argument is not set, data will be merge with the existing stored object so it must also be an object. Note: Specify array of fields (data argument) to delete multiple fields of as store data Object.

Return false if the update failed

Example with Array Data

const data = [ 'foo' ];
store.set('attr', data);

// Example with Array Data
store.update('attr', 'bar', 'push') // add new value to the Array
console.log( store.get('attr') ) // [ 'foo', 'bar' ]

Example with Object Data


const data = { foo: 'bar' };
store.set('attr', data );

const data1 = { bar: 'foo' }
store.update('attr', data1) // The new object will be merge with the existing stored data
console.log( store.get('attr') ) // { foo: 'bar', bar: 'foo' }

// Update by deleting object field: The second argument c
store.update('attr', 'foo', 'delete');
console.log( store.get('attr') ); // { bar: 'foo' } : the `foo` field is deleted

clear(attributes)

Clear single or multiple store set.

// Clear single set
store.clear('greeting');

// Clear multiple set
store.clear([ 'greeting', 'attr' ]);

flush([prefix])

Clear all stored set with the attribute prefix specify in the options. Most important use case of the prefix

store.flush('my_');

Additional feature

Sometimes, when using a View rendering engine like handlebars, twig, ... for instance, the injected scope data, instead of being hold in a global variable, can be immediately stored in one of the localstorage once the DOM get loaded. Use case example:

<body>
    <!-- UserData is injected: Eg. Using handlebar view engine -->
    <div data-store="profile" data-store-type="set" data-store-value="{{ UserData }}">

    <script src="/localstorage.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        var store = new Storage()

        // Display the content of `UserData` injected
        console.log( store.get('profile') )
    </script>
</body>

These HTML attributes can be use anywhere in the document to trigger this feature.

  • data-store Specify the attribute of the store

  • data-store-type Specify the method to use for storing the data. Only set, flash, update can be use for now.

  • data-store-value Payload of the data to store (Must be a String)

    Note:

    The various HTML tag attributes must be set before to initialize the Storage, otherwise, it won't works

That's it!

Feedback & Contribution

You know the say: No one is whole alone! So, feedbacks and the smallest contributions you can think of are all welcome. Kindly report any encounted Issues here and I'll be glad to work on it right away. Thank you.

License

This software is free to use under the MIT license. See the LICENSE file for license text and copyright information.