UNPKG

social-link-parser

Version:

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

62 lines 2.17 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.threads = void 0; const types_1 = require("../../core/types"); const url_1 = require("../../utils/url"); const url_2 = require("../../utils/url"); const constants_1 = require("../../utils/constants"); const domains = ['threads.net']; const subdomains = []; const DOMAIN_PATTERN = (0, url_2.createDomainPattern)(domains, subdomains); exports.threads = { id: types_1.Platforms.Threads, name: 'Threads', domains: domains, subdomains: subdomains, patterns: { profile: new RegExp(`^https?://${DOMAIN_PATTERN}/@([a-zA-Z0-9._]{2,30})/?(?!post/)${constants_1.QUERY_HASH}$`, 'i'), handle: /^@?[a-zA-Z0-9._]{2,30}$/, content: { post: new RegExp(`^https?://${DOMAIN_PATTERN}/@([a-zA-Z0-9._]{2,30})/post/([A-Za-z0-9]{2,})/?${constants_1.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 profileMatch = this.patterns.profile.exec(url); if (profileMatch) { res.username = profileMatch[1]; res.metadata.isProfile = true; res.metadata.contentType = 'profile'; } }, validateHandle(h) { return /^@?[a-zA-Z0-9._]{2,30}$/i.test(h); }, buildProfileUrl(u) { return `https://threads.net/@${u.replace('@', '')}`; }, normalizeUrl(u) { return (0, url_1.normalize)(u); }, }; //# sourceMappingURL=index.js.map