@ctrl/magnet-link 4.2.0 → 4.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  Port of [webtorrent/magnet-uri](https://github.com/webtorrent/magnet-uri) by [feross](https://github.com/feross) that uses fewer dependencies in typescript
6
6
 
7
- **Demo**: https://magnet-link.vercel.app
7
+ **Demo**: https://magnet-link.ep.workers.dev
8
8
 
9
9
  ### Install
10
10
 
package/dist/src/bep53.js CHANGED
@@ -9,10 +9,10 @@ export function composeRange(range) {
9
9
  }, [])
10
10
  .map(cur => (cur.length > 1 ? `${cur[0]}-${cur[cur.length - 1]}` : `${cur[0]}`));
11
11
  }
12
+ const generateRange = (start, end = start) => Array.from({ length: end - start + 1 }, (_, idx) => idx + start);
12
13
  export function parseRange(range) {
13
- const generateRange = (start, end = start) => Array.from({ length: end - start + 1 }, (_, idx) => idx + start);
14
14
  return range.reduce((acc, cur) => {
15
- const r = cur.split('-').map(cur => parseInt(cur, 10));
16
- return acc.concat(generateRange(r[0], r[1]));
15
+ const r = cur.split('-').map(cur => Number.parseInt(cur, 10));
16
+ return [...acc, ...generateRange(r[0], r[1])];
17
17
  }, []);
18
18
  }
package/dist/src/index.js CHANGED
@@ -4,7 +4,7 @@ import * as bep53Range from './bep53.js';
4
4
  const start = 'magnet:?';
5
5
  export function magnetDecode(uri) {
6
6
  // Support 'stream-magnet:' as well
7
- const data = uri.substr(uri.indexOf(start) + start.length);
7
+ const data = uri.slice(uri.indexOf(start) + start.length);
8
8
  const params = data && data.length >= 0 ? data.split('&') : [];
9
9
  const result = {};
10
10
  params.forEach(param => {
@@ -82,14 +82,14 @@ export function magnetDecode(uri) {
82
82
  }
83
83
  result.urlList = [];
84
84
  if (typeof result.as === 'string' || Array.isArray(result.as)) {
85
- result.urlList = result.urlList.concat(result.as);
85
+ result.urlList = [...result.urlList, ...(Array.isArray(result.as) ? result.as : [result.as])];
86
86
  }
87
87
  if (typeof result.ws === 'string' || Array.isArray(result.ws)) {
88
- result.urlList = result.urlList.concat(result.ws);
88
+ result.urlList = [...result.urlList, ...(Array.isArray(result.ws) ? result.ws : [result.ws])];
89
89
  }
90
90
  result.peerAddresses = [];
91
91
  if (typeof result['x.pe'] === 'string' || Array.isArray(result['x.pe'])) {
92
- result.peerAddresses = result.peerAddresses.concat(result['x.pe']);
92
+ result.peerAddresses = [...result.peerAddresses, ...(Array.isArray(result['x.pe']) ? result['x.pe'] : [result['x.pe']])];
93
93
  }
94
94
  result.announce = [...new Set(result.announce)].sort((a, b) => a.localeCompare(b));
95
95
  result.urlList = [...new Set(result.urlList)].sort((a, b) => a.localeCompare(b));
@@ -145,7 +145,7 @@ export function magnetEncode(data) {
145
145
  if (obj.infoHashV2) {
146
146
  xts.add(`urn:btmh:1220${obj.infoHashV2}`);
147
147
  }
148
- const xtsDeduped = Array.from(xts);
148
+ const xtsDeduped = [...xts];
149
149
  if (xtsDeduped.length === 1) {
150
150
  obj.xt = xtsDeduped[0];
151
151
  }
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@ctrl/magnet-link",
3
- "version": "4.2.0",
3
+ "version": "4.2.1",
4
4
  "description": "Parse a magnet URI into an object",
5
5
  "author": "Scott Cooper <scttcper@gmail.com>",
6
- "homepage": "https://magnet-link.vercel.app",
6
+ "homepage": "https://magnet-link.ep.workers.dev",
7
7
  "license": "MIT",
8
8
  "repository": "scttcper/magnet-link",
9
9
  "keywords": [
@@ -23,34 +23,25 @@
23
23
  "dev": "npm run demo:watch",
24
24
  "demo:build": "npm run build --workspace=demo",
25
25
  "demo:watch": "npm run dev --workspace=demo",
26
- "lint": "oxlint . && prettier --check . --experimental-cli",
27
- "lint:fix": "oxlint . --fix && prettier --write . --log-level=error --experimental-cli",
26
+ "lint": "oxlint . && oxlint .",
27
+ "lint:fix": "oxlint . --fix && oxlint . --fix",
28
28
  "prepare": "npm run build",
29
29
  "build": "tsc",
30
30
  "test": "vitest run",
31
- "test:watch": "vitest",
32
- "test:ci": "vitest run --coverage --reporter=default --reporter=junit --outputFile=./junit.xml"
31
+ "test:watch": "vitest"
33
32
  },
34
33
  "dependencies": {
35
34
  "rfc4648": "^1.5.4",
36
35
  "uint8array-extras": "^1.5.0"
37
36
  },
38
37
  "devDependencies": {
39
- "@ctrl/oxlint-config": "1.2.6",
40
- "@sindresorhus/tsconfig": "8.0.1",
41
- "@types/node": "24.6.1",
42
- "@vitest/coverage-v8": "3.2.4",
43
- "oxlint": "1.19.0",
44
- "prettier": "3.6.2",
38
+ "@ctrl/oxlint-config": "1.4.0",
39
+ "@sindresorhus/tsconfig": "8.1.0",
40
+ "@types/node": "25.2.3",
41
+ "oxfmt": "0.33.0",
42
+ "oxlint": "1.48.0",
45
43
  "typescript": "5.9.3",
46
- "vitest": "3.2.4"
47
- },
48
- "prettier": {
49
- "singleQuote": true,
50
- "trailingComma": "all",
51
- "arrowParens": "avoid",
52
- "semi": true,
53
- "printWidth": 100
44
+ "vitest": "4.0.18"
54
45
  },
55
46
  "workspaces": [
56
47
  "demo"
@@ -65,6 +56,6 @@
65
56
  ]
66
57
  },
67
58
  "engines": {
68
- "node": ">=18"
59
+ "node": ">20"
69
60
  }
70
61
  }