Socket
Socket
Sign inDemoInstall

formidable

Package Overview
Dependencies
0
Maintainers
10
Versions
78
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.0-canary.20200129.2 to 2.0.0-canary.20200129.3

2

package.json
{
"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 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc