social-link-parser
Version:
Extract usernames, IDs, and metadata from social media URLs across 100+ platforms
65 lines • 2.43 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.vimeo = 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 = ['vimeo.com'];
const subdomains = [];
const DOMAIN_PATTERN = (0, url_2.createDomainPattern)(domains, subdomains);
exports.vimeo = {
id: types_1.Platforms.Vimeo,
name: 'Vimeo',
color: '#1AB7EA',
domains: domains,
subdomains: subdomains,
patterns: {
profile: new RegExp(`^https?://${DOMAIN_PATTERN}/(?:user\\d+|[A-Za-z0-9_]{3,32})/?${constants_1.QUERY_HASH}$`, 'i'),
handle: /^(?:user\d+|[A-Za-z0-9_]{3,32})$/,
content: {
video: new RegExp(`^https?://${DOMAIN_PATTERN}/(\\d{6,12})/?${constants_1.QUERY_HASH}$`, 'i'),
channel: new RegExp(`^https?://${DOMAIN_PATTERN}/channels/([A-Za-z0-9_-]{3,32})/?${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?.video?.test(url)) ||
!!(this.patterns.content?.channel?.test(url));
},
extract(url, res) {
const videoMatch = this.patterns.content?.video?.exec(url);
if (videoMatch) {
res.ids.videoId = videoMatch[1];
res.metadata.isVideo = true;
res.metadata.contentType = 'video';
return;
}
const channelMatch = this.patterns.content?.channel?.exec(url);
if (channelMatch) {
res.username = channelMatch[1];
res.metadata.isChannel = true;
res.metadata.contentType = 'channel';
return;
}
const profMatch = this.patterns.profile.exec(url);
if (profMatch) {
const path = url.split('/').pop()?.split('?')[0] || '';
res.username = path;
res.metadata.isProfile = true;
res.metadata.contentType = 'profile';
}
},
validateHandle(handle) {
return this.patterns.handle.test(handle);
},
buildProfileUrl(username) {
return `https://vimeo.com/${username}`;
},
normalizeUrl(url) {
return (0, url_1.normalize)(url);
},
};
//# sourceMappingURL=index.js.map