UNPKG

social-link-parser

Version:

Extract usernames, IDs, and metadata from social media URLs across 100+ platforms

56 lines 1.91 kB
import { Platforms } from '../../core/types.js'; import { normalize } from '../../utils/url.js'; import { createDomainPattern } from '../../utils/url.js'; import { QUERY_HASH } from '../../utils/constants.js'; const domains = ['liketoknow.it']; const subdomains = []; const DOMAIN_PATTERN = createDomainPattern(domains, subdomains); export const liketoknowit = { id: Platforms.LikeToKnowIt, name: 'LikeToKnowIt', color: '#000000', domains: domains, subdomains: subdomains, patterns: { profile: new RegExp(`^https?://${DOMAIN_PATTERN}/([A-Za-z0-9_.-]{3,40})/?${QUERY_HASH}$`, 'i'), handle: /^[A-Za-z0-9_.-]{3,40}$/, content: { post: new RegExp(`^https?://${DOMAIN_PATTERN}/p/([A-Za-z0-9]+)/?${QUERY_HASH}$`, 'i'), }, }, detect(url) { if (!this.domains.some(domain => url.includes(domain))) return false; return this.patterns.profile.test(url) || !!(this.patterns.content?.post?.test(url)); }, extract(url, res) { const post = this.patterns.content?.post?.exec(url); if (post) { res.ids.postId = post[1]; res.metadata.isPost = true; res.metadata.contentType = 'post'; return; } const prof = this.patterns.profile.exec(url); if (prof) { res.username = prof[1]; res.metadata.isProfile = true; res.metadata.contentType = 'profile'; } }, validateHandle(handle) { return this.patterns.handle.test(handle); }, buildProfileUrl(username) { return `https://liketoknow.it/${username}`; }, buildContentUrl(contentType, id) { if (contentType === 'post') return `https://liketoknow.it/p/${id}`; return ''; }, normalizeUrl(url) { return normalize(url); }, }; //# sourceMappingURL=index.js.map