@unavatar/core 3.54.0 → 3.55.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
@@ -27,6 +27,7 @@
27
27
  - [Bluesky](#bluesky)
28
28
  - [Buy Me a Coffee](#buy-me-a-coffee)
29
29
  - [Cash App](#cash-app)
30
+ - [Chess.com](#chesscom)
30
31
  - [Codeforces](#codeforces)
31
32
  - [CodePen](#codepen)
32
33
  - [Cults3D](#cults3d)
@@ -626,6 +627,12 @@ Get any Cash App user's profile picture by their Cashtag.
626
627
 
627
628
  e.g., [unavatar.io/cashapp/ninja](https://unavatar.io/cashapp/ninja)
628
629
 
630
+ ### Chess.com
631
+
632
+ Get any Chess.com player's profile picture by their username.
633
+
634
+ e.g., [unavatar.io/chesscom/hikaru](https://unavatar.io/chesscom/hikaru)
635
+
629
636
  ### Codeforces
630
637
 
631
638
  Get any Codeforces user's profile picture by their handle.
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.54.0",
5
+ "version": "3.55.0",
6
6
  "main": "src/index.js",
7
7
  "exports": {
8
8
  ".": "./src/index.js",
@@ -0,0 +1,26 @@
1
+ 'use strict'
2
+
3
+ const API_URL = 'https://api.chess.com/pub/player'
4
+
5
+ const getAvatarUrl = input =>
6
+ `${API_URL}/${encodeURIComponent(input.toLowerCase())}`
7
+
8
+ const getAvatar = body => {
9
+ const pic = body?.avatar
10
+ return typeof pic === 'string' && pic ? pic : undefined
11
+ }
12
+
13
+ module.exports = ({ got }) =>
14
+ async function chesscom (input) {
15
+ const { body, statusCode } = await got(getAvatarUrl(input), {
16
+ responseType: 'json',
17
+ throwHttpErrors: false
18
+ })
19
+
20
+ if (statusCode >= 400) return
21
+
22
+ return getAvatar(body)
23
+ }
24
+
25
+ module.exports.getAvatarUrl = getAvatarUrl
26
+ module.exports.getAvatar = getAvatar
@@ -12,6 +12,7 @@ const providerTiers = {
12
12
  'bluesky',
13
13
  'buymeacoffee',
14
14
  'cashapp',
15
+ 'chesscom',
15
16
  'codeforces',
16
17
  'codepen',
17
18
  'cults3d',
@@ -104,6 +105,7 @@ module.exports = ctx => {
104
105
  bluesky: require('./bluesky')(ctx),
105
106
  buymeacoffee: require('./buymeacoffee')(ctx),
106
107
  cashapp: require('./cashapp')(ctx),
108
+ chesscom: require('./chesscom')(ctx),
107
109
  codeforces: require('./codeforces')(ctx),
108
110
  codepen: require('./codepen')(ctx),
109
111
  cults3d: require('./cults3d')(ctx),