metascraper 5.54.0 → 5.54.1
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.d.ts +7 -9
- package/src/rules.js +5 -6
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "metascraper",
|
|
3
3
|
"description": "Scrape metadata from any URL using Open Graph, JSON-LD, HTML meta tags, and smart fallbacks.",
|
|
4
4
|
"homepage": "https://metascraper.js.org",
|
|
5
|
-
"version": "5.54.
|
|
5
|
+
"version": "5.54.1",
|
|
6
6
|
"types": "src/index.d.ts",
|
|
7
7
|
"main": "src/index.js",
|
|
8
8
|
"repository": {
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"unfurl"
|
|
28
28
|
],
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@metascraper/helpers": "5.54.
|
|
30
|
+
"@metascraper/helpers": "5.54.1",
|
|
31
31
|
"cheerio": "~1.2.0",
|
|
32
32
|
"debug-logfmt": "~1.4.12",
|
|
33
33
|
"whoops": "~5.1.2"
|
|
@@ -55,5 +55,5 @@
|
|
|
55
55
|
"tsd": {
|
|
56
56
|
"directory": "test/types"
|
|
57
57
|
},
|
|
58
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "9f72883982e1c5486f2b3dbc6fa4d7958885e518"
|
|
59
59
|
}
|
package/src/index.d.ts
CHANGED
|
@@ -34,6 +34,11 @@ declare namespace createMetascraper {
|
|
|
34
34
|
* Ensure the URL provided is validated as a WHATWG URL API compliant.
|
|
35
35
|
*/
|
|
36
36
|
validateUrl?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Runs inside `findRule` after each rule produces a value. Falsy or throw
|
|
39
|
+
* rejects that candidate and continues with the next rule.
|
|
40
|
+
*/
|
|
41
|
+
validate?: Validate;
|
|
37
42
|
/**
|
|
38
43
|
* A Set of property names to omit from the metadata extraction process.
|
|
39
44
|
* These properties will be filtered out before processing the rules.
|
|
@@ -116,8 +121,8 @@ declare namespace createMetascraper {
|
|
|
116
121
|
export type Test = (options: RulesTestOptions) => boolean;
|
|
117
122
|
|
|
118
123
|
/**
|
|
119
|
-
*
|
|
120
|
-
*
|
|
124
|
+
* Scrape-level check inside `findRule`. Falsy or throw rejects the candidate
|
|
125
|
+
* and continues with the next rule.
|
|
121
126
|
*/
|
|
122
127
|
export type Validate = (
|
|
123
128
|
value: string,
|
|
@@ -142,11 +147,6 @@ declare namespace createMetascraper {
|
|
|
142
147
|
* The test function to be executed for skipping rules that doesn't return `true`.
|
|
143
148
|
*/
|
|
144
149
|
test?: Test;
|
|
145
|
-
/**
|
|
146
|
-
* Copied onto each rule in the bundle. Runs after a rule produces a value;
|
|
147
|
-
* falsy or throw rejects that candidate and continues.
|
|
148
|
-
*/
|
|
149
|
-
validate?: Validate;
|
|
150
150
|
/**
|
|
151
151
|
* The package name associated with the rule, used for debugging purposes.
|
|
152
152
|
*/
|
|
@@ -160,7 +160,6 @@ declare namespace createMetascraper {
|
|
|
160
160
|
| Array<RulesOptions>
|
|
161
161
|
| RulesOptions
|
|
162
162
|
| Test
|
|
163
|
-
| Validate
|
|
164
163
|
| string
|
|
165
164
|
| undefined;
|
|
166
165
|
}
|
|
@@ -172,7 +171,6 @@ declare namespace createMetascraper {
|
|
|
172
171
|
| undefined
|
|
173
172
|
| Promise<string | null | undefined>;
|
|
174
173
|
test?: Test;
|
|
175
|
-
validate?: Validate;
|
|
176
174
|
pkgName?: string;
|
|
177
175
|
}
|
|
178
176
|
|
package/src/rules.js
CHANGED
|
@@ -2,10 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
const castArray = value => (Array.isArray(value) ? value : [value])
|
|
4
4
|
|
|
5
|
-
const attachRuleMeta = (rules, test,
|
|
5
|
+
const attachRuleMeta = (rules, test, pkgName) => {
|
|
6
6
|
for (const rule of rules) {
|
|
7
7
|
if (test) rule.test = test
|
|
8
|
-
if (validate) rule.validate = validate
|
|
9
8
|
if (pkgName) rule.pkgName = pkgName
|
|
10
9
|
}
|
|
11
10
|
}
|
|
@@ -13,10 +12,10 @@ const attachRuleMeta = (rules, test, validate, pkgName) => {
|
|
|
13
12
|
const loadRules = rulesBundle => {
|
|
14
13
|
const acc = {}
|
|
15
14
|
|
|
16
|
-
for (const { test,
|
|
15
|
+
for (const { test, pkgName, validate: _validate, ...rules } of rulesBundle) {
|
|
17
16
|
for (const [propName, innerRules] of Object.entries(rules)) {
|
|
18
17
|
const processedRules = castArray(innerRules)
|
|
19
|
-
attachRuleMeta(processedRules, test,
|
|
18
|
+
attachRuleMeta(processedRules, test, pkgName)
|
|
20
19
|
|
|
21
20
|
if (acc[propName]) {
|
|
22
21
|
acc[propName].push(...processedRules)
|
|
@@ -61,12 +60,12 @@ const mergeRules = (
|
|
|
61
60
|
return Object.entries(result)
|
|
62
61
|
}
|
|
63
62
|
|
|
64
|
-
for (const { test,
|
|
63
|
+
for (const { test, pkgName, validate: _validate, ...ruleSet } of rules) {
|
|
65
64
|
for (const [propName, innerRules] of Object.entries(ruleSet)) {
|
|
66
65
|
if (!shouldIncludeProp(propName)) continue
|
|
67
66
|
|
|
68
67
|
const processedRules = castArray(innerRules)
|
|
69
|
-
attachRuleMeta(processedRules, test,
|
|
68
|
+
attachRuleMeta(processedRules, test, pkgName)
|
|
70
69
|
|
|
71
70
|
if (result[propName]) {
|
|
72
71
|
result[propName] = processedRules.concat(result[propName])
|