@wooksjs/http-body 0.2.17 → 0.2.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -9,15 +9,14 @@
9
9
  </a>
10
10
  </p>
11
11
 
12
-
13
12
  Wooks Body is composable body parser for [@wooksjs/event-http](https://github.com/wooksjs/wooksjs/tree/main/packages/event-http).
14
13
 
15
14
  Supported content types:
16
15
 
17
- - ✅ application/json
18
- - ✅ text/*
19
- - ✅ multipart/form-data
20
- - ✅ application/x-www-form-urlencoded
16
+ - ✅ application/json
17
+ - ✅ text/\*
18
+ - ✅ multipart/form-data
19
+ - ✅ application/x-www-form-urlencoded
21
20
 
22
21
  Body parser does not parse every request's body. The parsing happens only when you call `parseBody` function.
23
22
 
@@ -36,6 +35,7 @@ app.post('test', async () => {
36
35
  ```
37
36
 
38
37
  ### Additional hooks
38
+
39
39
  ```ts
40
40
  import { useBody } from '@wooksjs/http-body'
41
41
  app.post('test', async () => {
package/dist/index.cjs CHANGED
@@ -16,6 +16,8 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
16
16
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17
17
  PERFORMANCE OF THIS SOFTWARE.
18
18
  ***************************************************************************** */
19
+ /* global Reflect, Promise */
20
+
19
21
 
20
22
  function __awaiter(thisArg, _arguments, P, generator) {
21
23
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
@@ -29,8 +31,8 @@ function __awaiter(thisArg, _arguments, P, generator) {
29
31
 
30
32
  const compressors = {
31
33
  identity: {
32
- compress: v => v,
33
- uncompress: v => v,
34
+ compress: (v) => v,
35
+ uncompress: (v) => v,
34
36
  },
35
37
  };
36
38
  function uncompressBody(encodings, body) {
@@ -69,7 +71,10 @@ function useBody() {
69
71
  }
70
72
  return false;
71
73
  });
72
- const contentEncodings = () => init('contentEncodings', () => (contentEncoding || '').split(',').map(p => p.trim()).filter(p => !!p));
74
+ const contentEncodings = () => init('contentEncodings', () => (contentEncoding || '')
75
+ .split(',')
76
+ .map((p) => p.trim())
77
+ .filter((p) => !!p));
73
78
  const parseBody = () => init('parsed', () => __awaiter(this, void 0, void 0, function* () {
74
79
  const body = yield uncompressBody(contentEncodings(), (yield rawBody()).toString());
75
80
  if (isJson())
@@ -95,7 +100,8 @@ function useBody() {
95
100
  return v;
96
101
  }
97
102
  function formDataParser(v) {
98
- const boundary = '--' + ((/boundary=([^;]+)(?:;|$)/.exec(contentType || '') || [, ''])[1]);
103
+ const boundary = '--' +
104
+ (/boundary=([^;]+)(?:;|$)/.exec(contentType || '') || [, ''])[1];
99
105
  if (!boundary)
100
106
  throw new eventHttp.HttpError(eventHttp.EHttpStatusCode.BadRequest, 'form-data boundary not recognized');
101
107
  const parts = v.trim().split(boundary);
@@ -107,7 +113,10 @@ function useBody() {
107
113
  key = '';
108
114
  partContentType = 'text/plain';
109
115
  let valueMode = false;
110
- const lines = part.trim().split(/\n/g).map(s => s.trim());
116
+ const lines = part
117
+ .trim()
118
+ .split(/\n/g)
119
+ .map((s) => s.trim());
111
120
  for (const line of lines) {
112
121
  if (valueMode) {
113
122
  if (!result[key]) {
@@ -125,7 +134,9 @@ function useBody() {
125
134
  }
126
135
  continue;
127
136
  }
128
- if (line.toLowerCase().startsWith('content-disposition: form-data;')) {
137
+ if (line
138
+ .toLowerCase()
139
+ .startsWith('content-disposition: form-data;')) {
129
140
  key = (/name=([^;]+)/.exec(line) || [])[1];
130
141
  if (!key)
131
142
  throw new eventHttp.HttpError(eventHttp.EHttpStatusCode.BadRequest, 'Could not read multipart name: ' + line);
package/dist/index.mjs CHANGED
@@ -14,6 +14,8 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
14
14
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15
15
  PERFORMANCE OF THIS SOFTWARE.
16
16
  ***************************************************************************** */
17
+ /* global Reflect, Promise */
18
+
17
19
 
18
20
  function __awaiter(thisArg, _arguments, P, generator) {
19
21
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
@@ -27,8 +29,8 @@ function __awaiter(thisArg, _arguments, P, generator) {
27
29
 
28
30
  const compressors = {
29
31
  identity: {
30
- compress: v => v,
31
- uncompress: v => v,
32
+ compress: (v) => v,
33
+ uncompress: (v) => v,
32
34
  },
33
35
  };
34
36
  function uncompressBody(encodings, body) {
@@ -67,7 +69,10 @@ function useBody() {
67
69
  }
68
70
  return false;
69
71
  });
70
- const contentEncodings = () => init('contentEncodings', () => (contentEncoding || '').split(',').map(p => p.trim()).filter(p => !!p));
72
+ const contentEncodings = () => init('contentEncodings', () => (contentEncoding || '')
73
+ .split(',')
74
+ .map((p) => p.trim())
75
+ .filter((p) => !!p));
71
76
  const parseBody = () => init('parsed', () => __awaiter(this, void 0, void 0, function* () {
72
77
  const body = yield uncompressBody(contentEncodings(), (yield rawBody()).toString());
73
78
  if (isJson())
@@ -93,7 +98,8 @@ function useBody() {
93
98
  return v;
94
99
  }
95
100
  function formDataParser(v) {
96
- const boundary = '--' + ((/boundary=([^;]+)(?:;|$)/.exec(contentType || '') || [, ''])[1]);
101
+ const boundary = '--' +
102
+ (/boundary=([^;]+)(?:;|$)/.exec(contentType || '') || [, ''])[1];
97
103
  if (!boundary)
98
104
  throw new HttpError(EHttpStatusCode.BadRequest, 'form-data boundary not recognized');
99
105
  const parts = v.trim().split(boundary);
@@ -105,7 +111,10 @@ function useBody() {
105
111
  key = '';
106
112
  partContentType = 'text/plain';
107
113
  let valueMode = false;
108
- const lines = part.trim().split(/\n/g).map(s => s.trim());
114
+ const lines = part
115
+ .trim()
116
+ .split(/\n/g)
117
+ .map((s) => s.trim());
109
118
  for (const line of lines) {
110
119
  if (valueMode) {
111
120
  if (!result[key]) {
@@ -123,7 +132,9 @@ function useBody() {
123
132
  }
124
133
  continue;
125
134
  }
126
- if (line.toLowerCase().startsWith('content-disposition: form-data;')) {
135
+ if (line
136
+ .toLowerCase()
137
+ .startsWith('content-disposition: form-data;')) {
127
138
  key = (/name=([^;]+)/.exec(line) || [])[1];
128
139
  if (!key)
129
140
  throw new HttpError(EHttpStatusCode.BadRequest, 'Could not read multipart name: ' + line);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wooksjs/http-body",
3
- "version": "0.2.17",
3
+ "version": "0.2.19",
4
4
  "description": "@wooksjs/http-body",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",
@@ -31,7 +31,7 @@
31
31
  "url": "https://github.com/wooksjs/wooksjs/issues"
32
32
  },
33
33
  "peerDependencies": {
34
- "@wooksjs/event-http": "0.2.17"
34
+ "@wooksjs/event-http": "0.2.19"
35
35
  },
36
36
  "homepage": "https://github.com/wooksjs/wooksjs/tree/main/packages/http-body#readme"
37
37
  }