{"id":17183,"library":"cache-control-esm","title":"HTTP Cache-Control Header Parser and Formatter (ESM)","description":"cache-control-esm is a JavaScript library specifically designed for parsing and formatting HTTP Cache-Control headers in strict adherence to RFC 7234. Currently at version 1.0.0, this package is a specialized fork of the `@tusbar/cache-control` library. Its primary differentiator is its explicit use of ECMAScript modules (`export default` and named exports), making it well-suited for modern bundlers and environments, especially within projects like `axios-cache-adapter`. Unlike other solutions that may bundle Express/Connect-like middleware or extensive interpretation logic, `cache-control-esm` maintains a narrow focus solely on the low-level parsing of header strings into a `CacheControl` object and formatting such objects back into valid HTTP header values. This focused approach ensures a lightweight and reliable tool for precise Cache-Control header manipulation without unnecessary overhead. Its release cadence is typically reactive to the needs of its consuming projects.","status":"active","version":"1.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/rascarlito/cache-control","tags":["javascript","cache-control","http","rfc7234"],"install":[{"cmd":"npm install cache-control-esm","lang":"bash","label":"npm"},{"cmd":"yarn add cache-control-esm","lang":"bash","label":"yarn"},{"cmd":"pnpm add cache-control-esm","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The package is ESM-only and exports named functions. CommonJS `require()` will not work.","wrong":"const { parse } = require('@rascarlito/cache-control')","symbol":"parse","correct":"import { parse } from '@rascarlito/cache-control'"},{"note":"Both `parse` and `format` are named exports. There is no default export for these functions.","wrong":"import format from '@rascarlito/cache-control'","symbol":"format","correct":"import { format } from '@rascarlito/cache-control'"},{"note":"The `CacheControl` class is also a named export, primarily for type inference or direct instantiation.","wrong":"const { CacheControl } = require('@rascarlito/cache-control')","symbol":"CacheControl","correct":"import { CacheControl } from '@rascarlito/cache-control'"}],"quickstart":{"code":"import { format, parse } from '@rascarlito/cache-control';\n\n// Simulate a response object\nconst res = {\n  _headers: {},\n  setHeader(name, value) {\n    this._headers[name] = value;\n  },\n  getHeader(name) {\n    return this._headers[name];\n  }\n};\n\n// Set a Cache-Control header using the format function\nres.setHeader('Cache-Control', format({\n  public: true,\n  immutable: true,\n  maxAge: 31536000\n}));\n\nconsole.log('Set Cache-Control header:', res.getHeader('Cache-Control'));\n\n// Parse a Cache-Control header from a string\nconst parsedHeader = parse('max-age=604800, public, no-transform');\nconsole.log('Parsed Cache-Control object:', parsedHeader);","lang":"typescript","description":"Demonstrates setting a Cache-Control header using `format` and parsing one using `parse`."},"warnings":[{"fix":"Always explicitly specify `@rascarlito/cache-control` in your `package.json` and installation commands.","message":"This package is a direct fork of the original `@tusbar/cache-control`. Ensure you are installing `@rascarlito/cache-control` if you intend to use the ESM-only version, as the original package might have different module export conventions.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure your project is configured for ESM (e.g., `\"type\": \"module\"` in `package.json`) or use a bundler that correctly handles ESM imports. Always use `import` statements.","message":"This package is ESM-only and utilizes `export` statements. It is incompatible with CommonJS `require()` syntax directly in Node.js environments unless transpiled or run with `--experimental-modules` (prior to Node.js 12.0.0, or in contexts where ESM is not the default).","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Implement your own cache interpretation logic based on the `CacheControl` object properties, or integrate with a caching library that handles this. This package is a low-level utility.","message":"The library focuses exclusively on parsing and formatting HTTP `Cache-Control` headers. It does not provide any higher-level logic for interpreting or acting upon the parsed directives (e.g., determining cache hit/miss, freshness, etc.).","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Change `const { parse } = require('@rascarlito/cache-control')` to `import { parse } from '@rascarlito/cache-control'` and ensure your Node.js environment is configured for ESM.","cause":"Attempting to import the ESM-only package using CommonJS `require()` syntax in a Node.js environment that expects ESM or where `package.json` does not specify `\"type\": \"commonjs\"`.","error":"TypeError: require is not a function"},{"fix":"Correct the import statement to use named imports: `import { parse } from '@rascarlito/cache-control'`.","cause":"Attempting to use a default import `import parse from '@rascarlito/cache-control'` when `parse` is a named export.","error":"SyntaxError: Named export 'parse' not found. The requested module '@rascarlito/cache-control' does not provide an export named 'parse'"}],"ecosystem":"npm","meta_description":null}