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

local-storage-proxy-wrapper

v2.0.6

Published

localstorage proxy wrapper with listener (available on browser and node)

Downloads

67

Readme

Local Storage Proxy (browser / node)

A library which provides assistance in managing the localStorage object and adds the capability to detect modifications to localStorage

Installation

To install the library, run the following command:

npm install local-storage-proxy-wrapper
# or
yarn add local-storage-proxy-wrapper

Purpose

It provides more intuitive way to use localStorage and various functionalities like setting, getting, and deleting values, listening for changes to localStorage, getting the history of previous changes, and getting or setting multiple keys...

Differences from standard localStorage

Change Listeners:

Per-Key Listeners: You can add listeners to specific keys that will be notified when the value associated with those keys changes.

Global Listeners: You can add listeners that will be notified of any changes to the localStorage.

History Tracking:

The library maintains a history of changes for each key, allowing you to retrieve the previous values up to a specified history size. This is particularly useful for undo functionalities or tracking changes over time.

Asynchronous Operations:

Asynchronous Get/Set: The library provides methods for getting and setting items in localStorage asynchronously, which can help in situations where you want to avoid blocking the main thread.

Memory Check:

Memory Limit Checking: Before setting a value, the library can check if the storage has reached its memory limit, preventing errors related to exceeding the storage quota.

Bulk Operations:

Set Multiple: You can set multiple key-value pairs at once with a single method call.

Get Multiple: You can retrieve multiple key-value pairs at once.

Remove Multiple: You can remove multiple keys at once.

Proxy Handling:

The library provides a proxy interface (localStorageProxy) that allows you to interact with localStorage as if it were a regular JavaScript object, while still benefiting from the added functionalities.

Documentation

For detailed documentation, visit the documentation page

React Example

import LocalStorageWrapper, {
    ListenerValue,
} from 'local-storage-proxy-wrapper';

const useLocalStorage = () => {
    const storage = new LocalStorageWrapper();

    const getAsyncValue = async (key: string) => {
        return await storage.get(storage, key, true);
    };

    const setAsyncValue = async (key: string, value: ListenerValue) => {
        await storage.set(storage, key, value, true);
    };

    return {
        getValue: getAsyncValue,
        setValue: setAsyncValue,
    };
};

const MyComponent = () => {
    const { getValue, setValue } = useLocalStorage();
    const [storedValue, setStoredValue] = useState(null);

    const fetchValue = async () => {
        const value = await getValue('myKey');
        setStoredValue(value);
    };

    useEffect(() => {
        fetchValue();
    }, []);

    const handleSetValue = async () => {
        await setValue('myKey', 'newValue');
        fetchValue(); // Refresh the stored value
    };

    return (
        <div>
            <p>Stored Value: {storedValue}</p>
            <button onClick={handleSetValue}>Set New Value</button>
    </div>
    );
};