Utility package to extract social media usernames from urls and create urls from usernames.
NPM:
npm i @elevatormedia/socialite
Yarn:
yarn add @elevatormedia/socialite
This package offers three functions extractUser
, buildUrl
, & isValidUrl
To extract a username from a social media url:
import { extractUser } from '@elevatormedia/socialite';
const rawURL = 'https://www.twitter.com/myUser';
console.log(extractUser(rawURL));
The above will output myUser
;
To retrieve the absolute URL from a given username and type
(e.g., facebook, instagram, twitter):
import { buildUrl } from '@elevatormedia/socialite';
const rawUsername = 'myUser';
const type = 'facebook';
console.log(buildUrl(rawUsername, type));
The above call will output https://www.facebook.com/myUser
;
To check if a given url is a valid case of a supported social type:
import { isValidDomain } from '@elevatormedia/socialite';
const url = 'https://www.soundcloud.com/myUser';
console.log(isValidDomain(url));
The above call will output true