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

@msobiecki/cookie-store

v1.6.0

Published

Typed cookie store API for browser, Express, and Next.js with React hooks support.

Readme

@msobiecki/cookie-store

License

Tiny, typed cookie API that works across browser, Express, and Next.js.

cookie-store

Features

  • One factory to create an adapter-specific cookie store.
  • A Promise-based API with get, set, and delete methods.
  • Optional React helpers for client-side apps.

Installation

npm install @msobiecki/cookie-store

If you use the Express adapter, also install cookie-parser:

npm install cookie-parser

To read/write signed cookies in Express, initialize cookie-parser with a secret:

app.use(cookieParser("your-secret"));

Quick Start

Browser

import { createCookieStore } from "@msobiecki/cookie-store";

const getCookieStore = createCookieStore({ adapter: "browser" });
const cookieStore = await getCookieStore();

await cookieStore.set("theme", "dark", {
  maxAge: 1000 * 60 * 60 * 24,
  path: "/",
});

const theme = await cookieStore.get("theme");
await cookieStore.delete("theme");

Express

import express from "express";
import cookieParser from "cookie-parser";
import { createCookieStore } from "@msobiecki/cookie-store";

const app = express();
app.use(cookieParser("your-secret"));

const getCookieStore = createCookieStore({ adapter: "express" });

app.post("/theme", async (request, response) => {
  const cookieStore = await getCookieStore(request, response);

  await cookieStore.set("theme", "dark", {
    maxAge: 1000 * 60 * 60 * 24,
    httpOnly: true,
    signed: true,
    path: "/",
  });

  const signedTheme = await cookieStore.get("theme", { signed: true });

  response.json({ ok: true, signedTheme });
});

Next.js (App Router)

import { createCookieStore } from "@msobiecki/cookie-store";

const getCookieStore = createCookieStore({ adapter: "next" });

export async function POST() {
  const cookieStore = await getCookieStore();

  await cookieStore.set("theme", "dark", {
    maxAge: 1000 * 60 * 60 * 24,
    path: "/",
  });

  return Response.json({ ok: true });
}

React Integration

Use CookieProvider in client components and read/update values with hooks.

"use client";

import {
  CookieProvider,
  useCookie,
  useCookies,
} from "@msobiecki/cookie-store/client";

function ThemeControls() {
  const [theme, setTheme, removeTheme] = useCookie("theme", {
    maxAge: 1000 * 60 * 60 * 24,
  });

  const allCookies = useCookies();

  return (
    <div>
      <p>Theme: {theme ?? "not set"}</p>
      <button onClick={() => setTheme(theme === "light" ? "dark" : "light")}>
        Toggle
      </button>
      <button onClick={() => removeTheme()}>Clear</button>
      <pre>{JSON.stringify(allCookies, null, 2)}</pre>
    </div>
  );
}

export default function App() {
  return (
    <CookieProvider>
      <ThemeControls />
    </CookieProvider>
  );
}

API

createCookieStore

createCookieStore({ adapter: "browser" | "express" | "next" });

Returns an async function:

  • browser: call with no arguments.
  • next: call with no arguments.
  • express: call with request and response.

TypeScript overloads return adapter-specific stores:

  • browser -> BrowserCookieStore
  • next -> NextCookieStore
  • express -> ExpressCookieStore

CookieStore

interface CookieStore {
  get(name: string): Promise<string | undefined>;
  set(name: string, value: string, options?: CookieOptions): Promise<void>;
  delete(name: string, options?: CookieOptions): Promise<void>;
  getAll(): Promise<Record<string, string>>;
}

Notes:

  • Browser adapter adds change listeners via subscribeChange and unsubscribeChange.
  • Browser adapter uses the Cookie Store API when available and falls back to document.cookie.

CookieOptions

interface CookieOptions {
  path?: string;
  domain?: string;
  expires?: Date;
  maxAge?: number;
  sameSite?: "strict" | "lax" | "none";
  partitioned?: boolean;
  secure?: boolean;
}

maxAge is in milliseconds.

Express Adapter Options

ExpressCookieStore extends the base store with signed-cookie reads and writes.

type ExpressCookieReadOptions = {
  signed?: boolean;
};

type ExpressCookieSetOptions = CookieOptions & {
  httpOnly?: boolean;
  signed?: boolean;
};

Usage:

await cookieStore.set("session", "abc", { signed: true, httpOnly: true });
const session = await cookieStore.get("session", { signed: true });
const allSigned = await cookieStore.getAll({ signed: true });

Next Adapter Options

NextCookieStore supports extra options accepted by next/headers cookies API:

type NextCookieOptions = CookieOptions & {
  httpOnly?: boolean;
  priority?: "low" | "medium" | "high";
};

Exports

export { createCookieStore };
export { useCookie, useCookies };
export { CookieProvider };

Examples

Runnable examples are included in:

  • examples/express
  • examples/vite-react-ts
  • examples/vite-vanilla-ts

Development

Build

npm run build

Watch Mode

npm run dev

Lint

npm run lint

License

See LICENSE file for details.