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

browser-storage-adapter

v1.1.2

Published

Browser storage adapter to crud 1-n different stores simultaneously

Downloads

55

Readme

Browser Storage Adapter 💾

npm version CI Known Vulnerabilities semantic-release: angular

This is a library to save key-value pairs to one or multiple storages (e.g. SessionStorage, LocalStorage, Cookie, ...).

Table of Contents

Installation

npm install browser-storage-adapter --save

Usage

Create an instance of the Adapter and specify the drivers, which should be enabled. By default, all drivers are disabled, expect of the in-memory driver, which is always enabled.

Besides, it is also possible to specify a custom namespace, so different instances of the Adapter don't interfere with each other, when they use the same key.

import { Adapter } from 'browser-storage-adapter';

const warehouse = new Adapter({
    driver: {
        cookie: {
            path: '/',
        },
        localStorage: true,
        sessionStorage: true,
    },
    namespace: 'auth'
});

// Set a key-value pair for the following drivers:
// cookie, localStorage & sessionStorage.
warehouse.set('token', 'xxx');

// Ensure that value is still the same for all drivers.
warehouse.sync('token', 'xxx');

// Get a key-value pair.
const token = warehouse.get('token');
console.log(token);
// xxx

Options

The Adapter accepts an OptionsInput object as input parameter, to modify the default behaviour.

import { CookieSerializeOptions } from 'cookie';

declare type OptionsInput = {
    /**
     * Specify a key prefix.
     * e.g.
     *  namespace: auth
     *  key: token
     *  keyWithNamespace: auth_token
     */
    namespace?: string,
    /**
     * Enable or disable some available drivers.
     */
    driver?: {
        localStorage?: boolean,
        sessionStorage?: boolean,
        cookie?: boolean | CookieSerializeOptions
    },
    /**
     * Check if the application is server rendered.
     */
    isServer?: () => boolean,

    /**
     * Set cookie.
     *
     * @param key
     * @param value
     */
    setCookie?: (key: string, value: unknown) => void,

    /**
     * Get cookie.
     *
     * @param key
     */
    getCookie?: (key: string) => unknown,

    /**
     * Append serialized cookie.
     *
     * @param value
     */
    setServerCookie?: (value: string) => void,
    /**
     * Ger serialized cookie(s).
     */
    getServerCookies?: () => string
}