Skip to content

Commit e658324

Browse files
authored
feat: don't promote IncomingForm; support exports.default (esm) (#529)
* chore: support `exports.default` * Update README.md * chore: update changelog Signed-off-by: Charlike Mike Reagent <[email protected]>
1 parent 2ba6d2a commit e658324

File tree

3 files changed

+28
-21
lines changed

3 files changed

+28
-21
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
* 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))
88
* possible partial fix of [#386](https://github.com/node-formidable/node-formidable/pull/386) with #380 (need tests and better implementation)
99
* use hasOwnProperty in check against files/fields ([#522](https://github.com/node-formidable/node-formidable/pull/522))
10+
* do not promote `IncomingForm` and add `exports.default` ([#529](https://github.com/node-formidable/node-formidable/pull/529))
11+
* Improve examples and tests ([#523](https://github.com/node-formidable/node-formidable/pull/523))
12+
* First step of Code quality improvements ([#525](https://github.com/node-formidable/node-formidable/pull/525))
1013

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

README.md

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,40 +34,41 @@ This is a low-level package, and if you're using a high-level framework it may a
3434
Parse an incoming file upload.
3535

3636
```js
37-
var formidable = require('formidable'),
38-
http = require('http'),
39-
util = require('util');
37+
const http = require('http');
38+
const util = require('util');
39+
const Formidable = require('formidable');
4040

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

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

5252
return;
5353
}
5454

5555
// show a file upload form
56-
res.writeHead(200, {'content-type': 'text/html'});
57-
res.end(
58-
'<form action="/upload" enctype="multipart/form-data" method="post">'+
59-
'<input type="text" name="title"><br>'+
60-
'<input type="file" name="upload" multiple="multiple"><br>'+
61-
'<input type="submit" value="Upload">'+
62-
'</form>'
63-
);
56+
res.writeHead(200, { 'content-type': 'text/html' });
57+
res.end(`
58+
<form action="/upload" enctype="multipart/form-data" method="post">
59+
<input type="text" name="title" /><br/>
60+
<input type="file" name="upload" multiple="multiple" /><br/>
61+
<input type="submit" value="Upload" />
62+
</form>
63+
`);
6464
}).listen(8080);
6565
```
66+
6667
## API
6768

68-
### Formidable.IncomingForm
69+
### Formidable
6970
```javascript
70-
var form = new formidable.IncomingForm()
71+
const form = new Formidable()
7172
```
7273
Creates a new incoming form.
7374

lib/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
var IncomingForm = require('./incoming_form').IncomingForm;
1+
const { IncomingForm } = require('./incoming_form');
2+
23
IncomingForm.IncomingForm = IncomingForm;
3-
module.exports = IncomingForm;
4+
5+
exports.default = IncomingForm;
6+
module.exports = exports.default;

0 commit comments

Comments
 (0)