unprint 0.18.12 → 0.18.14

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unprint",
3
- "version": "0.18.12",
3
+ "version": "0.18.14",
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
@@ -736,7 +736,7 @@ function extractDate(dateString, format, customOptions) {
736
736
  }
737
737
 
738
738
  const options = {
739
- match: /((\d{1,4}[/-]\d{1,2}[/-]\d{1,4})|(\w+\s+\d{1,2},?\s+\d{4})|(\d{1,2}-\w+-\d{2,4}))((T|\s+)\d{1,2}:\d{2}(:\d{2})?)?/g, // matches any of 01-01-1970, 1970-01-01, 01-Jan-70 and January 1, 1970 with optional 00:00[:00] time
739
+ match: /((\d{1,4}[/-]\d{1,2}[/-]\d{1,4})|(\w+\s+\d{1,2}([a-z]{2})?,?\s+\d{4})|(\d{1,2}-\w+-\d{2,4}))((T|\s+)\d{1,2}:\d{2}(:\d{2})?)?/gi, // matches any of 01-01-1970, 1970-01-01, 01-Jan-70 and January 1, 1970 with optional 00:00[:00] time
740
740
  matchIndex: 0,
741
741
  timezone: 'UTC',
742
742
  ...customOptions,
@@ -1115,15 +1115,17 @@ function curateHeaders(headers, options) {
1115
1115
  }
1116
1116
 
1117
1117
  function curateCookies(headers) {
1118
- const setCookie = typeof headers.get === 'function'
1119
- ? headers.get('set-cookie')
1120
- : headers['set-cookie'];
1118
+ if (headers) {
1119
+ const setCookie = typeof headers.get === 'function'
1120
+ ? headers.get('set-cookie')
1121
+ : headers['set-cookie'];
1121
1122
 
1122
- if (setCookie) {
1123
- try {
1124
- return cookie.parseCookie(setCookie);
1125
- } catch (_error) {
1126
- // invalid cookie
1123
+ if (setCookie) {
1124
+ try {
1125
+ return cookie.parseCookie(setCookie);
1126
+ } catch (_error) {
1127
+ // invalid cookie
1128
+ }
1127
1129
  }
1128
1130
  }
1129
1131
 
@@ -1134,6 +1136,7 @@ function curateResponse(res, data, options, { url, control, customOptions }) {
1134
1136
  const base = {
1135
1137
  ok: true,
1136
1138
  data,
1139
+ body: data,
1137
1140
  status: res.statusCode || res.status,
1138
1141
  statusText: res.statusText,
1139
1142
  headers: res.headers,
@@ -1522,12 +1525,8 @@ async function request(url, body, customOptions = {}, method = 'GET', redirects
1522
1525
  return request(newUrl, body, options, method, redirects + 1);
1523
1526
  }
1524
1527
 
1525
- const data = options.interface === 'fetch'
1526
- ? await res.text()
1527
- : await res.body.text();
1528
-
1529
1528
  if (!(status >= 200 && status < 300)) {
1530
- handleError(new Error(`HTTP response from ${url} not OK (${status} ${res.statusText}): ${data}`), 'HTTP_NOT_OK');
1529
+ handleError(new Error(`HTTP response from ${url} not OK (${status} ${res.statusText})`), 'HTTP_NOT_OK');
1531
1530
 
1532
1531
  events.emit('requestError', {
1533
1532
  ...feedbackBase,
@@ -1546,6 +1545,10 @@ async function request(url, body, customOptions = {}, method = 'GET', redirects
1546
1545
  };
1547
1546
  }
1548
1547
 
1548
+ const data = options.interface === 'fetch'
1549
+ ? await res.text()
1550
+ : await res.body.text();
1551
+
1549
1552
  events.emit('requestSuccess', {
1550
1553
  ...feedbackBase,
1551
1554
  status,
package/tests/init.js CHANGED
@@ -48,7 +48,7 @@ async function initTest() {
48
48
 
49
49
  const proxyRes = await unprint.get('https://api.ipify.org?format=json', {
50
50
  interface: 'request',
51
- useProxy: true,
51
+ useProxy: false,
52
52
  });
53
53
 
54
54
  console.log('JSON RES', jsonRes);