Skip to content

client-parser

A small, type-safe library that classifies the browser, OS, device, and bot behind a request from User-Agent strings, Client Hints, and HTTP headers.

Role
Library design and package engineering
Scope
Typed APIs, compatibility, and package distribution
Status
Pre-1.0 package

Problem

Analytics and diagnostics need a normalized view of which browser, OS, device, or bot made a request. The raw User-Agent string can be changed by any client, and many parsers are heavy or quietly encourage using the result for decisions it cannot support.

Constraints

  1. C1

    User-Agent classification is heuristic, and any client can spoof it.

  2. C2

    Client Hints availability varies and may be restricted for privacy.

  3. C3

    Results cannot safely drive authentication, authorization, or capability decisions.

Architecture

Pure parsing and normalization rules produce a typed result model, packaged with zero dependencies in both ESM and CommonJS. A workspace-linked playground and documentation app runs the library locally, and a regression corpus guards the rules as clients change.

01

Core library

Pure parsing and normalization rules turn client strings and hints into a typed result model.

02

Package builds

The library ships as a zero-dependency package in both ESM and CommonJS formats.

03

Documentation app

A workspace-linked playground and docs app sits alongside a regression corpus of representative client strings.

Decisions

D1

State the heuristic boundary in the API

The documentation says results suit analytics and presentation, points to feature detection for behavior, and rules out security decisions. Users build on whatever an API implies, so the limit belongs in the contract.

D2

Merge two signals into one result

Combining User-Agent parsing and Client Hints into a single normalized output means consumers do not reconcile two inconsistent sources themselves.

D3

Stay zero-dependency and pre-1.0

Parsing rules change as clients change, so the project relies on a maintained test corpus and changelog review rather than promising stability it cannot yet guarantee.

Contribution

  • Implemented browser, OS, device, mobile, and bot classification.
  • Added Client Hints support and normalized typed results.
  • Created representative regression tests and package builds.
  • Built a playground that parses input locally in the page without a server parser.

Outcomes

  • Consumers can classify common client strings.
  • Results are enriched with Client Hints when they are available.
  • Analytics and presentation code can distinguish bots, devices, and browsers.
  • Developers can inspect parsing behavior in the playground without sending their input anywhere.

Product screenshot

client-parser documentation home page with the headline 'Know the client. Keep the uncertainty.' and a classification example
The playground classifies pasted client strings locally and labels the result as a heuristic, not a fact.

Verified stack

  • TypeScript
  • ESM
  • CommonJS
  • tsup
  • TanStack Start
  • React
  • Tailwind CSS
  • Vite
  • Vitest
  • Netlify
  • GitHub Actions
  • CI/CD

Working through something similar?

Share your challenge, scope, and timeline to start a focused conversation.