generated from beefchimi/template-common
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🏗️ [Socialite] Author new package (#1)
* 🏗️ [Socialite] Author new package * ✨ [Socialite] Now mostly working * 👷 [Socialite] Majority test coverage * 🔥 [Network] Remove title property * ✨ [Socialite] Now supporting both string and RegExp types * 🏗️ [Socialite] Add all unique social networks * 👷 [Socialite] Test coverage for each social network * ♻️ [Socialite] No longer capture subdomain from regex * ♻️ [Socialite] No longer allow a single slash in path * ✨ [Socialite] Now supporting subdomain users * 🚚 [Tests] Split social network tests into separate files * 🎨 [Helpers] Improve readability of getUrlGroups * 🚚 [Utilities] Better organization * 💩 [Utilities] Removing regex util because of mysterious circular dep * 🎨 [Socialite] A bit of method re-org * ⬆️ [Dependency] Bump all deps * 🔧 [Eslint] Enable partially accurate jest linting for vitest * 🎨 [Tests] Lint all test files * ⬆️ [Dependency] Define c8 as dependency * 👷 [Utilities] Author tests * 👍 [Socialite] Review cleanup
- Loading branch information
Showing
82 changed files
with
3,410 additions
and
512 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import {UrlCaptureId} from './types'; | ||
|
||
// NOTE: Don't be mislead by the `\\` in some capture groups. | ||
// This is a consequence of embedding within a `string`. | ||
// Once constructed by `RegExp()`, it will be properly reduced to a single `\`. | ||
|
||
function constructFullLineRegExp(...captureGroups: (string | RegExp)[]) { | ||
return new RegExp(['^', ...captureGroups, '$'].join('')); | ||
} | ||
|
||
export const urlCaptureGroup = { | ||
scheme: `(?<${UrlCaptureId.Scheme}>https?://)?`, | ||
domain: `(?<${UrlCaptureId.Domain}>[\\w\\.-]+?)`, | ||
tldomain: `(?<${UrlCaptureId.Tldomain}>\\.\\w{2,5}[/]?)?`, | ||
port: `(?<${UrlCaptureId.Port}>:\\d+?[/]?)?`, | ||
path: `(?<${UrlCaptureId.Path}>\\/.+?(?=[\\?|#]?))?`, | ||
parameters: `(?<${UrlCaptureId.Parameters}>\\?.+?(?=[#]?))?`, | ||
anchor: `(?<${UrlCaptureId.Anchor}>\\#.+?)?`, | ||
}; | ||
|
||
export const urlRegExp = constructFullLineRegExp( | ||
urlCaptureGroup.scheme, | ||
urlCaptureGroup.domain, | ||
urlCaptureGroup.tldomain, | ||
urlCaptureGroup.port, | ||
urlCaptureGroup.path, | ||
urlCaptureGroup.parameters, | ||
urlCaptureGroup.anchor, | ||
); | ||
|
||
export const profileReplacement = { | ||
user: '{REPLACE_PROFILE_USER}', | ||
prefix: '{REPLACE_PROFILE_PREFIX}', | ||
}; | ||
|
||
export const defaultUserMatcher = { | ||
subdomain: /[^.]+/, | ||
path: /[^/]+/, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import * as networks from './networks'; | ||
|
||
export const allSocialNetworks = Object.values(networks); | ||
export const defaultSocialNetworks = [ | ||
networks.facebook, | ||
networks.instagram, | ||
networks.linkedin, | ||
networks.reddit, | ||
networks.tiktok, | ||
networks.twitch, | ||
networks.twitter, | ||
networks.youtube, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,27 @@ | ||
import type {SocialiteTest} from './types'; | ||
export { | ||
urlCaptureGroup, | ||
urlRegExp, | ||
profileReplacement, | ||
defaultUserMatcher, | ||
} from './capture'; | ||
|
||
export function socialite({message = '@beefchimi'}: SocialiteTest) { | ||
return `This is a ${message} package!`; | ||
} | ||
export {allSocialNetworks, defaultSocialNetworks} from './data'; | ||
export {socialNetworkPrefixes} from './prefixes'; | ||
export {Socialite} from './socialite'; | ||
|
||
export { | ||
filterNullishValuesFromObject, | ||
filterNetworkProperties, | ||
mergeRegExp, | ||
getUrlGroups, | ||
getUrlWithSubstitutions, | ||
} from './utilities'; | ||
|
||
export {MatchUserSource, UrlCaptureId} from './types'; | ||
export type { | ||
UrlAnatomy, | ||
SocialProfile, | ||
SocialNetwork, | ||
SocialNetworkProperty, | ||
SocialNetworkProperties, | ||
} from './types'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import {profileReplacement} from '../capture'; | ||
import type {SocialNetwork} from '../types'; | ||
|
||
export const behance: SocialNetwork = { | ||
id: 'behance', | ||
preferredUrl: `https://behance.net/${profileReplacement.user}`, | ||
matcher: { | ||
domain: /behance/, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import {profileReplacement} from '../capture'; | ||
import type {SocialNetwork} from '../types'; | ||
|
||
export const devto: SocialNetwork = { | ||
id: 'dev_to', | ||
preferredUrl: `https://dev.to/${profileReplacement.user}`, | ||
matcher: { | ||
domain: /^dev$/, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import {profileReplacement} from '../capture'; | ||
import type {SocialNetwork} from '../types'; | ||
|
||
export const discord: SocialNetwork = { | ||
id: 'discord', | ||
preferredUrl: `https://discordapp.com/users/${profileReplacement.user}`, | ||
matcher: { | ||
domain: /discord/, | ||
user: /^(?:\/users\/)?(?:\/)?([^/]+)/, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import {profileReplacement} from '../capture'; | ||
import type {SocialNetwork} from '../types'; | ||
|
||
export const dribbble: SocialNetwork = { | ||
id: 'dribbble', | ||
preferredUrl: `https://dribbble.com/${profileReplacement.user}`, | ||
matcher: { | ||
domain: /dribbble/, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import {profileReplacement} from '../capture'; | ||
import type {SocialNetwork} from '../types'; | ||
|
||
export const exercism: SocialNetwork = { | ||
id: 'exercism', | ||
preferredUrl: `https://exercism.io/profiles/${profileReplacement.user}`, | ||
matcher: { | ||
domain: /exercism/, | ||
user: /^(?:\/profiles\/)?(?:\/)?([^/]+)/, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import {profileReplacement} from '../capture'; | ||
import type {SocialNetwork} from '../types'; | ||
|
||
export const facebook: SocialNetwork = { | ||
id: 'facebook', | ||
preferredUrl: `https://facebook.com/${profileReplacement.user}`, | ||
appUrl: `https://m.facebook.com/${profileReplacement.user}`, | ||
matcher: { | ||
domain: /facebook/, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import {profileReplacement} from '../capture'; | ||
import type {SocialNetwork} from '../types'; | ||
|
||
export const github: SocialNetwork = { | ||
id: 'github', | ||
preferredUrl: `https://github.com/${profileReplacement.user}`, | ||
matcher: { | ||
domain: /github/, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
export {behance} from './behance'; | ||
export {devto} from './devto'; | ||
export {discord} from './discord'; | ||
export {dribbble} from './dribbble'; | ||
export {exercism} from './exercism'; | ||
export {facebook} from './facebook'; | ||
export {github} from './github'; | ||
export {instagram} from './instagram'; | ||
export {keybase} from './keybase'; | ||
export {linkedin} from './linkedin'; | ||
export {medium} from './medium'; | ||
export {patreon} from './patreon'; | ||
export {pinterest} from './pinterest'; | ||
export {reddit} from './reddit'; | ||
export {stackoverflow} from './stackoverflow'; | ||
export {substack} from './substack'; | ||
export {telegram} from './telegram'; | ||
export {tiktok} from './tiktok'; | ||
export {twitch} from './twitch'; | ||
export {twitter} from './twitter'; | ||
export {vimeo} from './vimeo'; | ||
export {yat} from './yat'; | ||
export {youtube} from './youtube'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import {profileReplacement} from '../capture'; | ||
import type {SocialNetwork} from '../types'; | ||
|
||
export const instagram: SocialNetwork = { | ||
id: 'instagram', | ||
preferredUrl: `https://instagram.com/${profileReplacement.user}`, | ||
appUrl: `https://m.instagram.com/${profileReplacement.user}`, | ||
matcher: { | ||
domain: /instagram/, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import {profileReplacement} from '../capture'; | ||
import type {SocialNetwork} from '../types'; | ||
|
||
export const keybase: SocialNetwork = { | ||
id: 'keybase', | ||
preferredUrl: `https://keybase.io/${profileReplacement.user}`, | ||
matcher: { | ||
domain: /keybase/, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import {profileReplacement} from '../capture'; | ||
import type {SocialNetwork} from '../types'; | ||
|
||
export const linkedin: SocialNetwork = { | ||
id: 'linkedin', | ||
preferredUrl: `https://linkedin.com/in/${profileReplacement.user}`, | ||
appUrl: `https://linkedin.com/mwlite/in/${profileReplacement.user}`, | ||
matcher: { | ||
domain: /linkedin/, | ||
user: /^(?:\/mwlite\/)?(?:[/]?in\/)?(?:\/)?([^/]+)/, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import {profileReplacement} from '../capture'; | ||
import {socialNetworkPrefixes} from '../prefixes'; | ||
import type {SocialNetwork} from '../types'; | ||
|
||
const {medium: prefix} = socialNetworkPrefixes; | ||
|
||
export const medium: SocialNetwork = { | ||
id: 'medium', | ||
preferredUrl: `https://medium.com/${prefix}${profileReplacement.user}`, | ||
matcher: { | ||
domain: /medium/, | ||
user: `${prefix}[^\\/]+`, | ||
}, | ||
prefix, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import {profileReplacement} from '../capture'; | ||
import type {SocialNetwork} from '../types'; | ||
|
||
export const patreon: SocialNetwork = { | ||
id: 'patreon', | ||
preferredUrl: `https://patreon.com/${profileReplacement.user}`, | ||
matcher: { | ||
domain: /patreon/, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import {profileReplacement} from '../capture'; | ||
import type {SocialNetwork} from '../types'; | ||
|
||
export const pinterest: SocialNetwork = { | ||
id: 'pinterest', | ||
preferredUrl: `https://pinterest.com/${profileReplacement.user}`, | ||
matcher: { | ||
domain: /pinterest/, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import {profileReplacement} from '../capture'; | ||
import type {SocialNetwork} from '../types'; | ||
|
||
export const reddit: SocialNetwork = { | ||
id: 'reddit', | ||
preferredUrl: `https://reddit.com/user/${profileReplacement.user}`, | ||
matcher: { | ||
domain: /reddit/, | ||
user: /^(?:\/user\/)?(?:\/)?([^/]+)/, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import {profileReplacement} from '../capture'; | ||
import type {SocialNetwork} from '../types'; | ||
|
||
export const stackoverflow: SocialNetwork = { | ||
id: 'stackoverflow', | ||
preferredUrl: `https://stackoverflow.com/users/${profileReplacement.user}`, | ||
matcher: { | ||
domain: /stackoverflow/, | ||
user: /^(?:\/users\/)?(?:[/]?\d+)?(?:\/)?([^/]+)/, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import {profileReplacement} from '../capture'; | ||
import {MatchUserSource} from '../types'; | ||
import type {SocialNetwork} from '../types'; | ||
|
||
export const substack: SocialNetwork = { | ||
id: 'substack', | ||
preferredUrl: `https://${profileReplacement.user}.substack.com`, | ||
matcher: { | ||
domain: /substack/, | ||
userSource: MatchUserSource.Subdomain, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import {profileReplacement} from '../capture'; | ||
import type {SocialNetwork} from '../types'; | ||
|
||
export const telegram: SocialNetwork = { | ||
id: 'telegram', | ||
preferredUrl: `https://t.me/${profileReplacement.user}`, | ||
matcher: { | ||
domain: /telegram|t$/, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import {allSocialNetworks} from '../../data'; | ||
import {Socialite} from '../../socialite'; | ||
import type {SocialProfile} from '../../types'; | ||
import {mockGenericUser} from '../../tests/fixtures'; | ||
import {behance} from '../behance'; | ||
|
||
describe('Social networks > behance', () => { | ||
const mockSocialite = new Socialite(allSocialNetworks); | ||
const mockCommonUrl = `https://www.behance.net/${mockGenericUser}`; | ||
|
||
it('returns expected `id` and `user` from common url', () => { | ||
const {id, user} = mockSocialite.parseProfile( | ||
mockCommonUrl, | ||
) as SocialProfile; | ||
|
||
expect(id).toBe(behance.id); | ||
expect(user).toBe(mockGenericUser); | ||
}); | ||
|
||
it('returns expected `id` and `user` from url with trailing path', () => { | ||
const mockUncommonUrl = `${mockCommonUrl}/trail-123`; | ||
const {id, user} = mockSocialite.parseProfile( | ||
mockUncommonUrl, | ||
) as SocialProfile; | ||
|
||
expect(id).toBe(behance.id); | ||
expect(user).toBe(mockGenericUser); | ||
}); | ||
}); |
Oops, something went wrong.