social-media-parser
v0.1.2
Published
Lightweight, zero-dependency library to parse, identify, and normalize social media URLs across 39+ platforms.
Maintainers
Readme
social-media-parser
A lightweight, zero-dependency TypeScript library for parsing, identifying, and normalizing social media URLs. Feed it any link from 39+ supported platforms and get back structured data — the platform name, content type, extracted entities (usernames, post IDs, video IDs), and a clean canonical URL with tracking parameters stripped away.
Built for link previews, analytics pipelines, content aggregators, social bookmarking tools, or anywhere you need to make sense of messy social media URLs.
Features
- ⚡ Fast URL parsing and canonical normalization
- 🌍 39+ platforms supported out of the box
- 🧩 Extensible — bring your own parsers or use only the ones you need
- 🧼 Cleans tracking params (
utm_*,fbclid,gclid,si,igshid, etc.) - 🔒 Zero runtime dependencies
- ✅ Fully typed API with 100% test coverage
Supported Platforms
- 🐦 Twitter / X
- 🎵 TikTok
- 🧑💻 GitHub
- ▶️ YouTube
- 🎧 Spotify
- 🐘 Mastodon
- ☁️ SoundCloud
- ☁️ Mixcloud
- 💬 Discord
- 📰 Substack
- ✍️ Medium
- 🇷🇺 Vkontakte (VK)
- 📺 Rumble
- 🎥 Kick
- 📻 Radio Javan
- 💸 Patreon
- 💬 LINE
- 🐧 QQ / Qzone
- 🎧 Last.fm
- ☕ Ko-fi
- 🔎 Search engines (Google, Bing, DuckDuckGo, Yahoo, Yandex, Baidu, Brave, Ecosia, Qwant, Startpage)
- 🧵 Threads
- 🦋 Bluesky
- 🎮 Twitch
- ✈️ Telegram
- 👻 Snapchat
- 🎬 Vimeo
- ▶️ Dailymotion
Installation
npm install social-media-parserQuick Example
import { parse, identify, normalize } from 'social-media-parser'
parse('https://twitter.com/elonmusk/status/1234567890')
// {
// platform: 'twitter',
// type: 'post',
// entities: { post_id: '1234567890', username: 'elonmusk' },
// url: 'https://x.com/i/status/1234567890'
// }
identify('https://www.instagram.com/johndoe/')
// 'instagram'
normalize('https://youtu.be/dQw4w9WgXcQ?si=abc&utm_source=test')
// 'https://youtube.com/watch?v=dQw4w9WgXcQ'API
parse(input, options?)
Returns:
SocialLinkParsedLinkwhen recognizednullwhen input is invalid or unsupported
identify(input, parsers?)
Returns:
- platform string (
'twitter','instagram', etc.) nullwhen unsupported
normalize(input, parsers?)
Returns:
- canonical URL string
nullwhen unsupported
Custom Parsers
import { parse, twitter } from 'social-media-parser'
const result = parse('https://x.com/elonmusk', { parsers: [twitter] })Forced Network
import { parse } from 'social-media-parser'
const result = parse('@elonmusk', { network: 'twitter' })Development
bun run typecheckbun run lintbun run lint:fixbun run testbun run test:coveragebun run buildbun run checkbun run releasebun run release:dry-run
bun run check enforces 100% coverage thresholds.
