UNPKG

social-link-parser

Version:

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

53 lines 2.13 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.bluesky = 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 = ['bsky.app']; const subdomains = []; const DOMAIN_PATTERN = (0, url_2.createDomainPattern)(domains, subdomains); exports.bluesky = { id: types_1.Platforms.Bluesky, name: 'Bluesky', domains: domains, subdomains: subdomains, patterns: { profile: new RegExp(`^https?://${DOMAIN_PATTERN}/profile/([a-zA-Z0-9.-]+\\.[a-zA-Z]+|did:[a-z]+:[a-zA-Z0-9]+)/?${constants_1.QUERY_HASH}$`, 'i'), handle: /^[a-zA-Z0-9.-]+\.[a-zA-Z]+$/, content: { post: new RegExp(`^https?://${DOMAIN_PATTERN}/profile/([a-zA-Z0-9.-]+\\.[a-zA-Z]+|did:[a-z]+:[a-zA-Z0-9]+)/post/([a-zA-Z0-9]{2,})/?${constants_1.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 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.-]+\.[a-zA-Z]+$/.test(h) || /^did:[a-z]+:[a-zA-Z0-9]+$/.test(h); }, buildProfileUrl(u) { const handle = u.includes('.') || u.startsWith('did:') ? u : `${u}.bsky.social`; return `https://bsky.app/profile/${handle}`; }, normalizeUrl(u) { return (0, url_1.normalize)(u); }, }; //# sourceMappingURL=index.js.map