
Product
Rust Support in Socket Is Now Generally Available
Socket’s Rust and Cargo support is now generally available, providing dependency analysis and supply chain visibility for Rust projects.
@ctrl/magnet-link
Advanced tools
Parse a magnet URI into an object
Port of webtorrent/magnet-uri by feross that uses fewer dependencies in typescript
Demo: https://magnet-link.vercel.app
npm install @ctrl/magnet-link
import { magnetDecode } from '@ctrl/magnet-link';
const uri = 'magnet:?xt=urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36&dn=Leaves+of+Grass+by+Walt+Whitman.epub&tr=udp%3A%2F%2Ftracker.example4.com%3A80&tr=udp%3A%2F%2Ftracker.example5.com%3A80&tr=udp%3A%2F%2Ftracker.example3.com%3A6969&tr=udp%3A%2F%2Ftracker.example2.com%3A80&tr=udp%3A%2F%2Ftracker.example1.com%3A1337';
const parsed = magnetDecode(uri);
console.log(parsed.dn) // "Leaves of Grass by Walt Whitman.epub"
console.log(parsed.infoHash) // "d2474e86c95b19b8bcfdb92bc12c9d44667cfa36"
The entire parsed object
{
"xt": "urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36",
"dn": "Leaves of Grass by Walt Whitman.epub",
"tr": [
"udp://tracker.example1.com:1337",
"udp://tracker.example2.com:80",
"udp://tracker.example3.com:6969",
"udp://tracker.example4.com:80",
"udp://tracker.example5.com:80"
],
"name": "Leaves of Grass by Walt Whitman.epub",
"infoHash": "d2474e86c95b19b8bcfdb92bc12c9d44667cfa36",
"announce": [
"udp://tracker.example1.com:1337",
"udp://tracker.example2.com:80",
"udp://tracker.example3.com:6969",
"udp://tracker.example4.com:80",
"udp://tracker.example5.com:80"
]
}
import { magnetEncode } from '@ctrl/magnet-link';
// convert object to magnet uri
const uri = magnetEncode({
xt: [
'urn:ed2k:354B15E68FB8F36D7CD88FF94116CDC1',
'urn:tree:tiger:7N5OAMRNGMSSEUE3ORHOKWN4WWIQ5X4EBOOTLJY',
'urn:btih:QHQXPYWMACKDWKP47RRVIV7VOURXFE5Q',
],
xl: '10826029',
dn: 'mediawiki-1.15.1.tar.gz',
tr: [
'udp://tracker.openbittorrent.com:80/announce',
],
as: 'http://download.wikimedia.org/mediawiki/1.15/mediawiki-1.15.1.tar.gz',
xs: [
'http://cache.example.org/XRX2PEFXOOEJFRVUCX6HMZMKS5TWG4K5',
'dchub://example.org',
],
});
You can also use convenience key names like name (dn), infoHash (xt), infoHashBuffer (xt), announce (tr), and keywords (kt).
FAQs
Parse a magnet URI into an object
The npm package @ctrl/magnet-link receives a total of 1,711 weekly downloads. As such, @ctrl/magnet-link popularity was classified as popular.
We found that @ctrl/magnet-link demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket’s Rust and Cargo support is now generally available, providing dependency analysis and supply chain visibility for Rust projects.

Security News
Chrome 144 introduces the Temporal API, a modern approach to date and time handling designed to fix long-standing issues with JavaScript’s Date object.

Research
Five coordinated Chrome extensions enable session hijacking and block security controls across enterprise HR and ERP platforms.