metascraper-x 5.45.6-0

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/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright © 2019 Microlink <hello@microlink.io> (microlink.io)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,46 @@
1
+ <div align="center">
2
+ <br>
3
+ <img style="width: 500px; margin:3rem 0 1.5rem;" src="https://metascraper.js.org/static/logo-banner.png" alt="metascraper">
4
+ <br>
5
+ <br>
6
+ <p align="center"><strong>metascraper-x</strong>: Metascraper integration for x.com.</p>
7
+ <p align="center">See our <a href="https://metascraper.js.org" target='_blank' rel='noopener noreferrer'>website</a> for more information.</p>
8
+ <br>
9
+ </div>
10
+
11
+ ## Install
12
+
13
+ ```bash
14
+ $ npm install metascraper-x --save
15
+ ```
16
+
17
+ ## API
18
+
19
+ ### metascraper-x([options])
20
+
21
+ #### options
22
+
23
+ ##### gotOpts
24
+
25
+ Type: `object`
26
+
27
+ Any option provided here will passed to [got#options](https://github.com/sindresorhus/got#options).
28
+
29
+ ##### resolveUrls
30
+
31
+ Type: `boolean`
32
+
33
+ Set to `true` if you want to resolve `t.co` URLs into the final URL.
34
+
35
+ ##### resolveUrl
36
+
37
+ Type: `function`
38
+
39
+ A decorator to be called after `t.co` is resolved. It doesn't do anything by default.
40
+
41
+ ## License
42
+
43
+ **metascraper-x** © [Microlink](https://microlink.io), released under the [MIT](https://github.com/microlinkhq/metascraper/blob/master/LICENSE.md) License.<br>
44
+ Authored and maintained by [Microlink](https://microlink.io) with help from [contributors](https://github.com/microlinkhq/metascraper/contributors).
45
+
46
+ > [microlink.io](https://microlink.io) · GitHub [microlinkhq](https://github.com/microlinkhq) · Twitter [@microlinkhq](https://twitter.com/microlinkhq)
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "metascraper-x",
3
+ "description": "Metascraper integration for x.com",
4
+ "homepage": "https://github.com/microlinkhq/metascraper/packages/metascraper-x",
5
+ "version": "5.45.6-0",
6
+ "types": "src/index.d.ts",
7
+ "main": "src/index.js",
8
+ "author": {
9
+ "email": "hello@microlink.io",
10
+ "name": "microlink.io",
11
+ "url": "https://microlink.io"
12
+ },
13
+ "repository": {
14
+ "directory": "packages/metascraper-x",
15
+ "type": "git",
16
+ "url": "git+https://github.com/microlinkhq/metascraper.git"
17
+ },
18
+ "bugs": {
19
+ "url": "https://github.com/microlinkhq/metascraper/issues"
20
+ },
21
+ "keywords": [
22
+ "audio",
23
+ "metascraper",
24
+ "spotify"
25
+ ],
26
+ "dependencies": {
27
+ "@metascraper/helpers": "^5.45.6",
28
+ "get-urls": "~10.0.1"
29
+ },
30
+ "devDependencies": {
31
+ "ava": "5"
32
+ },
33
+ "engines": {
34
+ "node": ">= 16"
35
+ },
36
+ "files": [
37
+ "src"
38
+ ],
39
+ "license": "MIT",
40
+ "scripts": {
41
+ "test": "NODE_PATH=.. TZ=UTC ava --timeout 15s"
42
+ }
43
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ declare function rules(): import('metascraper').Rules;
2
+ export = rules;
package/src/index.js ADDED
@@ -0,0 +1,87 @@
1
+ 'use strict'
2
+
3
+ const reachableUrl = require('reachable-url')
4
+ const getUrls = require('get-urls')
5
+
6
+ const {
7
+ author,
8
+ image,
9
+ memoizeOne,
10
+ parseUrl,
11
+ title,
12
+ toRule,
13
+ description,
14
+ url
15
+ } = require('@metascraper/helpers')
16
+
17
+ const toAuthor = toRule(author)
18
+ const toImage = toRule(image)
19
+ const toTitle = toRule(title)
20
+ const toDescription = toRule(description)
21
+ const toUrl = toRule(url)
22
+
23
+ const test = memoizeOne(url =>
24
+ ['twitter', 'x'].includes(parseUrl(url).domainWithoutSuffix)
25
+ )
26
+
27
+ module.exports = ({
28
+ gotOpts,
29
+ resolveUrls = false,
30
+ resolveUrl = url => url
31
+ } = {}) => {
32
+ const rules = {
33
+ author: [
34
+ toAuthor($ => {
35
+ const author = $('meta[property="og:title"]').attr('content')
36
+ return author?.includes(' on X') ? author.split(' on X')[0] : author
37
+ })
38
+ ],
39
+ title: [toTitle(($, url) => `@${url.split('/')[3]} on X`)],
40
+ url: [
41
+ toUrl($ =>
42
+ $('link[rel="canonical"]').attr('href').replace('twitter.com', 'x.com')
43
+ )
44
+ ],
45
+ description: [
46
+ toDescription(async $ => {
47
+ let description = $('meta[property="og:description"]').attr('content')
48
+ if (!resolveUrls) return description
49
+
50
+ const urls = Array.from(getUrls(description))
51
+
52
+ const resolvedUrls = await Promise.all(
53
+ urls.map(async url => {
54
+ const response = await reachableUrl(url, gotOpts)
55
+ if (reachableUrl.isReachable(response)) {
56
+ return resolveUrl(response.url)
57
+ }
58
+ return url
59
+ })
60
+ )
61
+
62
+ for (const [index, url] of resolvedUrls.entries()) {
63
+ const original = urls[index]
64
+ description = description.replace(original, url)
65
+ }
66
+
67
+ return description
68
+ })
69
+ ],
70
+ image: [
71
+ toImage($ => {
72
+ let imageUrl = $('meta[property="og:image"]').attr('content')
73
+ if (imageUrl.endsWith('_200x200.jpg')) {
74
+ imageUrl = imageUrl.replace('_200x200.jpg', '_400x400.jpg')
75
+ }
76
+ return imageUrl
77
+ })
78
+ ],
79
+ publisher: () => 'X'
80
+ }
81
+
82
+ rules.test = ({ url }) => test(url)
83
+
84
+ return rules
85
+ }
86
+
87
+ module.exports.test = test