Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Re-create the module with TypeScript (#152)
* refactor: imporve the return type for shouldParseBodyAs method * test: coverage 100% * feat: support the already parsed body * feat: prevent runtime problems * feat: add patchNode option to support patching ctx.req.body * feat: add parsedMethods option to parse only the passed ones * feat: support extra value under the content-type + use async/await over done in testing
- Loading branch information
1 parent
5678a79
commit b89581a
Showing
21 changed files
with
1,146 additions
and
672 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: Continuous Integration | ||
|
||
on: | ||
- push | ||
- pull_request | ||
|
||
jobs: | ||
ci: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
node-version: | ||
- 16 | ||
- 18 | ||
- 20 | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v3 | ||
- name: Install dependencies | ||
run: yarn install | ||
- name: Check linter | ||
run: yarn lint | ||
- name: Run tests | ||
run: yarn test-ci |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"prettier": true, | ||
"space": true, | ||
"extends": [ | ||
"xo-lass" | ||
], | ||
"rules": { | ||
"node/no-deprecated-api": "off", | ||
"no-unused-vars": "off", | ||
"no-prototype-builtins": "off", | ||
"prefer-rest-params": "off", | ||
"n/prefer-global/process": "off", | ||
"@typescript-eslint/restrict-template-expressions": "off", | ||
"@typescript-eslint/naming-convention": "off", | ||
"@typescript-eslint/prefer-nullish-coalescing": "off", | ||
"unicorn/no-array-reduce": "off" | ||
}, | ||
"ignores": [ | ||
"test/**", | ||
"examples/**" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
const Koa = require('koa'); | ||
const bodyParser = require('.'); | ||
const bodyParser = require('../../dist').default; | ||
|
||
const app = new Koa(); | ||
app.use(bodyParser()); | ||
|
||
app.use(async function() { | ||
app.use((ctx) => { | ||
// the parsed body will store in this.request.body | ||
this.body = this.request.body; | ||
ctx.body = ctx.request.body; | ||
}); | ||
|
||
const PORT = process.env.PORT || 3000; | ||
|
||
app.listen(PORT, () => | ||
console.log(`Server ready at http://localhost:${PORT} π ..`) | ||
console.log(`Server ready at http://localhost:${PORT} π ..`), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import Koa from 'koa'; | ||
import bodyParser from '../../dist/index.mjs'; | ||
|
||
const app = new Koa(); | ||
app.use(bodyParser()); | ||
|
||
app.use((ctx) => { | ||
// the parsed body will store in this.request.body | ||
ctx.body = ctx.request.body; | ||
}); | ||
|
||
const PORT = process.env.PORT || 3000; | ||
|
||
app.listen(PORT, () => console.log(`Server ready at http://localhost:${PORT} π ..`)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import Koa from 'koa'; | ||
import {bodyParser} from '../../src'; | ||
|
||
const app = new Koa(); | ||
app.use(bodyParser()); | ||
|
||
app.use((ctx) => { | ||
// the parsed body will store in this.request.body | ||
ctx.body = ctx.request.body; // eslint-disable-line @typescript-eslint/no-unsafe-assignment | ||
}); | ||
|
||
const PORT = process.env.PORT || 3000; | ||
|
||
app.listen(PORT, () => { | ||
console.log(`Server ready at http://localhost:${PORT} π ..`); | ||
}); |
Oops, something went wrong.