social-link-parser
Version:
Extract usernames, IDs, and metadata from social media URLs across 100+ platforms
57 lines • 1.91 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 = ['dispo.fun'];
const subdomains = [];
const DOMAIN_PATTERN = createDomainPattern(domains, subdomains);
export const dispo = {
id: Platforms.Dispo,
name: 'Dispo',
color: '#FFCC00',
domains: domains,
subdomains: subdomains,
patterns: {
profile: new RegExp(`^https?://${DOMAIN_PATTERN}/@([A-Za-z0-9_.]{3,30})/?${QUERY_HASH}$`, 'i'),
handle: /^@?[A-Za-z0-9_.]{3,30}$/,
content: {
roll: new RegExp(`^https?://${DOMAIN_PATTERN}/r/([A-Za-z0-9_-]{3,40})/?${QUERY_HASH}$`, 'i'),
},
},
detect(url) {
if (!this.domains.some(domain => url.includes(domain)))
return false;
return this.patterns.profile.test(url) || !!(this.patterns.content?.roll?.test(url));
},
extract(url, res) {
const roll = this.patterns.content?.roll?.exec(url);
if (roll) {
res.ids.rollId = roll[1];
res.metadata.isRoll = true;
res.metadata.contentType = 'roll';
return;
}
const prof = this.patterns.profile.exec(url);
if (prof) {
res.username = prof[1];
res.metadata.isProfile = true;
res.metadata.contentType = 'profile';
}
},
validateHandle(handle) {
return this.patterns.handle.test(handle);
},
buildProfileUrl(username) {
return `https://dispo.fun/@${username.replace(/^@/, '')}`;
},
buildContentUrl(contentType, id) {
if (contentType === 'roll') {
return `https://dispo.fun/r/${id}`;
}
return '';
},
normalizeUrl(url) {
return normalize(url);
},
};
//# sourceMappingURL=index.js.map