UNPKG

social-link-parser

Version:

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

58 lines 1.96 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 = ['kick.com']; const subdomains = []; const DOMAIN_PATTERN = createDomainPattern(domains, subdomains); const usernamePattern = /^[A-Za-z0-9_]{3,25}$/; export const kick = { id: Platforms.Kick, name: 'Kick', color: '#52FF00', domains: domains, subdomains: subdomains, patterns: { profile: new RegExp(`^https?://${DOMAIN_PATTERN}/([A-Za-z0-9_]{3,25})/?${QUERY_HASH}$`, 'i'), handle: usernamePattern, content: { video: new RegExp(`^https?://${DOMAIN_PATTERN}/video/(\\d{5,})/?${QUERY_HASH}$`, 'i'), }, }, detect(url) { if (!this.domains.some(domain => url.includes(domain))) return false; return this.patterns.profile.test(url) || !!(this.patterns.content?.video?.test(url)); }, extract(url, result) { const vid = this.patterns.content?.video?.exec(url); if (vid) { result.ids.videoId = vid[1]; result.metadata.isVideo = true; result.metadata.contentType = 'video'; return; } const prof = this.patterns.profile.exec(url); if (prof) { result.username = prof[1]; result.metadata.isProfile = true; result.metadata.contentType = 'profile'; return; } }, validateHandle(handle) { return usernamePattern.test(handle); }, buildProfileUrl(username) { return `https://kick.com/${username}`; }, buildContentUrl(type, id) { if (type === 'video') return `https://kick.com/video/${id}`; return `https://kick.com/${id}`; }, normalizeUrl(url) { return normalize(url); }, }; //# sourceMappingURL=index.js.map