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 +1 -1
- package/src/app.js +7 -7
- package/tests/init.js +1 -0
package/package.json
CHANGED
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(
|
|
456
|
-
if (!
|
|
455
|
+
function extractJson(dataString) {
|
|
456
|
+
if (!dataString) {
|
|
457
457
|
return null;
|
|
458
458
|
}
|
|
459
459
|
|
|
460
460
|
try {
|
|
461
|
-
return JSON.parse(
|
|
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
|
|
468
|
+
const dataString = queryContent(context, selector, customOptions);
|
|
469
469
|
|
|
470
|
-
return extractJson(
|
|
470
|
+
return extractJson(dataString);
|
|
471
471
|
}
|
|
472
472
|
|
|
473
473
|
function queryJsons(context, selector, customOptions) {
|
|
474
|
-
const
|
|
474
|
+
const dataStrings = queryContents(context, selector, customOptions);
|
|
475
475
|
|
|
476
|
-
return
|
|
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'));
|