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

whoopie

v0.0.2

Published

Super-fast cookie parser and storage that works on both server and client.

Readme

Super-fast cookie parser and storage that works on both server and client.

Just 1 kB gzipped with zero dependencies.

npm install --save-prod whoopie

🔰 API documentation is available here.

Usage

Use documentCookieStorage to read and write cookies from document.cookie:

import { documentCookieStorage } from 'whoopie';

documentCookieStorage.set('hello', 'world');

documentCookieStorage.get('hello');
// ⮕ 'world'

JSON cookies are supported out of the box:

documentCookieStorage.set('users', ['bob', 'bill', 'barry']);

documentCookieStorage.get('users');
// ⮕ ['bob', 'bill', 'barry']

Use createCookieStorage to create a custom cookie storage:

import { createCookieStorage, jsonCookieSerializer } from 'whoopie';

const myStorage = createCookieStorage({
  getCookie() {
    return document.cookie;
  },

  setCookie(cookie) {
    document.cookie = cookie;
  },

  serializer: jsonCookieSerializer,
});

myStorage.set('hello', 'world');

myStorage.get('hello');
// ⮕ 'world'

Here, jsonCookieSerializer is a built-in cookie value serializer that supports JSON values. This serializer never throws errors during parsing. If a cookie value isn't valid JSON, it's returned as a string.

// Unambiguous strings aren't wrapped in double quotes
jsonCookieSerializer.stringify('hello');
// ⮕ 'hello'

jsonCookieSerializer.parse('hello');
// ⮕ 'hello'

// Ambiguous strings are wrapped in double quotes
jsonCookieSerializer.stringify('true');
// ⮕ '"true"'

jsonCookieSerializer.stringify(42);
// ⮕ '42'

jsonCookieSerializer.parse('42');
// ⮕ 42

You can create server-side cookie storage that reads cookies from a request and writes to the response:

import { createCookieStorage, jsonCookieSerializer } from 'whoopie';

function createServerCookieStorage(requestHeaders: Headers, responseHeaders: Headers): CookieStorage {
  return createCookieStorage({
    getCookie() {
      return requestHeaders.get('Cookie');
    },

    setCookie(cookie) {
      responseHeaders.set('Set-Cookie', cookie);
    },

    serializer: jsonCookieSerializer,
  });
}

Be sure to create a new cookie store for each request.

export function handleRequest(request: Request): Response {
  const responseHeaders = new Headers();

  const myStorage = createServerCookieStorage(request.headers, responseHeaders);

  myStorage.set('hello', 'world');

  myStorage.get('hello');

  return Response.json({}, { headers: responseHeaders });
}

Signed cookies

Signed cookies are needed to ensure integrity and authenticity of data stored in the browser. Ordinary cookies are stored and sent by the browser, but the user can modify them using developer tools.

Signed cookies guarantee that the cookies value wasn't forged by adding a signature to the cookie value and verifying this signature when cookie is read:

import { documentCookieStorage } from 'whoopie';

const SECRET_KEY = 'my_secret_key';

documentCookieStorage.setSigned('hello', 'world', SECRET_KEY);

documentCookieStorage.getSigned('hello', SECRET_KEY);
// ⮕ 'world'

Make sure that secret key cannot be accessed by the user.

Utilities

Whoopie exports a set of functional utilities that streamline working with cookies without the need to create a storage.

Parse Cookie header value or document.cookie as a key-value mapping:

parseCookies('hello=world');
// ⮕ { hello: 'world' }

Get names of all cookies:

getCookieNames('hello=world');
// ⮕ ['hello']

Get value of a cookie by its name:

getCookieValue('hello=world', 'hello');
// ⮕ 'world'

Stringify a cookie, so it can be used as a Set-Cookie header value or assigned to document.cookie:

stringifyCookie('hello', 'world', { maxAge: 24 * 60 * 60 });
// ⮕ 'hello=world; Max-Age=86400'

Type-safe cookies

Add typings to the documentCookieStorage:

interface MyCookies {
  userAge?: number;
}

export const myStorage: CookieStorage<MyCookies> = documentCookieStorage;

myStorage doesn't provide runtime type-safety, but provides compile-time type safety:

myStorage.set('userAge', 'hello');
// ❌ TypeScript error: userAge must be of type number

myStorage.get('userAge');
// 🟡 Ooops, type isn't guaranteed at runtime

The types of JSON cookies cannot be guaranteed at runtime, as cookies can be altered by the user or directly mutated via document.cookie. To mitigate this issue, use a validation library such as Doubter:

import * as d from 'doubter';

// ✅ Runtime type-safety is ensured
const userAge = d.number().catch().parse(myStorage.get('userAge'));
// ⮕ number | undefined