unprint 0.18.11 → 0.18.12

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.
Files changed (3) hide show
  1. package/README.md +1 -0
  2. package/package.json +1 -1
  3. package/src/app.js +11 -11
package/README.md CHANGED
@@ -228,6 +228,7 @@ Options
228
228
  * `select`: Pre-query and initialize a specific element on the page.
229
229
  * `selectAll`: Pre-query and initialize multiple specific element on the page.
230
230
  * `interface`: Use undici `fetch` (browser-like, default) or `request` (raw)
231
+ * `form`: Encode POST body as urlencoded form rather than JSON
231
232
  * `userAgent`: The default user agent header
232
233
  * `browserUserAgent`: The default user agent header for browser-like requests (`get` interface `fetch` and `browserRequest`)
233
234
  * `apiUserAgent`: The default user agent header for raw requests (`get` interface `request`)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unprint",
3
- "version": "0.18.11",
3
+ "version": "0.18.12",
4
4
  "description": "Simplify common web scraping tasks while staying in control of the data.",
5
5
  "main": "src/app.js",
6
6
  "scripts": {},
package/src/app.js CHANGED
@@ -1433,21 +1433,21 @@ async function browserRequest(url, customOptions = {}) {
1433
1433
  });
1434
1434
  }
1435
1435
 
1436
- function curateRequestBody(body) {
1436
+ function curateRequestBody(body, options) {
1437
1437
  if (!body) {
1438
1438
  return { body };
1439
1439
  }
1440
1440
 
1441
- if (body instanceof undici.FormData) {
1442
- return {
1443
- body: qs.stringify(body),
1444
- headers: {
1445
- 'content-type': 'application/x-www-form-urlencoded',
1446
- },
1447
- };
1448
- }
1449
-
1450
1441
  if (typeof body === 'object') {
1442
+ if (options.form) {
1443
+ return {
1444
+ body: qs.stringify(body),
1445
+ headers: {
1446
+ 'content-type': 'application/x-www-form-urlencoded',
1447
+ },
1448
+ };
1449
+ }
1450
+
1451
1451
  return {
1452
1452
  body: JSON.stringify(body),
1453
1453
  headers: {
@@ -1485,7 +1485,7 @@ async function request(url, body, customOptions = {}, method = 'GET', redirects
1485
1485
 
1486
1486
  events.emit('requestInit', feedbackBase);
1487
1487
 
1488
- const curatedBody = curateRequestBody(body);
1488
+ const curatedBody = curateRequestBody(body, options);
1489
1489
  const curatedCookie = getCookie(options);
1490
1490
 
1491
1491
  const headers = curateHeaders({