UNPKG

social-link-parser

Version:

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

58 lines 1.97 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 = ['vsco.co']; const subdomains = []; const DOMAIN_PATTERN = createDomainPattern(domains, subdomains); export const vsco = { id: Platforms.VSCO, name: 'VSCO', 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: { image: new RegExp(`^https?://${DOMAIN_PATTERN}/([A-Za-z0-9_.-]{3,40})/media/(\\d+)/?${QUERY_HASH}$`, 'i'), }, }, detect(url) { if (!this.domains.some(domain => url.includes(domain))) return false; return this.patterns.profile.test(url) || !!(this.patterns.content?.image?.test(url)); }, extract(url, res) { const img = this.patterns.content?.image?.exec(url); if (img) { res.username = img[1]; res.ids.imageId = img[2]; res.metadata.isImage = true; res.metadata.contentType = 'image'; 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://vsco.co/${username.replace(/^@/, '')}`; }, buildContentUrl(contentType, id) { if (contentType === 'image') { return `https://vsco.co/undefined/media/${id}`; } return ''; }, normalizeUrl(url) { return normalize(url); }, }; //# sourceMappingURL=index.js.map