@tryghost/social-urls 0.1.43 → 0.1.45
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/LICENSE +1 -1
- package/README.md +1 -1
- package/lib/index.js +91 -1
- package/package.json +5 -5
package/LICENSE
CHANGED
package/README.md
CHANGED
package/lib/index.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
module.exports.twitter = function twitter(username) {
|
|
6
6
|
// Creates the canonical twitter URL without the '@'
|
|
7
|
-
return 'https://
|
|
7
|
+
return 'https://x.com/' + username.replace(/^@/, '');
|
|
8
8
|
};
|
|
9
9
|
|
|
10
10
|
/**
|
|
@@ -15,3 +15,93 @@ module.exports.facebook = function facebook(username) {
|
|
|
15
15
|
// Handles a starting slash, this shouldn't happen, but just in case
|
|
16
16
|
return 'https://www.facebook.com/' + username.replace(/^\//, '');
|
|
17
17
|
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @param {string} username
|
|
21
|
+
* @returns {string}
|
|
22
|
+
*/
|
|
23
|
+
module.exports.threads = function threads(username) {
|
|
24
|
+
// a threads profile url is always prefixed with @
|
|
25
|
+
username = username.replace(/^@/, '');
|
|
26
|
+
return 'https://www.threads.net/@' + username;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @param {string} username
|
|
31
|
+
* @returns {string}
|
|
32
|
+
*/
|
|
33
|
+
module.exports.bluesky = function bluesky(username) {
|
|
34
|
+
// Bluesky URLs use profile path, no @ in stored handle
|
|
35
|
+
return 'https://bsky.app/profile/' + username;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @param {string} username
|
|
40
|
+
* @returns {string}
|
|
41
|
+
*/
|
|
42
|
+
module.exports.mastodon = function mastodon(username) {
|
|
43
|
+
// Remove any leading @ symbols from the username
|
|
44
|
+
username = username.replace(/^@+/, '');
|
|
45
|
+
|
|
46
|
+
// Check if the input is in @username@instance format
|
|
47
|
+
if (username.includes('@') && !username.includes('/')) {
|
|
48
|
+
const [user, instance] = username.split('@');
|
|
49
|
+
return `https://${instance}/@${user}`;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Check if the input is in instance/@username format
|
|
53
|
+
if (username.includes('/@')) {
|
|
54
|
+
return `https://${username}`;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Check if the input is in hostInstance/@username@userInstance format
|
|
58
|
+
if (username.includes('/@') && username.includes('@', username.indexOf('/@') + 1)) {
|
|
59
|
+
return `https://${username}`;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// If we have a simple instance/username format
|
|
63
|
+
if (username.includes('/')) {
|
|
64
|
+
const [instance, user] = username.split('/');
|
|
65
|
+
return `https://${instance}/@${user}`;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Default case: assume it's a local handle on the instance
|
|
69
|
+
return `https://${username}`;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @param {string} username
|
|
74
|
+
* @returns {string}
|
|
75
|
+
*/
|
|
76
|
+
module.exports.tiktok = function tiktok(username) {
|
|
77
|
+
// TikTok URLs include @, handles stored with or without @
|
|
78
|
+
username = username.startsWith('@') ? username : '@' + username;
|
|
79
|
+
return 'https://www.tiktok.com/' + username;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* @param {string} username
|
|
84
|
+
* @returns {string}
|
|
85
|
+
*/
|
|
86
|
+
module.exports.youtube = function youtube(username) {
|
|
87
|
+
// YouTube handles include @, user/, or channel/, stored as-is
|
|
88
|
+
return 'https://www.youtube.com/' + username;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* @param {string} username
|
|
93
|
+
* @returns {string}
|
|
94
|
+
*/
|
|
95
|
+
module.exports.instagram = function instagram(username) {
|
|
96
|
+
// Instagram URLs have no @, stored without @
|
|
97
|
+
return 'https://www.instagram.com/' + username;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* @param {string} username
|
|
102
|
+
* @returns {string}
|
|
103
|
+
*/
|
|
104
|
+
module.exports.linkedin = function linkedin(username) {
|
|
105
|
+
// LinkedIn URLs use /in/, stored without @
|
|
106
|
+
return 'https://www.linkedin.com/in/' + username;
|
|
107
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryghost/social-urls",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.45",
|
|
4
4
|
"repository": "https://github.com/TryGhost/SDK/tree/main/packages/social-urls",
|
|
5
5
|
"author": "Ghost Foundation",
|
|
6
6
|
"license": "MIT",
|
|
@@ -18,10 +18,10 @@
|
|
|
18
18
|
"access": "public"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
|
-
"c8": "
|
|
22
|
-
"mocha": "
|
|
21
|
+
"c8": "10.1.3",
|
|
22
|
+
"mocha": "11.1.0",
|
|
23
23
|
"should": "13.2.3",
|
|
24
|
-
"sinon": "
|
|
24
|
+
"sinon": "20.0.0"
|
|
25
25
|
},
|
|
26
|
-
"gitHead": "
|
|
26
|
+
"gitHead": "5f82bd658f044ec36a0afef179eda718ccbaac7f"
|
|
27
27
|
}
|