From 9c9c887bac99653c8a781e5023f131f9f74f0df7 Mon Sep 17 00:00:00 2001 From: Joseph Lee Date: Mon, 31 Mar 2025 16:37:26 +0900 Subject: [PATCH] feat: registerProtocol --- src/index.ts | 4 ++-- src/protocols-table.ts | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index f4e5e607..e3546509 100644 --- a/src/index.ts +++ b/src/index.ts @@ -95,7 +95,7 @@ import { stringTuplesToTuples, tuplesToBytes } from './codec.js' import { Multiaddr as MultiaddrClass, symbol } from './multiaddr.js' -import { getProtocol } from './protocols-table.js' +import { getProtocol, registerProtocol } from './protocols-table.js' import type { Resolver } from './resolvers/index.js' import type { DNS } from '@multiformats/dns' @@ -627,4 +627,4 @@ export function multiaddr (addr?: MultiaddrInput): Multiaddr { return new MultiaddrClass(addr) } -export { getProtocol as protocols } +export { getProtocol as protocols, registerProtocol } diff --git a/src/protocols-table.ts b/src/protocols-table.ts index 0d85beb5..c5f90a89 100644 --- a/src/protocols-table.ts +++ b/src/protocols-table.ts @@ -96,3 +96,8 @@ export function getProtocol (proto: number | string): Protocol { throw new Error(`invalid protocol id type: ${typeof proto}`) } + +export function registerProtocol (protocol: Protocol): void { + codes[protocol.code] = protocol + names[protocol.name] = protocol +}