UNPKG

social-link-parser

Version:

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

63 lines 2.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.shopmy = void 0; const types_1 = require("../../core/types"); const url_1 = require("../../utils/url"); const url_2 = require("../../utils/url"); const constants_1 = require("../../utils/constants"); const domains = ['shopmy.us']; const subdomains = []; const DOMAIN_PATTERN = (0, url_2.createDomainPattern)(domains, subdomains); exports.shopmy = { id: types_1.Platforms.ShopMy, name: 'ShopMy', domains: domains, subdomains: subdomains, patterns: { profile: new RegExp(`^https?://${DOMAIN_PATTERN}/(?!collections/)(?!p/)([A-Za-z0-9_-]{2,})/?${constants_1.QUERY_HASH}$`, 'i'), handle: /^[A-Za-z0-9_-]{2,}$/, content: { collection: new RegExp(`^https?://${DOMAIN_PATTERN}/collections/(\\d+)/?${constants_1.QUERY_HASH}$`, 'i'), product: new RegExp(`^https?://${DOMAIN_PATTERN}/p/([A-Za-z0-9]{2,})/?${constants_1.QUERY_HASH}$`, 'i'), }, }, detect(url) { if (!domains.some((domain) => url.includes(domain))) return false; if (this.patterns.profile.test(url)) return true; if (this.patterns.content) { for (const pattern of Object.values(this.patterns.content)) { if (pattern && pattern.test(url)) return true; } } return false; }, extract(url, result) { const collectionMatch = this.patterns.content?.collection?.exec(url); if (collectionMatch) { result.ids.collectionId = collectionMatch[1]; result.metadata.isCollection = true; result.metadata.contentType = 'collection'; return; } const productMatch = this.patterns.content?.product?.exec(url); if (productMatch) { result.ids.productId = productMatch[1]; result.metadata.isProduct = true; result.metadata.contentType = 'product'; return; } const profileMatch = this.patterns.profile.exec(url); if (profileMatch) { result.username = profileMatch[1]; result.metadata.isProfile = true; result.metadata.contentType = 'storefront'; } }, validateHandle: (h) => /^[A-Za-z0-9_-]{2,}$/.test(h), buildProfileUrl: (username) => `https://shopmy.us/${username}`, normalizeUrl: (u) => (0, url_1.normalize)(u), }; //# sourceMappingURL=index.js.map