unprint 0.9.1 → 0.9.2

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.9.1",
3
+ "version": "0.9.2",
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
@@ -452,28 +452,28 @@ function queryPosters(context, selector = 'video', customOptions) {
452
452
  return posterUrls.map((posterUrl) => prefixUrl(posterUrl, options.origin, options));
453
453
  }
454
454
 
455
- function extractJson(element) {
456
- if (!element) {
455
+ function extractJson(dataString) {
456
+ if (!dataString) {
457
457
  return null;
458
458
  }
459
459
 
460
460
  try {
461
- return JSON.parse(element.innerHTML);
461
+ return JSON.parse(dataString);
462
462
  } catch (error) {
463
463
  return null;
464
464
  }
465
465
  }
466
466
 
467
467
  function queryJson(context, selector, customOptions) {
468
- const target = queryElement(context, selector, customOptions);
468
+ const dataString = queryContent(context, selector, customOptions);
469
469
 
470
- return extractJson(target);
470
+ return extractJson(dataString);
471
471
  }
472
472
 
473
473
  function queryJsons(context, selector, customOptions) {
474
- const targets = queryElements(context, selector, customOptions);
474
+ const dataStrings = queryContents(context, selector, customOptions);
475
475
 
476
- return targets.map((target) => extractJson(target)).filter(Boolean);
476
+ return dataStrings.map((dataString) => extractJson(dataString)).filter(Boolean);
477
477
  }
478
478
 
479
479
  function extractDate(dateString, format, customOptions) {
package/tests/init.js CHANGED
@@ -23,6 +23,7 @@ async function initTest() {
23
23
  console.log('timestamp', res.context.query.duration('#timestamp'));
24
24
  console.log('number', res.context.query.number('.number'));
25
25
  console.log('numbers', res.context.query.numbers('.number'));
26
+ console.log('number indexed', res.context.query.number('.number', { match: /(\d+)/, matchIndex: 1 }));
26
27
  console.log('data', res.context.query.json('#json'));
27
28
  console.log('items', res.context.query.contents('.item'));
28
29
  console.log('link', res.context.query.url('#link'));