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 - npm Package Compare versions

Comparing version 1.1.0 to 1.1.1

8

index.d.ts
/**
* A simple enum that can help determine the header names.
* A simple enum that can help with directives.
*

@@ -12,6 +12,6 @@ * The {@link CacheControl} object uses camelCase parameters to help with the javascript

*
* const maxAge = cacheControl[HEADER_NAME['max-age']];
* const maxAge = cacheControl[Directive['max-age']];
* ```
*/
export declare enum HEADER_NAME {
export declare const enum Directive {
immutable = 'immutable',

@@ -56,2 +56,4 @@ maxAge = 'max-age',

*
* #### The output is sorted by alphabetical order
*
* The cache control object does not need to be a CacheControl object from the

@@ -58,0 +60,0 @@ * {@link CacheControl}.This means that the parameter do not have to pass in the

!(function (root) {
/** Unique identifier */
var symbolKey = (Symbol || String)('cache-parser');
var symbolKey = Symbol('cache-parser');
/** (camelCase=kebabCase) and (kebabCase=camelCase) */
var HEADER_NAME = {
var Directive = {
immutable: 'immutable',

@@ -25,4 +25,4 @@ maxAge: 'max-age',

for (var key in HEADER_NAME) {
HEADER_NAME[HEADER_NAME[key]] = key;
for (var key in Directive) {
Directive[Directive[key]] = key;
}

@@ -57,30 +57,30 @@

toBoolean(header.immutable) && tokens.push(HEADER_NAME.immutable);
toBoolean(header.immutable) && tokens.push(Directive.immutable);
toDuration(header.maxAge) &&
tokens.push(HEADER_NAME.maxAge + '=' + Number(header.maxAge));
tokens.push(Directive.maxAge + '=' + Number(header.maxAge));
toDuration(header.maxStale) &&
tokens.push(HEADER_NAME.maxStale + '=' + Number(header.maxStale));
tokens.push(Directive.maxStale + '=' + Number(header.maxStale));
toDuration(header.minFresh) &&
tokens.push(HEADER_NAME.minFresh + '=' + Number(header.minFresh));
tokens.push(Directive.minFresh + '=' + Number(header.minFresh));
toBoolean(header.mustRevalidate) && tokens.push(HEADER_NAME.mustRevalidate);
toBoolean(header.mustUnderstand) && tokens.push(HEADER_NAME.mustUnderstand);
toBoolean(header.noCache) && tokens.push(HEADER_NAME.noCache);
toBoolean(header.noStore) && tokens.push(HEADER_NAME.noStore);
toBoolean(header.noTransform) && tokens.push(HEADER_NAME.noTransform);
toBoolean(header.onlyIfCached) && tokens.push(HEADER_NAME.onlyIfCached);
toBoolean(header.private) && tokens.push(HEADER_NAME.private);
toBoolean(header.proxyRevalidate) && tokens.push(HEADER_NAME.proxyRevalidate);
toBoolean(header.public) && tokens.push(HEADER_NAME.public);
toBoolean(header.mustRevalidate) && tokens.push(Directive.mustRevalidate);
toBoolean(header.mustUnderstand) && tokens.push(Directive.mustUnderstand);
toBoolean(header.noCache) && tokens.push(Directive.noCache);
toBoolean(header.noStore) && tokens.push(Directive.noStore);
toBoolean(header.noTransform) && tokens.push(Directive.noTransform);
toBoolean(header.onlyIfCached) && tokens.push(Directive.onlyIfCached);
toBoolean(header.private) && tokens.push(Directive.private);
toBoolean(header.proxyRevalidate) && tokens.push(Directive.proxyRevalidate);
toBoolean(header.public) && tokens.push(Directive.public);
toDuration(header.sMaxAge) &&
tokens.push(HEADER_NAME.sMaxAge + '=' + Number(header.sMaxAge));
tokens.push(Directive.sMaxAge + '=' + Number(header.sMaxAge));
toDuration(header.staleIfError) &&
tokens.push(HEADER_NAME.staleIfError + '=' + Number(header.staleIfError));
tokens.push(Directive.staleIfError + '=' + Number(header.staleIfError));
toDuration(header.staleWhileRevalidate) &&
tokens.push(
HEADER_NAME.staleWhileRevalidate + '=' + Number(header.staleWhileRevalidate)
Directive.staleWhileRevalidate + '=' + Number(header.staleWhileRevalidate)
);

@@ -113,29 +113,27 @@

toBoolean(rawHeaders[HEADER_NAME.immutable]) && (header.immutable = true);
toBoolean(rawHeaders[Directive.immutable]) && (header.immutable = true);
toDuration(rawHeaders[HEADER_NAME.maxAge]) &&
(header.maxAge = Number(rawHeaders[HEADER_NAME.maxAge]));
toDuration(rawHeaders[HEADER_NAME.maxStale]) &&
(header.maxStale = Number(rawHeaders[HEADER_NAME.maxStale]));
toDuration(rawHeaders[HEADER_NAME.minFresh]) &&
(header.minFresh = Number(rawHeaders[HEADER_NAME.minFresh]));
toDuration(rawHeaders[Directive.maxAge]) &&
(header.maxAge = Number(rawHeaders[Directive.maxAge]));
toDuration(rawHeaders[Directive.maxStale]) &&
(header.maxStale = Number(rawHeaders[Directive.maxStale]));
toDuration(rawHeaders[Directive.minFresh]) &&
(header.minFresh = Number(rawHeaders[Directive.minFresh]));
toBoolean(rawHeaders[HEADER_NAME.mustRevalidate]) && (header.mustRevalidate = true);
toBoolean(rawHeaders[HEADER_NAME.mustUnderstand]) && (header.mustUnderstand = true);
toBoolean(rawHeaders[HEADER_NAME.noCache]) && (header.noCache = true);
toBoolean(rawHeaders[HEADER_NAME.noStore]) && (header.noStore = true);
toBoolean(rawHeaders[HEADER_NAME.noTransform]) && (header.noTransform = true);
toBoolean(rawHeaders[HEADER_NAME.onlyIfCached]) && (header.onlyIfCached = true);
toBoolean(rawHeaders[HEADER_NAME.private]) && (header.private = true);
toBoolean(rawHeaders[HEADER_NAME.proxyRevalidate]) && (header.proxyRevalidate = true);
toBoolean(rawHeaders[HEADER_NAME.public]) && (header.public = true);
toBoolean(rawHeaders[Directive.mustRevalidate]) && (header.mustRevalidate = true);
toBoolean(rawHeaders[Directive.mustUnderstand]) && (header.mustUnderstand = true);
toBoolean(rawHeaders[Directive.noCache]) && (header.noCache = true);
toBoolean(rawHeaders[Directive.noStore]) && (header.noStore = true);
toBoolean(rawHeaders[Directive.noTransform]) && (header.noTransform = true);
toBoolean(rawHeaders[Directive.onlyIfCached]) && (header.onlyIfCached = true);
toBoolean(rawHeaders[Directive.private]) && (header.private = true);
toBoolean(rawHeaders[Directive.proxyRevalidate]) && (header.proxyRevalidate = true);
toBoolean(rawHeaders[Directive.public]) && (header.public = true);
toDuration(rawHeaders[HEADER_NAME.sMaxAge]) &&
(header.sMaxAge = Number(rawHeaders[HEADER_NAME.sMaxAge]));
toDuration(rawHeaders[HEADER_NAME.staleIfError]) &&
(header.staleIfError = Number(rawHeaders[HEADER_NAME.staleIfError]));
toDuration(rawHeaders[HEADER_NAME.staleWhileRevalidate]) &&
(header.staleWhileRevalidate = Number(
rawHeaders[HEADER_NAME.staleWhileRevalidate]
));
toDuration(rawHeaders[Directive.sMaxAge]) &&
(header.sMaxAge = Number(rawHeaders[Directive.sMaxAge]));
toDuration(rawHeaders[Directive.staleIfError]) &&
(header.staleIfError = Number(rawHeaders[Directive.staleIfError]));
toDuration(rawHeaders[Directive.staleWhileRevalidate]) &&
(header.staleWhileRevalidate = Number(rawHeaders[Directive.staleWhileRevalidate]));

@@ -145,3 +143,3 @@ return header;

root.HEADER_NAME = HEADER_NAME;
root.Directive = Directive;
root.toDuration = toDuration;

@@ -148,0 +146,0 @@ root.toBoolean = toBoolean;

@@ -1,1 +0,1 @@

!function(e){var a=(Symbol||String)("cache-parser"),r={immutable:"immutable",maxAge:"max-age",maxStale:"max-stale",minFresh:"min-fresh",mustRevalidate:"must-revalidate",mustUnderstand:"must-understand",noCache:"no-cache",noStore:"no-store",noTransform:"no-transform",onlyIfCached:"only-if-cached",private:"private",proxyRevalidate:"proxy-revalidate",public:"public",sMaxAge:"s-maxage",staleIfError:"stale-if-error",staleWhileRevalidate:"stale-while-revalidate"};for(var t in r)r[r[t]]=t;function n(e){return("string"==typeof e||"number"==typeof e)&&(e=Number(e))>=0&&e<1/0}function s(e){return!0===e||"number"==typeof e||"string"==typeof e&&"false"!==e}e.HEADER_NAME=r,e.toDuration=n,e.toBoolean=s,e.isCacheControl=function(e){return!!e&&!!e[a]},e.tokenize=function(e){if(!e||"object"!=typeof e)return[];var a=[];return s(e.immutable)&&a.push(r.immutable),n(e.maxAge)&&a.push(r.maxAge+"="+Number(e.maxAge)),n(e.maxStale)&&a.push(r.maxStale+"="+Number(e.maxStale)),n(e.minFresh)&&a.push(r.minFresh+"="+Number(e.minFresh)),s(e.mustRevalidate)&&a.push(r.mustRevalidate),s(e.mustUnderstand)&&a.push(r.mustUnderstand),s(e.noCache)&&a.push(r.noCache),s(e.noStore)&&a.push(r.noStore),s(e.noTransform)&&a.push(r.noTransform),s(e.onlyIfCached)&&a.push(r.onlyIfCached),s(e.private)&&a.push(r.private),s(e.proxyRevalidate)&&a.push(r.proxyRevalidate),s(e.public)&&a.push(r.public),n(e.sMaxAge)&&a.push(r.sMaxAge+"="+Number(e.sMaxAge)),n(e.staleIfError)&&a.push(r.staleIfError+"="+Number(e.staleIfError)),n(e.staleWhileRevalidate)&&a.push(r.staleWhileRevalidate+"="+Number(e.staleWhileRevalidate)),a},e.parse=function(e){var t=Object.defineProperty({},a,{configurable:!1,enumerable:!1,writable:!1,value:1});if(!e||"string"!=typeof e)return t;var o={},l=e.toLowerCase().replace(/\s+/g,"").split(",");for(var i in l){var u=l[i].split("=",2);o[u[0]]=1===u.length||u[1]}return s(o[r.immutable])&&(t.immutable=!0),n(o[r.maxAge])&&(t.maxAge=Number(o[r.maxAge])),n(o[r.maxStale])&&(t.maxStale=Number(o[r.maxStale])),n(o[r.minFresh])&&(t.minFresh=Number(o[r.minFresh])),s(o[r.mustRevalidate])&&(t.mustRevalidate=!0),s(o[r.mustUnderstand])&&(t.mustUnderstand=!0),s(o[r.noCache])&&(t.noCache=!0),s(o[r.noStore])&&(t.noStore=!0),s(o[r.noTransform])&&(t.noTransform=!0),s(o[r.onlyIfCached])&&(t.onlyIfCached=!0),s(o[r.private])&&(t.private=!0),s(o[r.proxyRevalidate])&&(t.proxyRevalidate=!0),s(o[r.public])&&(t.public=!0),n(o[r.sMaxAge])&&(t.sMaxAge=Number(o[r.sMaxAge])),n(o[r.staleIfError])&&(t.staleIfError=Number(o[r.staleIfError])),n(o[r.staleWhileRevalidate])&&(t.staleWhileRevalidate=Number(o[r.staleWhileRevalidate])),t}}("undefined"!=typeof exports?exports:window.CacheParser||(window.CacheParser={}));
!function(e){var a=Symbol("cache-parser"),r={immutable:"immutable",maxAge:"max-age",maxStale:"max-stale",minFresh:"min-fresh",mustRevalidate:"must-revalidate",mustUnderstand:"must-understand",noCache:"no-cache",noStore:"no-store",noTransform:"no-transform",onlyIfCached:"only-if-cached",private:"private",proxyRevalidate:"proxy-revalidate",public:"public",sMaxAge:"s-maxage",staleIfError:"stale-if-error",staleWhileRevalidate:"stale-while-revalidate"};for(var t in r)r[r[t]]=t;function s(e){return("string"==typeof e||"number"==typeof e)&&(e=Number(e))>=0&&e<1/0}function n(e){return!0===e||"number"==typeof e||"string"==typeof e&&"false"!==e}e.Directive=r,e.toDuration=s,e.toBoolean=n,e.isCacheControl=function(e){return!!e&&!!e[a]},e.tokenize=function(e){if(!e||"object"!=typeof e)return[];var a=[];return n(e.immutable)&&a.push(r.immutable),s(e.maxAge)&&a.push(r.maxAge+"="+Number(e.maxAge)),s(e.maxStale)&&a.push(r.maxStale+"="+Number(e.maxStale)),s(e.minFresh)&&a.push(r.minFresh+"="+Number(e.minFresh)),n(e.mustRevalidate)&&a.push(r.mustRevalidate),n(e.mustUnderstand)&&a.push(r.mustUnderstand),n(e.noCache)&&a.push(r.noCache),n(e.noStore)&&a.push(r.noStore),n(e.noTransform)&&a.push(r.noTransform),n(e.onlyIfCached)&&a.push(r.onlyIfCached),n(e.private)&&a.push(r.private),n(e.proxyRevalidate)&&a.push(r.proxyRevalidate),n(e.public)&&a.push(r.public),s(e.sMaxAge)&&a.push(r.sMaxAge+"="+Number(e.sMaxAge)),s(e.staleIfError)&&a.push(r.staleIfError+"="+Number(e.staleIfError)),s(e.staleWhileRevalidate)&&a.push(r.staleWhileRevalidate+"="+Number(e.staleWhileRevalidate)),a},e.parse=function(e){var t=Object.defineProperty({},a,{configurable:!1,enumerable:!1,writable:!1,value:1});if(!e||"string"!=typeof e)return t;var o={},i=e.toLowerCase().replace(/\s+/g,"").split(",");for(var l in i){var u=i[l].split("=",2);o[u[0]]=1===u.length||u[1]}return n(o[r.immutable])&&(t.immutable=!0),s(o[r.maxAge])&&(t.maxAge=Number(o[r.maxAge])),s(o[r.maxStale])&&(t.maxStale=Number(o[r.maxStale])),s(o[r.minFresh])&&(t.minFresh=Number(o[r.minFresh])),n(o[r.mustRevalidate])&&(t.mustRevalidate=!0),n(o[r.mustUnderstand])&&(t.mustUnderstand=!0),n(o[r.noCache])&&(t.noCache=!0),n(o[r.noStore])&&(t.noStore=!0),n(o[r.noTransform])&&(t.noTransform=!0),n(o[r.onlyIfCached])&&(t.onlyIfCached=!0),n(o[r.private])&&(t.private=!0),n(o[r.proxyRevalidate])&&(t.proxyRevalidate=!0),n(o[r.public])&&(t.public=!0),s(o[r.sMaxAge])&&(t.sMaxAge=Number(o[r.sMaxAge])),s(o[r.staleIfError])&&(t.staleIfError=Number(o[r.staleIfError])),s(o[r.staleWhileRevalidate])&&(t.staleWhileRevalidate=Number(o[r.staleWhileRevalidate])),t}}("undefined"!=typeof exports?exports:window.CacheParser||(window.CacheParser={}));
{
"name": "cache-parser",
"version": "1.1.0",
"version": "1.1.1",
"description": "A minimal Cache-Control header parser",

@@ -5,0 +5,0 @@ "main": "./index.min.js",

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