UNPKG

social-link-parser

Version:

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

46 lines 1.8 kB
import { Platforms } from '../../core/types.js'; import { createDomainPattern } from '../../utils/url.js'; import { QUERY_HASH } from '../../utils/constants.js'; const domains = ['aliexpress.com', 'aliexpress.us', 'aliexpress.ru']; const subdomains = ['m']; const DOMAIN_PATTERN = createDomainPattern(domains, subdomains); export const aliexpress = { id: Platforms.AliExpress, name: 'AliExpress', color: '#FF4747', domains: domains, subdomains: subdomains, patterns: { profile: new RegExp(`^https?://${DOMAIN_PATTERN}/store/(\\d+)/?${QUERY_HASH}$`, 'i'), handle: /^[a-zA-Z0-9_-]+$/, content: { item: new RegExp(`^https?://${DOMAIN_PATTERN}/(?:item|i)/(\\d+)(?:\\.html)?/?${QUERY_HASH}$`, 'i'), } }, detect(url) { if (!this.domains.some(domain => url.includes(domain))) return false; return this.patterns.profile.test(url) || !!(this.patterns.content?.item?.test(url)); }, extract(url, result) { const profileMatch = this.patterns.profile.exec(url); if (profileMatch) { result.ids.storeId = profileMatch[1]; result.metadata.isProfile = true; return; } const itemMatch = this.patterns.content?.item?.exec(url); if (itemMatch) { result.ids.productId = itemMatch[1]; result.metadata.contentType = 'product'; result.metadata.isProduct = true; } }, validateHandle(h) { return this.patterns.handle.test(h); }, buildProfileUrl(storeId) { return `https://www.aliexpress.com/store/${storeId}`; }, buildContentUrl(_t, id) { return `https://www.aliexpress.com/item/${id}.html`; }, normalizeUrl(url) { return url; } }; //# sourceMappingURL=index.js.map