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

http-cache-control-kit

v0.1.0

Published

Parse and format Cache-Control headers with structured diagnostics.

Readme

http-cache-control-kit

License: MPL-2.0 CI

Parse and format HTTP Cache-Control headers with structured diagnostics.

http-cache-control-kit is a clean-room TypeScript utility for small browser, worker, CLI and server tooling. It has no runtime dependencies and does not use Node-only APIs.

Demo

Try the browser demo: packages.wasta-wocket.fr/http-cache-control-kit.

Package quality

  • TypeScript types are generated from the source.
  • ESM-only package with no runtime dependencies.
  • Marked as side-effect free for bundlers.
  • CI runs npm ci, typecheck, build, and test.
  • Tested on Node.js 20 and 22 with GitHub Actions.
  • Browser-friendly implementation with no Node-only APIs.

Install

npm install http-cache-control-kit

Quick Start

import {
  formatCacheControl,
  getCacheControlDeltaSeconds,
  parseCacheControl
} from "http-cache-control-kit";

const parsed = parseCacheControl("public, max-age=3600, stale-while-revalidate=30");

if (parsed.ok) {
  console.log(parsed.values.public); // true
  console.log(getCacheControlDeltaSeconds(parsed, "max-age")); // 3600
}

const header = formatCacheControl({
  public: true,
  "max-age": "3600",
  "stale-while-revalidate": "30"
});

Why This Package

Use this package when you need to inspect a Cache-Control header and explain what is wrong with it. The parser returns directives plus stable diagnostic codes for duplicate directives, missing delta-seconds values, invalid quoted strings and unknown directives.

It intentionally does not evaluate full HTTP cache semantics across Expires, Age, ETag, request method or request-vs-response context. For that broader job, use a full cache semantics library.

API

parseCacheControl(input, options?)

Returns a result object. Invalid input and invalid directives are reported in diagnostics instead of throwing.

const result = parseCacheControl('private="Authorization, Cookie", max-age=60');

result.values.private; // "Authorization, Cookie"
result.values["max-age"]; // "60"

The parser accepts both request and response directives. For example, max-stale is valid without a value in request headers, but if a value is provided it must be valid delta-seconds.

parseCacheControl("max-stale").values["max-stale"]; // true
getCacheControlDeltaSeconds(parseCacheControl("max-stale=120"), "max-stale"); // 120

formatCacheControl(values, options?)

Formats a directive map or parsed directive array back into a header string.

formatCacheControl({ "max-age": "60", private: "Authorization, Cookie" }, { sort: true });
// 'max-age=60, private="Authorization, Cookie"'

hasCacheControlDirective(result, directive)

Case-insensitive presence check against a parse result.

getCacheControlDeltaSeconds(result, directive)

Returns a numeric delta-seconds value when the directive exists and contains a non-negative integer.

Diagnostics

Diagnostic codes are stable strings for tests, UI hints and logs:

  • empty-input
  • expected-string
  • empty-directive
  • invalid-directive-name
  • missing-value
  • duplicate-directive
  • invalid-quoted-string
  • invalid-delta-seconds
  • unknown-directive

Options

| Option | Default | Description | | --- | --- | --- | | allowUnknown | false | Keep unknown directives but report them as diagnostics unless enabled. | | allowDuplicates | false | Keep repeated directives instead of reporting and ignoring later values. | | sort | false | Sort formatted directives by name. | | quoteValues | "auto" | Quote formatted values automatically, always or never. |

Browser Compatibility

The core only uses strings, arrays, objects and regular expressions. It performs no I/O and has no dependency on fs, path, Buffer, process or network APIs.

License

MPL-2.0