UNPKG

social-link-parser

Version:

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

57 lines 1.99 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 = ['poshmark.com']; const subdomains = []; const DOMAIN_PATTERN = createDomainPattern(domains, subdomains); export const poshmark = { id: Platforms.Poshmark, name: 'Poshmark', color: '#C03838', domains: domains, subdomains: subdomains, patterns: { profile: new RegExp(`^https?://${DOMAIN_PATTERN}/closet/([A-Za-z0-9_.-]{3,40})/?${QUERY_HASH}$`, 'i'), handle: /^[A-Za-z0-9_.-]{3,40}$/, content: { listing: new RegExp(`^https?://${DOMAIN_PATTERN}/listing/([A-Za-z0-9_-]+)-(\\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?.listing?.test(url)); }, extract(url, res) { const lst = this.patterns.content?.listing?.exec(url); if (lst) { res.ids.listingSlug = lst[1]; res.ids.listingId = lst[2]; res.metadata.isListing = true; res.metadata.contentType = 'listing'; return; } const prof = this.patterns.profile.exec(url); if (prof) { res.username = prof[1]; res.metadata.isCloset = true; res.metadata.contentType = 'closet'; } }, validateHandle(handle) { return this.patterns.handle.test(handle); }, buildProfileUrl(username) { return `https://poshmark.com/closet/${username}`; }, buildContentUrl(contentType, id) { if (contentType === 'listing') return `https://poshmark.com/listing/${id}`; return ''; }, normalizeUrl(url) { return normalize(url); }, }; //# sourceMappingURL=index.js.map