@unavatar/core 3.64.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
@@ -45,6 +45,7 @@
45
45
  - [Duolingo](#duolingo)
46
46
  - [Email](#email)
47
47
  - [Facebook](#facebook)
48
+ - [Farcaster](#farcaster)
48
49
  - [Flickr](#flickr)
49
50
  - [Gitee](#gitee)
50
51
  - [GitHub](#github)
@@ -778,6 +779,15 @@ Available inputs:
778
779
  - Username, e.g., [unavatar.io/facebook/zuck](https://unavatar.io/facebook/zuck)
779
780
  - Page, e.g., [unavatar.io/facebook/windtodayco](https://unavatar.io/facebook/windtodayco)
780
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
+
781
791
  ### Flickr
782
792
 
783
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.64.0",
5
+ "version": "3.65.0",
6
6
  "main": "src/index.js",
7
7
  "exports": {
8
8
  ".": "./src/index.js",
@@ -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
@@ -27,6 +27,7 @@ const providerTiers = {
27
27
  'dribbble',
28
28
  'duolingo',
29
29
  'facebook',
30
+ 'farcaster',
30
31
  'flickr',
31
32
  'gitee',
32
33
  'github',
@@ -130,6 +131,7 @@ module.exports = ctx => {
130
131
  duckduckgo: require('./duckduckgo')(ctx),
131
132
  duolingo: require('./duolingo')(ctx),
132
133
  facebook: require('./facebook')(ctx),
134
+ farcaster: require('./farcaster')(ctx),
133
135
  flickr: require('./flickr')(ctx),
134
136
  gitee: require('./gitee')(ctx),
135
137
  github: require('./github')(ctx),