cache-control-parser is a JavaScript/TypeScript utility for parsing and stringifying HTTP `Cache-Control` header directives. Its current stable version is 2.2.0, with regular updates that enhance its functionality, such as the introduction of the `stringify` function in v2.0.0. The library is designed to be fault-tolerant and case-insensitive when parsing, handling common HTTP caching scenarios robustly. Key differentiators include its zero-dependency footprint, comprehensive built-in TypeScript definitions, and the capability to both convert `Cache-Control` strings into structured JavaScript objects and convert objects back into valid header strings, making it suitable for both consuming and generating HTTP responses in Node.js and browser environments.
npm install cache-control-parserVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates parsing a Cache-Control header, accessing its directives, and then stringifying a new set of directives, including TypeScript type usage.
Upgrade to `cache-control-parser@^2.0.0` or higher to use the `stringify` function.
Prefer `import { parse, stringify } from 'cache-control-parser';` for modern JavaScript environments. If strictly using CommonJS, ensure your setup correctly transpiles or handles ESM imports.Understand that explicitly setting a boolean directive to `false` will result in its absence from the stringified header, effectively turning it 'off' rather than outputting `no-cache=false` (which is not a valid HTTP header pattern).
Update your package to `npm install cache-control-parser@latest` (or at least `^2.0.0`).
Use ESM import: `import { parse } from 'cache-control-parser';` instead of `const parse = require('cache-control-parser').parse;`.No dependency data recorded yet.