UNPKG

social-link-parser

Version:

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

58 lines 2.03 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 = ['flickr.com']; const subdomains = []; const DOMAIN_PATTERN = createDomainPattern(domains, subdomains); const handlePattern = /^[A-Za-z0-9@_-]{3,50}$/; export const flickr = { id: Platforms.Flickr, name: 'Flickr', color: '#0063DC', domains: domains, subdomains: subdomains, patterns: { profile: new RegExp(`^https?://${DOMAIN_PATTERN}/photos/([A-Za-z0-9@_-]{3,50})/?${QUERY_HASH}$`, 'i'), handle: handlePattern, content: { photo: new RegExp(`^https?://${DOMAIN_PATTERN}/photos/([A-Za-z0-9@_-]{3,50})/(\\d{6,})/?${QUERY_HASH}$`, 'i'), }, }, detect(url) { if (!this.domains.some(domain => url.includes(domain))) return false; return this.patterns.profile.test(url) || !!(this.patterns.content?.photo?.test(url)); }, extract(url, result) { const ph = this.patterns.content?.photo?.exec(url); if (ph) { result.username = ph[1]; result.ids.photoId = ph[2]; result.metadata.isPhoto = true; result.metadata.contentType = 'photo'; return; } const p = this.patterns.profile.exec(url); if (p) { result.username = p[1]; result.metadata.isProfile = true; result.metadata.contentType = 'profile'; } }, validateHandle(handle) { return handlePattern.test(handle); }, buildProfileUrl(username) { return `https://www.flickr.com/photos/${username}`; }, buildContentUrl(type, id) { if (type === 'photo') return `https://www.flickr.com/photos/me/${id}`; return `https://www.flickr.com/${id}`; }, normalizeUrl(url) { return normalize(url); }, }; //# sourceMappingURL=index.js.map