cache-control-parser
Advanced tools
+1
-1
| { | ||
| "name": "cache-control-parser", | ||
| "version": "2.0.1", | ||
| "version": "2.0.2", | ||
| "description": "A humble cache-control parser", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/etienne-martin/cache-control-parser", |
+38
-6
| # cache-control-parser | ||
| A humble cache-control parser. | ||
| A humble [cache-control](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control) parser. | ||
@@ -18,3 +18,3 @@ [](https://coveralls.io/github/etienne-martin/cache-control-parser) | ||
| ✨ **New:** you can now stringify parsed cache controls | ||
| ✨ **New:** you can now stringify cache control objects | ||
@@ -33,3 +33,3 @@ ## Getting Started | ||
| **Example** - parse a cache control string into an object: | ||
| **Example** - parse a string of cache control directives into an object: | ||
@@ -40,3 +40,3 @@ ```javascript | ||
| const directives = parse( | ||
| "public, max-age=86400, no-transform" | ||
| "public, max-age=300, no-transform" | ||
| ); | ||
@@ -52,3 +52,3 @@ | ||
| "public": true, | ||
| "max-age": 86400, | ||
| "max-age": 300, | ||
| "no-transform": true | ||
@@ -58,5 +58,37 @@ } | ||
| **Example** - stringify a cache control object into a string: | ||
| **Example** - destructuring the cache control object: | ||
| ```javascript | ||
| import { parse } from "cache-control-parser"; | ||
| const directives = parse( | ||
| "max-age=300, s-maxage=0" | ||
| ); | ||
| const { "max-age": maxAge, "s-maxage": sMaxAge } = directives; | ||
| ``` | ||
| **Example** - retrieve the shared proxy cache TTL: | ||
| ```javascript | ||
| import { parse } from "cache-control-parser"; | ||
| const cacheControl = parse( | ||
| "max-age=300, s-maxage=0" | ||
| ); | ||
| const ttl = cacheControl["s-maxage"] ?? cacheControl["max-age"]; | ||
| console.log("ttl:", ttl); | ||
| ``` | ||
| Output: | ||
| ```json | ||
| ttl: 0 | ||
| ``` | ||
| **Example** - stringify a cache control object: | ||
| ```javascript | ||
| import { stringify } from "cache-control-parser"; | ||
@@ -63,0 +95,0 @@ |
10869
5.97%168
23.53%