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

@kontsedal/olas-persist

v0.0.6

Published

Olas persistence composables — usePersisted with a localStorage adapter.

Downloads

989

Readme

@kontsedal/olas-persist

Persist a Signal<T> or Field<T> (or anything with .value + .set + .subscribe) to localStorage — or any custom StorageAdapter. Optional cross-tab sync. Works with async storage backends.

Install

pnpm add @kontsedal/olas-persist @kontsedal/olas-core @preact/signals-core

30-second example

import { defineController, signal } from '@kontsedal/olas-core'
import { usePersisted } from '@kontsedal/olas-persist'

const settings = defineController((ctx) => {
  const theme = signal<'light' | 'dark'>('light')

  // Reads from localStorage on construction, writes on every change.
  const persisted = usePersisted(ctx, 'app.theme', theme)

  return { theme, ready: persisted.ready }
})

persisted.ready flips to true once the initial load completes — synchronous for localStorage, useful for async storage adapters.

API

function usePersisted<T>(
  ctx: Ctx,
  key: string,
  source: PersistableSource<T>,
  options?: {
    storage?: StorageAdapter        // default: localStorageAdapter
    serialize?: (value: T) => string
    deserialize?: (raw: string) => T
    crossTab?: boolean              // wire window 'storage' event
  },
): { ready: ReadSignal<boolean> }

Defaults: JSON.stringify / JSON.parse. Override serialize / deserialize for custom shapes (Dates, Maps, etc.). Cleanup is registered via ctx.onDispose.

Note on serializer parity with @kontsedal/olas-cross-tab. @kontsedal/olas-persist defaults to JSON; @kontsedal/olas-cross-tab uses structured clone via BroadcastChannel. They differ in what survives a round-trip: Date becomes a string under JSON but survives cross-tab; Map/Set are dropped by JSON but survive cross-tab; functions and symbols are dropped by both. If you use both packages on the same value, supply a serialize / deserialize pair to persist that matches cross-tab's structured-clone semantics.

Cross-tab delete. When another tab calls localStorage.removeItem(key) (or your custom adapter signals null through onChange), the local source is reset to undefined. Consumers whose T excludes undefined should treat this as "value gone, fall back to your own initial".

Full signatures and types in ../../API.md.

Custom storage adapter

The default localStorageAdapter is exported. Implement StorageAdapter for sessionStorage, IndexedDB, mobile native storage, etc.:

type StorageAdapter = {
  get(key: string): string | null | Promise<string | null>
  set(key: string, value: string): void | Promise<void>
  delete(key: string): void | Promise<void>
  onChange?(handler: (key: string, value: string | null) => void): () => void
}

get returning a Promise is supported — ready stays false until the load completes. Writes during the "not yet ready" window are skipped so a stale storage value doesn't get clobbered by the source's initial-state default.

Cross-tab sync

{ crossTab: true } wires the adapter's onChange(...) callback. The default localStorage adapter wires it to the browser's storage event. Updates from other tabs deserialize and call source.set(value) without echoing the write back.

Further reading