Skip to content

Commit

Permalink
feat: don't promote IncomingForm; support exports.default (esm) (#529)
Browse files Browse the repository at this point in the history
* chore: support `exports.default`

* Update README.md

* chore: update changelog

Signed-off-by: Charlike Mike Reagent <opensource@tunnckocore.com>
  • Loading branch information
tunnckoCore committed Dec 6, 2019
1 parent 2ba6d2a commit e658324
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 21 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
* Array support for fields and files ([#380](https://github.com/node-formidable/node-formidable/pull/380), [#340](https://github.com/node-formidable/node-formidable/pull/340), [#367](https://github.com/node-formidable/node-formidable/pull/367), [#33](https://github.com/node-formidable/node-formidable/issues/33), [#498](https://github.com/node-formidable/node-formidable/issues/498), [#280](https://github.com/node-formidable/node-formidable/issues/280), [#483](https://github.com/node-formidable/node-formidable/issues/483))
* possible partial fix of [#386](https://github.com/node-formidable/node-formidable/pull/386) with #380 (need tests and better implementation)
* use hasOwnProperty in check against files/fields ([#522](https://github.com/node-formidable/node-formidable/pull/522))
* do not promote `IncomingForm` and add `exports.default` ([#529](https://github.com/node-formidable/node-formidable/pull/529))
* Improve examples and tests ([#523](https://github.com/node-formidable/node-formidable/pull/523))
* First step of Code quality improvements ([#525](https://github.com/node-formidable/node-formidable/pull/525))

### v1.2.1 (2018-03-20)

Expand Down
39 changes: 20 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,40 +34,41 @@ This is a low-level package, and if you're using a high-level framework it may a
Parse an incoming file upload.

```js
var formidable = require('formidable'),
http = require('http'),
util = require('util');
const http = require('http');
const util = require('util');
const Formidable = require('formidable');

http.createServer(function(req, res) {
if (req.url == '/upload' && req.method.toLowerCase() == 'post') {
http.createServer((req, res) => {
if (req.url === '/upload' && req.method.toLowerCase() === 'post') {
// parse a file upload
var form = new formidable.IncomingForm();
const form = new Formidable();

form.parse(req, function(err, fields, files) {
res.writeHead(200, {'content-type': 'text/plain'});
form.parse(req, (err, fields, files) => {
res.writeHead(200, { 'content-type': 'text/plain' });
res.write('received upload:\n\n');
res.end(util.inspect({fields: fields, files: files}));
res.end(util.inspect({ fields: fields, files: files }));
});

return;
}

// show a file upload form
res.writeHead(200, {'content-type': 'text/html'});
res.end(
'<form action="/upload" enctype="multipart/form-data" method="post">'+
'<input type="text" name="title"><br>'+
'<input type="file" name="upload" multiple="multiple"><br>'+
'<input type="submit" value="Upload">'+
'</form>'
);
res.writeHead(200, { 'content-type': 'text/html' });
res.end(`
<form action="/upload" enctype="multipart/form-data" method="post">
<input type="text" name="title" /><br/>
<input type="file" name="upload" multiple="multiple" /><br/>
<input type="submit" value="Upload" />
</form>
`);
}).listen(8080);
```

## API

### Formidable.IncomingForm
### Formidable
```javascript
var form = new formidable.IncomingForm()
const form = new Formidable()
```
Creates a new incoming form.

Expand Down
7 changes: 5 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
var IncomingForm = require('./incoming_form').IncomingForm;
const { IncomingForm } = require('./incoming_form');

IncomingForm.IncomingForm = IncomingForm;
module.exports = IncomingForm;

exports.default = IncomingForm;
module.exports = exports.default;

0 comments on commit e658324

Please sign in to comment.