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

cdcrft-web-storage

v1.1.2

Published

Small lib made to simplify persistent storage of all type of data with the localStorage Web API

Readme

Codecraft Simple Web Storage

This small library aims at facilitating the storage of every kind of value using the web local storage API.

WARNING : The Storage object in this library does not follow the native Storage web interface. This library is an overlay with its own interface. The library makes use of the native web Storage interface.

Install

If you use webpack you can install the library using npm :

npm install cdcrft-web-storage

or download source code from repo and include it inside your html page directly :

<script type="text/javascript" src="js-folder/cdcrft-web-storage/dist/index.js"></script>

<script type="text/javascript" >
    // Access the module :
    let storage = new cdcrftWebStorage.Storage();
</script>

Basic usage

First in order to use this library you need to configure the storage keys :

let config = {
    'type': 'local',
    'storage-keys': {
        SOME_ARRAY_OF_OBJECTS: {
            name: 'some.array.of.objects',
            default: [],
            parse: customParseFunction
            stringify: customStringifyFunction
        },
        TOKEN_STRING: {
            name: 'token.string',
            default: null,
            keep: true
        }
    }
}

Here is an explanation of this config file :

The first value "type" represents the type of storage you want your object to handle. If you need to save your values using the window.localStorage object, then use 'local' if you need to use the window.sessionStorage object then use 'session'.

Then you need an array indexed with the 'storage-keys' key. This array contains all of the values you wish to save :

name

This option is a string representing the name under which your value will be saved inside the local storage

default

Default value that should be returned by the storage if none was stored

stringify

Function that will be used to transform your value into a string that can be saved in local storage

Defaults to JSON.stringify

parse

Function that will be used to reverse transform the saved value into your original value

Defaults to JSON.parse

keep

Set this to true if you wish that no parse or stringify value be applied to your original value when saved (use this if your original value is a string)

Then you need to create your storage object with the config you just created :

let storage = new Storage(config);

Save value :

let keys = storage.keys();
// You can use it directly with saved config
storage.store(keys.SOMME_ARRAY_OF_OBJECTS, arrayOfObjects)
// But also with a simple string
storage.store('SOME_ARRAY_OF_OBJECTS', arrayOfObjects);

Get value :

let keys = storage.keys();
let value = storage.get(keys.SOMME_ARRAY_OF_OBJECTS)
let value = storage.get('SOMME_ARRAY_OF_OBJECTS');

Remove value

let keys = storage.keys();
storage.clear(keys.SOME_ARRAY_OF_OBJECTS);
storage.clear('SOME_ARRAY_OF_OBJECTS');

Remove all values

storage.clearAll();

Last but not least, you can also save values that you did not configure :

storage.store('UNCONFIGURED_VALUE', {foo: 'bar'});

If you use above solution, with just a string, default configuration will be used for the value : Configuration will be as if you did this :

let config = {
    'storage-keys': {
        UNCONFIGURED_VALUE:
        {
            name: 'UNCONFIGURED_VALUE',
            default: '',
            parse: JSON.parse,
            stringify: JSON.stringify,
            keep: false
        }
    }
}

If you need to save a value that was not configured but you need a specific configuration, you also can do it :

let config = {
    name: 'whatever.the.name',
    default: '{"foo": "bar"}',
    parse: customParseFunction,
    stringify: customStringifyFunction,
    keep: false
}

storage.store(config, myValue);

With this solution, you will never be able to call it using the keys().WHATEVER_THE_NAME solution.

WARNING :

For storing boolean values, please use provided utils for configuration. Otherwise you expose yourself to some troubles.

import {parseBoolean, stringifyBoolean} from 'cdcrft-web-storage';

let config = {
    'storage-keys': {
        BOOLEAN: {
            name: 'demo.boolean',
            default: true,
            parse: parseBoolean,
            stringify: stringifyBoolean,
        }
    }
}