Skip to content

Commit a79a7af

Browse files
authored
fix: inspect deprecation warning (#109)
1 parent 9ffafdb commit a79a7af

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/index.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const varint = require('varint')
66
const bs58 = require('bs58')
77
const CID = require('cids')
88
const withIs = require('class-is')
9+
const inspect = Symbol.for('nodejs.util.inspect.custom')
910

1011
/**
1112
* Creates a [multiaddr](https://github.com/multiformats/multiaddr) from
@@ -86,7 +87,25 @@ Multiaddr.prototype.toOptions = function toOptions () {
8687
}
8788

8889
/**
89-
* Returns Multiaddr as a human-readable string
90+
* Returns Multiaddr as a human-readable string.
91+
* For post Node.js v10.0.0.
92+
* https://nodejs.org/api/deprecations.html#deprecations_dep0079_custom_inspection_function_on_objects_via_inspect
93+
*
94+
* @returns {String}
95+
* @example
96+
* console.log(Multiaddr('/ip4/127.0.0.1/tcp/4001'))
97+
* // '<Multiaddr 047f000001060fa1 - /ip4/127.0.0.1/tcp/4001>'
98+
*/
99+
Multiaddr.prototype[inspect] = function inspectCustom () {
100+
return '<Multiaddr ' +
101+
this.buffer.toString('hex') + ' - ' +
102+
codec.bufferToString(this.buffer) + '>'
103+
}
104+
105+
/**
106+
* Returns Multiaddr as a human-readable string.
107+
* Fallback for pre Node.js v10.0.0.
108+
* https://nodejs.org/api/deprecations.html#deprecations_dep0079_custom_inspection_function_on_objects_via_inspect
90109
*
91110
* @returns {String}
92111
* @example

0 commit comments

Comments
 (0)