milliparsec 2.2.2 → 3.0.0
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/README.md +4 -3
- package/dist/index.d.ts +4 -5
- package/dist/index.js +4 -5
- package/package.json +12 -14
package/README.md
CHANGED
|
@@ -17,9 +17,10 @@ Check out [deno-libs/parsec](https://github.com/deno-libs/parsec) for Deno port.
|
|
|
17
17
|
|
|
18
18
|
- ⏩ built with `async` / `await`
|
|
19
19
|
- 🛠 JSON / raw / urlencoded data support
|
|
20
|
-
- 📦 tiny package size (
|
|
20
|
+
- 📦 tiny package size (675B)
|
|
21
21
|
- 🔥 no dependencies
|
|
22
|
-
-
|
|
22
|
+
- ✨ [tinyhttp](https://github.com/tinyhttp/tinyhttp) and Express support
|
|
23
|
+
- ⚡ 30% faster than body-parser
|
|
23
24
|
|
|
24
25
|
## Install
|
|
25
26
|
|
|
@@ -108,6 +109,6 @@ The parsec is a unit of length used to measure large distances to astronomical o
|
|
|
108
109
|
[npm-url]: https://www.npmjs.com/package/milliparsec
|
|
109
110
|
[dl-badge-url]: https://img.shields.io/npm/dt/milliparsec?style=for-the-badge&color=25608B
|
|
110
111
|
[github-actions]: https://github.com/talentlessguy/milliparsec/actions
|
|
111
|
-
[gh-actions-img]: https://img.shields.io/github/workflow/status/
|
|
112
|
+
[gh-actions-img]: https://img.shields.io/github/actions/workflow/status/tinyhttp/milliparsec/main.yml?branch=master&style=for-the-badge&color=25608B&label=&logo=github
|
|
112
113
|
[cov-img]: https://img.shields.io/coveralls/github/tinyhttp/milliparsec?style=for-the-badge&color=25608B
|
|
113
114
|
[cov-url]: https://coveralls.io/github/tinyhttp/milliparsec
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
import { ServerResponse as Response
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export declare type ReqWithBody<T = any> = IncomingMessage & {
|
|
1
|
+
import type { EventEmitter } from 'node:events';
|
|
2
|
+
import type { IncomingMessage, ServerResponse as Response } from 'node:http';
|
|
3
|
+
type NextFunction = (err?: any) => void;
|
|
4
|
+
export type ReqWithBody<T = any> = IncomingMessage & {
|
|
6
5
|
body?: T;
|
|
7
6
|
} & EventEmitter;
|
|
8
7
|
export declare const hasBody: (method: string) => boolean;
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
const hasBody = (method) => ['POST', 'PUT', 'PATCH', 'DELETE'].includes(method);
|
|
1
|
+
export const hasBody = (method) => ['POST', 'PUT', 'PATCH', 'DELETE'].includes(method);
|
|
2
2
|
// Main function
|
|
3
|
-
const p = (fn) => async (req, _res, next) => {
|
|
3
|
+
export const p = (fn) => async (req, _res, next) => {
|
|
4
4
|
try {
|
|
5
5
|
let body = '';
|
|
6
6
|
for await (const chunk of req)
|
|
@@ -18,7 +18,7 @@ const custom = (fn) => async (req, _res, next) => {
|
|
|
18
18
|
};
|
|
19
19
|
const json = () => async (req, res, next) => {
|
|
20
20
|
if (hasBody(req.method)) {
|
|
21
|
-
req.body = await p((x) => JSON.parse(x.toString()))(req, res, next);
|
|
21
|
+
req.body = await p((x) => (x ? JSON.parse(x.toString()) : {}))(req, res, next);
|
|
22
22
|
next();
|
|
23
23
|
}
|
|
24
24
|
else
|
|
@@ -51,5 +51,4 @@ const urlencoded = () => async (req, res, next) => {
|
|
|
51
51
|
else
|
|
52
52
|
next();
|
|
53
53
|
};
|
|
54
|
-
|
|
55
|
-
export { custom, hasBody, json, p, raw, text, urlencoded };
|
|
54
|
+
export { custom, json, raw, text, urlencoded };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "milliparsec",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "tiniest body parser in the universe",
|
|
5
5
|
"repository": "https://github.com/talentlessguy/parsec.git",
|
|
6
6
|
"author": "talentlessguy <pilll.PL22@gmail.com>",
|
|
@@ -14,28 +14,26 @@
|
|
|
14
14
|
"body-parsing"
|
|
15
15
|
],
|
|
16
16
|
"engines": {
|
|
17
|
-
"node": ">=12.
|
|
17
|
+
"node": ">=12.20"
|
|
18
18
|
},
|
|
19
19
|
"exports": "./dist/index.js",
|
|
20
20
|
"devDependencies": {
|
|
21
|
-
"@
|
|
22
|
-
"@tinyhttp/app": "^2.
|
|
23
|
-
"@types/node": "^
|
|
24
|
-
"c8": "
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"typescript": "^4.5.5",
|
|
30
|
-
"uvu": "^0.5.3"
|
|
21
|
+
"@biomejs/biome": "1.8.3",
|
|
22
|
+
"@tinyhttp/app": "^2.2.4",
|
|
23
|
+
"@types/node": "^20.14.9",
|
|
24
|
+
"c8": "10.1.2",
|
|
25
|
+
"supertest-fetch": "^2.0.0",
|
|
26
|
+
"tsm": "^2.3.0",
|
|
27
|
+
"typescript": "^5.5.3",
|
|
28
|
+
"uvu": "^0.5.6"
|
|
31
29
|
},
|
|
32
30
|
"files": [
|
|
33
31
|
"dist"
|
|
34
32
|
],
|
|
35
33
|
"scripts": {
|
|
36
|
-
"test": "
|
|
34
|
+
"test": "uvu -r tsm",
|
|
37
35
|
"test:coverage": "c8 --include=src pnpm test",
|
|
38
36
|
"test:report": "c8 report --reporter=text-lcov > coverage.lcov",
|
|
39
|
-
"build": "
|
|
37
|
+
"build": "tsc -p tsconfig.build.json"
|
|
40
38
|
}
|
|
41
39
|
}
|