@unavatar/core 3.66.0 → 3.67.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
@@ -106,6 +106,7 @@
106
106
  - [Twitch](#twitch)
107
107
  - [Venmo](#venmo)
108
108
  - [Vimeo](#vimeo)
109
+ - [Wattpad](#wattpad)
109
110
  - [Weibo](#weibo)
110
111
  - [WhatsApp](#whatsapp)
111
112
  - [Wise](#wise)
@@ -1244,6 +1245,12 @@ Get any Vimeo user's profile picture by their username.
1244
1245
 
1245
1246
  e.g., [unavatar.io/vimeo/ladieswithlenses](https://unavatar.io/vimeo/ladieswithlenses)
1246
1247
 
1248
+ ### Wattpad
1249
+
1250
+ Get any Wattpad user's profile picture by their username.
1251
+
1252
+ e.g., [unavatar.io/wattpad/Wattpad](https://unavatar.io/wattpad/Wattpad)
1253
+
1247
1254
  ### Weibo
1248
1255
 
1249
1256
  Get any Weibo user's profile picture by numeric user ID or screen name.
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.66.0",
5
+ "version": "3.67.0",
6
6
  "main": "src/index.js",
7
7
  "exports": {
8
8
  ".": "./src/index.js",
@@ -85,6 +85,7 @@ const providerTiers = {
85
85
  'twitch',
86
86
  'venmo',
87
87
  'vimeo',
88
+ 'wattpad',
88
89
  'weibo',
89
90
  'whatsapp',
90
91
  'wise',
@@ -194,6 +195,7 @@ module.exports = ctx => {
194
195
  twitch: require('./twitch')(ctx),
195
196
  venmo: require('./venmo')(ctx),
196
197
  vimeo: require('./vimeo')(ctx),
198
+ wattpad: require('./wattpad')(ctx),
197
199
  weibo: require('./weibo')(ctx),
198
200
  whatsapp: require('./whatsapp')(ctx),
199
201
  wise: require('./wise')(ctx),
@@ -0,0 +1,34 @@
1
+ 'use strict'
2
+
3
+ const API_URL = 'https://www.wattpad.com/api/v3/users'
4
+
5
+ const MAX_AVATAR_SIZE = 256
6
+
7
+ const AVATAR_SIZE_RE = /\.\d+(\.\d+\.\w+)$/
8
+
9
+ const STOCK_DEFAULT_AVATAR_RE = /\/useravatar\/[0-9a-f]\.\d+\.\w+$/
10
+
11
+ const getAvatarUrl = input =>
12
+ `${API_URL}/${encodeURIComponent(input.replace(/^@/, ''))}?fields=avatar`
13
+
14
+ const getAvatar = body => {
15
+ const avatar = body?.avatar
16
+ if (typeof avatar !== 'string' || !avatar) return
17
+ if (STOCK_DEFAULT_AVATAR_RE.test(avatar)) return
18
+ return avatar.replace(AVATAR_SIZE_RE, `.${MAX_AVATAR_SIZE}$1`)
19
+ }
20
+
21
+ module.exports = ({ got }) =>
22
+ async function wattpad (input) {
23
+ const { body, statusCode } = await got(getAvatarUrl(input), {
24
+ responseType: 'json',
25
+ throwHttpErrors: false
26
+ })
27
+
28
+ if (statusCode >= 400) return
29
+
30
+ return getAvatar(body)
31
+ }
32
+
33
+ module.exports.getAvatarUrl = getAvatarUrl
34
+ module.exports.getAvatar = getAvatar