milliparsec 2.2.0 → 2.2.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/README.md +4 -5
- package/dist/index.js +5 -4
- package/package.json +41 -40
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
<br /><br />
|
|
5
5
|
|
|
6
6
|
![Vulnerabilities][vulns-badge-url]
|
|
7
|
-
[![Version][v-badge-url]][npm-url] [![Coverage][
|
|
7
|
+
[![Version][v-badge-url]][npm-url] [![Coverage][cov-img]][cov-url] [![Github actions][gh-actions-img]][github-actions] [![Downloads][dl-badge-url]][npm-url]
|
|
8
8
|
|
|
9
9
|
</div>
|
|
10
10
|
<br />
|
|
@@ -79,7 +79,7 @@ Converts request body to string.
|
|
|
79
79
|
|
|
80
80
|
### `urlencoded(req, res, cb)`
|
|
81
81
|
|
|
82
|
-
Parses request body using `
|
|
82
|
+
Parses request body using `new URLSearchParams`.
|
|
83
83
|
|
|
84
84
|
### `json(req, res, cb)`
|
|
85
85
|
|
|
@@ -109,6 +109,5 @@ The parsec is a unit of length used to measure large distances to astronomical o
|
|
|
109
109
|
[dl-badge-url]: https://img.shields.io/npm/dt/milliparsec?style=for-the-badge&color=25608B
|
|
110
110
|
[github-actions]: https://github.com/talentlessguy/milliparsec/actions
|
|
111
111
|
[gh-actions-img]: https://img.shields.io/github/workflow/status/talentlessguy/milliparsec/CI?style=for-the-badge&color=25608B&label=&logo=github
|
|
112
|
-
[
|
|
113
|
-
[
|
|
114
|
-
[codacy-coverage]: https://img.shields.io/codacy/coverage/f72e0f9927c5489f90a7d0318888a38d?style=for-the-badge&color=25608B
|
|
112
|
+
[cov-img]: https://img.shields.io/coveralls/github/tinyhttp/milliparsec?style=for-the-badge&color=25608B
|
|
113
|
+
[cov-url]: https://coveralls.io/github/tinyhttp/milliparsec
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const hasBody = (method) => ['POST', 'PUT', 'PATCH'].includes(method);
|
|
1
|
+
const hasBody = (method) => ['POST', 'PUT', 'PATCH', 'DELETE'].includes(method);
|
|
4
2
|
// Main function
|
|
5
3
|
const p = (fn) => async (req, _res, next) => {
|
|
6
4
|
try {
|
|
@@ -40,7 +38,10 @@ const text = () => async (req, _res, next) => {
|
|
|
40
38
|
};
|
|
41
39
|
const urlencoded = () => async (req, res, next) => {
|
|
42
40
|
if (hasBody(req.method)) {
|
|
43
|
-
req.body = await p((x) =>
|
|
41
|
+
req.body = await p((x) => {
|
|
42
|
+
const urlSearchParam = new URLSearchParams(x.toString());
|
|
43
|
+
return Object.fromEntries(urlSearchParam.entries());
|
|
44
|
+
})(req, res, next);
|
|
44
45
|
next();
|
|
45
46
|
}
|
|
46
47
|
else
|
package/package.json
CHANGED
|
@@ -1,41 +1,42 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
2
|
+
"name": "milliparsec",
|
|
3
|
+
"version": "2.2.1",
|
|
4
|
+
"description": "tiniest body parser in the universe",
|
|
5
|
+
"repository": "https://github.com/talentlessguy/parsec.git",
|
|
6
|
+
"author": "talentlessguy <pilll.PL22@gmail.com>",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"type": "module",
|
|
10
|
+
"keywords": [
|
|
11
|
+
"body-parser",
|
|
12
|
+
"express",
|
|
13
|
+
"http",
|
|
14
|
+
"body-parsing"
|
|
15
|
+
],
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">=12.4"
|
|
18
|
+
},
|
|
19
|
+
"exports": "./dist/index.js",
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@rollup/plugin-typescript": "6",
|
|
22
|
+
"@tinyhttp/app": "^2.0.16",
|
|
23
|
+
"@types/node": "^17.0.12",
|
|
24
|
+
"c8": "7.11.0",
|
|
25
|
+
"esbuild-node-loader": "^0.6.4",
|
|
26
|
+
"rollup": "^2.66.1",
|
|
27
|
+
"supertest-fetch": "^1.5.0",
|
|
28
|
+
"tslib": "^2.3.1",
|
|
29
|
+
"typescript": "^4.5.5",
|
|
30
|
+
"uvu": "^0.5.3"
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"dist"
|
|
34
|
+
],
|
|
35
|
+
"scripts": {
|
|
36
|
+
"test": "node --experimental-loader esbuild-node-loader test.ts",
|
|
37
|
+
"test:coverage": "c8 --include=src pnpm test",
|
|
38
|
+
"test:report": "c8 report --reporter=text-lcov > coverage.lcov",
|
|
39
|
+
"build": "rollup -c"
|
|
40
|
+
},
|
|
41
|
+
"readme": "<div align=\"center\">\n<br /><br /><br />\n<img src=\"logo.png\" width=\"400px\" />\n<br /><br />\n\n![Vulnerabilities][vulns-badge-url]\n[![Version][v-badge-url]][npm-url] [![Coverage][cov-img]][cov-url] [![Github actions][gh-actions-img]][github-actions] [![Downloads][dl-badge-url]][npm-url]\n\n</div>\n<br />\n\nTiniest body parser in the universe. Built for modern Node.js.\n\nCheck out [deno-libs/parsec](https://github.com/deno-libs/parsec) for Deno port.\n\n## Features\n\n- ⏩ built with `async` / `await`\n- 🛠 JSON / raw / urlencoded data support\n- 📦 tiny package size (728B)\n- 🔥 no dependencies\n- ⚡ [tinyhttp](https://github.com/talentlessguy/tinyhttp) and Express support\n\n## Install\n\n```sh\n# pnpm\npnpm i milliparsec\n\n# yarn\nyarn add milliparsec\n\n# npm\nnpm i milliparsec\n```\n\n## Usage\n\n### Basic example\n\nUse a middleware inside a server:\n\n```js\nimport { createServer } from 'http'\nimport { json } from 'milliparsec'\n\nconst server = createServer(async (req: ReqWithBody, res) => {\n await json()(req, res, (err) => void err && console.log(err))\n\n res.setHeader('Content-Type', 'application/json')\n\n res.end(JSON.stringify(req.body))\n})\n```\n\n### Web frameworks integration\n\n#### tinyhttp\n\n```ts\nimport { App } from '@tinyhttp/app'\nimport { urlencoded } from 'milliparsec'\n\nnew App()\n .use(urlencoded())\n .post('/', (req, res) => void res.send(req.body))\n .listen(3000, () => console.log(`Started on http://localhost:3000`))\n```\n\n## API\n\n### `raw(req, res, cb)`\n\nMinimal body parsing without any formatting.\n\n### `text(req, res, cb)`\n\nConverts request body to string.\n\n### `urlencoded(req, res, cb)`\n\nParses request body using `new URLSearchParams`.\n\n### `json(req, res, cb)`\n\nParses request body using `JSON.parse`.\n\n### `custom(fn)(req, res, cb)`\n\nCustom function for `parsec`.\n\n```js\n// curl -d \"this text must be uppercased\" localhost\nawait custom(\n req,\n (d) => d.toUpperCase(),\n (err) => {}\n)\nres.end(req.body) // \"THIS TEXT MUST BE UPPERCASED\"\n```\n\n### What is \"parsec\"?\n\nThe parsec is a unit of length used to measure large distances to astronomical objects outside the Solar System.\n\n[vulns-badge-url]: https://img.shields.io/snyk/vulnerabilities/npm/milliparsec.svg?style=for-the-badge&color=25608B&label=vulns\n[v-badge-url]: https://img.shields.io/npm/v/milliparsec.svg?style=for-the-badge&color=25608B&logo=npm&label=\n[npm-url]: https://www.npmjs.com/package/milliparsec\n[dl-badge-url]: https://img.shields.io/npm/dt/milliparsec?style=for-the-badge&color=25608B\n[github-actions]: https://github.com/talentlessguy/milliparsec/actions\n[gh-actions-img]: https://img.shields.io/github/workflow/status/talentlessguy/milliparsec/CI?style=for-the-badge&color=25608B&label=&logo=github\n[cov-img]: https://img.shields.io/coveralls/github/tinyhttp/milliparsec?style=for-the-badge&color=25608B\n[cov-url]: https://coveralls.io/github/tinyhttp/milliparsec\n"
|
|
42
|
+
}
|