@unavatar/core 3.61.0 → 3.62.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
@@ -51,6 +51,7 @@
51
51
  - [Google](#google)
52
52
  - [Google Play](#google-play)
53
53
  - [Gravatar](#gravatar)
54
+ - [Gumroad](#gumroad)
54
55
  - [Hevy](#hevy)
55
56
  - [Hugging Face](#hugging-face)
56
57
  - [Instagram](#instagram)
@@ -839,6 +840,12 @@ When you pass an email address directly in the URL, it is visible in plain text
839
840
 
840
841
  To avoid this, pass a pre-computed `MD5` or `SHA256` hash of the email instead. Unavatar detects the hash automatically and routes it to Gravatar, which natively supports both hash formats.
841
842
 
843
+ ### Gumroad
844
+
845
+ Get any Gumroad creator's profile picture by their username (the subdomain of their store).
846
+
847
+ e.g., [unavatar.io/gumroad/sahil](https://unavatar.io/gumroad/sahil)
848
+
842
849
  ### Hevy
843
850
 
844
851
  Get any Hevy user's profile picture by their username.
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.61.0",
5
+ "version": "3.62.0",
6
6
  "main": "src/index.js",
7
7
  "exports": {
8
8
  ".": "./src/index.js",
@@ -0,0 +1,45 @@
1
+ 'use strict'
2
+
3
+ const { get } = require('lodash')
4
+
5
+ const SUBDOMAIN_REGEX = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/i
6
+ const DEFAULT_AVATAR_MARKER = 'gumroad-default-avatar'
7
+
8
+ const parseInput = input =>
9
+ typeof input === 'string' && SUBDOMAIN_REGEX.test(input)
10
+ ? input.toLowerCase()
11
+ : undefined
12
+
13
+ const getAvatarUrl = input => `https://${input}.gumroad.com/`
14
+
15
+ const getAvatar = ({ $, NOT_FOUND }) => {
16
+ const page = $('#app').attr('data-page')
17
+ if (!page) return
18
+ const avatarUrl = get(JSON.parse(page), [
19
+ 'props',
20
+ 'creator_profile',
21
+ 'avatar_url'
22
+ ])
23
+ if (!avatarUrl || avatarUrl.includes(DEFAULT_AVATAR_MARKER)) return NOT_FOUND
24
+ return avatarUrl
25
+ }
26
+
27
+ module.exports = ({ createHtmlProvider, NOT_FOUND }) => {
28
+ const htmlProvider = createHtmlProvider({
29
+ name: 'gumroad',
30
+ url: getAvatarUrl,
31
+ getter: $ => getAvatar({ $, NOT_FOUND })
32
+ })
33
+
34
+ const provider = (input, context) => {
35
+ const username = parseInput(input)
36
+ return username ? htmlProvider(username, context) : undefined
37
+ }
38
+
39
+ provider.getUrl = getAvatarUrl
40
+ return provider
41
+ }
42
+
43
+ module.exports.parseInput = parseInput
44
+ module.exports.getAvatarUrl = getAvatarUrl
45
+ module.exports.getAvatar = getAvatar
@@ -31,6 +31,7 @@ const providerTiers = {
31
31
  'github',
32
32
  'gitlab',
33
33
  'google-play',
34
+ 'gumroad',
34
35
  'huggingface',
35
36
  'hevy',
36
37
  'instagram',
@@ -134,6 +135,7 @@ module.exports = ctx => {
134
135
  google: require('./google')(ctx),
135
136
  'google-play': require('./google-play')(ctx),
136
137
  gravatar: require('./gravatar')(ctx),
138
+ gumroad: require('./gumroad')(ctx),
137
139
  huggingface: require('./huggingface')(ctx),
138
140
  hevy: require('./hevy')(ctx),
139
141
  instagram: require('./instagram')(ctx),