A minimal parser for the Cache-Control header.
npm install cache-parser











ā
Cache Parser
Cache Parser is a minimal parser for the Cache-Control header.- Table of Contents
- Installing
- Node
- Browser
- Url Import
- Getting Started
- Usage
- License
``sh`
npm install cache-parser # or yarn add cache-parser
`js`
const { parse, tokenize } = require('cache-parser');
import { parse, tokenize } from 'cache-parser';
`html`
crossorigin
src="https://cdn.jsdelivr.net/npm/cache-parser@latest/dist/index.umd.js"
>
`js`
const { parse, tokenize } = window.cacheParser;
`ts`
import { parse, tokenize } from 'https://cdn.skypack.dev/cache-parser@latest';
This package is a parser and builder for all Cache-Control directives. You can parse a
string with parse() and build a http ready header with
tokenize().
All needed documentation is available in form of TSDoc comments.
`ts
import { parse, CacheControl } from 'cache-parser';
const rawHeader = 'public, max-age=3600';
const {
public, // true
maxAge, // 3600
immutable // undefined
} = parse(rawHeader);
const cacheProperties: CacheControl = { public: true, maxAge: 3600 };
// ['public', 'max-age=3600']
const cacheTokens = tokenize(cacheProperties);
// 'public, max-age=3600'
const httpHeader = tokens.join(', ');
`
Licensed under the MIT. See LICENSE` for more informations.
