social-link-parser
Version:
Extract usernames, IDs, and metadata from social media URLs across 100+ platforms
68 lines • 2.38 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.tumblr = void 0;
const types_1 = require("../../core/types");
const url_1 = require("../../utils/url");
const constants_1 = require("../../utils/constants");
const domains = ['tumblr.com'];
const subdomains = [];
exports.tumblr = {
id: types_1.Platforms.Tumblr,
name: 'Tumblr',
domains: domains,
subdomains: subdomains,
patterns: {
profile: new RegExp(`^https?://([a-zA-Z0-9-]{3,})\\.tumblr\\.com/?${constants_1.QUERY_HASH}$`, 'i'),
handle: /^[a-zA-Z0-9-]{3,}$/,
content: {
post: new RegExp(`^https?://([a-zA-Z0-9-]+)\\.tumblr\\.com/post/(\\d+)(?:/[^?#]*)?/?${constants_1.QUERY_HASH}$`, 'i'),
profileBlog: new RegExp(`^https?://(?:www\\.)?tumblr\\.com/([a-zA-Z0-9-]{3,})/?${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, res) {
const postMatch = this.patterns.content?.post?.exec(url);
if (postMatch) {
res.username = postMatch[1];
res.ids.postId = postMatch[2];
res.metadata.isPost = true;
res.metadata.contentType = 'post';
return;
}
const subdomainMatch = this.patterns.profile.exec(url);
if (subdomainMatch) {
res.username = subdomainMatch[1];
res.metadata.isProfile = true;
res.metadata.contentType = 'profile';
return;
}
const pathMatch = this.patterns.content?.profileBlog?.exec(url);
if (pathMatch) {
res.username = pathMatch[1];
res.metadata.isProfile = true;
res.metadata.contentType = 'profile';
}
},
validateHandle(h) {
return /^[a-zA-Z0-9-]{3,}$/.test(h);
},
buildProfileUrl(u) {
return `https://${u}.tumblr.com`;
},
normalizeUrl(u) {
return (0, url_1.normalize)(u);
},
};
//# sourceMappingURL=index.js.map