Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,3 @@ jobs:
- name: Run Biome
run: biome ci .
- run: pnpm publish --no-git-checks
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@
"source.fixAll": "explicit",
"source.organizeImports.biome": "explicit"
},
"typescript.tsdk": "node_modules/typescript/lib"
"typescript.tsdk": "node_modules/typescript/lib",
"[typescript]": {
"editor.defaultFormatter": "biomejs.biome"
}
}
7 changes: 4 additions & 3 deletions bench/formidable.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { createReadStream } from 'node:fs'
// @ts-check

import { createReadStream } from 'node:fs'
import { createServer } from 'node:http'
import formidable from 'formidable'

const form = formidable({})

const server = createServer((req, res) => {
form.parse(req, (_, fields, files) => {
// @ts-expect-error this is JS
form.parse(req, (_, _fields, files) => {
// @ts-expect-error the file is guaaranteed in payload
const file = createReadStream(files.file[0].filepath)
file.pipe(res)
})
Expand Down
3 changes: 2 additions & 1 deletion bench/milliparsec-multipart.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

import { createServer } from 'node:http'
import * as bodyParser from '../dist/index.js'

const mw = bodyParser.multipart()

const server = createServer((req, res) => {
mw(req, res, () => {
/**
* @type {File}
*/
// @ts-ignore
// @ts-expect-error
const file = req.body.file[0]
const stream = file.stream()

Expand Down
6 changes: 3 additions & 3 deletions bench/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
"author": "",
"license": "ISC",
"devDependencies": {
"@types/body-parser": "^1.19.5",
"@types/body-parser": "^1.19.6",
"@types/formidable": "^3.4.5",
"autocannon": "^8.0.0",
"body-parser": "^1.20.3"
"body-parser": "^2.2.0"
},
"dependencies": {
"formidable": "^3.5.2"
"formidable": "^3.5.4"
}
}
388 changes: 231 additions & 157 deletions bench/pnpm-lock.yaml

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions biome.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://biomejs.dev/schemas/1.8.2/schema.json",
"$schema": "https://biomejs.dev/schemas/2.2.2/schema.json",
"files": {
"ignore": ["node_modules", "dist", "coverage", ".pnpm-store", "package.json"]
"includes": ["**", "!node_modules", "!dist", "!coverage"]
},
"formatter": {
"enabled": true,
Expand All @@ -12,7 +12,6 @@
"lineWidth": 120,
"attributePosition": "auto"
},
"organizeImports": { "enabled": true },
"linter": {
"enabled": true,
"rules": {
Expand All @@ -32,7 +31,6 @@
},
"javascript": {
"formatter": {
"jsxQuoteStyle": "double",
"quoteProperties": "asNeeded",
"trailingCommas": "none",
"semicolons": "asNeeded",
Expand Down
24 changes: 24 additions & 0 deletions migration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Migrating from body-parser

| API | body-parser | milliparsec |
| ------------------------------------------------ | ----------- | ---------------------------------- |
| `inflate` option | ✅ | ❌ |
| `limit` option | ✅ | ✅ (`payloadLimit` in milliparsec) |
| `verify` option | ✅ | ❌ |
| `type` option | ✅ | ✅ (`type` in milliparsec)* |
| `raw()` | ✅ | ✅ |
| `json()` | ✅ | ✅ |
| `json()` `reviver` option | ✅ | ✅ |
| `urlencoded()` | ✅ | ✅ |
| `urlencoded()` `parameterLimit` option | ✅ | ❌ |
| `urlencoded()` `extended` option | ✅ | ❌ |
| `urlencoded()` `defaultCharset` option | ✅ | ❌ |
| `urlencoded()` `charsetSentinel` option | ✅ | ❌ |
| `urlencoded()` `interpretNumericEntities` option | ✅ | ❌ |
| `urlencoded()` `depth` option | ✅ | ❌ |

\* The `type` option can be a string or a function. `milliparsec` does not
depend on the `type-is` package and does not support wildcard MIME strings (for
example `*/json`). It only does a simple string comparisong of the first part of
the `Content-Type` header. Unlike body-parser, milliparsec does not set default
`type` on parsers.
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
},
"exports": "./dist/index.js",
"devDependencies": {
"@biomejs/biome": "1.9.3",
"@biomejs/biome": "2.2.2",
"@tinyhttp/app": "^2.4.0",
"@types/express": "^5.0.3",
"@types/node": "^18.19.76",
"c8": "10.1.2",
"express": "^5.1.0",
"supertest-fetch": "^2.0.0",
"tsx": "^4.19.1",
"typescript": "^5.6.2"
Expand All @@ -40,8 +42,5 @@
"prepublishOnly": "pnpm build && pnpm test",
"check": "biome check --write"
},
"packageManager": "[email protected]",
"publishConfig": {
"provenance": true
}
"packageManager": "[email protected]"
}
Loading
Loading