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 parser.

  • 1.2.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
49K
decreased by-58.02%
Maintainers
1
Weekly downloads
 
Created
Source

  

⌛ Cache Parser




Stars License Size Downloads NPM Coverage



cache-parser is a minimal parser for the Cache-Control header



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

<script
  crossorigin
  src="https://cdn.jsdelivr.net/npm/cache-parser@1/index.umd.js"
></script>
<!-- or -->
<script crossorigin src="https://unpkg.com/cache-parser@1/dist/index.umd.js"></script>
const { parse, tokenize } = window.CacheParser;

Getting Started

This library consists of two important functions: parse and tokenize.

This is a pretty straightforward library, so, every documentation needed by every piece of code is in form of TSDoc and JSDoc comments.

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.


FAQs

Package last updated on 28 Feb 2022

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