@unavatar/core 3.63.0 → 3.65.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/README.md CHANGED
@@ -42,8 +42,10 @@
42
42
  - [Domain](#domain)
43
43
  - [Dribbble](#dribbble)
44
44
  - [DuckDuckGo](#duckduckgo)
45
+ - [Duolingo](#duolingo)
45
46
  - [Email](#email)
46
47
  - [Facebook](#facebook)
48
+ - [Farcaster](#farcaster)
47
49
  - [Flickr](#flickr)
48
50
  - [Gitee](#gitee)
49
51
  - [GitHub](#github)
@@ -738,6 +740,12 @@ Get the favicon or logo for any domain via DuckDuckGo's icon service. Useful as
738
740
 
739
741
  e.g., [unavatar.io/duckduckgo/microsoft.com](https://unavatar.io/duckduckgo/microsoft.com)
740
742
 
743
+ ### Duolingo
744
+
745
+ Get any Duolingo learner's profile picture by their username.
746
+
747
+ e.g., [unavatar.io/duolingo/luis](https://unavatar.io/duolingo/luis)
748
+
741
749
  ### Email
742
750
 
743
751
  Resolve user avatars from an email address with a single URL. The `/email/:key` route uses the same provider chain as a bare `/user@domain` path: the service tries Gravatar and GitHub, then Libravatar, then BIMI until one returns an image. No API keys and no SDK are required.
@@ -771,6 +779,15 @@ Available inputs:
771
779
  - Username, e.g., [unavatar.io/facebook/zuck](https://unavatar.io/facebook/zuck)
772
780
  - Page, e.g., [unavatar.io/facebook/windtodayco](https://unavatar.io/facebook/windtodayco)
773
781
 
782
+ ### Farcaster
783
+
784
+ Get any Farcaster user's profile picture by their username (fname). ENS-style usernames are supported.
785
+
786
+ Available inputs:
787
+
788
+ - Username, e.g., [unavatar.io/farcaster/dwr](https://unavatar.io/farcaster/dwr)
789
+ - ENS username, e.g., [unavatar.io/farcaster/vitalik.eth](https://unavatar.io/farcaster/vitalik.eth)
790
+
774
791
  ### Flickr
775
792
 
776
793
  Get any Flickr user's buddy icon or group icon by username or group slug.
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.63.0",
5
+ "version": "3.65.0",
6
6
  "main": "src/index.js",
7
7
  "exports": {
8
8
  ".": "./src/index.js",
@@ -0,0 +1,37 @@
1
+ 'use strict'
2
+
3
+ const stringify = require('../util/stringify')
4
+
5
+ const ORIGIN = 'https://www.duolingo.com'
6
+ const API_URL = `${ORIGIN}/2017-06-30/users`
7
+ const PICTURE_SIZE = 'xxlarge'
8
+ const DEFAULT_PICTURE_PATH_RE = /^\/avatar\/default_\d+\/?$/
9
+
10
+ const getAvatarUrl = input =>
11
+ `${API_URL}?${stringify({ username: input, fields: 'users{picture}' })}`
12
+
13
+ const getAvatar = body => {
14
+ const pic = body?.users?.[0]?.picture
15
+ if (typeof pic !== 'string' || !pic) return
16
+
17
+ const url = new URL(pic, ORIGIN)
18
+ if (DEFAULT_PICTURE_PATH_RE.test(url.pathname)) return
19
+
20
+ url.pathname = `${url.pathname.replace(/\/$/, '')}/${PICTURE_SIZE}`
21
+ return url.toString()
22
+ }
23
+
24
+ module.exports = ({ got }) =>
25
+ async function duolingo (input) {
26
+ const { body, statusCode } = await got(getAvatarUrl(input), {
27
+ responseType: 'json',
28
+ throwHttpErrors: false
29
+ })
30
+
31
+ if (statusCode >= 400) return
32
+
33
+ return getAvatar(body)
34
+ }
35
+
36
+ module.exports.getAvatarUrl = getAvatarUrl
37
+ module.exports.getAvatar = getAvatar
@@ -0,0 +1,29 @@
1
+ 'use strict'
2
+
3
+ const API_URL = 'https://api.warpcast.com/v2/user-by-username'
4
+
5
+ const parseInput = input => input.trim().replace(/^@/, '').toLowerCase()
6
+
7
+ const getAvatarUrl = input =>
8
+ `${API_URL}?username=${encodeURIComponent(parseInput(input))}`
9
+
10
+ const getAvatar = body => {
11
+ const pic = body?.result?.user?.pfp?.url
12
+ return typeof pic === 'string' && pic ? pic : undefined
13
+ }
14
+
15
+ module.exports = ({ got }) =>
16
+ async function farcaster (input) {
17
+ const { body, statusCode } = await got(getAvatarUrl(input), {
18
+ responseType: 'json',
19
+ throwHttpErrors: false
20
+ })
21
+
22
+ if (statusCode >= 400) return
23
+
24
+ return getAvatar(body)
25
+ }
26
+
27
+ module.exports.parseInput = parseInput
28
+ module.exports.getAvatarUrl = getAvatarUrl
29
+ module.exports.getAvatar = getAvatar
@@ -25,7 +25,9 @@ const providerTiers = {
25
25
  'discord',
26
26
  'dockerhub',
27
27
  'dribbble',
28
+ 'duolingo',
28
29
  'facebook',
30
+ 'farcaster',
29
31
  'flickr',
30
32
  'gitee',
31
33
  'github',
@@ -127,7 +129,9 @@ module.exports = ctx => {
127
129
  dockerhub: require('./dockerhub')(ctx),
128
130
  dribbble: require('./dribbble')(ctx),
129
131
  duckduckgo: require('./duckduckgo')(ctx),
132
+ duolingo: require('./duolingo')(ctx),
130
133
  facebook: require('./facebook')(ctx),
134
+ farcaster: require('./farcaster')(ctx),
131
135
  flickr: require('./flickr')(ctx),
132
136
  gitee: require('./gitee')(ctx),
133
137
  github: require('./github')(ctx),