Skip to content

Commit

Permalink
feat(@nanoexpress/middleware-formidable): add second initialize arg…
Browse files Browse the repository at this point in the history
…ument to middleware
  • Loading branch information
dalisoft committed May 24, 2021
1 parent 37da45e commit 7127ce8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
8 changes: 7 additions & 1 deletion packages/formidable/formidable.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import IncomingForm from '@types/formidable/Formidable';
import { Options } from 'formidable';
import { RequestListener } from 'http';

declare function formidable(options?: Options): Promise<RequestListener>;
declare function formidable(
options?: Options,
initialize?: (formidable: IncomingForm) => void
): Promise<RequestListener>;

export = formidable;
6 changes: 5 additions & 1 deletion packages/formidable/formidable.es.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ import Formidable from 'formidable';
/**
* Formidable plugin
* @param {object} options Formidable options
* @param {Function} initialize **Formidable** instance handler
* @example
* app.use(formidable())
*/
export default function formidable(config = { multiples: true }) {
export default function formidable(config = { multiples: true }, initialize) {
const form = Formidable(config);
if (typeof initialize === 'function') {
initialize(form);
}
return async function formidableHandler(req) {
Object.assign(req.stream, req);
await new Promise((resolve, reject) =>
Expand Down

0 comments on commit 7127ce8

Please sign in to comment.