milliparsec 5.0.0 → 5.0.1

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/dist/index.d.ts CHANGED
@@ -20,33 +20,33 @@ export type ParserOptions = Partial<{
20
20
  */
21
21
  payloadLimitErrorFn: LimitErrorFn;
22
22
  }>;
23
- export declare const p: <T = any>(fn: (body: Buffer) => void, payloadLimit?: number, payloadLimitErrorFn?: LimitErrorFn) => (req: ReqWithBody<T>, _res: Response, next: (err?: any) => void) => Promise<void>;
23
+ export declare const p: <T = any>(fn: (body: Buffer) => void, payloadLimit?: number, payloadLimitErrorFn?: LimitErrorFn) => (req: ReqWithBody<T>, _res: Response, next?: (err?: any) => void) => Promise<void>;
24
24
  /**
25
25
  * Parse payload with a custom function
26
26
  * @param fn
27
27
  */
28
- declare const custom: <T = any>(fn: (body: Buffer) => any) => (req: ReqWithBody, _res: Response, next: NextFunction) => Promise<void>;
28
+ declare const custom: <T = any>(fn: (body: Buffer) => any) => (req: ReqWithBody, _res: Response, next?: NextFunction) => Promise<void>;
29
29
  /**
30
30
  * Parse JSON payload
31
31
  * @param options
32
32
  */
33
- declare const json: ({ payloadLimit, payloadLimitErrorFn }?: ParserOptions) => (req: ReqWithBody, res: Response, next: NextFunction) => Promise<void>;
33
+ declare const json: ({ payloadLimit, payloadLimitErrorFn }?: ParserOptions) => (req: ReqWithBody, res: Response, next?: NextFunction) => Promise<void>;
34
34
  /**
35
35
  * Parse raw payload
36
36
  * @param options
37
37
  */
38
- declare const raw: ({ payloadLimit, payloadLimitErrorFn }?: ParserOptions) => (req: ReqWithBody, _res: Response, next: NextFunction) => Promise<void>;
38
+ declare const raw: ({ payloadLimit, payloadLimitErrorFn }?: ParserOptions) => (req: ReqWithBody, _res: Response, next?: NextFunction) => Promise<void>;
39
39
  /**
40
40
  * Stringify request payload
41
41
  * @param param0
42
42
  * @returns
43
43
  */
44
- declare const text: ({ payloadLimit, payloadLimitErrorFn }?: ParserOptions) => (req: ReqWithBody, _res: Response, next: NextFunction) => Promise<void>;
44
+ declare const text: ({ payloadLimit, payloadLimitErrorFn }?: ParserOptions) => (req: ReqWithBody, _res: Response, next?: NextFunction) => Promise<void>;
45
45
  /**
46
46
  * Parse urlencoded payload
47
47
  * @param options
48
48
  */
49
- declare const urlencoded: ({ payloadLimit, payloadLimitErrorFn }?: ParserOptions) => (req: ReqWithBody, _res: Response, next: NextFunction) => Promise<void>;
49
+ declare const urlencoded: ({ payloadLimit, payloadLimitErrorFn }?: ParserOptions) => (req: ReqWithBody, _res: Response, next?: NextFunction) => Promise<void>;
50
50
  type MultipartOptions = Partial<{
51
51
  /**
52
52
  * Limit number of files
@@ -67,5 +67,5 @@ type MultipartOptions = Partial<{
67
67
  * Does not restrict total payload size by default.
68
68
  * @param options
69
69
  */
70
- declare const multipart: ({ payloadLimit, payloadLimitErrorFn, ...opts }?: MultipartOptions & ParserOptions) => (req: ReqWithBody, res: Response, next: NextFunction) => Promise<void>;
70
+ declare const multipart: ({ payloadLimit, payloadLimitErrorFn, ...opts }?: MultipartOptions & ParserOptions) => (req: ReqWithBody, res: Response, next?: NextFunction) => Promise<void>;
71
71
  export { custom, json, raw, text, urlencoded, multipart };
package/dist/index.js CHANGED
@@ -15,7 +15,7 @@ export const p = (fn, payloadLimit = defaultPayloadLimit, payloadLimitErrorFn =
15
15
  return fn(Buffer.concat(body));
16
16
  }
17
17
  catch (e) {
18
- next(e);
18
+ next === null || next === void 0 ? void 0 : next(e);
19
19
  }
20
20
  };
