added doga

This commit is contained in:
szabomarton
2025-02-25 09:55:29 +01:00
parent 5174ab4cc4
commit 13254e5623
1149 changed files with 80161 additions and 0 deletions

21
25_02_24/node_modules/milliparsec/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2019 v 1 r t l
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

121
25_02_24/node_modules/milliparsec/README.md generated vendored Normal file
View File

@@ -0,0 +1,121 @@
<div align="center">
<br /><br /><br />
<img src="logo.png" width="400px" />
<br /><br />
![Vulnerabilities][vulns-badge-url]
[![Version][v-badge-url]][npm-url] [![Coverage][cov-img]][cov-url] [![Github actions][gh-actions-img]][github-actions] [![Downloads][dl-badge-url]][npm-url]
</div>
<br />
Tiniest body parser in the universe. Built for modern Node.js.
Check out [deno-libs/parsec](https://github.com/deno-libs/parsec) for Deno port.
## Features
- ⏩ built with `async` / `await`
- 🛠 JSON / raw / urlencoded data support
- 📦 tiny package size (8KB dist size)
- 🔥 no dependencies
- ✨ [tinyhttp](https://github.com/tinyhttp/tinyhttp) and Express support
- ⚡ 30% faster than body-parser
## Install
```sh
# pnpm
pnpm i milliparsec
# bun
bun i milliparsec
```
## Usage
### Basic example
Use a middleware inside a server:
```js
import { createServer } from 'node:http'
import { json } from 'milliparsec'
const server = createServer(async (req: ReqWithBody, res) => {
await json()(req, res, (err) => void err && console.log(err))
res.setHeader('Content-Type', 'application/json')
res.end(JSON.stringify(req.body))
})
```
### Web frameworks integration
#### tinyhttp
```ts
import { App } from '@tinyhttp/app'
import { urlencoded } from 'milliparsec'
new App()
.use(urlencoded())
.post('/', (req, res) => void res.send(req.body))
.listen(3000, () => console.log(`Started on http://localhost:3000`))
```
## API
### `raw(req, res, cb)`
Minimal body parsing without any formatting.
### `text(req, res, cb)`
Converts request body to string.
### `urlencoded(req, res, cb)`
Parses request body using `new URLSearchParams`.
### `json(req, res, cb)`
Parses request body using `JSON.parse`.
### `multipart(req, res, cb)`
Parses request body using `multipart/form-data` content type and boundary. Supports files as well.
```js
// curl -F "textfield=textfield" -F "someother=textfield with text" localhost:3000
await multipart()(req, res, (err) => void err && console.log(err))
res.end(req.body) // { textfield: "textfield", someother: "textfield with text" }
```
### `custom(fn)(req, res, cb)`
Custom function for `parsec`.
```js
// curl -d "this text must be uppercased" localhost:3000
await custom(
req,
(d) => d.toUpperCase(),
(err) => {}
)
res.end(req.body) // "THIS TEXT MUST BE UPPERCASED"
```
### What is "parsec"?
The parsec is a unit of length used to measure large distances to astronomical objects outside the Solar System.
[vulns-badge-url]: https://img.shields.io/snyk/vulnerabilities/npm/milliparsec.svg?style=for-the-badge&color=25608B&label=vulns
[v-badge-url]: https://img.shields.io/npm/v/milliparsec.svg?style=for-the-badge&color=25608B&logo=npm&label=
[npm-url]: https://www.npmjs.com/package/milliparsec
[dl-badge-url]: https://img.shields.io/npm/dt/milliparsec?style=for-the-badge&color=25608B
[github-actions]: https://github.com/talentlessguy/milliparsec/actions
[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
[cov-img]: https://img.shields.io/coveralls/github/tinyhttp/milliparsec?style=for-the-badge&color=25608B
[cov-url]: https://coveralls.io/github/tinyhttp/milliparsec

15
25_02_24/node_modules/milliparsec/dist/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,15 @@
import type { EventEmitter } from 'node:events';
import type { IncomingMessage, ServerResponse as Response } from 'node:http';
type NextFunction = (err?: any) => void;
export type ReqWithBody<T = any> = IncomingMessage & {
body?: T;
} & EventEmitter;
export declare const hasBody: (method: string) => boolean;
export declare const p: <T = any>(fn: (body: any) => any) => (req: ReqWithBody<T>, _res: Response, next: (err?: any) => void) => Promise<any>;
declare const custom: <T = any>(fn: (body: any) => any) => (req: ReqWithBody, _res: Response, next: NextFunction) => Promise<void>;
declare const json: () => (req: ReqWithBody, res: Response, next: NextFunction) => Promise<void>;
declare const raw: () => (req: ReqWithBody, _res: Response, next: NextFunction) => Promise<void>;
declare const text: () => (req: ReqWithBody, _res: Response, next: NextFunction) => Promise<void>;
declare const urlencoded: () => (req: ReqWithBody, res: Response, next: NextFunction) => Promise<void>;
declare const multipart: () => (req: ReqWithBody, res: Response, next: NextFunction) => Promise<void>;
export { custom, json, raw, text, urlencoded, multipart };

87
25_02_24/node_modules/milliparsec/dist/index.js generated vendored Normal file
View File

@@ -0,0 +1,87 @@
export const hasBody = (method) => ['POST', 'PUT', 'PATCH', 'DELETE'].includes(method);
export const p = (fn) => async (req, _res, next) => {
try {
let body = '';
for await (const chunk of req)
body += chunk;
return fn(body);
}
catch (e) {
next(e);
}
};
const custom = (fn) => async (req, _res, next) => {
req.body = await p(fn)(req, _res, next);
next();
};
const json = () => async (req, res, next) => {
if (hasBody(req.method)) {
req.body = await p((x) => (x ? JSON.parse(x.toString()) : {}))(req, res, next);
next();
}
else
next();
};
const raw = () => async (req, _res, next) => {
if (hasBody(req.method)) {
req.body = await p((x) => x)(req, _res, next);
next();
}
else
next();
};
const text = () => async (req, _res, next) => {
if (hasBody(req.method)) {
req.body = await p((x) => x.toString())(req, _res, next);
next();
}
else
next();
};
const urlencoded = () => async (req, res, next) => {
if (hasBody(req.method)) {
req.body = await p((x) => {
const urlSearchParam = new URLSearchParams(x.toString());
return Object.fromEntries(urlSearchParam.entries());
})(req, res, next);
next();
}
else
next();
};
const getBoundary = (contentType) => {
const match = /boundary=(.+);?/.exec(contentType);
return match ? `--${match[1]}` : null;
};
const parseMultipart = (body, boundary) => {
const parts = body.split(new RegExp(`${boundary}(--)?`)).filter((part) => !!part && /content-disposition/i.test(part));
const parsedBody = {};
parts.map((part) => {
const [headers, ...lines] = part.split('\r\n').filter((part) => !!part);
const data = lines.join('\r\n').trim();
const name = /name="(.+?)"/.exec(headers)[1];
const filename = /filename="(.+?)"/.exec(headers);
if (filename) {
const contentTypeMatch = /Content-Type: (.+)/i.exec(data);
const fileContent = data.slice(contentTypeMatch[0].length + 2);
return Object.assign(parsedBody, {
[name]: new File([fileContent], filename[1], { type: contentTypeMatch[1] })
});
}
return Object.assign(parsedBody, { [name]: data });
});
return parsedBody;
};
const multipart = () => async (req, res, next) => {
if (hasBody(req.method)) {
req.body = await p((x) => {
const boundary = getBoundary(req.headers['content-type']);
if (boundary)
return parseMultipart(x, boundary);
})(req, res, next);
next();
}
else
next();
};
export { custom, json, raw, text, urlencoded, multipart };

44
25_02_24/node_modules/milliparsec/package.json generated vendored Normal file
View File

@@ -0,0 +1,44 @@
{
"name": "milliparsec",
"version": "4.0.0",
"description": "tiniest body parser in the universe",
"repository": {
"type": "git",
"url": "https://github.com/tinyhttp/milliparsec"
},
"author": "talentlessguy <hi@v1rtl.site>",
"license": "MIT",
"types": "./dist/index.d.ts",
"type": "module",
"keywords": [
"body-parser",
"express",
"http",
"body-parsing"
],
"engines": {
"node": ">=20"
},
"exports": "./dist/index.js",
"devDependencies": {
"@biomejs/biome": "1.8.3",
"@types/node": "^20.14.9",
"c8": "10.1.2",
"supertest-fetch": "^2.0.0",
"tsm": "^2.3.0",
"typescript": "^5.5.3",
"uvu": "^0.5.6"
},
"files": [
"dist"
],
"publishConfig": {
"provenance": true
},
"scripts": {
"test": "uvu -r tsm",
"test:coverage": "c8 --include=src pnpm test",
"test:report": "c8 report --reporter=text-lcov > coverage.lcov",
"build": "tsc -p tsconfig.build.json"
}
}