diff --git a/types/magnet-uri/.npmignore b/types/magnet-uri/.npmignore
index 93e307400a5456..0c0a46f107d0dc 100644
--- a/types/magnet-uri/.npmignore
+++ b/types/magnet-uri/.npmignore
@@ -3,3 +3,4 @@
!**/*.d.cts
!**/*.d.mts
!**/*.d.*.ts
+/v5/
diff --git a/types/magnet-uri/index.d.ts b/types/magnet-uri/index.d.ts
index a05e9022799597..2d2d66c212c72d 100644
--- a/types/magnet-uri/index.d.ts
+++ b/types/magnet-uri/index.d.ts
@@ -1,30 +1,38 @@
-///
-
-declare const MagnetUri: MagnetUri.MagnetUri;
+export interface Instance {
+ dn?: string | string[] | undefined;
+ tr?: string | string[] | undefined;
+ xs?: string | string[] | undefined;
+ as?: string | string[] | undefined;
+ ws?: string | string[] | undefined;
+ kt?: string[] | undefined;
+ ix?: number | number[] | undefined;
+ xt?: string | string[] | undefined;
+ so?: any;
+ infoHash?: string | undefined;
+ infoHashBuffer?: Uint8Array | undefined;
+ infoHashV2?: string | undefined;
+ infoHashV2Buffer?: Uint8Array | undefined;
+ publicKey?: string | undefined;
+ publicKeyBuffer?: Uint8Array | undefined;
+ name?: string | undefined;
+ keywords?: string[] | undefined;
+ announce?: string[] | undefined;
+ urlList?: string[] | undefined;
+ peerAddresses?: string[] | undefined;
+ [key: string]: any;
+}
-declare namespace MagnetUri {
- interface MagnetUri {
- (uri: string): Instance;
- decode(uri: string): Instance;
- encode(parsed: Instance): string;
- }
+/**
+ * Parse a magnet URI and return an object of keys/values
+ */
+export default function magnetURIDecode(uri: string): Instance;
- interface Instance extends Object {
- dn?: string | string[] | undefined;
- tr?: string | string[] | undefined;
- xs?: string | string[] | undefined;
- as?: string | string[] | undefined;
- ws?: string | string[] | undefined;
- kt?: string[] | undefined;
- ix?: number | number[] | undefined;
- xt?: string | string[] | undefined;
- infoHash?: string | undefined;
- infoHashBuffer?: Buffer | undefined;
- name?: string | string[] | undefined;
- keywords?: string | string[] | undefined;
- announce?: string[] | undefined;
- urlList?: string[] | undefined;
- }
-}
+/**
+ * Encode an object of keys/values into a magnet URI string
+ */
+export function encode(obj: Instance): string;
-export = MagnetUri;
+/**
+ * Parse a magnet URI (alias for default export)
+ */
+export function decode(uri: string): Instance;
diff --git a/types/magnet-uri/magnet-uri-tests.ts b/types/magnet-uri/magnet-uri-tests.ts
index 31113a2d01ccf4..a9ed99e2c70114 100644
--- a/types/magnet-uri/magnet-uri-tests.ts
+++ b/types/magnet-uri/magnet-uri-tests.ts
@@ -1,9 +1,24 @@
-import * as magnet from "magnet-uri";
+import magnetURIDecode, { decode, encode, type Instance } from "magnet-uri";
// "Leaves of Grass" by Walt Whitman
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 = magnet.decode(uri);
-console.log(parsed);
-console.log(magnet.encode(parsed));
+// default export
+const parsed1 = magnetURIDecode(uri);
+// $ExpectType string | undefined
+parsed1.infoHash;
+// $ExpectType string[] | undefined
+parsed1.announce;
+// $ExpectType string | undefined
+parsed1.name;
+
+// decode alias
+const parsed2 = decode(uri);
+// $ExpectType string | undefined
+parsed2.infoHash;
+
+// encode
+const magnetUri = encode(parsed1);
+// $ExpectType string
+magnetUri;
diff --git a/types/magnet-uri/package.json b/types/magnet-uri/package.json
index 7fd7ff540195cc..8910e44ce2763d 100644
--- a/types/magnet-uri/package.json
+++ b/types/magnet-uri/package.json
@@ -1,13 +1,18 @@
{
"private": true,
"name": "@types/magnet-uri",
- "version": "5.1.9999",
+ "version": "7.0.9999",
+ "type": "module",
+ "exports": {
+ ".": {
+ "types": {
+ "default": "./index.d.ts"
+ }
+ }
+ },
"projects": [
"https://github.com/webtorrent/magnet-uri"
],
- "dependencies": {
- "@types/node": "*"
- },
"devDependencies": {
"@types/magnet-uri": "workspace:."
},
diff --git a/types/magnet-uri/v5/.npmignore b/types/magnet-uri/v5/.npmignore
new file mode 100644
index 00000000000000..93e307400a5456
--- /dev/null
+++ b/types/magnet-uri/v5/.npmignore
@@ -0,0 +1,5 @@
+*
+!**/*.d.ts
+!**/*.d.cts
+!**/*.d.mts
+!**/*.d.*.ts
diff --git a/types/magnet-uri/v5/index.d.ts b/types/magnet-uri/v5/index.d.ts
new file mode 100644
index 00000000000000..a05e9022799597
--- /dev/null
+++ b/types/magnet-uri/v5/index.d.ts
@@ -0,0 +1,30 @@
+///
+
+declare const MagnetUri: MagnetUri.MagnetUri;
+
+declare namespace MagnetUri {
+ interface MagnetUri {
+ (uri: string): Instance;
+ decode(uri: string): Instance;
+ encode(parsed: Instance): string;
+ }
+
+ interface Instance extends Object {
+ dn?: string | string[] | undefined;
+ tr?: string | string[] | undefined;
+ xs?: string | string[] | undefined;
+ as?: string | string[] | undefined;
+ ws?: string | string[] | undefined;
+ kt?: string[] | undefined;
+ ix?: number | number[] | undefined;
+ xt?: string | string[] | undefined;
+ infoHash?: string | undefined;
+ infoHashBuffer?: Buffer | undefined;
+ name?: string | string[] | undefined;
+ keywords?: string | string[] | undefined;
+ announce?: string[] | undefined;
+ urlList?: string[] | undefined;
+ }
+}
+
+export = MagnetUri;
diff --git a/types/magnet-uri/v5/magnet-uri-tests.ts b/types/magnet-uri/v5/magnet-uri-tests.ts
new file mode 100644
index 00000000000000..31113a2d01ccf4
--- /dev/null
+++ b/types/magnet-uri/v5/magnet-uri-tests.ts
@@ -0,0 +1,9 @@
+import * as magnet from "magnet-uri";
+
+// "Leaves of Grass" by Walt Whitman
+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 = magnet.decode(uri);
+console.log(parsed);
+console.log(magnet.encode(parsed));
diff --git a/types/magnet-uri/v5/package.json b/types/magnet-uri/v5/package.json
new file mode 100644
index 00000000000000..7fd7ff540195cc
--- /dev/null
+++ b/types/magnet-uri/v5/package.json
@@ -0,0 +1,20 @@
+{
+ "private": true,
+ "name": "@types/magnet-uri",
+ "version": "5.1.9999",
+ "projects": [
+ "https://github.com/webtorrent/magnet-uri"
+ ],
+ "dependencies": {
+ "@types/node": "*"
+ },
+ "devDependencies": {
+ "@types/magnet-uri": "workspace:."
+ },
+ "owners": [
+ {
+ "name": "Tomasz Łaziuk",
+ "githubUsername": "tlaziuk"
+ }
+ ]
+}
diff --git a/types/magnet-uri/v5/tsconfig.json b/types/magnet-uri/v5/tsconfig.json
new file mode 100644
index 00000000000000..f16c61efff34c7
--- /dev/null
+++ b/types/magnet-uri/v5/tsconfig.json
@@ -0,0 +1,20 @@
+{
+ "compilerOptions": {
+ "module": "node16",
+ "lib": [
+ "es6",
+ "dom"
+ ],
+ "noImplicitAny": true,
+ "noImplicitThis": true,
+ "strictNullChecks": true,
+ "strictFunctionTypes": true,
+ "types": [],
+ "noEmit": true,
+ "forceConsistentCasingInFileNames": true
+ },
+ "files": [
+ "index.d.ts",
+ "magnet-uri-tests.ts"
+ ]
+}
diff --git a/types/parse-torrent/.npmignore b/types/parse-torrent/.npmignore
index 93e307400a5456..0c0a46f107d0dc 100644
--- a/types/parse-torrent/.npmignore
+++ b/types/parse-torrent/.npmignore
@@ -3,3 +3,4 @@
!**/*.d.cts
!**/*.d.mts
!**/*.d.*.ts
+/v5/
diff --git a/types/parse-torrent/index.d.ts b/types/parse-torrent/index.d.ts
index 568cc7cbc75462..3ced5f8690e35f 100644
--- a/types/parse-torrent/index.d.ts
+++ b/types/parse-torrent/index.d.ts
@@ -1,31 +1,59 @@
///
-import MagnetUri = require("magnet-uri");
-import ParseTorrentFile = require("parse-torrent-file");
-
-declare const ParseTorrent: ParseTorrent.ParseTorrent;
-
-declare namespace ParseTorrent {
- interface ParseTorrent {
- (torrent: string): MagnetUri.Instance;
- (torrent: Buffer): MagnetUri.Instance | ParseTorrentFile.Instance;
- (torrent: Instance | MagnetUri.Instance | ParseTorrentFile.Instance): Instance;
-
- toMagnetURI: typeof MagnetUri.encode;
- toTorrentFile: typeof ParseTorrentFile.encode;
-
- remote(
- torrent: string | Buffer | Instance | MagnetUri.Instance | ParseTorrentFile.Instance | Blob,
- cb?: (err: Error, torrent?: Instance) => void,
- ): void;
- }
-
- interface Instance extends MagnetUri.Instance, ParseTorrentFile.Instance {
- infoHash: string;
- name?: string | undefined;
- announce?: string[] | undefined;
- urlList?: string[] | undefined;
- }
+import type { Instance as MagnetUriInstance } from "magnet-uri";
+
+export interface ParsedFile {
+ path: string;
+ name: string;
+ length: number;
+ offset: number;
+}
+
+export interface Instance extends MagnetUriInstance {
+ info?: any;
+ infoBuffer?: Uint8Array;
+ infoHash: string;
+ infoHashBuffer?: Uint8Array;
+ name?: string;
+ private?: boolean;
+ created?: Date;
+ createdBy?: string;
+ comment?: string;
+ announce: string[];
+ urlList?: string[];
+ files?: ParsedFile[];
+ length?: number;
+ pieceLength?: number;
+ lastPieceLength?: number;
+ pieces?: string[];
}
-export = ParseTorrent;
+export type TorrentId = string | Uint8Array | Instance;
+
+/**
+ * Parse a torrent identifier (magnet uri, .torrent file, info hash)
+ */
+export default function parseTorrent(torrentId: TorrentId): Promise;
+
+/**
+ * Parse a torrent from a remote source (URL, Blob, or filesystem path)
+ */
+export function remote(
+ torrentId: string | Uint8Array | Instance | Blob,
+ opts: RequestInit,
+ cb: (err: Error | null, torrent?: Instance) => void,
+): void;
+export function remote(
+ torrentId: string | Uint8Array | Instance | Blob,
+ cb: (err: Error | null, torrent?: Instance) => void,
+): void;
+
+/**
+ * Convert a parsed torrent object back into a .torrent file buffer
+ */
+export function toTorrentFile(parsed: Instance): Uint8Array;
+
+/**
+ * Convert a parsed torrent object into a magnet URI string
+ */
+export function toMagnetURI(parsed: MagnetUriInstance): string;
diff --git a/types/parse-torrent/package.json b/types/parse-torrent/package.json
index 4cc9dfaa10cf3d..c1a26c1b460741 100644
--- a/types/parse-torrent/package.json
+++ b/types/parse-torrent/package.json
@@ -1,14 +1,21 @@
{
"private": true,
"name": "@types/parse-torrent",
- "version": "5.8.9999",
+ "version": "11.0.9999",
+ "type": "module",
+ "exports": {
+ ".": {
+ "types": {
+ "default": "./index.d.ts"
+ }
+ }
+ },
"projects": [
"https://github.com/webtorrent/parse-torrent"
],
"dependencies": {
"@types/magnet-uri": "*",
- "@types/node": "*",
- "@types/parse-torrent-file": "*"
+ "@types/node": "*"
},
"devDependencies": {
"@types/parse-torrent": "workspace:."
diff --git a/types/parse-torrent/parse-torrent-tests.ts b/types/parse-torrent/parse-torrent-tests.ts
index 8b5e8923edd57b..833f8c47387479 100644
--- a/types/parse-torrent/parse-torrent-tests.ts
+++ b/types/parse-torrent/parse-torrent-tests.ts
@@ -1,95 +1,103 @@
-import parseTorrent = require("parse-torrent");
import * as fs from "fs";
+import parseTorrent, { type Instance, remote, toMagnetURI, toTorrentFile } from "parse-torrent";
// info hash (as a hex string)
-parseTorrent("d2474e86c95b19b8bcfdb92bc12c9d44667cfa36");
-// { infoHash: 'd2474e86c95b19b8bcfdb92bc12c9d44667cfa36' }
+const hash = "d2474e86c95b19b8bcfdb92bc12c9d44667cfa36";
+const result1 = await parseTorrent(hash);
+// $ExpectType string
+result1.infoHash;
-// info hash (as a Buffer)
-parseTorrent(new Buffer("d2474e86c95b19b8bcfdb92bc12c9d44667cfa36", "hex"));
-// { infoHash: 'd2474e86c95b19b8bcfdb92bc12c9d44667cfa36' }
+// info hash (as a Uint8Array)
+const result2 = await parseTorrent(new Uint8Array(20));
+// $ExpectType string
+result2.infoHash;
// magnet uri (as a utf8 string)
-parseTorrent("magnet:?xt=urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36");
-// { xt: 'urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36',
-// infoHash: 'd2474e86c95b19b8bcfdb92bc12c9d44667cfa36' }
+const magnet = `magnet:?xt=urn:btih:${hash}`;
+const result3 = await parseTorrent(magnet);
+// $ExpectType string
+result3.infoHash;
+
+// stream-magnet uri
+const streamMagnet = `stream-magnet:?xt=urn:btih:${hash}`;
+const result4 = await parseTorrent(streamMagnet);
+// $ExpectType string
+result4.infoHash;
// magnet uri with torrent name
-parseTorrent(
- "magnet:?xt=urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36&dn=Leaves%20of%20Grass%20by%20Walt%20Whitman.epub",
+const result5 = await parseTorrent(
+ `magnet:?xt=urn:btih:${hash}&dn=Leaves%20of%20Grass%20by%20Walt%20Whitman.epub`,
);
-// { xt: 'urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36',
-// dn: 'Leaves of Grass by Walt Whitman.epub',
-// infoHash: 'd2474e86c95b19b8bcfdb92bc12c9d44667cfa36',
-// name: 'Leaves of Grass by Walt Whitman.epub' }
+// $ExpectType string | undefined
+result5.name;
// magnet uri with trackers
-parseTorrent(
- "magnet:?xt=urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36&tr=http%3A%2F%2Ftracker.example.com%2Fannounce",
+const result6 = await parseTorrent(
+ `magnet:?xt=urn:btih:${hash}&tr=http%3A%2F%2Ftracker.example.com%2Fannounce`,
);
-// { xt: 'urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36',
-// tr: 'http://tracker.example.com/announce',
-// infoHash: 'd2474e86c95b19b8bcfdb92bc12c9d44667cfa36',
-// announce: [ 'http://tracker.example.com/announce' ] }
+// $ExpectType string[]
+result6.announce;
-// .torrent file (as a Buffer)
-parseTorrent(fs.readFileSync(__dirname + "/torrents/leaves.torrent"));
-// { info:
-// { length: 362017,
-// name: ,
-// 'piece length': 16384,
-// pieces: },
-// infoBuffer: ,
-// infoHash: 'd2474e86c95b19b8bcfdb92bc12c9d44667cfa36',
-// name: 'Leaves of Grass by Walt Whitman.epub',
-// private: false,
-// created: Thu Aug 01 2013 06:27:46 GMT-0700 (PDT),
-// comment: 'Downloaded from http://TheTorrent.org',
-// announce:
-// [ 'http://tracker.example.com/announce' ],
-// urlList: [],
-// files:
-// [ { path: 'Leaves of Grass by Walt Whitman.epub',
-// name: 'Leaves of Grass by Walt Whitman.epub',
-// length: 362017,
-// offset: 0 } ],
-// length: 362017,
-// pieceLength: 16384,
-// lastPieceLength: 1569,
-// pieces:
-// [ '1f9c3f59beec079715ec53324bde8569e4a0b4eb',
-// 'ec42307d4ce5557b5d3964c5ef55d354cf4a6ecc',
-// '7bf1bcaf79d11fa5e0be06593c8faafc0c2ba2cf',
-// '76d71c5b01526b23007f9e9929beafc5151e6511',
-// '0931a1b44c21bf1e68b9138f90495e690dbc55f5',
-// '72e4c2944cbacf26e6b3ae8a7229d88aafa05f61',
-// 'eaae6abf3f07cb6db9677cc6aded4dd3985e4586',
-// '27567fa7639f065f71b18954304aca6366729e0b',
-// '4773d77ae80caa96a524804dfe4b9bd3deaef999',
-// 'c9dd51027467519d5eb2561ae2cc01467de5f643',
-// '0a60bcba24797692efa8770d23df0a830d91cb35',
-// 'b3407a88baa0590dc8c9aa6a120f274367dcd867',
-// 'e88e8338c572a06e3c801b29f519df532b3e76f6',
-// '70cf6aee53107f3d39378483f69cf80fa568b1ea',
-// 'c53b506159e988d8bc16922d125d77d803d652c3',
-// 'ca3070c16eed9172ab506d20e522ea3f1ab674b3',
-// 'f923d76fe8f44ff32e372c3b376564c6fb5f0dbe',
-// '52164f03629fd1322636babb2c014b7dae582da4',
-// '1363965261e6ce12b43701f0a8c9ed1520a70eba',
-// '004400a267765f6d3dd5c7beb5bd3c75f3df2a54',
-// '560a61801147fa4ec7cf568e703acb04e5610a4d',
-// '56dcc242d03293e9446cf5e457d8eb3d9588fd90',
-// 'c698de9b0dad92980906c026d8c1408fa08fe4ec' ] }
+// .torrent file (as a Uint8Array)
+const torrentBuf = fs.readFileSync("torrents/leaves.torrent");
+const result7 = await parseTorrent(new Uint8Array(torrentBuf));
+// $ExpectType string
+result7.infoHash;
+// $ExpectType string | undefined
+result7.name;
+// $ExpectType string[]
+result7.announce;
+// $ExpectType ParsedFile[] | undefined
+result7.files;
+// $ExpectType number | undefined
+result7.length;
+// $ExpectType number | undefined
+result7.pieceLength;
+// $ExpectType number | undefined
+result7.lastPieceLength;
+// $ExpectType string[] | undefined
+result7.pieces;
-const uri = parseTorrent.toMagnetURI({
- infoHash: "d2474e86c95b19b8bcfdb92bc12c9d44667cfa36",
-});
+// parsed torrent (as an Object)
+const parsedObj: Instance = {
+ infoHash: hash,
+ announce: [],
+};
+const result8 = await parseTorrent(parsedObj);
+// $ExpectType string
+result8.infoHash;
+
+// toMagnetURI
+const magnetUri = toMagnetURI({ infoHash: hash });
+// $ExpectType string
+magnetUri;
-const buf = parseTorrent.toTorrentFile({
- infoHash: "d2474e86c95b19b8bcfdb92bc12c9d44667cfa36",
+// toTorrentFile
+const torrentFile = toTorrentFile({ infoHash: hash, announce: [] });
+
+// remote with callback
+remote(hash, (err, torrent) => {
+ // $ExpectType Error | null
+ err;
+ // $ExpectType Instance | undefined
+ torrent;
});
-parseTorrent.remote("d2474e86c95b19b8bcfdb92bc12c9d44667cfa36", (err, parsedTorrent) => {
- // if (err) throw err
- // console.log(parsedTorrent)
+// remote with options and callback
+remote(hash, { signal: AbortSignal.timeout(5000) }, (err, torrent) => {
+ // $ExpectType Error | null
+ err;
+ // $ExpectType Instance | undefined
+ torrent;
});
+
+// remote with Blob
+if (typeof Blob !== "undefined") {
+ const blob = new Blob([new Uint8Array([1, 2, 3])]);
+ remote(blob, (err, torrent) => {
+ // $ExpectType Error | null
+ err;
+ // $ExpectType Instance | undefined
+ torrent;
+ });
+}
diff --git a/types/parse-torrent/v5/.npmignore b/types/parse-torrent/v5/.npmignore
new file mode 100644
index 00000000000000..93e307400a5456
--- /dev/null
+++ b/types/parse-torrent/v5/.npmignore
@@ -0,0 +1,5 @@
+*
+!**/*.d.ts
+!**/*.d.cts
+!**/*.d.mts
+!**/*.d.*.ts
diff --git a/types/parse-torrent/v5/index.d.ts b/types/parse-torrent/v5/index.d.ts
new file mode 100644
index 00000000000000..568cc7cbc75462
--- /dev/null
+++ b/types/parse-torrent/v5/index.d.ts
@@ -0,0 +1,31 @@
+///
+
+import MagnetUri = require("magnet-uri");
+import ParseTorrentFile = require("parse-torrent-file");
+
+declare const ParseTorrent: ParseTorrent.ParseTorrent;
+
+declare namespace ParseTorrent {
+ interface ParseTorrent {
+ (torrent: string): MagnetUri.Instance;
+ (torrent: Buffer): MagnetUri.Instance | ParseTorrentFile.Instance;
+ (torrent: Instance | MagnetUri.Instance | ParseTorrentFile.Instance): Instance;
+
+ toMagnetURI: typeof MagnetUri.encode;
+ toTorrentFile: typeof ParseTorrentFile.encode;
+
+ remote(
+ torrent: string | Buffer | Instance | MagnetUri.Instance | ParseTorrentFile.Instance | Blob,
+ cb?: (err: Error, torrent?: Instance) => void,
+ ): void;
+ }
+
+ interface Instance extends MagnetUri.Instance, ParseTorrentFile.Instance {
+ infoHash: string;
+ name?: string | undefined;
+ announce?: string[] | undefined;
+ urlList?: string[] | undefined;
+ }
+}
+
+export = ParseTorrent;
diff --git a/types/parse-torrent/v5/package.json b/types/parse-torrent/v5/package.json
new file mode 100644
index 00000000000000..3b2785d14c652d
--- /dev/null
+++ b/types/parse-torrent/v5/package.json
@@ -0,0 +1,26 @@
+{
+ "private": true,
+ "name": "@types/parse-torrent",
+ "version": "5.8.9999",
+ "projects": [
+ "https://github.com/webtorrent/parse-torrent"
+ ],
+ "dependencies": {
+ "@types/magnet-uri": "^5",
+ "@types/node": "*",
+ "@types/parse-torrent-file": "*"
+ },
+ "devDependencies": {
+ "@types/parse-torrent": "workspace:."
+ },
+ "owners": [
+ {
+ "name": "Bazyli Brzóska",
+ "githubUsername": "niieani"
+ },
+ {
+ "name": "Tomasz Łaziuk",
+ "githubUsername": "tlaziuk"
+ }
+ ]
+}
diff --git a/types/parse-torrent/v5/parse-torrent-tests.ts b/types/parse-torrent/v5/parse-torrent-tests.ts
new file mode 100644
index 00000000000000..8b5e8923edd57b
--- /dev/null
+++ b/types/parse-torrent/v5/parse-torrent-tests.ts
@@ -0,0 +1,95 @@
+import parseTorrent = require("parse-torrent");
+import * as fs from "fs";
+
+// info hash (as a hex string)
+parseTorrent("d2474e86c95b19b8bcfdb92bc12c9d44667cfa36");
+// { infoHash: 'd2474e86c95b19b8bcfdb92bc12c9d44667cfa36' }
+
+// info hash (as a Buffer)
+parseTorrent(new Buffer("d2474e86c95b19b8bcfdb92bc12c9d44667cfa36", "hex"));
+// { infoHash: 'd2474e86c95b19b8bcfdb92bc12c9d44667cfa36' }
+
+// magnet uri (as a utf8 string)
+parseTorrent("magnet:?xt=urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36");
+// { xt: 'urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36',
+// infoHash: 'd2474e86c95b19b8bcfdb92bc12c9d44667cfa36' }
+
+// magnet uri with torrent name
+parseTorrent(
+ "magnet:?xt=urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36&dn=Leaves%20of%20Grass%20by%20Walt%20Whitman.epub",
+);
+// { xt: 'urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36',
+// dn: 'Leaves of Grass by Walt Whitman.epub',
+// infoHash: 'd2474e86c95b19b8bcfdb92bc12c9d44667cfa36',
+// name: 'Leaves of Grass by Walt Whitman.epub' }
+
+// magnet uri with trackers
+parseTorrent(
+ "magnet:?xt=urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36&tr=http%3A%2F%2Ftracker.example.com%2Fannounce",
+);
+// { xt: 'urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36',
+// tr: 'http://tracker.example.com/announce',
+// infoHash: 'd2474e86c95b19b8bcfdb92bc12c9d44667cfa36',
+// announce: [ 'http://tracker.example.com/announce' ] }
+
+// .torrent file (as a Buffer)
+parseTorrent(fs.readFileSync(__dirname + "/torrents/leaves.torrent"));
+// { info:
+// { length: 362017,
+// name: ,
+// 'piece length': 16384,
+// pieces: },
+// infoBuffer: ,
+// infoHash: 'd2474e86c95b19b8bcfdb92bc12c9d44667cfa36',
+// name: 'Leaves of Grass by Walt Whitman.epub',
+// private: false,
+// created: Thu Aug 01 2013 06:27:46 GMT-0700 (PDT),
+// comment: 'Downloaded from http://TheTorrent.org',
+// announce:
+// [ 'http://tracker.example.com/announce' ],
+// urlList: [],
+// files:
+// [ { path: 'Leaves of Grass by Walt Whitman.epub',
+// name: 'Leaves of Grass by Walt Whitman.epub',
+// length: 362017,
+// offset: 0 } ],
+// length: 362017,
+// pieceLength: 16384,
+// lastPieceLength: 1569,
+// pieces:
+// [ '1f9c3f59beec079715ec53324bde8569e4a0b4eb',
+// 'ec42307d4ce5557b5d3964c5ef55d354cf4a6ecc',
+// '7bf1bcaf79d11fa5e0be06593c8faafc0c2ba2cf',
+// '76d71c5b01526b23007f9e9929beafc5151e6511',
+// '0931a1b44c21bf1e68b9138f90495e690dbc55f5',
+// '72e4c2944cbacf26e6b3ae8a7229d88aafa05f61',
+// 'eaae6abf3f07cb6db9677cc6aded4dd3985e4586',
+// '27567fa7639f065f71b18954304aca6366729e0b',
+// '4773d77ae80caa96a524804dfe4b9bd3deaef999',
+// 'c9dd51027467519d5eb2561ae2cc01467de5f643',
+// '0a60bcba24797692efa8770d23df0a830d91cb35',
+// 'b3407a88baa0590dc8c9aa6a120f274367dcd867',
+// 'e88e8338c572a06e3c801b29f519df532b3e76f6',
+// '70cf6aee53107f3d39378483f69cf80fa568b1ea',
+// 'c53b506159e988d8bc16922d125d77d803d652c3',
+// 'ca3070c16eed9172ab506d20e522ea3f1ab674b3',
+// 'f923d76fe8f44ff32e372c3b376564c6fb5f0dbe',
+// '52164f03629fd1322636babb2c014b7dae582da4',
+// '1363965261e6ce12b43701f0a8c9ed1520a70eba',
+// '004400a267765f6d3dd5c7beb5bd3c75f3df2a54',
+// '560a61801147fa4ec7cf568e703acb04e5610a4d',
+// '56dcc242d03293e9446cf5e457d8eb3d9588fd90',
+// 'c698de9b0dad92980906c026d8c1408fa08fe4ec' ] }
+
+const uri = parseTorrent.toMagnetURI({
+ infoHash: "d2474e86c95b19b8bcfdb92bc12c9d44667cfa36",
+});
+
+const buf = parseTorrent.toTorrentFile({
+ infoHash: "d2474e86c95b19b8bcfdb92bc12c9d44667cfa36",
+});
+
+parseTorrent.remote("d2474e86c95b19b8bcfdb92bc12c9d44667cfa36", (err, parsedTorrent) => {
+ // if (err) throw err
+ // console.log(parsedTorrent)
+});
diff --git a/types/parse-torrent/v5/tsconfig.json b/types/parse-torrent/v5/tsconfig.json
new file mode 100644
index 00000000000000..a1602491600563
--- /dev/null
+++ b/types/parse-torrent/v5/tsconfig.json
@@ -0,0 +1,20 @@
+{
+ "compilerOptions": {
+ "module": "node16",
+ "lib": [
+ "es6",
+ "dom"
+ ],
+ "noImplicitAny": true,
+ "noImplicitThis": true,
+ "strictNullChecks": true,
+ "strictFunctionTypes": true,
+ "types": [],
+ "noEmit": true,
+ "forceConsistentCasingInFileNames": true
+ },
+ "files": [
+ "index.d.ts",
+ "parse-torrent-tests.ts"
+ ]
+}
diff --git a/types/webtorrent/package.json b/types/webtorrent/package.json
index 12b0d3ab6df853..c5ded4d413c5a6 100644
--- a/types/webtorrent/package.json
+++ b/types/webtorrent/package.json
@@ -9,7 +9,7 @@
"dependencies": {
"@types/bittorrent-protocol": "*",
"@types/node": "*",
- "@types/parse-torrent": "*",
+ "@types/parse-torrent": "^5",
"@types/simple-peer": "*"
},
"devDependencies": {