@unavatar/core 3.41.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 +7 -0
- package/package.json +1 -1
- package/src/providers/cashapp.js +48 -0
- package/src/providers/index.js +2 -0
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)
|
|
@@ -576,6 +577,12 @@ Get any Buy Me a Coffee creator's profile picture by their username.
|
|
|
576
577
|
|
|
577
578
|
e.g., [unavatar.io/buymeacoffee/mikebarnesdrums](https://unavatar.io/buymeacoffee/mikebarnesdrums)
|
|
578
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
|
+
|
|
579
586
|
### CodePen
|
|
580
587
|
|
|
581
588
|
Get any CodePen 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.
|
|
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
|
package/src/providers/index.js
CHANGED
|
@@ -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',
|
|
@@ -70,6 +71,7 @@ module.exports = ctx => {
|
|
|
70
71
|
behance: require('./behance')(ctx),
|
|
71
72
|
bluesky: require('./bluesky')(ctx),
|
|
72
73
|
buymeacoffee: require('./buymeacoffee')(ctx),
|
|
74
|
+
cashapp: require('./cashapp')(ctx),
|
|
73
75
|
codepen: require('./codepen')(ctx),
|
|
74
76
|
cults3d: require('./cults3d')(ctx),
|
|
75
77
|
cursor: require('./cursor')(ctx),
|