@unavatar/core 3.7.76 → 3.7.78

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.76",
5
+ "version": "3.7.78",
6
6
  "main": "src/index.js",
7
7
  "exports": {
8
8
  ".": "./src/index.js",
@@ -1,8 +1,18 @@
1
1
  'use strict'
2
2
 
3
+ const getAvatarUrl = input => {
4
+ const [first, second] = input.split(':')
5
+ const type = second ? first : 'user'
6
+ const id = second ?? first
7
+ const path = type === 'user' ? 'in' : type
8
+ return `https://www.linkedin.com/${path}/${id}`
9
+ }
10
+
3
11
  module.exports = ({ createHtmlProvider, getOgImage }) =>
4
12
  createHtmlProvider({
5
13
  name: 'linkedin',
6
- url: input => `https://www.linkedin.com/in/${input}`,
14
+ url: getAvatarUrl,
7
15
  getter: getOgImage
8
16
  })
17
+
18
+ module.exports.getAvatarUrl = getAvatarUrl
@@ -53,6 +53,7 @@ module.exports = ({ got, isReservedIp }) => {
53
53
  return body?.avatar
54
54
  }
55
55
 
56
- mastodon.parseMastodonInput = parseMastodonInput
57
56
  return mastodon
58
57
  }
58
+
59
+ module.exports.parseMastodonInput = parseMastodonInput
@@ -4,8 +4,7 @@ const { get } = require('lodash')
4
4
 
5
5
  const getAvatarUrl = $ => {
6
6
  const text = $('script[type="application/ld+json"]').contents().text()
7
- if (!text) return
8
- return get(JSON.parse(text), 'mainEntity.image')
7
+ return text ? get(JSON.parse(text), 'mainEntity.image') : undefined
9
8
  }
10
9
 
11
10
  module.exports = ({ createHtmlProvider }) =>
@@ -21,3 +20,5 @@ module.exports = ({ createHtmlProvider }) =>
21
20
  }
22
21
  })
23
22
  })
23
+
24
+ module.exports.getAvatarUrl = getAvatarUrl
@@ -1,20 +1,24 @@
1
1
  'use strict'
2
2
 
3
+ const OPENSTREETMAP_API_URL = 'https://api.openstreetmap.org/api/0.6/user'
4
+
3
5
  const OPENSTREETMAP_USER_ID_REGEX = /^\d+$/
4
6
 
5
7
  module.exports = ({ got, createHtmlProvider }) => {
6
- const fromID = userId =>
7
- got(`https://api.openstreetmap.org/api/0.6/user/${userId}.json`, {
8
- responseType: 'json'
9
- }).then(({ body }) => body?.user?.img?.href)
10
-
11
8
  const fromUsername = createHtmlProvider({
12
9
  name: 'openstreetmap',
13
- url: username => `https://www.openstreetmap.org/user/${encodeURIComponent(username)}`,
10
+ url: username =>
11
+ `https://www.openstreetmap.org/user/${encodeURIComponent(username)}`,
14
12
  getter: $ => $('img.user_image').attr('src')
15
13
  })
16
14
 
17
- return function openstreetmap ({ input }) {
18
- return OPENSTREETMAP_USER_ID_REGEX.test(input) ? fromID(input) : fromUsername(...arguments)
15
+ return function openstreetmap (ctx) {
16
+ return OPENSTREETMAP_USER_ID_REGEX.test(ctx.input)
17
+ ? got(`${OPENSTREETMAP_API_URL}/${ctx.input}.json`, {
18
+ responseType: 'json'
19
+ }).then(({ body }) => body?.user?.img?.href)
20
+ : fromUsername(ctx)
19
21
  }
20
22
  }
23
+
24
+ module.exports.OPENSTREETMAP_USER_ID_REGEX = OPENSTREETMAP_USER_ID_REGEX
@@ -26,13 +26,11 @@ const getRscAvatar = $ => {
26
26
  const getAvatar = $ =>
27
27
  $jsonld('mainEntity.image.contentUrl')($) || getRscAvatar($)
28
28
 
29
- const factory = ({ createHtmlProvider }) =>
29
+ module.exports = ({ createHtmlProvider }) =>
30
30
  createHtmlProvider({
31
31
  name: 'patreon',
32
32
  url: username => `https://www.patreon.com/${username}`,
33
33
  getter: getAvatar
34
34
  })
35
35
 
36
- factory.getAvatar = getAvatar
37
-
38
- module.exports = factory
36
+ module.exports.getAvatar = getAvatar
@@ -1,11 +1,13 @@
1
1
  'use strict'
2
2
 
3
+ const getAvatarUrl = input =>
4
+ `https://www.printables.com/${input.startsWith('@') ? input : `@${input}`}`
5
+
3
6
  module.exports = ({ createHtmlProvider, getOgImage }) =>
4
7
  createHtmlProvider({
5
8
  name: 'printables',
6
- url: input =>
7
- `https://www.printables.com/${
8
- input.startsWith('@') ? input : `@${input}`
9
- }`,
9
+ url: getAvatarUrl,
10
10
  getter: getOgImage
11
11
  })
12
+
13
+ module.exports.getAvatarUrl = getAvatarUrl
@@ -1,18 +1,20 @@
1
1
  'use strict'
2
2
 
3
- const spotifyUri = input => {
3
+ const getAvatarUrl = input => {
4
4
  const [first, second] = input.split(':')
5
5
  const type = second ? first : 'user'
6
6
  const id = second ?? first
7
- return `${type}/${id}`
7
+ return `https://open.spotify.com/${type}/${id}`
8
8
  }
9
9
 
10
10
  module.exports = ({ createHtmlProvider, getOgImage }) =>
11
11
  createHtmlProvider({
12
12
  name: 'spotify',
13
- url: input => `https://open.spotify.com/${spotifyUri(input)}`,
13
+ url: getAvatarUrl,
14
14
  getter: getOgImage,
15
15
  htmlOpts: () => ({
16
16
  prerender: true
17
17
  })
18
18
  })
19
+
20
+ module.exports.getAvatarUrl = getAvatarUrl
@@ -12,7 +12,9 @@ const getBestSrcsetUrl = srcset => {
12
12
  }))
13
13
 
14
14
  if (candidates.length === 0) return
15
- return candidates.reduce((best, current) => (current.score > best.score ? current : best)).url
15
+ return candidates.reduce((best, current) =>
16
+ current.score > best.score ? current : best
17
+ ).url
16
18
  }
