@metascraper/helpers 5.49.23 → 5.49.25
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 +3 -3
- package/src/index.js +7 -3
- package/src/load-iframe/index.js +30 -5
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://github.com/microlinkhq/metascraper/packages/metascraper-helpers",
|
|
5
|
-
"version": "5.49.
|
|
5
|
+
"version": "5.49.25",
|
|
6
6
|
"main": "src/index.js",
|
|
7
7
|
"author": {
|
|
8
8
|
"email": "hello@microlink.io",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"cheerio": "latest"
|
|
54
54
|
},
|
|
55
55
|
"engines": {
|
|
56
|
-
"node": ">=
|
|
56
|
+
"node": ">= 22"
|
|
57
57
|
},
|
|
58
58
|
"files": [
|
|
59
59
|
"src"
|
|
@@ -65,5 +65,5 @@
|
|
|
65
65
|
"publishConfig": {
|
|
66
66
|
"access": "public"
|
|
67
67
|
},
|
|
68
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "b656312fda1e8c1cd65b4e92cdf9713a16cfdd3b"
|
|
69
69
|
}
|
package/src/index.js
CHANGED
|
@@ -349,8 +349,10 @@ const title = (value, { removeSeparator = false, ...opts } = {}) =>
|
|
|
349
349
|
const isMime = (contentType, type) =>
|
|
350
350
|
type === get(EXTENSIONS, mimeExtension(contentType))
|
|
351
351
|
|
|
352
|
+
const isSameHtmlDom = (newHtmlDom, oldHtmlDom) => newHtmlDom === oldHtmlDom
|
|
353
|
+
|
|
352
354
|
memoizeOne.EqualityUrlAndHtmlDom = (newArgs, oldArgs) =>
|
|
353
|
-
newArgs[0] === oldArgs[0] && newArgs[1]
|
|
355
|
+
newArgs[0] === oldArgs[0] && isSameHtmlDom(newArgs[1], oldArgs[1])
|
|
354
356
|
|
|
355
357
|
memoizeOne.EqualityFirstArgument = (newArgs, oldArgs) =>
|
|
356
358
|
newArgs[0] === oldArgs[0]
|
|
@@ -378,11 +380,13 @@ const jsonld = memoizeOne(
|
|
|
378
380
|
const { '@graph': graph, ...props } = json
|
|
379
381
|
return Array.isArray(graph)
|
|
380
382
|
? graph.map(item => ({ ...props, ...item }))
|
|
381
|
-
:
|
|
383
|
+
: graph
|
|
384
|
+
? props
|
|
385
|
+
: json
|
|
382
386
|
})
|
|
383
387
|
.get()
|
|
384
388
|
.filter(Boolean),
|
|
385
|
-
(newArgs, oldArgs) => newArgs[0]
|
|
389
|
+
(newArgs, oldArgs) => isSameHtmlDom(newArgs[0], oldArgs[0])
|
|
386
390
|
)
|
|
387
391
|
|
|
388
392
|
const $jsonld = propName => $ => {
|
package/src/load-iframe/index.js
CHANGED
|
@@ -10,12 +10,37 @@ const SCRIPT_PATH = (
|
|
|
10
10
|
|
|
11
11
|
module.exports = (url, $, { timeout = 5000 } = {}) => {
|
|
12
12
|
const worker = new Worker(SCRIPT_PATH(), {
|
|
13
|
-
workerData: { url, html: $.html(), timeout }
|
|
14
|
-
stdout: true,
|
|
15
|
-
stderr: true
|
|
13
|
+
workerData: { url, html: $.html(), timeout }
|
|
16
14
|
})
|
|
17
15
|
const { promise, resolve, reject } = Promise.withResolvers()
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
let settled = false
|
|
17
|
+
|
|
18
|
+
const onMessage = html => {
|
|
19
|
+
if (settled) return
|
|
20
|
+
settled = true
|
|
21
|
+
resolve($.load(html || ''))
|
|
22
|
+
worker.terminate().catch(() => {})
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const onError = error => {
|
|
26
|
+
if (settled) return
|
|
27
|
+
settled = true
|
|
28
|
+
reject(error)
|
|
29
|
+
worker.terminate().catch(() => {})
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const onExit = code => {
|
|
33
|
+
if (settled) return
|
|
34
|
+
settled = true
|
|
35
|
+
if (code === 0) {
|
|
36
|
+
resolve($.load(''))
|
|
37
|
+
return
|
|
38
|
+
}
|
|
39
|
+
reject(new Error(`loadIframe worker exited unexpectedly with code ${code}`))
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
worker.once('message', onMessage)
|
|
43
|
+
worker.once('error', onError)
|
|
44
|
+
worker.once('exit', onExit)
|
|
20
45
|
return promise
|
|
21
46
|
}
|