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

server-timing-parse

v0.1.0

Published

Zero-dependency parser and serializer for HTTP Server-Timing response headers

Readme

server-timing-parse

Zero-dependency parser and serializer for HTTP Server-Timing response headers.

Parse Server-Timing: db;desc="Database Query";dur=53, app;dur=47.2 into structured data — no external dependencies.

Quick Start

npm install server-timing-parse
import { parseServerTiming, serializeServerTiming } from 'server-timing-parse';

// Parse
const metrics = parseServerTiming('db;desc="Database Query";dur=53');
// → [ServerTimingMetric { name: 'db', description: 'Database Query', duration: 53 }]

// Multi-metric
const multi = parseServerTiming('db;dur=53, app;dur=47.2');
// → [ServerTimingMetric { name: 'db', duration: 53 }, ServerTimingMetric { name: 'app', duration: 47.2 }]

// Serialize
const header = serializeServerTiming([
  { name: 'db', description: 'Database Query', duration: 53 },
  { name: 'app', duration: 47.2 },
]);
// → 'db;desc="Database Query";dur=53, app;dur=47.2'

Why server-timing-parse?

HTTP Server-Timing headers expose performance metrics (database query time, cache latency, application processing time) to developer tools and clients. The W3C Server-Timing spec defines a structured format — but no zero-dependency npm package existed to parse it.

Existing options:

  • server-timing npm package — creates/serializes headers but cannot parse incoming header values. Also pulls in 2 runtime dependencies.
  • No Python equivalent — this library fills the gap for the Node.js ecosystem.

Key Features

  • Zero runtime dependencies — no package.json dependencies array
  • TypeScript definitions includedindex.d.ts ships with the package
  • Frozen objects — parsed metrics are deeply immutable
  • Handles real-world edge cases — escaped quotes in descriptions, semicolons inside quoted strings, unknown params (ignored for forward-compatibility), large decimal durations
  • Both parser and serializer — full round-trip support

API Reference

parseServerTiming(header: string): readonly ServerTimingMetric[]

Parses a Server-Timing header value into an array of frozen metric objects.

parseServerTiming('db;desc="DB";dur=53, app;dur=47.2')
// → [
//     ServerTimingMetric { name: 'db', description: 'DB', duration: 53 },
//     ServerTimingMetric { name: 'app', description: null, duration: 47.2 }
//   ]

Errors: Throws InvalidServerTimingHeader for malformed input (non-string input, unclosed quotes, invalid duration format, negative durations, empty metric name).

serializeServerTiming(metrics: ServerTimingMetric[]): string

Serializes an array of metric objects into a Server-Timing header string. Canonical output order: name;desc="...";dur=...

serializeServerTiming([{ name: 'db', description: 'DB', duration: 53 }])
// → 'db;desc="DB";dur=53'

Errors: Throws InvalidServerTimingHeader for invalid input (non-array, missing name, non-string name).

ServerTimingMetric

interface ServerTimingMetric {
  readonly name: string;
  readonly description: string | null;
  readonly duration: number | null;
}

InvalidServerTimingHeader

Error class thrown for malformed header input.

Limitations

  • Whitespace inside quoted descriptions is preserved (e.g., desc=" spaces " → description " spaces ")
  • Duration must be non-negative; negative durations raise InvalidServerTimingHeader
  • Empty metric names raise InvalidServerTimingHeader
  • Semicolons inside quoted descriptions are handled correctly (desc="a;b;c" → description a;b;c)

Non-goals

  • Enforcing Server-Timing policy or middleware that automatically injects metrics
  • Network I/O, HTTP server/client functionality
  • Integration with specific APM vendors (Datadog, New Relic, etc.)
  • Async or streaming metric collection
  • Parsing the W3C PerformanceServerTiming interface (browser-side API)

License

MIT