mirror of
https://github.com/fluencelabs/examples
synced 2025-05-03 06:32:15 +00:00
23 lines
435 B
TypeScript
23 lines
435 B
TypeScript
import { Multiaddr, protocols } from "multiaddr";
|
|
|
|
export const decapsulateP2P = (rpcAddr: string) => {
|
|
return new Multiaddr(rpcAddr)
|
|
.decapsulateCode(protocols.names.p2p.code)
|
|
.toString();
|
|
};
|
|
|
|
export const fromOption = <T>(opt: T | T[] | null): T | null => {
|
|
if (Array.isArray(opt)) {
|
|
if (opt.length === 0) {
|
|
return null;
|
|
}
|
|
|
|
opt = opt[0];
|
|
}
|
|
if (opt === null) {
|
|
return null;
|
|
}
|
|
|
|
return opt;
|
|
};
|