@unavatar/core 3.68.0 → 3.69.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
@@ -44,6 +44,7 @@
44
44
  - [DuckDuckGo](#duckduckgo)
45
45
  - [Duolingo](#duolingo)
46
46
  - [Email](#email)
47
+ - [ENS](#ens)
47
48
  - [Facebook](#facebook)
48
49
  - [Farcaster](#farcaster)
49
50
  - [Flickr](#flickr)
@@ -773,6 +774,14 @@ Target a specific provider when you know where the avatar comes from.
773
774
 
774
775
  e.g., [unavatar.io/email/hello@microlink.io](https://unavatar.io/email/hello@microlink.io)
775
776
 
777
+ ### ENS
778
+
779
+ Get the avatar set on any Ethereum Name Service (ENS) name, including subnames like `jesse.base.eth`. A bare label is treated as a `.eth` name.
780
+
781
+ e.g., [unavatar.io/ens/vitalik.eth](https://unavatar.io/ens/vitalik.eth)
782
+
783
+ Names ending in `.eth` are detected automatically, so [unavatar.io/vitalik.eth](https://unavatar.io/vitalik.eth) resolves through ENS too.
784
+
776
785
  ### Facebook
777
786
 
778
787
  Get any Facebook user, page, or group profile picture by their username or ID.
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.68.0",
5
+ "version": "3.69.0",
6
6
  "main": "src/index.js",
7
7
  "exports": {
8
8
  ".": "./src/index.js",
@@ -119,6 +119,7 @@
119
119
  "youtube"
120
120
  ],
121
121
  "dependencies": {
122
+ "@adraffy/ens-normalize": "~1.11.1",
122
123
  "@keyvhq/compress": "~2.2.0",
123
124
  "@keyvhq/core": "~2.2.7",
124
125
  "@keyvhq/memoize": "~2.2.1",
@@ -15,11 +15,13 @@ const ExtendableError = require('../util/error')
15
15
 
16
16
  const DATA_URI_REGEX = dataUriRegex()
17
17
  const DOMAIN_REGEX = urlRegex({ strict: false })
18
+ const ENS_REGEX = /^[^\s/.][^\s/]*\.eth$/i
18
19
 
19
20
  const isHash = require('../util/is-hash')
20
21
 
21
22
  const getInputType = input => {
22
23
  if (isEmail(input) || isHash(input)) return 'email'
24
+ if (ENS_REGEX.test(input.trim())) return 'ens'
23
25
  if (stableRegex(DOMAIN_REGEX, input)) return 'domain'
24
26
  return 'username'
25
27
  }
@@ -0,0 +1,26 @@
1
+ 'use strict'
2
+
3
+ const { ens_normalize: normalizeEnsName } = require('@adraffy/ens-normalize')
4
+
5
+ const ENS_AVATAR_URL = 'https://metadata.ens.domains/mainnet/avatar'
6
+ const ENS_TLD = '.eth'
7
+
8
+ const parseInput = input => {
9
+ const name = input.trim()
10
+ try {
11
+ return normalizeEnsName(name.includes('.') ? name : `${name}${ENS_TLD}`)
12
+ } catch {}
13
+ }
14
+
15
+ const getAvatarUrl = input => {
16
+ const name = parseInput(input)
17
+ return name && `${ENS_AVATAR_URL}/${encodeURIComponent(name)}`
18
+ }
19
+
20
+ module.exports = () =>
21
+ function ens (input) {
22
+ return getAvatarUrl(input)
23
+ }
24
+
25
+ module.exports.parseInput = parseInput
26
+ module.exports.getAvatarUrl = getAvatarUrl
@@ -96,7 +96,8 @@ const providerTiers = {
96
96
  'zhihu'
97
97
  ]
98
98
  ],
99
- domain: [['bimi'], ['duckduckgo', 'google', 'microlink']]
99
+ domain: [['bimi'], ['duckduckgo', 'google', 'microlink']],
100
+ ens: [['ens']]
100
101
  }
101
102
 
102
103
  const { emailHash, ...publicTiers } = providerTiers
@@ -133,6 +134,7 @@ module.exports = ctx => {
133
134
  dribbble: require('./dribbble')(ctx),
134
135
  duckduckgo: require('./duckduckgo')(ctx),
135
136
  duolingo: require('./duolingo')(ctx),
137
+ ens: require('./ens')(ctx),
136
138
  facebook: require('./facebook')(ctx),
137
139
  farcaster: require('./farcaster')(ctx),
138
140
  flickr: require('./flickr')(ctx),