UNPKG

social-link-parser

Version:

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

64 lines 2.67 kB
import { Platforms } from '../../core/types.js'; import { normalize } from '../../utils/url.js'; import { QUERY_HASH } from '../../utils/constants.js'; const domains = ['myshopify.com']; const subdomains = ['*']; export const shopify = { id: Platforms.Shopify, name: 'Shopify Store', domains: domains, subdomains: subdomains, patterns: { profile: new RegExp(`^https?://([a-z0-9-]+)\\.myshopify\\.com/?${QUERY_HASH}$`, 'i'), handle: /^[a-z0-9-]+$/i, content: { product: new RegExp(`^https?://([a-z0-9-]+)\\.myshopify\\.com/products/([a-z0-9-]+)/?${QUERY_HASH}$`, 'i'), collection: new RegExp(`^https?://([a-z0-9-]+)\\.myshopify\\.com/collections/([a-z0-9-]+)/?${QUERY_HASH}$`, 'i'), page: new RegExp(`^https?://([a-z0-9-]+)\\.myshopify\\.com/pages/([a-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) || this.patterns.content?.collection?.test(url) || this.patterns.content?.page?.test(url)); }, extract(url, res) { const productMatch = this.patterns.content?.product?.exec(url); if (productMatch) { res.ids.storeName = productMatch[1]; res.ids.productHandle = productMatch[2]; res.metadata.isProduct = true; res.metadata.contentType = 'product'; return; } const collectionMatch = this.patterns.content?.collection?.exec(url); if (collectionMatch) { res.ids.storeName = collectionMatch[1]; res.ids.collectionName = collectionMatch[2]; res.metadata.isCollection = true; res.metadata.contentType = 'collection'; return; } const pageMatch = this.patterns.content?.page?.exec(url); if (pageMatch) { res.ids.storeName = pageMatch[1]; res.ids.pageSlug = pageMatch[2]; res.metadata.isPage = true; res.metadata.contentType = 'page'; return; } const storeMatch = this.patterns.profile.exec(url); if (storeMatch) { res.ids.storeName = storeMatch[1]; res.metadata.isProfile = true; res.metadata.contentType = 'storefront'; } }, validateHandle(h) { return /^[a-z0-9-]+$/i.test(h); }, buildProfileUrl(u) { return `https://${u}.myshopify.com`; }, normalizeUrl(u) { return normalize(u); }, }; //# sourceMappingURL=index.js.map