unprint 0.18.8 → 0.18.11

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/app.js +22 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unprint",
3
- "version": "0.18.8",
3
+ "version": "0.18.11",
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
@@ -783,11 +783,11 @@ function extractDateAgo(dateString, customOptions) {
783
783
  }
784
784
 
785
785
  const options = {
786
- match: /(\d+)\s*(\w+)/,
786
+ match: /(\d+)\s*(\w+)/i,
787
787
  ...customOptions,
788
788
  };
789
789
 
790
- const timeMatch = dateString.match(options.match);
790
+ const timeMatch = dateString.toLowerCase().match(options.match);
791
791
 
792
792
  if (timeMatch) {
793
793
  const [n, period] = timeMatch.slice(1);
@@ -1114,6 +1114,22 @@ function curateHeaders(headers, options) {
1114
1114
  return headers;
1115
1115
  }
1116
1116
 
1117
+ function curateCookies(headers) {
1118
+ const setCookie = typeof headers.get === 'function'
1119
+ ? headers.get('set-cookie')
1120
+ : headers['set-cookie'];
1121
+
1122
+ if (setCookie) {
1123
+ try {
1124
+ return cookie.parseCookie(setCookie);
1125
+ } catch (_error) {
1126
+ // invalid cookie
1127
+ }
1128
+ }
1129
+
1130
+ return null;
1131
+ }
1132
+
1117
1133
  function curateResponse(res, data, options, { url, control, customOptions }) {
1118
1134
  const base = {
1119
1135
  ok: true,
@@ -1121,6 +1137,7 @@ function curateResponse(res, data, options, { url, control, customOptions }) {
1121
1137
  status: res.statusCode || res.status,
1122
1138
  statusText: res.statusText,
1123
1139
  headers: res.headers,
1140
+ cookies: curateCookies(res.headers),
1124
1141
  response: res,
1125
1142
  res,
1126
1143
  control,
@@ -1355,6 +1372,7 @@ async function browserRequest(url, customOptions = {}) {
1355
1372
  status,
1356
1373
  statusText,
1357
1374
  headers,
1375
+ cookies: curateCookies(headers),
1358
1376
  response: res,
1359
1377
  res,
1360
1378
  };
@@ -1380,6 +1398,7 @@ async function browserRequest(url, customOptions = {}) {
1380
1398
  status,
1381
1399
  statusText,
1382
1400
  headers,
1401
+ cookies: curateCookies(headers),
1383
1402
  response: res,
1384
1403
  res,
1385
1404
  };
@@ -1521,6 +1540,7 @@ async function request(url, body, customOptions = {}, method = 'GET', redirects
1521
1540
  status,
1522
1541
  statusText: res.statusText,
1523
1542
  headers: res.headers,
1543
+ cookies: curateCookies(res.headers),
1524
1544
  response: res,
1525
1545
  res,
1526
1546
  };