UNPKG

social-link-parser

Version:

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

67 lines 2.82 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.shopify = void 0; const types_1 = require("../../core/types"); const url_1 = require("../../utils/url"); const constants_1 = require("../../utils/constants"); const domains = ['myshopify.com']; const subdomains = ['*']; exports.shopify = { id: types_1.Platforms.Shopify, name: 'Shopify Store', domains: domains, subdomains: subdomains, patterns: { profile: new RegExp(`^https?://([a-z0-9-]+)\\.myshopify\\.com/?${constants_1.QUERY_HASH}$`, 'i'), handle: /^[a-z0-9-]+$/i, content: { product: new RegExp(`^https?://([a-z0-9-]+)\\.myshopify\\.com/products/([a-z0-9-]+)/?${constants_1.QUERY_HASH}$`, 'i'), collection: new RegExp(`^https?://([a-z0-9-]+)\\.myshopify\\.com/collections/([a-z0-9-]+)/?${constants_1.QUERY_HASH}$`, 'i'), page: new RegExp(`^https?://([a-z0-9-]+)\\.myshopify\\.com/pages/([a-z0-9-]+)/?${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?.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 (0, url_1.normalize)(u); }, }; //# sourceMappingURL=index.js.map