@fastify/formbody
Advanced tools
Comparing version 7.3.0 to 7.4.0
'use strict' | ||
const fp = require('fastify-plugin') | ||
const { parse } = require('fast-querystring') | ||
const { parse: defaultParser } = require('fast-querystring') | ||
function defaultParser (str) { | ||
return parse(str) | ||
} | ||
function formBodyPlugin (fastify, options, next) { | ||
function fastifyFormbody (fastify, options, next) { | ||
const opts = Object.assign({ parser: defaultParser }, options) | ||
@@ -29,5 +25,7 @@ if (typeof opts.parser !== 'function') { | ||
module.exports = fp(formBodyPlugin, { | ||
module.exports = fp(fastifyFormbody, { | ||
fastify: '4.x', | ||
name: '@fastify/formbody' | ||
}) | ||
module.exports.default = fastifyFormbody | ||
module.exports.fastifyFormbody = fastifyFormbody |
{ | ||
"name": "@fastify/formbody", | ||
"version": "7.3.0", | ||
"version": "7.4.0", | ||
"description": "A module for Fastify to parse x-www-form-urlencoded bodies", | ||
@@ -35,3 +35,3 @@ "main": "formbody.js", | ||
"fastify": "^4.0.0-rc.2", | ||
"form-auto-content": "^2.2.0", | ||
"form-auto-content": "^3.0.0", | ||
"qs": "^6.5.1", | ||
@@ -41,3 +41,3 @@ "snazzy": "^9.0.0", | ||
"tap": "^16.0.0", | ||
"tsd": "^0.23.0" | ||
"tsd": "^0.24.1" | ||
}, | ||
@@ -44,0 +44,0 @@ "dependencies": { |
import { FastifyPluginCallback } from 'fastify' | ||
export interface FormBodyPluginOptions { | ||
bodyLimit?: number | ||
parser?: (str: string) => Record<string, unknown> | ||
type FastifyFormbody = FastifyPluginCallback<fastifyFormbody.FastifyFormbodyOptions> | ||
declare namespace fastifyFormbody { | ||
export interface FastifyFormbodyOptions { | ||
bodyLimit?: number | ||
parser?: (str: string) => Record<string, unknown> | ||
} | ||
/** | ||
* @deprecated Use FastifyFormbodyOptions instead | ||
*/ | ||
export type FormBodyPluginOptions = FastifyFormbodyOptions | ||
export const fastifyFormbody: FastifyFormbody | ||
export { fastifyFormbody as default } | ||
} | ||
declare const formBodyPlugin: FastifyPluginCallback<FormBodyPluginOptions>; | ||
export default formBodyPlugin | ||
declare function fastifyFormbody(...params: Parameters<FastifyFormbody>): ReturnType<FastifyFormbody> | ||
export = fastifyFormbody |
import fastify from 'fastify' | ||
import querystring from 'querystring' | ||
import formBodyPlugin, { FormBodyPluginOptions } from '..' | ||
import { expectDeprecated, expectError, expectType } from 'tsd' | ||
import formBodyPlugin, { FastifyFormbodyOptions, FormBodyPluginOptions } from '..' | ||
@@ -8,13 +9,13 @@ const app = fastify() | ||
const emptyOpts: FormBodyPluginOptions = {} | ||
app.register(formBodyPlugin, emptyOpts) | ||
const bodyLimitOpts: FormBodyPluginOptions = { | ||
app.register(formBodyPlugin, { }) | ||
app.register(formBodyPlugin, { | ||
bodyLimit: 1000 | ||
} | ||
app.register(formBodyPlugin, bodyLimitOpts) | ||
}) | ||
app.register(formBodyPlugin, { | ||
parser: (s) => querystring.parse(s) | ||
}) | ||
const parserOpts: FormBodyPluginOptions = { | ||
parser: (s) => querystring.parse(s) | ||
} | ||
app.register(formBodyPlugin, parserOpts) | ||
expectType<FormBodyPluginOptions>({} as FastifyFormbodyOptions) | ||
expectDeprecated({} as FormBodyPluginOptions) | ||
expectError(app.register(formBodyPlugin, { invalid: true })) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14305
210