@trenskow/app 0.9.1 → 0.9.2

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/lib/router.js CHANGED
@@ -6,7 +6,13 @@
6
6
  // For license see LICENSE.
7
7
  //
8
8
 
9
- import { isObject, resolveInlineImport, methods } from './util.js';
9
+ import {
10
+ isObject,
11
+ resolveInlineImport,
12
+ methods,
13
+ methodsRead,
14
+ methodsWrite
15
+ } from './util.js';
10
16
 
11
17
  export default class Router {
12
18
 
@@ -20,6 +26,18 @@ export default class Router {
20
26
  };
21
27
  });
22
28
 
29
+ this.use.read = (...handlers) => {
30
+ methodsRead.forEach((method) => {
31
+ return this.#_use(handlers, method);
32
+ });
33
+ };
34
+
35
+ this.use.write = (...handlers) => {
36
+ methodsWrite.forEach((method) => {
37
+ return this.#_use(handlers, method);
38
+ });
39
+ };
40
+
23
41
  }
24
42
 
25
43
  #_use(handlers, method) {
package/lib/util.js CHANGED
@@ -11,6 +11,8 @@ import { METHODS } from 'http';
11
11
  import caseit from '@trenskow/caseit';
12
12
 
13
13
  const methods = METHODS.map((method) => method.toLowerCase());
14
+ const methodsWrite = ['post', 'put', 'patch', 'delete'];
15
+ const methodsRead = methods.filter((method) => !methodsWrite.includes(method));
14
16
 
15
17
  const isObject = (value) => value?.constructor === Object;
16
18
 
@@ -26,6 +28,8 @@ const resolveInlineImport = (value) => {
26
28
 
27
29
  export {
28
30
  methods,
31
+ methodsWrite,
32
+ methodsRead,
29
33
  isObject,
30
34
  matchPath,
31
35
  resolveInlineImport
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trenskow/app",
3
- "version": "0.9.1",
3
+ "version": "0.9.2",
4
4
  "description": "A small HTTP router.",
5
5
  "type": "module",
6
6
  "main": "index.js",