Skip to content

Commit ea7d18d

Browse files
authored
feat: migrate to typescript + support node.js 20 and upper + support koa v3 (#98)
1 parent 9a88f97 commit ea7d18d

File tree

12 files changed

+5330
-1754
lines changed

12 files changed

+5330
-1754
lines changed

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
test/*.*.ts
2+
tsup.config.ts

.github/workflows/node.js.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313

1414
strategy:
1515
matrix:
16-
node-version: [18.x, 20.x, 22.x]
16+
node-version: [20.x, 22.x, 24.x]
1717

1818
steps:
1919
- uses: actions/checkout@v2

.gitignore

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,24 @@
1-
.DS_Store*
1+
# OS #
2+
###################
3+
.DS_Store
4+
.idea
5+
Thumbs.db
6+
tmp/
7+
temp/
8+
9+
10+
# Node.js #
11+
###################
212
node_modules
3-
*.log
13+
14+
15+
# Build #
16+
###################
17+
dist
18+
build
19+
20+
# NYC #
21+
###################
422
coverage
23+
*.lcov
24+
.nyc_output

README.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
2-
# Koa Body Parsers
1+
# [**@koa/body-parsers**](https://github.com/koajs/body-parsers)
32

43
[![NPM version][npm-image]][npm-url]
54

@@ -14,21 +13,22 @@ Includes a `json` and `urlencoded` parsers.
1413
Initialization:
1514

1615
```js
17-
import koaBodyParsers from 'koa-body-parsers'
18-
import Koa from 'koa'
16+
// import withBodyParsers from 'koa-body-parsers'
17+
import { withBodyParsers } from "koa-body-parsers";
18+
import Koa from "koa";
1919

20-
const app = new Koa()
21-
koaBodyParsers(app)
20+
const app = new Koa();
21+
withBodyParsers(app);
2222

2323
// example usage
2424
app.use(async (ctx) => {
25-
const currentUser = UserService.getCurrentUser(ctx)
26-
ctx.assert(currentUser, 401)
25+
const currentUser = UserService.getCurrentUser(ctx);
26+
ctx.assert(currentUser, 401);
2727

28-
ctx.assert(ctx.request.is('json'), 415)
29-
const body = await ctx.request.json('100kb')
30-
ctx.body = body
31-
})
28+
ctx.assert(ctx.request.is("json"), 415);
29+
const body = await ctx.request.json("100kb");
30+
ctx.body = body;
31+
});
3232
```
3333

3434
Because this module is a plugin for the `context`, the API signature is different.
@@ -41,8 +41,8 @@ Otherwise, create your server like this:
4141
```js
4242
const fn = app.callback();
4343
const server = http.createServer(); // or whatever server you use
44-
server.on('request', fn); // regular requests
45-
server.on('checkContinue', function (req, res) {
44+
server.on("request", fn); // regular requests
45+
server.on("checkContinue", function (req, res) {
4646
// tag requests with `Expect: 100-continue`
4747
req.checkContinue = true;
4848
fn(req, res);
@@ -57,11 +57,11 @@ but you would still have to call it if you're doing something like:
5757

5858
```js
5959
app.use(async (ctx) => {
60-
if (ctx.request.is('image/*')) {
60+
if (ctx.request.is("image/*")) {
6161
ctx.response.writeContinue();
62-
const buffer = await ctx.request.buffer()
62+
const buffer = await ctx.request.buffer();
6363
}
64-
})
64+
});
6565
```
6666

6767
### const body = await ctx.request.json([limit])

index.js

Lines changed: 0 additions & 87 deletions
This file was deleted.

0 commit comments

Comments
 (0)