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

@open-pioneer/local-storage

v4.10.0

Published

Provides access to the browser's local storage and session storage.

Readme

@open-pioneer/local-storage

This package provides access to the browser's local storage and session storage.

It provides two services with an identical API, differing only in the lifetime and the visibility of their data:

| Service | Interface name | Lifetime | Visibility | | ----------------------- | ------------------------------------- | ------------------------------------------ | ------------------------------------- | | LocalStorageService | local-storage.LocalStorageService | until explicitly removed | shared by all tabs of the same origin | | SessionStorageService | local-storage.SessionStorageService | until the tab is closed (survives reloads) | the current tab only |

A single storage key (configurable, see Configuration) is used to keep track of the application's data. Packages using these services can work with arbitrary values (including nested data structures) through a convenient API.

NOTE: Both services read their data from the browser on application startup. Changes made via a service are reflected in the browser's storage immediately. Concurrent changes made to the browser's storage are not reflected by the services. In other words, there is no two-way synchronization between the two systems while the application is running.

You should not attempt to modify the storage value managed by these services (see storageId in Configuration) through the "raw" Browser APIs while the application is running. Other keys are safe to use.

Usage

Reference the interface name local-storage.LocalStorageService to inject an instance of LocalStorageService, or local-storage.SessionStorageService to inject an instance of SessionStorageService.

// build.config.mjs
import { defineBuildConfig } from "@open-pioneer/build-support";

export default defineBuildConfig({
    services: {
        MyService: {
            references: {
                localStorage: "local-storage.LocalStorageService",
                sessionStorage: "local-storage.SessionStorageService"
            }
        }
    }
});

Checking for storage support

Not all browsers implement or enable support for local storage and session storage. Use the .isSupported property to check whether the storage can be used at all:

const storageService = ...; // injected
console.log(storageService.isSupported);

If the storage is not supported, other methods (such as get() and set()) throw an error.

Reading and writing values

In its most basic form, you can use either service similar to a map. In the background, changes to the service are always persisted into the browser's storage.

All values used in these services are serialized to JSON via JSON.stringify(). Thus, only values supported by JSON can be used.

Example:

const storageService = ...; // injected
storageService.set("foo", "bar");
storageService.set("foo", ["array"]);
storageService.set("foo", {
    nested: {
        object: "hello world"
    }
});
storageService.get("foo"); // returns (copy of) previous value
storageService.remove("foo");
storageService.removeAll();

Namespaces

You can use either service to manage hierarchical data, including objects and arrays (see above). Namespaces can help you treat an object as a group of (nested) properties. Getting or setting entries in the namespace updates an object behind the scenes.

To use a namespace, call getNamespace(key) on either service or on another StorageNamespace object. The key used in getNamespace(key) should either already be associated with an object or it should not be set to a value at all. If key is not yet associated with an existing object, a new empty object is created.

Example:

const storageService = ...; // injected
const namespace = storageService.getNamespace("my-key");
namespace.set("foo", "bar"); // actually sets `"my-key" -> "foo"`

getNamespace("my-key") returns a StorageNamespace instance that manipulates the object at "my-key".

Namespaces provide a convenient way to scope your component's values, avoiding conflicts with other packages. For example, you can use your package name as the namespace key:

const storageService = ...; // injected
const namespace = storageService.getNamespace("my-package-name");
namespace.set("my-state", "some-value-to-save");

NOTE: Multiple namespace instances using the same key manipulate the same object and see each other's effects.

Configuration

| Name | Type | Description | | ----------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | storageId | String | The key under which the data is saved. This value should be configured to a reasonably unique value to avoid clashes with other applications at the same origin. Defaults to trails-state (with a warning). |

storageId applies to both services.

// app.ts
const Element = createCustomElement({
    // ...
    config: {
        properties: {
            "@open-pioneer/local-storage": {
                storageId: "my-app"
            } satisfies StorageProperties
        }
    }
});

Implementation notes

Each service manages its data as a single, hierarchical JSON object. This JSON object is loaded from and saved to the respective browser storage area using the storageId key.

The top level value is always an object; its properties are manipulated when calling get, set etc. on the service. Nested values can be arbitrary (JSON-compatible) values.

License

Apache-2.0 (see LICENSE file)