Skip to content

Commit 84a7569

Browse files
committed
Prettier
1 parent e057f63 commit 84a7569

File tree

9 files changed

+3350
-635
lines changed

9 files changed

+3350
-635
lines changed

.github/dependabot.yml

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
version: 2
22
updates:
3-
- package-ecosystem: npm
4-
directory: "/"
5-
schedule:
6-
interval: daily
7-
open-pull-requests-limit: 10
8-
ignore:
9-
- dependency-name: eslint
10-
versions:
11-
- 7.18.0
12-
- 7.19.0
13-
- 7.20.0
14-
- 7.21.0
15-
- 7.22.0
16-
- 7.23.0
17-
- 7.24.0
18-
- dependency-name: mocha
19-
versions:
20-
- 8.3.0
21-
- 8.3.1
3+
- package-ecosystem: npm
4+
directory: '/'
5+
schedule:
6+
interval: daily
7+
open-pull-requests-limit: 10
8+
ignore:
9+
- dependency-name: eslint
10+
versions:
11+
- 7.18.0
12+
- 7.19.0
13+
- 7.20.0
14+
- 7.21.0
15+
- 7.22.0
16+
- 7.23.0
17+
- 7.24.0
18+
- dependency-name: mocha
19+
versions:
20+
- 8.3.0
21+
- 8.3.1

.github/workflows/nodejs.yml

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,25 @@ name: Node.js CI
22

33
on:
44
push:
5-
branches: [ master ]
5+
branches: [master]
66
pull_request:
7-
branches: [ master ]
7+
branches: [master]
88

99
jobs:
1010
build:
11-
1211
runs-on: ubuntu-latest
1312

1413
strategy:
1514
matrix:
1615
node-version: [10.x, 12.x, 14.x]
1716

1817
steps:
19-
- uses: actions/checkout@v2
20-
- name: Use Node.js ${{ matrix.node-version }}
21-
uses: actions/setup-node@v1
22-
with:
23-
node-version: ${{ matrix.node-version }}
24-
- run: npm ci
25-
- run: npm test
26-
env:
27-
CI: true
18+
- uses: actions/checkout@v2
19+
- name: Use Node.js ${{ matrix.node-version }}
20+
uses: actions/setup-node@v1
21+
with:
22+
node-version: ${{ matrix.node-version }}
23+
- run: npm ci
24+
- run: npm test
25+
env:
26+
CI: true

.prettierrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"bracketSpacing": true,
3+
"singleQuote": true,
4+
"trailingComma": "all"
5+
}

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,33 @@
11
# Change Log
2+
23
All notable changes to this project will be documented in this file.
34
This project adheres to [Semantic Versioning](http://semver.org/).
45

56
## [2.0.1] - 2020-12-02
7+
68
### Updated
9+
710
- Update dependencies and test against node 14.
811

912
## [2.0.0] - 2020-03-25
13+
1014
### Fixed
15+
1116
- Ensure `done` callback is not called multiple times #4
1217
- Support bodyparser's 'type' option as function #5
1318

1419
### Breaking
20+
1521
- Remove support for node < 10
1622

1723
## [1.1.0] - 2016-03-18
24+
1825
### Added
26+
1927
- Ability to set a custom `Content-Type` for the expected XML-formatted request.
2028

2129
## 1.0.0 - 2015-12-19
30+
2231
Initial Release.
2332

2433
[2.0.1]: https://github.com/fiznool/body-parser-xml/compare/v2.0.0...v2.0.1

README.md

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ This library adds an `xml` method to the `body-parser` object.
2222

2323
Initialise like so:
2424

25-
``` js
25+
```js
2626
const bodyParser = require('body-parser');
2727
require('body-parser-xml')(bodyParser);
2828
```
2929

3030
Once initialised, you can use it just like any other `body-parser` middleware:
3131

32-
``` js
32+
```js
3333
const app = require('express')();
3434
app.use(bodyParser.xml());
3535
```
@@ -48,7 +48,7 @@ If you need to match against a custom `Content-Type` header, pass in the `type`
4848

4949
You can also pass in options:
5050

51-
``` js
51+
```js
5252
app.use(bodyParser.xml(options));
5353
```
5454

@@ -68,7 +68,7 @@ Controls the maximum request body size. If this is a number, then the value spec
6868

6969
#### type
7070

71-
The type option is used to determine what media type the middleware will parse. This option can be a string, array of strings, or a function. If not a function, type option is passed directly to the type-is library and this can be an extension name (like xml), a mime type (like application/xml), or a mime type with a wildcard (like */* or */xml). If a function, the type option is called as fn(req) and the request is parsed if it returns a truthy value. Defaults to `['*/xml', '+xml']`.
71+
The type option is used to determine what media type the middleware will parse. This option can be a string, array of strings, or a function. If not a function, type option is passed directly to the type-is library and this can be an extension name (like xml), a mime type (like application/xml), or a mime type with a wildcard (like _/_ or _/xml). If a function, the type option is called as fn(req) and the request is parsed if it returns a truthy value. Defaults to `['_/xml', '+xml']`.
7272

7373
#### verify
7474

@@ -80,30 +80,31 @@ This option controls the behaviour of the XML parser. You can pass any option th
8080

8181
## Example
8282

83-
``` js
83+
```js
8484
const express = require('express');
8585
const bodyParser = require('body-parser');
8686

8787
require('body-parser-xml')(bodyParser);
8888

8989
const app = express();
90-
app.use(bodyParser.xml({
91-
limit: '1MB', // Reject payload bigger than 1 MB
92-
xmlParseOptions: {
93-
normalize: true, // Trim whitespace inside text nodes
94-
normalizeTags: true, // Transform tags to lowercase
95-
explicitArray: false // Only put nodes in array if >1
96-
}
97-
}));
98-
99-
app.post('/users', function(req, res, body) {
90+
app.use(
91+
bodyParser.xml({
92+
limit: '1MB', // Reject payload bigger than 1 MB
93+
xmlParseOptions: {
94+
normalize: true, // Trim whitespace inside text nodes
95+
normalizeTags: true, // Transform tags to lowercase
96+
explicitArray: false, // Only put nodes in array if >1
97+
},
98+
}),
99+
);
100+
101+
app.post('/users', function (req, res, body) {
100102
// Any request with an XML payload will be parsed
101103
// and a JavaScript object produced on req.body
102104
// corresponding to the request payload.
103105
console.log(req.body);
104106
res.status(200).end();
105107
});
106-
107108
```
108109

109110
## Motivation

index.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ const xml2js = require('xml2js');
44

55
const DEFAULT_TYPES = ['*/xml', '+xml'];
66

7-
module.exports = function(bodyParser) {
8-
if(bodyParser.xml) {
7+
module.exports = function (bodyParser) {
8+
if (bodyParser.xml) {
99
// We already setup the XML parser.
1010
// End early.
1111
return;
@@ -19,22 +19,26 @@ module.exports = function(bodyParser) {
1919
const textParser = bodyParser.text(options);
2020
return function xmlParser(req, res, next) {
2121
// First, run the body through the text parser.
22-
textParser(req, res, function(err) {
23-
if(err) { return next(err); }
24-
if(typeof req.body !== 'string') { return next(); }
22+
textParser(req, res, function (err) {
23+
if (err) {
24+
return next(err);
25+
}
26+
if (typeof req.body !== 'string') {
27+
return next();
28+
}
2529

2630
// Then, parse as XML.
2731
const xmlParseOptions = {
2832
...options.xmlParseOptions,
2933
// Always opt-in to async mode.
30-
async: true
34+
async: true,
3135
};
3236
const parser = new xml2js.Parser(xmlParseOptions);
3337

3438
// In some cases xml2js.Parser parseString() can throw an error after executing the callback.
3539

36-
parser.parseString(req.body, function(err, xml) {
37-
if(err) {
40+
parser.parseString(req.body, function (err, xml) {
41+
if (err) {
3842
err.status = 400;
3943
return next(err);
4044
}
@@ -50,8 +54,8 @@ module.exports = function(bodyParser) {
5054
Object.defineProperty(bodyParser, 'xml', {
5155
configurable: true,
5256
enumerable: true,
53-
get: function() {
57+
get: function () {
5458
return xml;
55-
}
59+
},
5660
});
5761
};

0 commit comments

Comments
 (0)