Comparing version 2.2.3 to 2.3.0
{ | ||
"name": "multiaddr", | ||
"version": "2.2.3", | ||
"version": "2.3.0", | ||
"description": "multiaddr implementation (binary + string representation of network addresses)", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -109,3 +109,3 @@ 'use strict' | ||
return extend(protocols(code)) | ||
// copy to prevent users from modifying the internal objs. | ||
// copy to prevent users from modifying the internal objs. | ||
}) | ||
@@ -239,3 +239,3 @@ } | ||
* | ||
* @return {String} peerId - The id of the peer | ||
* @return {String|null} peerId - The id of the peer or null if invalid or missing from the ma | ||
* @example | ||
@@ -245,18 +245,19 @@ * const mh1 = Multiaddr('/ip4/8.8.8.8/tcp/1080/ipfs/QmValidBase58string') | ||
* | ||
* const peerId | ||
* | ||
* try { | ||
* peerId = mh1.getPeerId() | ||
* } catch (err) { | ||
* // not a valid base58 address | ||
* } | ||
* // should return QmValidBase58string or null if the id is missing or invalid | ||
* const peerId = mh1.getPeerId() | ||
*/ | ||
Multiaddr.prototype.getPeerId = function getPeerId () { | ||
let b58str = this.stringTuples().filter((tuple) => { | ||
if (tuple[0] === protocols.names['ipfs'].code) { | ||
return true | ||
} | ||
})[0][1] | ||
let b58str = null | ||
try { | ||
b58str = this.stringTuples().filter((tuple) => { | ||
if (tuple[0] === protocols.names['ipfs'].code) { | ||
return true | ||
} | ||
})[0][1] | ||
bs58.decode(b58str) | ||
bs58.decode(b58str) | ||
} catch (e) { | ||
b58str = null | ||
} | ||
return b58str | ||
@@ -263,0 +264,0 @@ } |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
641047