UNPKG

social-link-parser

Version:

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

65 lines 2.24 kB
import { Platforms } from '../../core/types.js'; import { normalize } from '../../utils/url.js'; import { QUERY_HASH } from '../../utils/constants.js'; const domains = ['tumblr.com']; const subdomains = []; export const tumblr = { id: Platforms.Tumblr, name: 'Tumblr', domains: domains, subdomains: subdomains, patterns: { profile: new RegExp(`^https?://([a-zA-Z0-9-]{3,})\\.tumblr\\.com/?${QUERY_HASH}$`, 'i'), handle: /^[a-zA-Z0-9-]{3,}$/, content: { post: new RegExp(`^https?://([a-zA-Z0-9-]+)\\.tumblr\\.com/post/(\\d+)(?:/[^?#]*)?/?${QUERY_HASH}$`, 'i'), profileBlog: new RegExp(`^https?://(?:www\\.)?tumblr\\.com/([a-zA-Z0-9-]{3,})/?${QUERY_HASH}$`, 'i'), }, }, detect(url) { if (!domains.some((domain) => url.includes(domain))) return false; if (this.patterns.profile.test(url)) return true; if (this.patterns.content) { for (const pattern of Object.values(this.patterns.content)) { if (pattern && pattern.test(url)) return true; } } return false; }, extract(url, res) { const postMatch = this.patterns.content?.post?.exec(url); if (postMatch) { res.username = postMatch[1]; res.ids.postId = postMatch[2]; res.metadata.isPost = true; res.metadata.contentType = 'post'; return; } const subdomainMatch = this.patterns.profile.exec(url); if (subdomainMatch) { res.username = subdomainMatch[1]; res.metadata.isProfile = true; res.metadata.contentType = 'profile'; return; } const pathMatch = this.patterns.content?.profileBlog?.exec(url); if (pathMatch) { res.username = pathMatch[1]; res.metadata.isProfile = true; res.metadata.contentType = 'profile'; } }, validateHandle(h) { return /^[a-zA-Z0-9-]{3,}$/.test(h); }, buildProfileUrl(u) { return `https://${u}.tumblr.com`; }, normalizeUrl(u) { return normalize(u); }, }; //# sourceMappingURL=index.js.map