UNPKG

social-link-parser

Version:

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

92 lines 3.71 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.linkedin = 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 = ['linkedin.com']; const DOMAIN_PATTERN = (0, url_2.createDomainPattern)(domains); exports.linkedin = { id: types_1.Platforms.LinkedIn, name: 'LinkedIn', color: '#0A66C2', domains: domains, patterns: { profile: new RegExp(`^https?://${DOMAIN_PATTERN}/in/([A-Za-z0-9-_%]{3,100})/?${constants_1.QUERY_HASH}$`, 'i'), handle: /^[A-Za-z0-9-]{3,100}$/, content: { company: new RegExp(`^https?://${DOMAIN_PATTERN}/company/([A-Za-z0-9-]+)/?${constants_1.QUERY_HASH}$`, 'i'), school: new RegExp(`^https?://${DOMAIN_PATTERN}/school/([A-Za-z0-9-]+)/?${constants_1.QUERY_HASH}$`, 'i'), post: new RegExp(`^https?://${DOMAIN_PATTERN}/posts/[A-Za-z0-9-_%]+_(.+?)/?${constants_1.QUERY_HASH}$`, 'i'), article: new RegExp(`^https?://${DOMAIN_PATTERN}/pulse/([A-Za-z0-9-]+)/?${constants_1.QUERY_HASH}$`, 'i'), feedUpdate: new RegExp(`^https?://${DOMAIN_PATTERN}/feed/update/urn:li:activity:(\\d+)/?${constants_1.QUERY_HASH}$`, 'i'), }, }, detect(url) { if (!url.includes('linkedin.com')) 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, result) { const companyMatch = this.patterns.content?.company?.exec(url); if (companyMatch) { result.ids.companyName = companyMatch[1]; result.metadata.isCompany = true; result.metadata.contentType = 'company'; return; } const schoolMatch = this.patterns.content?.school?.exec(url); if (schoolMatch) { result.ids.schoolName = schoolMatch[1]; result.metadata.isSchool = true; result.metadata.contentType = 'school'; return; } const postMatch = this.patterns.content?.post?.exec(url); if (postMatch) { result.ids.postId = postMatch[1]; result.metadata.isPost = true; result.metadata.contentType = 'post'; return; } const articleMatch = this.patterns.content?.article?.exec(url); if (articleMatch) { result.ids.articleSlug = articleMatch[1]; result.metadata.isArticle = true; result.metadata.contentType = 'article'; return; } const feedMatch = this.patterns.content?.feedUpdate?.exec(url); if (feedMatch) { result.ids.postId = feedMatch[1]; result.metadata.isPost = true; result.metadata.contentType = 'post'; return; } const profileMatch = this.patterns.profile.exec(url); if (profileMatch) { result.username = profileMatch[1]; result.metadata.isProfile = true; result.metadata.contentType = 'profile'; } }, validateHandle(handle) { return this.patterns.handle.test(handle); }, buildProfileUrl(username) { return `https://linkedin.com/in/${username}`; }, normalizeUrl(url) { return (0, url_1.normalize)(url.replace(/[?&]trk=[^&]+/g, '')); }, }; //# sourceMappingURL=index.js.map