metascraper 5.40.0 → 5.42.5
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 +11 -4
- package/src/index.d.ts +96 -33
package/package.json
CHANGED
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
"name": "metascraper",
|
|
3
3
|
"description": "A library to easily scrape metadata from an article on the web using Open Graph, JSON+LD, regular HTML metadata, and series of fallbacks.",
|
|
4
4
|
"homepage": "https://metascraper.js.org",
|
|
5
|
-
"version": "5.
|
|
5
|
+
"version": "5.42.5",
|
|
6
6
|
"main": "src/index.js",
|
|
7
|
+
"types": "src/index.d.ts",
|
|
7
8
|
"repository": {
|
|
8
9
|
"type": "git",
|
|
9
10
|
"url": "git+https://github.com/microlinkhq/metascraper.git"
|
|
@@ -57,13 +58,14 @@
|
|
|
57
58
|
"website"
|
|
58
59
|
],
|
|
59
60
|
"dependencies": {
|
|
60
|
-
"@metascraper/helpers": "^5.
|
|
61
|
+
"@metascraper/helpers": "^5.42.5",
|
|
61
62
|
"cheerio": "~1.0.0-rc.12",
|
|
62
63
|
"lodash": "~4.17.21",
|
|
63
64
|
"whoops": "~4.1.4"
|
|
64
65
|
},
|
|
65
66
|
"devDependencies": {
|
|
66
|
-
"ava": "5"
|
|
67
|
+
"ava": "5",
|
|
68
|
+
"tsd": "latest"
|
|
67
69
|
},
|
|
68
70
|
"engines": {
|
|
69
71
|
"node": ">= 16"
|
|
@@ -72,6 +74,8 @@
|
|
|
72
74
|
"src"
|
|
73
75
|
],
|
|
74
76
|
"scripts": {
|
|
77
|
+
"lint": "tsd",
|
|
78
|
+
"pretest": "npm run lint",
|
|
75
79
|
"test": "NODE_PATH=.. TZ=UTC ava --timeout 15s"
|
|
76
80
|
},
|
|
77
81
|
"license": "MIT",
|
|
@@ -79,5 +83,8 @@
|
|
|
79
83
|
"failFast": true,
|
|
80
84
|
"timeout": "5m"
|
|
81
85
|
},
|
|
82
|
-
"
|
|
86
|
+
"tsd": {
|
|
87
|
+
"directory": "test/types"
|
|
88
|
+
},
|
|
89
|
+
"gitHead": "044f875812fff95bba404baad18c087eb154b7b0"
|
|
83
90
|
}
|
package/src/index.d.ts
CHANGED
|
@@ -1,39 +1,102 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
export interface MetascraperOptions {
|
|
2
|
+
/**
|
|
3
|
+
* The URL associated with the HTML markup.
|
|
4
|
+
* It is used for resolve relative links that can be present in the HTML markup.
|
|
5
|
+
* it can be used as fallback field for different rules as well.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
url: string;
|
|
9
|
+
/**
|
|
10
|
+
* The HTML markup for extracting the content.
|
|
11
|
+
*/
|
|
12
|
+
html?: string;
|
|
13
|
+
/**
|
|
14
|
+
* You can pass additional rules to add on execution time.
|
|
15
|
+
* These rules will be merged with your loaded rules at the beginning.
|
|
16
|
+
*/
|
|
17
|
+
rules?: Rules[];
|
|
18
|
+
/**
|
|
19
|
+
* Ensure the URL provided is validated as a WHATWG URL API compliant.
|
|
20
|
+
*/
|
|
21
|
+
validateUrl?: boolean;
|
|
22
|
+
}
|
|
12
23
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
24
|
+
export interface Metadata {
|
|
25
|
+
/**
|
|
26
|
+
* Get audio property from HTML markup
|
|
27
|
+
* The package [metascraper-audio](https://example.com/metascraper-audio) needs to be loaded.
|
|
28
|
+
*/
|
|
29
|
+
audio?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Get author property from HTML markup.
|
|
32
|
+
* The package [metascraper-author](https://example.com/metascraper-author) needs to be loaded.
|
|
33
|
+
*/
|
|
34
|
+
author?: string;
|
|
35
|
+
/**
|
|
36
|
+
* Get date property from HTML markup.
|
|
37
|
+
* The package [metascraper-date](https://example.com/metascraper-date) needs to be loaded.
|
|
38
|
+
*/
|
|
39
|
+
date?: string;
|
|
40
|
+
/**
|
|
41
|
+
* Get description property from HTML markup.
|
|
42
|
+
* The package [metascraper-description](https://example.com/metascraper-description) needs to be loaded.
|
|
43
|
+
*/
|
|
44
|
+
description?: string;
|
|
45
|
+
/**
|
|
46
|
+
* Get image property from HTML markup.
|
|
47
|
+
* The package [metascraper-image](https://example.com/metascraper-image) needs to be loaded.
|
|
48
|
+
*/
|
|
49
|
+
image?: string;
|
|
50
|
+
/**
|
|
51
|
+
* Get lang property from HTML markup
|
|
52
|
+
* The package [metascraper-lang](https://example.com/metascraper-lang) needs to be loaded.
|
|
53
|
+
*/
|
|
54
|
+
lang?: string;
|
|
55
|
+
/**
|
|
56
|
+
* Get logo property from HTML markup
|
|
57
|
+
* The package [metascraper-logo](https://example.com/metascraper-logo) needs to be loaded.
|
|
58
|
+
*/
|
|
59
|
+
logo?: string;
|
|
60
|
+
/**
|
|
61
|
+
* Get publisher property from HTML markup
|
|
62
|
+
* The package [metascraper-publisher](https://example.com/metascraper-publisher) needs to be loaded.
|
|
63
|
+
*/
|
|
64
|
+
publisher?: string;
|
|
65
|
+
/**
|
|
66
|
+
* Get title property from HTML markup
|
|
67
|
+
* The package [metascraper-title](https://example.com/metascraper-title) needs to be loaded.
|
|
68
|
+
*/
|
|
69
|
+
title?: string;
|
|
70
|
+
/**
|
|
71
|
+
* Get url property from HTML markup
|
|
72
|
+
* The package [metascraper-url](https://example.com/metascraper-url) needs to be loaded.
|
|
73
|
+
*/
|
|
74
|
+
url?: string;
|
|
75
|
+
/**
|
|
76
|
+
* Get video property from HTML markup
|
|
77
|
+
* The package [metascraper-video](https://example.com/metascraper-video) needs to be loaded.
|
|
78
|
+
*/
|
|
79
|
+
video?: string;
|
|
80
|
+
[key: string]: string | undefined;
|
|
81
|
+
}
|
|
22
82
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
83
|
+
export type Rules = {
|
|
84
|
+
[C in keyof Metadata]?: Array<RulesOptions> | RulesOptions;
|
|
85
|
+
} & {
|
|
86
|
+
test?: (options: RulesTestOptions) => boolean;
|
|
87
|
+
};
|
|
28
88
|
|
|
29
|
-
|
|
89
|
+
export type RulesOptions = (options: RulesTestOptions) => string | null | undefined;
|
|
30
90
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
91
|
+
export interface RulesTestOptions {
|
|
92
|
+
htmlDom: import('cheerio').CheerioAPI;
|
|
93
|
+
url: string;
|
|
35
94
|
}
|
|
36
95
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
96
|
+
export type Metascraper = (options: MetascraperOptions) => Promise<Metadata>;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* It creates a [metascraper](https://metascraper.js.org/) instance, declaring the rules bundle to be used explicitly.
|
|
100
|
+
* @param rules - The [rules bundles](https://metascraper.js.org/#/?id=rules-bundles) to be applied for metadata extraction.
|
|
101
|
+
*/
|
|
102
|
+
export default function createMetascraper(rules: Rules[]): Metascraper;
|