@unavatar/core 3.40.0 → 3.42.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
@@ -22,6 +22,7 @@
22
22
  - [Behance](#behance)
23
23
  - [Bluesky](#bluesky)
24
24
  - [Buy Me a Coffee](#buy-me-a-coffee)
25
+ - [Cash App](#cash-app)
25
26
  - [CodePen](#codepen)
26
27
  - [Cults3D](#cults3d)
27
28
  - [DeviantArt](#deviantart)
@@ -68,6 +69,7 @@
68
69
  - [TikTok](#tiktok)
69
70
  - [Tumblr](#tumblr)
70
71
  - [Twitch](#twitch)
72
+ - [Venmo](#venmo)
71
73
  - [Vimeo](#vimeo)
72
74
  - [WhatsApp](#whatsapp)
73
75
  - [Wise](#wise)
@@ -575,6 +577,12 @@ Get any Buy Me a Coffee creator's profile picture by their username.
575
577
 
576
578
  e.g., [unavatar.io/buymeacoffee/mikebarnesdrums](https://unavatar.io/buymeacoffee/mikebarnesdrums)
577
579
 
580
+ ### Cash App
581
+
582
+ Get any Cash App user's profile picture by their $cashtag.
583
+
584
+ e.g., [unavatar.io/cashapp/ninja](https://unavatar.io/cashapp/ninja)
585
+
578
586
  ### CodePen
579
587
 
580
588
  Get any CodePen user's profile picture by their username.
@@ -943,6 +951,12 @@ Get any Twitch streamer's profile picture by their username.
943
951
 
944
952
  e.g., [unavatar.io/twitch/midudev](https://unavatar.io/twitch/midudev)
945
953
 
954
+ ### Venmo
955
+
956
+ Get any Venmo user's profile picture by their username.
957
+
958
+ e.g., [unavatar.io/venmo/Jessica-Lee-77](https://unavatar.io/venmo/Jessica-Lee-77)
959
+
946
960
  ### Vimeo
947
961
 
948
962
  Get any Vimeo 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.40.0",
5
+ "version": "3.42.0",
6
6
  "main": "src/index.js",
7
7
  "exports": {
8
8
  ".": "./src/index.js",
@@ -0,0 +1,48 @@
1
+ 'use strict'
2
+
3
+ const { get } = require('lodash')
4
+
5
+ const getAvatarUrl = input => `https://cash.app/$${input.replace(/^\$/, '')}`
6
+
7
+ // Extracts the first balanced `{...}` object after `marker`, respecting string
8
+ // literals so a `}` inside a value (e.g. a display name) doesn't end it early.
9
+ const extractObject = (source, marker) => {
10
+ const start = source.indexOf(marker)
11
+ if (start === -1) return
12
+ const open = source.indexOf('{', start)
13
+ if (open === -1) return
14
+ let depth = 0
15
+ let inString = false
16
+ let escaped = false
17
+ for (let index = open; index < source.length; index++) {
18
+ const char = source[index]
19
+ if (inString) {
20
+ if (escaped) escaped = false
21
+ else if (char === '\\') escaped = true
22
+ else if (char === '"') inString = false
23
+ } else if (char === '"') inString = true
24
+ else if (char === '{') depth++
25
+ else if (char === '}' && --depth === 0) return source.slice(open, index + 1)
26
+ }
27
+ }
28
+
29
+ const getAvatar = ({ $, NOT_FOUND }) => {
30
+ const script = $('script')
31
+ .filter((_, el) => $(el).text().includes('var profile ='))
32
+ .text()
33
+ const json = extractObject(script, 'var profile =')
34
+ if (!json) return NOT_FOUND
35
+ return get(JSON.parse(json), ['avatar', 'image_url']) ?? NOT_FOUND
36
+ }
37
+
38
+ const factory = ({ createHtmlProvider, NOT_FOUND }) =>
39
+ createHtmlProvider({
40
+ name: 'cashapp',
41
+ url: getAvatarUrl,
42
+ getter: $ => getAvatar({ $, NOT_FOUND })
43
+ })
44
+
45
+ factory.getAvatarUrl = getAvatarUrl
46
+ factory.getAvatar = getAvatar
47
+
48
+ module.exports = factory
@@ -8,6 +8,7 @@ const providersBy = {
8
8
  'behance',
9
9
  'bluesky',
10
10
  'buymeacoffee',
11
+ 'cashapp',
11
12
  'codepen',
12
13
  'cults3d',
13
14
  'cursor',
@@ -53,6 +54,7 @@ const providersBy = {
53
54
  'tiktok',
54
55
  'tumblr',
55
56
  'twitch',
57
+ 'venmo',
56
58
  'vimeo',
57
59
  'wise',
58
60
  'x',
@@ -69,6 +71,7 @@ module.exports = ctx => {
69
71
  behance: require('./behance')(ctx),
70
72
  bluesky: require('./bluesky')(ctx),
71
73
  buymeacoffee: require('./buymeacoffee')(ctx),
74
+ cashapp: require('./cashapp')(ctx),
72
75
  codepen: require('./codepen')(ctx),
73
76
  cults3d: require('./cults3d')(ctx),
74
77
  cursor: require('./cursor')(ctx),
@@ -118,6 +121,7 @@ module.exports = ctx => {
118
121
  tiktok: require('./tiktok')(ctx),
119
122
  tumblr: require('./tumblr')(ctx),
120
123
  twitch: require('./twitch')(ctx),
124
+ venmo: require('./venmo')(ctx),
121
125
  vimeo: require('./vimeo')(ctx),
122
126
  whatsapp: require('./whatsapp')(ctx),
123
127
  wise: require('./wise')(ctx),
@@ -0,0 +1,28 @@
1
+ 'use strict'
2
+
3
+ const { get } = require('lodash')
4
+
5
+ const getAvatarUrl = input => `https://account.venmo.com/u/${input}`
6
+
7
+ const getAvatar = $ => {
8
+ const text = $('#__NEXT_DATA__').contents().text()
9
+ if (!text) return
10
+ return get(JSON.parse(text), [
11
+ 'props',
12
+ 'pageProps',
13
+ 'user',
14
+ 'profilePictureUrl'
15
+ ])
16
+ }
17
+
18
+ const factory = ({ createHtmlProvider }) =>
19
+ createHtmlProvider({
20
+ name: 'venmo',
21
+ url: getAvatarUrl,
22
+ getter: getAvatar
23
+ })
24
+
25
+ factory.getAvatarUrl = getAvatarUrl
26
+ factory.getAvatar = getAvatar
27
+
28
+ module.exports = factory