UNPKG

social-link-parser

Version:

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

58 lines 1.98 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 = ['revolve.com']; const subdomains = []; const DOMAIN_PATTERN = createDomainPattern(domains, subdomains); export const revolve = { id: Platforms.Revolve, name: 'Revolve', color: '#000000', domains: domains, subdomains: subdomains, patterns: { profile: new RegExp(`^https?://${DOMAIN_PATTERN}/brands/([A-Za-z0-9_-]+)/?${QUERY_HASH}$`, 'i'), handle: /^[A-Za-z0-9_-]{3,40}$/, content: { product: new RegExp(`^https?://${DOMAIN_PATTERN}/([A-Za-z0-9_-]+)/dp/([A-Za-z0-9]+)/?${QUERY_HASH}$`, 'i'), }, }, detect(url) { if (!this.domains.some(domain => url.includes(domain))) return false; return this.patterns.profile.test(url) || !!(this.patterns.content?.product?.test(url)); }, extract(url, res) { const prod = this.patterns.content?.product?.exec(url); if (prod) { res.ids.productSlug = prod[1]; res.ids.productCode = prod[2]; res.metadata.isProduct = true; res.metadata.contentType = 'product'; return; } const brand = this.patterns.profile.exec(url); if (brand) { res.username = brand[1]; res.metadata.isBrand = true; res.metadata.contentType = 'brand'; } }, validateHandle(handle) { return this.patterns.handle.test(handle); }, buildProfileUrl(brand) { return `https://revolve.com/brands/${brand}`; }, buildContentUrl(contentType, id) { if (contentType === 'product') { return `https://revolve.com/${id}`; } return ''; }, normalizeUrl(url) { return normalize(url); }, }; //# sourceMappingURL=index.js.map