Cache-control header utility that parses human readable time strings into seconds.
npm install pretty-cache-headerCache-control header utility that parses human readable time strings into seconds.
Time based values use Template Literal Types to help avoid passing invalid time string formats.
``sh`
npm i pretty-cache-header
`node
import { cacheHeader } from 'pretty-cache-header';
return new Response(..., {
headers: {
// sets cache control header to "public, max-age=604800, stale-while-revalidate=31536000"
'Cache-Control': cacheHeader({
public: true,
maxAge: '1week',
staleWhileRevalidate: '1year'
})
}
})
`
Any number followed by a timestring keyword:
1. ms, milli, millisecond, milliseconds - will parse to millisecondss
2. , sec, secs, second, seconds - will parse to secondsm
3. , min, mins, minute, minutes - will parse to minutesh
4. , hr, hrs, hour, hours - will parse to hoursd
5. , day, days - will parse to daysw
6. , week, weeks - will parse to weeksmon
7. , mth, mths, month, months - will parse to monthsy
8. , yr, yrs, year, years` - will parse to years