17
19
 
18
20
  const getPictureAvatar = $ => {
@@ -21,15 +23,14 @@ const getPictureAvatar = $ => {
21
23
  return getBestSrcsetUrl(srcset) || pictureImg.attr('src')
22
24
  }
23
25
 
24
- const getAvatarUrl = $ => $jsonld('publisher.logo.url')($) || getPictureAvatar($)
26
+ const getAvatarUrl = $ =>
27
+ $jsonld('publisher.logo.url')($) || getPictureAvatar($)
25
28
 
26
- const factory = ({ createHtmlProvider }) =>
29
+ module.exports = ({ createHtmlProvider }) =>
27
30
  createHtmlProvider({
28
31
  name: 'substack',
29
32
  url: input => `https://${input}.substack.com`,
30
33
  getter: getAvatarUrl
31
34
  })
32
35
 
33
- factory.getAvatarUrl = getAvatarUrl
34
-
35
- module.exports = factory
36
+ module.exports.getAvatarUrl = getAvatarUrl
@@ -14,13 +14,11 @@ const getAvatarUrl = $ => {
14
14
  ])
15
15
  }
16
16
 
17
- const factory = ({ createHtmlProvider }) =>
17
+ module.exports = ({ createHtmlProvider }) =>
18
18
  createHtmlProvider({
19
19
  name: 'tiktok',
20
20
  url: input => `https://www.tiktok.com/@${input}`,
21
21
  getter: getAvatarUrl
22
22
  })
23
23
 
24
- factory.getAvatarUrl = getAvatarUrl
25
-
26
- module.exports = factory
24
+ module.exports.getAvatarUrl = getAvatarUrl
@@ -8,7 +8,7 @@ const whatsappURI = input => {
8
8
  }
9
9
  }
10
10
 
11
- const whatsappURL = input => {
11
+ const getAvatarUrl = input => {
12
12
  const { type, id } = whatsappURI(input)
13
13
  switch (type) {
14
14
  case 'phone':
@@ -26,6 +26,8 @@ const whatsappURL = input => {
26
26
  module.exports = ({ createHtmlProvider, getOgImage }) =>
27
27
  createHtmlProvider({
28
28
  name: 'whatsapp',
29
- url: whatsappURL,
29
+ url: getAvatarUrl,
30
30
  getter: getOgImage
31
31
  })
32
+
33
+ module.exports.getAvatarUrl = getAvatarUrl
@@ -18,13 +18,11 @@ const getProfileImage = $ =>
18
18
  $('meta[property="og:image"]').attr('content')
19
19
  )
20
20
 
21
- const factory = ({ createHtmlProvider }) =>
21
+ module.exports = ({ createHtmlProvider }) =>
22
22
  createHtmlProvider({
23
23
  name: 'x',
24
24
  url: input => `https://x.com/${input}`,
25
25
  getter: getProfileImage
26
26
  })
27
27
 
28
- factory.getProfileImage = getProfileImage
29
-
30
- module.exports = factory
28
+ module.exports.getProfileImage = getProfileImage
@@ -1,18 +1,22 @@
1
1
  'use strict'
2
2
 
3
+ const getAvatarUrl = input => {
4
+ let path
5
+ if (input.startsWith('@')) {
6
+ path = input
7
+ } else if (input.startsWith('UC') && input.length === 24) {
8
+ path = `channel/${input}`
9
+ } else {
10
+ path = `@${input}`
11
+ }
12
+ return `https://www.youtube.com/${path}`
13
+ }
14
+
3
15
  module.exports = ({ createHtmlProvider, getOgImage }) =>
4
16
  createHtmlProvider({
5
17
  name: 'youtube',
6
- url: input => {
7
- let path
8
- if (input.startsWith('@')) {
9
- path = input
10
- } else if (input.startsWith('UC') && input.length === 24) {
11
- path = `channel/${input}`
12
- } else {
13
- path = `@${input}`
14
- }
15
- return `https://www.youtube.com/${path}`
16
- },
18
+ url: getAvatarUrl,
17
19
  getter: getOgImage
18
20
  })
21
+
22
+ module.exports.getAvatarUrl = getAvatarUrl