diff --git a/package-lock.json b/package-lock.json index 2d1a5fa..55bdaed 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "socialitejs", - "version": "0.0.4", + "version": "0.0.5", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "socialitejs", - "version": "0.0.4", + "version": "0.0.5", "license": "ISC", "devDependencies": { "@changesets/cli": "^2.27.1", diff --git a/src/data.ts b/src/data.ts index b9258bc..54791e0 100644 --- a/src/data.ts +++ b/src/data.ts @@ -4,6 +4,7 @@ export const defaultSocialiteNetworks = [ networks.facebook, networks.instagram, networks.linkedin, + networks.onlyfans, networks.reddit, networks.tiktok, networks.twitch, diff --git a/src/networks/index.ts b/src/networks/index.ts index 7fecc1c..a2fcaca 100644 --- a/src/networks/index.ts +++ b/src/networks/index.ts @@ -9,6 +9,7 @@ export {instagram} from './instagram'; export {keybase} from './keybase'; export {linkedin} from './linkedin'; export {medium} from './medium'; +export {onlyfans} from './onlyfans'; export {patreon} from './patreon'; export {pinterest} from './pinterest'; export {reddit} from './reddit'; diff --git a/src/networks/onlyfans.ts b/src/networks/onlyfans.ts new file mode 100644 index 0000000..2649c3e --- /dev/null +++ b/src/networks/onlyfans.ts @@ -0,0 +1,11 @@ +import {profileReplacement} from '../capture'; +import type {SocialiteNetwork} from '../types'; + +export const onlyfans: SocialiteNetwork = { + id: 'onlyfans', + preferredUrl: `https://onlyfans.com/${profileReplacement.user}`, + matcher: { + domain: /onlyfans/, + user: `[^\\/]+`, + }, +}; diff --git a/src/networks/tests/onlyfans.test.ts b/src/networks/tests/onlyfans.test.ts new file mode 100644 index 0000000..fcc571c --- /dev/null +++ b/src/networks/tests/onlyfans.test.ts @@ -0,0 +1,30 @@ +import {describe, it, expect} from 'vitest'; + +import {Socialite} from '../../socialite'; +import type {SocialiteProfile} from '../../types'; +import {allSocialiteNetworks, mockGenericUser} from '../../tests/fixtures'; +import {onlyfans} from '../onlyfans'; + +describe('Social networks > onlyfans', () => { + const mockSocialite = new Socialite(allSocialiteNetworks); + const mockCommonUrl = `https://www.onlyfans.com/${mockGenericUser}`; + + it('returns expected `id` and `user` from common url', () => { + const {id, user} = mockSocialite.parseProfile( + mockCommonUrl, + ) as SocialiteProfile; + + expect(id).toBe(onlyfans.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 SocialiteProfile; + + expect(id).toBe(onlyfans.id); + expect(user).toBe(mockGenericUser); + }); +});