Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cache-parser

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cache-parser

A minimal Cache-Control header parser

  • 1.1.1
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

  

⌛ Cache Parser




Stars License Size Downloads NPM Coverage



cache-parser is a minimal Cache-Control header parser



Table of contents


Installing

Node
npm install --save cache-parser
# or
yarn add cache-parser
const { parse, tokenize } = require('cache-parser');
// or
import { parse, tokenize } from 'cache-parser';
Browser

Downloads

<!-- Make sure to use the latest version -->

<script
  crossorigin
  src="https://cdn.jsdelivr.net/npm/cache-parser@VERSION/index.min.js"
></script>
<!-- or -->
<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); // true
console.log(maxAge); // 3600
console.log(typeof maxAge); // number
console.log(immutable); // undefined

Simple header building:

import { tokenize } from 'cache-parser';

/** @type {import('cache-parser').CacheControl} */
const cacheProperties = { public: true, maxAge: 3600 };

// ['public', 'max-age=3600']
const cacheTokens = tokenize(cacheProperties);

// 'public, max-age=3600'
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.


Keywords

FAQs

Package last updated on 13 Dec 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc