@reykjavik/webtools 0.1.27 → 0.1.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -4,6 +4,13 @@
4
4
 
5
5
  - ... <!-- Add new lines here. -->
6
6
 
7
+ ## 0.1.28
8
+
9
+ _2024-08-26_
10
+
11
+ - `@reykjavik/webtools/http`:
12
+ - feat: `cacheControl` now also accepts `Map<string, string>` for headers
13
+
7
14
  ## 0.1.27
8
15
 
9
16
  _2024-07-18_
package/README.md CHANGED
@@ -112,10 +112,10 @@ codes, are also available:
112
112
  ### `cacheControl` helper
113
113
 
114
114
  **Syntax:**
115
- `cacheConrol(response: ServerResponse | { res: ServerResponse }, ttlCfg: TTLConfig, eTag?: string|number): void`
115
+ `cacheConrol(response: ServerResponse | Response | Map<string, string> | { res: ServerResponse | Response }, ttlCfg: TTLConfig, eTag?: string|number): void`
116
116
 
117
117
  Use this function to quickly set the `Cache-Control` header with a `max-age=`
118
- on a HTTP response.
118
+ on a HTTP response (or a `Map` object representing response headers).
119
119
 
120
120
  ```js
121
121
  import { cacheControl } from '@reykjavik/webtools/http';
package/esm/http.d.ts CHANGED
@@ -168,7 +168,7 @@ type ServerResponseStub = Pick<ServerResponse, 'setHeader' | 'getHeader' | 'remo
168
168
  headers?: Record<string, string | Array<string>>;
169
169
  };
170
170
  type ResponseStub = {
171
- headers: Pick<Headers, 'set' | 'get' | 'delete' | 'append'>;
171
+ headers: Pick<Headers, 'set' | 'get' | 'delete'>;
172
172
  };
173
173
  /**
174
174
  * Use this function to quickly set the `Cache-Control` header with a `max-age=`
@@ -176,7 +176,7 @@ type ResponseStub = {
176
176
  *
177
177
  * @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#getcssbundleurl
178
178
  */
179
- export declare const cacheControl: (response: ServerResponseStub | ResponseStub | {
179
+ export declare const cacheControl: (response: ServerResponseStub | ResponseStub | Map<string, string> | {
180
180
  res: ServerResponseStub | ResponseStub;
181
181
  }, ttlCfg: TTLConfig, eTag?: string | number) => void;
182
182
  export {};
package/esm/http.js CHANGED
@@ -147,6 +147,9 @@ export const toSec = (ttl) => {
147
147
  return Math.max(0, Math.round(ttl)) || 0;
148
148
  };
149
149
  const toRespnseStubHeaders = (response) => {
150
+ if (response instanceof Map) {
151
+ return response;
152
+ }
150
153
  if ('headers' in response && !('setHeader' in response)) {
151
154
  return response.headers;
152
155
  }
@@ -159,15 +162,6 @@ const toRespnseStubHeaders = (response) => {
159
162
  return val != null ? `${val}` : null;
160
163
  },
161
164
  set: (name, value) => response.setHeader(name, value),
162
- append: (name, value) => {
163
- const existing = response.getHeader(name);
164
- if (existing) {
165
- response.setHeader(name, `${existing}, ${value}`);
166
- }
167
- else {
168
- response.setHeader(name, value);
169
- }
170
- },
171
165
  delete: (name) => response.removeHeader(name),
172
166
  };
173
167
  };
package/http.d.ts CHANGED
@@ -168,7 +168,7 @@ type ServerResponseStub = Pick<ServerResponse, 'setHeader' | 'getHeader' | 'remo
168
168
  headers?: Record<string, string | Array<string>>;
169
169
  };
170
170
  type ResponseStub = {
171
- headers: Pick<Headers, 'set' | 'get' | 'delete' | 'append'>;
171
+ headers: Pick<Headers, 'set' | 'get' | 'delete'>;
172
172
  };
173
173
  /**
174
174
  * Use this function to quickly set the `Cache-Control` header with a `max-age=`
@@ -176,7 +176,7 @@ type ResponseStub = {
176
176
  *
177
177
  * @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#getcssbundleurl
178
178
  */
179
- export declare const cacheControl: (response: ServerResponseStub | ResponseStub | {
179
+ export declare const cacheControl: (response: ServerResponseStub | ResponseStub | Map<string, string> | {
180
180
  res: ServerResponseStub | ResponseStub;
181
181
  }, ttlCfg: TTLConfig, eTag?: string | number) => void;
182
182
  export {};
package/http.js CHANGED
@@ -152,6 +152,9 @@ const toSec = (ttl) => {
152
152
  };
153
153
  exports.toSec = toSec;
154
154
  const toRespnseStubHeaders = (response) => {
155
+ if (response instanceof Map) {
156
+ return response;
157
+ }
155
158
  if ('headers' in response && !('setHeader' in response)) {
156
159
  return response.headers;
157
160
  }
@@ -164,15 +167,6 @@ const toRespnseStubHeaders = (response) => {
164
167
  return val != null ? `${val}` : null;
165
168
  },
166
169
  set: (name, value) => response.setHeader(name, value),
167
- append: (name, value) => {
168
- const existing = response.getHeader(name);
169
- if (existing) {
170
- response.setHeader(name, `${existing}, ${value}`);
171
- }
172
- else {
173
- response.setHeader(name, value);
174
- }
175
- },
176
170
  delete: (name) => response.removeHeader(name),
177
171
  };
178
172
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reykjavik/webtools",
3
- "version": "0.1.27",
3
+ "version": "0.1.28",
4
4
  "description": "Misc. JS/TS helpers used by Reykjavík City's web dev teams.",
5
5
  "main": "index.js",
6
6
  "repository": "ssh://git@github.com:reykjavikcity/webtools.git",