@unavatar/core 3.7.67 → 3.7.68

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 CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@unavatar/core",
3
3
  "description": "Get unified user avatar from social networks, including Instagram, SoundCloud, Telegram, Twitter, YouTube & more.",
4
4
  "homepage": "https://unavatar.io",
5
- "version": "3.7.67",
5
+ "version": "3.7.68",
6
6
  "main": "src/index.js",
7
7
  "exports": {
8
8
  ".": "./src/index.js",
@@ -2,9 +2,37 @@
2
2
 
3
3
  const { $jsonld } = require('@metascraper/helpers')
4
4
 
5
- module.exports = ({ createHtmlProvider }) =>
5
+ const unescapeUnicode = str =>
6
+ str.replace(/\\u([0-9a-fA-F]{4})/g, (_, hex) =>
7
+ String.fromCharCode(parseInt(hex, 16))
8
+ )
9
+
10
+ const getRscAvatar = $ => {
11
+ let url
12
+ $('script').each((_, el) => {
13
+ const text = $(el).html() || ''
14
+ if (!text.includes('avatarPhotoImageUrls')) return
15
+ const match = text.match(
16
+ /avatarPhotoImageUrls[\s\S]*?\\"original\\":\\"((?:[^\\"]|\\u[0-9a-fA-F]{4})+)/
17
+ )
18
+ if (match) {
19
+ url = unescapeUnicode(match[1])
20
+ return false
21
+ }
22
+ })
23
+ return url
24
+ }
25
+
26
+ const getAvatar = $ =>
27
+ $jsonld('mainEntity.image.contentUrl')($) || getRscAvatar($)
28
+
29
+ const factory = ({ createHtmlProvider }) =>
6
30
  createHtmlProvider({
7
31
  name: 'patreon',
8
32
  url: username => `https://www.patreon.com/${username}`,
9
- getter: $ => $jsonld('mainEntity.image.thumbnailUrl')($)
33
+ getter: getAvatar
10
34
  })
35
+
36
+ factory.getAvatar = getAvatar
37
+
38
+ module.exports = factory