social-link-parser
Version:
Extract usernames, IDs, and metadata from social media URLs across 100+ platforms
57 lines • 1.96 kB
JavaScript
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 = ['dribbble.com'];
const subdomains = [];
const DOMAIN_PATTERN = createDomainPattern(domains, subdomains);
const usernamePattern = /^[A-Za-z0-9_-]{3,32}$/;
export const dribbble = {
id: Platforms.Dribbble,
name: 'Dribbble',
color: '#EA4C89',
domains: domains,
subdomains: subdomains,
patterns: {
profile: new RegExp(`^https?://${DOMAIN_PATTERN}/([A-Za-z0-9_-]{3,32})/?${QUERY_HASH}$`, 'i'),
handle: usernamePattern,
content: {
shot: new RegExp(`^https?://${DOMAIN_PATTERN}/shots/(\\d{5,})(?:-[A-Za-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?.shot?.test(url));
},
extract(url, result) {
const s = this.patterns.content?.shot?.exec(url);
if (s) {
result.ids.shotId = s[1];
result.metadata.isPost = true;
result.metadata.contentType = 'shot';
return;
}
const p = this.patterns.profile.exec(url);
if (p) {
result.username = p[1];
result.metadata.isProfile = true;
result.metadata.contentType = 'profile';
}
},
validateHandle(handle) {
return usernamePattern.test(handle);
},
buildProfileUrl(username) {
return `https://dribbble.com/${username}`;
},
buildContentUrl(type, id) {
if (type === 'shot')
return `https://dribbble.com/shots/${id}`;
return `https://dribbble.com/${id}`;
},
normalizeUrl(url) {
return normalize(url);
},
};
//# sourceMappingURL=index.js.map