formidable
Advanced tools
Comparing version 2.0.0-canary.20200129.2 to 2.0.0-canary.20200129.3
{ | ||
"name": "formidable", | ||
"version": "2.0.0-canary.20200129.2", | ||
"version": "2.0.0-canary.20200129.3", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "description": "A node.js module for parsing form data, especially file uploads.", |
@@ -186,3 +186,4 @@ <p align="center"> | ||
Parses an incoming Node.js `request` containing form data. If `callback` is provided, all fields and files are collected and passed to the callback: | ||
Parses an incoming Node.js `request` containing form data. | ||
If `callback` is provided, all fields and files are collected and passed to the callback. | ||
@@ -202,2 +203,54 @@ ```js | ||
In the example below, we listen on couple of events and direct them to the `data` listener, | ||
so you can do whatever you choose there, based on whether its before the file been emitted, | ||
the header value, the header name, on field, on file and etc. | ||
Or the other way could be to just override the `form.onPart` as it's shown a bit later. | ||
```js | ||
form.once('error', console.error); | ||
form.on('fileBegin', (filename, file) => { | ||
form.emit('data', { name: 'fileBegin', filename, value: file }); | ||
}); | ||
form.on('file', (filename, file) => { | ||
form.emit('data', { name: 'file', key: filename, value: file }); | ||
}); | ||
form.on('field', (fieldName, fieldValue) => { | ||
form.emit('data', { name: 'field', key: fieldName, value: fieldValue }); | ||
}); | ||
form.once('end', () => { | ||
console.log('Done!'); | ||
}); | ||
// If you want to customize whatever you want... | ||
form.on('data', ({ name, key, value, buffer, start, end, ...more }) => { | ||
if (name === 'partBegin') { | ||
} | ||
if (name === 'partData') { | ||
} | ||
if (name === 'headerField') { | ||
} | ||
if (name === 'headerValue') { | ||
} | ||
if (name === 'headerEnd') { | ||
} | ||
if (name === 'headersEnd') { | ||
} | ||
if (name === 'field') { | ||
console.log('field name:', key); | ||
console.log('field value:', value); | ||
} | ||
if (name === 'file') { | ||
console.log('file:', key, value); | ||
} | ||
if (name === 'fileBegin') { | ||
console.log('fileBegin:', key, value); | ||
} | ||
}); | ||
``` | ||
### form.onPart | ||
@@ -256,3 +309,3 @@ | ||
// If hash calculation was set, you can read the hex digest out of this var. | ||
// If `options.hash` calculation was set, you can read the hex digest out of this var. | ||
file.hash: string | 'sha1' | 'md5' | 'sha256' | null; | ||
@@ -259,0 +312,0 @@ } |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
51292
402
0