Socialite
Socialite
is a quick and easy way to parse a url: string
to determine:
- What social network it belongs to.
- What the
user
handle is. - What the social
prefix
is (if relevant). - What each url segment is, broken up into groups.
The minimum criteria for parsing a url
is:
domain
: https:// www. domain .com /pathtldomain
: https:// www. domain .com /path
Installation
Simply install via the command-line or include in your package.json
, just like any other dependency.
npm install @beefchimi/socialite
How to use
By default, Socialite
includes only a small collection of the most common social networks. A typical use case looks like:
import {Socialite} from '@beefchimi/socialite';
const socialiteInstance = new Socialite();
const mySocialUrl = 'https://www.twitter.com/@SomeFakeUserHandle';
const parsedSocialUrl = socialiteInstance.parseProfile(mySocialUrl);
console.log(parsedSocialUrl);
The above will log the following SocialProfile
(object) to the console:
{
id: 'twitter',
prefix: '@',
user: 'SomeFakeUserHandle',
originalUrl: 'https://www.twitter.com/@SomeFakeUserHandle',
preferredUrl: 'https://twitter.com/@SomeFakeUserHandle',
appUrl: 'https://mobile.twitter.com/@SomeFakeUserHandle',
urlGroups: {
scheme: 'https://',
subdomain: 'www.',
domain: 'twitter',
tldomain: '.com',
path: '/@SomeFakeUserHandle',
},
}
For a more robust collection of social networks, you can import and pass in allSocialNetworks
:
import {Socialite, allSocialNetworks} from '@beefchimi/socialite';
const socialiteInstance = new Socialite(allSocialNetworks);
console.log(socialiteInstance.getNetworks());
Features
...this section is incomplete... check back later for API documentation.