21
21
  /**
@@ -25,7 +25,7 @@ export const p = (fn, payloadLimit = defaultPayloadLimit, payloadLimitErrorFn =
25
25
  const custom = (fn) => async (req, _res, next) => {
26
26
  if (hasBody(req.method))
27
27
  req.body = await p(fn)(req, _res, next);
28
- next();
28
+ next === null || next === void 0 ? void 0 : next();
29
29
  };
30
30
  /**
31
31
  * Parse JSON payload
@@ -38,8 +38,7 @@ const json = ({ payloadLimit, payloadLimitErrorFn } = {}) => async (req, res, ne
38
38
  return str ? JSON.parse(str) : {};
39
39
  }, payloadLimit, payloadLimitErrorFn)(req, res, next);
40
40
  }
41
- else
42
- next();
41
+ next === null || next === void 0 ? void 0 : next();
43
42
  };
44
43
  /**
45
44
  * Parse raw payload
@@ -49,8 +48,7 @@ const raw = ({ payloadLimit, payloadLimitErrorFn } = {}) => async (req, _res, ne
49
48
  if (hasBody(req.method)) {
50
49
  req.body = await p((x) => x, payloadLimit, payloadLimitErrorFn)(req, _res, next);
51
50
  }
52
- else
53
- next();
51
+ next === null || next === void 0 ? void 0 : next();
54
52
  };
55
53
  const td = new TextDecoder();
56
54
  /**
@@ -62,8 +60,7 @@ const text = ({ payloadLimit, payloadLimitErrorFn } = {}) => async (req, _res, n
62
60
  if (hasBody(req.method)) {
63
61
  req.body = await p((x) => td.decode(x), payloadLimit, payloadLimitErrorFn)(req, _res, next);
64
62
  }
65
- else
66
- next();
63
+ next === null || next === void 0 ? void 0 : next();
67
64
  };
68
65
  /**
69
66
  * Parse urlencoded payload
@@ -73,8 +70,7 @@ const urlencoded = ({ payloadLimit, payloadLimitErrorFn } = {}) => async (req, _
73
70
  if (hasBody(req.method)) {
74
71
  req.body = await p((x) => Object.fromEntries(new URLSearchParams(x.toString()).entries()), payloadLimit, payloadLimitErrorFn)(req, _res, next);
75
72
  }
76
- else
77
- next();
73
+ next === null || next === void 0 ? void 0 : next();
78
74
  };
79
75
  const getBoundary = (contentType) => {
80
76
  const match = /boundary=(.+);?/.exec(contentType);
@@ -123,7 +119,6 @@ const multipart = ({ payloadLimit = Number.POSITIVE_INFINITY, payloadLimitErrorF
123
119
  return {};
124
120
  }, payloadLimit, payloadLimitErrorFn)(req, res, next);
125
121
  }
126
- else
127
- next();
122
+ next === null || next === void 0 ? void 0 : next();
128
123
  };
129
124
  export { custom, json, raw, text, urlencoded, multipart };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "milliparsec",
3
- "version": "5.0.0",
3
+ "version": "5.0.1",
4
4
  "description": "tiniest body parser in the universe",
5
5
  "repository": {
6
6
  "type": "git",
@@ -22,6 +22,7 @@
22
22
  "exports": "./dist/index.js",
23
23
  "devDependencies": {
24
24
  "@biomejs/biome": "1.9.3",
25
+ "@tinyhttp/app": "^2.4.0",
25
26
  "@types/node": "^22.7.4",
26
27
  "c8": "10.1.2",
27
28
  "supertest-fetch": "^2.0.0",
@@ -38,6 +39,7 @@
38
39
  "test": "tsx --test test.ts",
39
40
  "test:coverage": "c8 --include=src pnpm test",
40
41
  "test:report": "c8 report --reporter=text-lcov > coverage.lcov",
41
- "build": "tsc -p tsconfig.build.json"
42
+ "build": "tsc -p tsconfig.build.json",
43
+ "check": "biome check --write"
42
44
  }
43
45
  }