Table of contents
Installing
Node
npm install --save cache-parser
yarn add cache-parser
const { parse, tokenize } = require('cache-parser');
import { parse, tokenize } from 'cache-parser';
Browser
<script
crossorigin
src="https://cdn.jsdelivr.net/npm/cache-parser@VERSION/index.min.js"
></script>
<script crossorigin src="https://unpkg.com/cache-parser@VERSION/index.min.js"></script>
const { parse, tokenize } = window.CacheParser;
Browser Compatibility
Currently this package supports until ES3. To maintain this compatibility, our CI is
using ES Check.
But you can test this yourself too by running yarn escheck
or npm run escheck
on this
code.
Getting Started
This library consists of two important functions: parse
and tokenize
.
Every documentation needed by every piece of code is in form of TSDoc
and JSDoc
comments. You can see them Here.
Some examples
Simple header parsing:
import { parse } from 'cache-parser';
const rawHeader = 'public, max-age=3600';
const { public, maxAge, immutable } = parse(rawHeader);
console.log(public);
console.log(maxAge);
console.log(typeof maxAge);
console.log(immutable);
Simple header building:
import { tokenize } from 'cache-parser';
const cacheProperties = { public: true, maxAge: 3600 };
const cacheTokens = tokenize(cacheProperties);
response.headers['Cache-Control'] = tokens.join(', ');
License
Licensed under the MIT. See LICENSE
for more informations.
Contact
See my contact information on my github profile or
open a new issue.