UNPKG

550 BJavaScriptView Raw
1import { format } from '@tusbar/cache-control';
2const SECOND = { unit: 'second', relativeTo: '1970-01-01' };
3const isDuration = (x) => (x === null || x === void 0 ? void 0 : x[Symbol.toStringTag]) === 'Temporal.Duration';
4export const caching = (options = {}) => async (ax) => {
5 const x = await ax;
6 const opts = Object.fromEntries(Object.entries(options).map(([k, v]) => [k, isDuration(v) ? v.total(SECOND) : v]));
7 x.effects.push(res => res.headers.set('Cache-Control', format(opts)));
8 return x;
9};
10//# sourceMappingURL=caching.js.map
\No newline at end of file