Socket
Socket
Sign inDemoInstall

magnet-uri

Package Overview
Dependencies
Maintainers
7
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

magnet-uri - npm Package Compare versions

Comparing version 5.3.0 to 5.4.0

28

index.js

@@ -7,2 +7,3 @@ /*! magnet-uri. MIT License. WebTorrent LLC <https://webtorrent.io/opensource> */

const base32 = require('thirty-two')
const bep53Range = require('bep53-range')

@@ -49,2 +50,5 @@ /**

// bep53
if (key === 'so') val = bep53Range.parse(decodeURIComponent(val).split(','))
// If there are repeated parameters, return an array of values

@@ -62,2 +66,9 @@ if (result[key]) {

if (result['x.pe']) {
// remove duplicates and convert to array
result['x.pe'] = Array.isArray(result['x.pe'])
? Array.from(new Set(result['x.pe']))
: [result['x.pe']]
}
// Convenience properties for parity with `parse-torrent-file` module

@@ -80,2 +91,3 @@ let m

if (result.kt) result.keywords = result.kt
if (result['x.pe']) result.peerAddresses = result['x.pe']

@@ -98,2 +110,8 @@ if (typeof result.tr === 'string') result.announce = [result.tr]

// convert x.pe into two level object
if (result['x.pe']) {
result.x = { pe: result['x.pe'] }
delete result['x.pe']
}
return result

@@ -116,10 +134,14 @@ }

}
if (obj.peerAddresses) obj['x.pe'] = obj.peerAddresses
// translate x.pe for processing
if (obj.x && obj.x.pe) obj['x.pe'] = obj.x.pe
let result = 'magnet:?'
Object.keys(obj)
.filter(key => key.length === 2)
.filter(key => key.length === 2 || key === 'x.pe')
.forEach((key, i) => {
const values = Array.isArray(obj[key]) ? obj[key] : [obj[key]]
values.forEach((val, j) => {
if ((i > 0 || j > 0) && (key !== 'kt' || j === 0)) result += '&'
if ((i > 0 || j > 0) && ((key !== 'kt' && key !== 'so') || j === 0)) result += '&'

@@ -131,2 +153,3 @@ if (key === 'dn') val = encodeURIComponent(val).replace(/%20/g, '+')

if (key === 'kt') val = encodeURIComponent(val)
if (key === 'so') return

@@ -136,2 +159,3 @@ if (key === 'kt' && j > 0) result += `+${val}`

})
if (key === 'so') result += `${key}=${bep53Range.compose(values)}`
})

@@ -138,0 +162,0 @@

5

package.json
{
"name": "magnet-uri",
"description": "Parse a magnet URI and return an object of keys/values",
"version": "5.3.0",
"version": "5.4.0",
"author": {

@@ -14,3 +14,4 @@ "name": "WebTorrent LLC",

"dependencies": {
"thirty-two": "^1.0.2"
"thirty-two": "^1.0.2",
"bep53-range": "^1.0.0"
},

@@ -17,0 +18,0 @@ "devDependencies": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc