Skip to content

Commit

Permalink
types: add Parser to options (#90)
Browse files Browse the repository at this point in the history
* types: add Parser to options

This is the same change as #61 with the review comments addressed.

* types: add tests for parser types
  • Loading branch information
pmmmwh authored Nov 13, 2021
1 parent 881118b commit 79256d0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions formbody.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { FastifyPlugin } from 'fastify'

export interface FormBodyPluginOptions {
bodyLimit?: number
parser?: (str: string) => Record<string, unknown>
}

declare const formBodyPlugin: FastifyPlugin<FormBodyPluginOptions>
Expand Down
10 changes: 8 additions & 2 deletions formbody.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import fastify from 'fastify'
import querystring from 'querystring'
import formBodyPlugin, { FormBodyPluginOptions } from './formbody'

const app = fastify()
Expand All @@ -7,7 +8,12 @@ app.register(formBodyPlugin)
const emptyOpts: FormBodyPluginOptions = {}
app.register(formBodyPlugin, emptyOpts)

const opts: FormBodyPluginOptions = {
const bodyLimitOpts: FormBodyPluginOptions = {
bodyLimit: 1000
}
app.register(formBodyPlugin, opts)
app.register(formBodyPlugin, bodyLimitOpts)

const parserOpts: FormBodyPluginOptions = {
parser: (s) => querystring.parse(s)
}
app.register(formBodyPlugin, parserOpts)

0 comments on commit 79256d0

Please sign in to comment.