@metascraper/helpers 5.29.6 → 5.29.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.
- package/index.js +38 -24
- package/package.json +4 -4
package/index.js
CHANGED
|
@@ -150,9 +150,19 @@ const titleize = (src, opts = {}) => {
|
|
|
150
150
|
return title
|
|
151
151
|
}
|
|
152
152
|
|
|
153
|
-
const $filter = ($,
|
|
154
|
-
|
|
155
|
-
|
|
153
|
+
const $filter = ($, matchedEl, fn = $filter.fn) => {
|
|
154
|
+
let matched
|
|
155
|
+
|
|
156
|
+
matchedEl.each(function () {
|
|
157
|
+
const result = fn($(this))
|
|
158
|
+
|
|
159
|
+
if (result) {
|
|
160
|
+
matched = result
|
|
161
|
+
return false
|
|
162
|
+
}
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
return matched
|
|
156
166
|
}
|
|
157
167
|
|
|
158
168
|
$filter.fn = el => condenseWhitespace(el.text())
|
|
@@ -227,7 +237,7 @@ const author = (value, opts) =>
|
|
|
227
237
|
isAuthor(value) ? getAuthor(value, opts) : undefined
|
|
228
238
|
|
|
229
239
|
const url = (value, { url = '' } = {}) => {
|
|
230
|
-
if (isEmpty(value)) return
|
|
240
|
+
if (isEmpty(value)) return
|
|
231
241
|
|
|
232
242
|
try {
|
|
233
243
|
const absoluteUrl = normalizeUrl(url, value)
|
|
@@ -242,7 +252,7 @@ const getISODate = date =>
|
|
|
242
252
|
|
|
243
253
|
const date = value => {
|
|
244
254
|
if (isDate(value)) return value.toISOString()
|
|
245
|
-
if (!(isString(value) || isNumber(value))) return
|
|
255
|
+
if (!(isString(value) || isNumber(value))) return
|
|
246
256
|
|
|
247
257
|
// remove whitespace for easier parsing
|
|
248
258
|
if (isString(value)) value = condenseWhitespace(value)
|
|
@@ -278,7 +288,7 @@ const date = value => {
|
|
|
278
288
|
}
|
|
279
289
|
|
|
280
290
|
const lang = input => {
|
|
281
|
-
if (isEmpty(input) || !isString(input)) return
|
|
291
|
+
if (isEmpty(input) || !isString(input)) return
|
|
282
292
|
const key = toLower(condenseWhitespace(input))
|
|
283
293
|
if (input.length === 3) return iso6393[key]
|
|
284
294
|
const lang = toLower(key.substring(0, 2))
|
|
@@ -397,34 +407,38 @@ const composeRule = rule => ({ from, to = from, ...opts }) => async ({
|
|
|
397
407
|
const has = value =>
|
|
398
408
|
value !== undefined && !Number.isNaN(value) && hasValues(value)
|
|
399
409
|
|
|
400
|
-
const
|
|
401
|
-
new Promise(resolve =>
|
|
402
|
-
dom.window.document.readyState === 'interactive' ||
|
|
403
|
-
dom.window.document.readyState === 'complete'
|
|
404
|
-
? resolve()
|
|
405
|
-
: dom.window.document.addEventListener('DOMContentLoaded', resolve)
|
|
406
|
-
)
|
|
407
|
-
|
|
408
|
-
const loadIframe = (url, html) =>
|
|
410
|
+
const loadIframe = (url, $, { timeout = 5000 } = {}) =>
|
|
409
411
|
new Promise(resolve => {
|
|
410
|
-
const dom = new JSDOM(html, {
|
|
412
|
+
const dom = new JSDOM($.html(), {
|
|
411
413
|
url,
|
|
412
414
|
virtualConsole: new VirtualConsole(),
|
|
413
415
|
runScripts: 'dangerously',
|
|
414
416
|
resources: 'usable'
|
|
415
417
|
})
|
|
416
418
|
|
|
417
|
-
const
|
|
419
|
+
const done = (html = '') => resolve($.load(html))
|
|
420
|
+
|
|
421
|
+
const listen = (element, method, fn) =>
|
|
422
|
+
element[`${method}EventListener`]('load', fn, {
|
|
423
|
+
capture: true,
|
|
424
|
+
once: true,
|
|
425
|
+
passive: true
|
|
426
|
+
})
|
|
418
427
|
|
|
419
|
-
const
|
|
420
|
-
|
|
421
|
-
? iframe.addEventListener('load', () => resolve(iframe.contentWindow))
|
|
422
|
-
: resolve()
|
|
428
|
+
const iframe = dom.window.document.querySelector('iframe')
|
|
429
|
+
if (!iframe) return done()
|
|
423
430
|
|
|
424
|
-
const
|
|
425
|
-
|
|
431
|
+
const timer = setTimeout(() => {
|
|
432
|
+
listen(iframe, 'remove', load)
|
|
433
|
+
done()
|
|
434
|
+
}, timeout)
|
|
435
|
+
|
|
436
|
+
function load () {
|
|
437
|
+
clearTimeout(timer)
|
|
438
|
+
done(iframe.contentDocument.documentElement.outerHTML)
|
|
439
|
+
}
|
|
426
440
|
|
|
427
|
-
|
|
441
|
+
listen(iframe, 'add', load)
|
|
428
442
|
})
|
|
429
443
|
|
|
430
444
|
module.exports = {
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@metascraper/helpers",
|
|
3
3
|
"description": "Collection of helper functions used by metascraper",
|
|
4
4
|
"homepage": "https://nicedoc.io/microlinkhq/metascraper/packages/metascraper-helpers",
|
|
5
|
-
"version": "5.29.
|
|
5
|
+
"version": "5.29.11",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"author": {
|
|
8
8
|
"email": "hello@microlink.io",
|
|
@@ -33,13 +33,13 @@
|
|
|
33
33
|
"is-uri": "~1.2.4",
|
|
34
34
|
"iso-639-3": "~2.2.0",
|
|
35
35
|
"isostring": "0.0.1",
|
|
36
|
-
"jsdom": "~
|
|
36
|
+
"jsdom": "~20.0.0",
|
|
37
37
|
"lodash": "~4.17.21",
|
|
38
38
|
"memoize-one": "~6.0.0",
|
|
39
39
|
"microsoft-capitalize": "~1.0.5",
|
|
40
40
|
"mime-types": "~2.1.35",
|
|
41
41
|
"normalize-url": "~6.1.0",
|
|
42
|
-
"re2": "~1.17.
|
|
42
|
+
"re2": "~1.17.7",
|
|
43
43
|
"smartquotes": "~2.3.2",
|
|
44
44
|
"url-regex-safe": "~3.0.0",
|
|
45
45
|
"video-extensions": "~1.2.0"
|
|
@@ -61,5 +61,5 @@
|
|
|
61
61
|
"publishConfig": {
|
|
62
62
|
"access": "public"
|
|
63
63
|
},
|
|
64
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "1eb987686ff110f16bbba78fc1ee0c881d78684d"
|
|
65
65
|
}
|