@unavatar/core 3.25.1 → 3.25.3
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/bin/index.js +1 -1
- package/package.json +1 -1
- package/src/providers/apple-store.js +26 -45
- package/src/providers/stackoverflow.js +6 -8
package/bin/index.js
CHANGED
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.25.
|
|
5
|
+
"version": "3.25.3",
|
|
6
6
|
"main": "src/index.js",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": "./src/index.js",
|
|
@@ -8,12 +8,32 @@ const COUNTRY_CODE_REGEX = /^[a-z]{2}$/i
|
|
|
8
8
|
const getArtworkUrl = result =>
|
|
9
9
|
result?.artworkUrl512 || result?.artworkUrl100 || result?.artworkUrl60
|
|
10
10
|
|
|
11
|
+
const normalizeName = value =>
|
|
12
|
+
typeof value === 'string'
|
|
13
|
+
? value
|
|
14
|
+
.trim()
|
|
15
|
+
.toLowerCase()
|
|
16
|
+
.normalize('NFD')
|
|
17
|
+
.replace(/[\u0300-\u036f]/g, '')
|
|
18
|
+
.replace(/\s+/g, ' ')
|
|
19
|
+
: ''
|
|
20
|
+
|
|
21
|
+
const isAppNameMatch = ({ result, name }) => {
|
|
22
|
+
const query = normalizeName(name)
|
|
23
|
+
if (!query) return false
|
|
24
|
+
|
|
25
|
+
const trackName = normalizeName(result?.trackName)
|
|
26
|
+
const trackCensoredName = normalizeName(result?.trackCensoredName)
|
|
27
|
+
|
|
28
|
+
return trackName === query || trackCensoredName === query
|
|
29
|
+
}
|
|
30
|
+
|
|
11
31
|
const withCountry = ({ query, country }) =>
|
|
12
32
|
country ? `${query}&country=${encodeURIComponent(country)}` : query
|
|
13
33
|
|
|
14
34
|
const parseInput = input => {
|
|
15
35
|
const separatorIndex = input.indexOf(':')
|
|
16
|
-
if (separatorIndex === -1) return { type: '
|
|
36
|
+
if (separatorIndex === -1) return { type: 'id', value: input }
|
|
17
37
|
|
|
18
38
|
return {
|
|
19
39
|
type: input.slice(0, separatorIndex),
|
|
@@ -54,44 +74,14 @@ const getAppAvatar = async ({ got, id, country }) => {
|
|
|
54
74
|
return getArtworkUrl(result)
|
|
55
75
|
}
|
|
56
76
|
|
|
57
|
-
const getDeveloperAvatar = async ({ got, id, country }) => {
|
|
58
|
-
const query = withCountry({
|
|
59
|
-
query: `id=${encodeURIComponent(id)}&entity=software&limit=200`,
|
|
60
|
-
country
|
|
61
|
-
})
|
|
62
|
-
const results = await getLookupResults({ got, query })
|
|
63
|
-
const softwareResult = results.find(result => result?.kind === 'software')
|
|
64
|
-
return getArtworkUrl(softwareResult)
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const getBundleAvatar = async ({ got, bundleId, country }) => {
|
|
68
|
-
const query = withCountry({
|
|
69
|
-
query: `bundleId=${encodeURIComponent(bundleId)}&entity=software&limit=1`,
|
|
70
|
-
country
|
|
71
|
-
})
|
|
72
|
-
const [result] = await getLookupResults({ got, query })
|
|
73
|
-
return getArtworkUrl(result)
|
|
74
|
-
}
|
|
75
|
-
|
|
76
77
|
const getAppNameAvatar = async ({ got, name, country, searchResults }) => {
|
|
77
78
|
const getSearchResults = searchResults || createGetSearchResults({ got })
|
|
78
79
|
const query = withCountry({
|
|
79
|
-
query: `term=${encodeURIComponent(name)}&entity=software&limit=
|
|
80
|
-
country
|
|
81
|
-
})
|
|
82
|
-
const [result] = await getSearchResults(query)
|
|
83
|
-
return getArtworkUrl(result)
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const getDeveloperNameAvatar = async ({ got, name, country, searchResults }) => {
|
|
87
|
-
const getSearchResults = searchResults || createGetSearchResults({ got })
|
|
88
|
-
const query = withCountry({
|
|
89
|
-
query: `term=${encodeURIComponent(
|
|
90
|
-
name
|
|
91
|
-
)}&entity=software&attribute=softwareDeveloper&limit=1`,
|
|
80
|
+
query: `term=${encodeURIComponent(name)}&entity=software&limit=5`,
|
|
92
81
|
country
|
|
93
82
|
})
|
|
94
|
-
const
|
|
83
|
+
const results = await getSearchResults(query)
|
|
84
|
+
const result = results.find(item => isAppNameMatch({ result: item, name }))
|
|
95
85
|
return getArtworkUrl(result)
|
|
96
86
|
}
|
|
97
87
|
|
|
@@ -103,16 +93,10 @@ module.exports = ({ got, itunesSearchCache }) => {
|
|
|
103
93
|
const { value, country } = parseCountry(rawValue)
|
|
104
94
|
|
|
105
95
|
switch (type) {
|
|
106
|
-
case '
|
|
96
|
+
case 'id':
|
|
107
97
|
return getAppAvatar({ got, id: value, country })
|
|
108
|
-
case '
|
|
109
|
-
return getDeveloperAvatar({ got, id: value, country })
|
|
110
|
-
case 'bundle':
|
|
111
|
-
return getBundleAvatar({ got, bundleId: value, country })
|
|
112
|
-
case 'app-name':
|
|
98
|
+
case 'name':
|
|
113
99
|
return getAppNameAvatar({ got, name: value, country, searchResults })
|
|
114
|
-
case 'dev-name':
|
|
115
|
-
return getDeveloperNameAvatar({ got, name: value, country, searchResults })
|
|
116
100
|
default:
|
|
117
101
|
throw new Error(`Unsupported Apple Store type: ${type}`)
|
|
118
102
|
}
|
|
@@ -120,7 +104,4 @@ module.exports = ({ got, itunesSearchCache }) => {
|
|
|
120
104
|
}
|
|
121
105
|
|
|
122
106
|
module.exports.getAppAvatar = getAppAvatar
|
|
123
|
-
module.exports.getDeveloperAvatar = getDeveloperAvatar
|
|
124
|
-
module.exports.getBundleAvatar = getBundleAvatar
|
|
125
107
|
module.exports.getAppNameAvatar = getAppNameAvatar
|
|
126
|
-
module.exports.getDeveloperNameAvatar = getDeveloperNameAvatar
|
|
@@ -2,16 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
const AVATAR_SELECTOR = '.js-usermini-avatar-container img'
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return normalizedInput
|
|
11
|
-
}
|
|
5
|
+
const normalizeUserId = input =>
|
|
6
|
+
input
|
|
7
|
+
.replace(/^\/+/, '')
|
|
8
|
+
.replace(/^users\//, '')
|
|
9
|
+
.split('/')[0]
|
|
12
10
|
|
|
13
11
|
const getProfileUrl = input =>
|
|
14
|
-
`https://stackoverflow.com/users/${
|
|
12
|
+
`https://stackoverflow.com/users/${normalizeUserId(input)}`
|
|
15
13
|
|
|
16
14
|
const getAvatarUrl = $ =>
|
|
17
15
|
$(`${AVATAR_SELECTOR}[width="128"]`).attr('src') ||
|