npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

magnet-uri-js

v0.0.2

Published

Library to convert Magnet URIS to objects

Downloads

22

Readme

Magnet-URI-JS Build Status

Library to convert Magnet URIS to objects

Install

npm install magnet-uri-js

Usage

Setup
const magneturi = require('magnet-uri-js');
Encoding Objects as Magnet URIS
Without Indexed Parameters
const obj = {
    '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'
        ]
};
const uri = magneturi.encode(obj);
magnet:?xt=urn:ed2k:354B15E68FB8F36D7CD88FF94116CDC1&xt=urn:tree:tiger:7N5OAMRNGMSSEUE3ORHOKWN4WWIQ5X4EBOOTLJY&xt=urn:btih:QHQXPYWMACKDWKP47RRVIV7VOURXFE5Q&xl=10826029&dn=mediawiki-1.15.1.tar.gz&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80%2Fannounce&as=http%3A%2F%2Fdownload.wikimedia.org%2Fmediawiki%2F1.15%2Fmediawiki-1.15.1.tar.gz&xs=http%3A%2F%2Fcache.example.org%2FXRX2PEFXOOEJFRVUCX6HMZMKS5TWG4K5&xs=dchub%3A%2F%2Fexample.org
With Indexed Parameters
const obj = {
  'xt':[
      'urn:sha1:YNCKHTQCWBTRNJIV4WNAE52SJUQCZO5C',
      'urn:sha1:TXGCZQTH26NL6OUQAJJPFALHG2LTGBC7'
  ]
};
const uri = magneturi.encode(obj, true);
magnet:?xt.1=urn:sha1:YNCKHTQCWBTRNJIV4WNAE52SJUQCZO5C&xt.2=urn:sha1:TXGCZQTH26NL6OUQAJJPFALHG2LTGBC7
Decoding Magnet URIS to Objects
const uri = 'magnet:?xt=urn:ed2k:31D6CFE0D16AE931B73C59D7E0C089C0&xl=0&dn=zero_len.fil&xt=urn:bitprint:3I42H3S6NNFQ2MSVX7XZKYAYSCX5QBYJ.LWPNACQDBZRYXW3VHJVCJ64QBZNGHOHHHZWCLNQ&xt=urn:md5:D41D8CD98F00B204E9800998ECF8427E';
const obj = magneturi.decode(uri);
{ xt:
   [ 'urn:ed2k:31D6CFE0D16AE931B73C59D7E0C089C0',
     'urn:bitprint:3I42H3S6NNFQ2MSVX7XZKYAYSCX5QBYJ.LWPNACQDBZRYXW3VHJVCJ64QBZNGHOHHHZWCLNQ ',
     'urn:md5:D41D8CD98F00B204E9800998ECF8427E' ],
  xl: '0',
  dn: 'zero_len.fil' }

Methods

encode ⇒ String

Encodes an object as a Magnet URI

| Param | Type | | --- | --- | | obj | Object | | multiParamIndexing | Boolean |

decode ⇒ Object

Decodes a Magnet URI and returns an object of all its parameters.

| Param | Type | | --- | --- | | magnet_uri | string |