File tree Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ const varint = require('varint')
6
6
const bs58 = require ( 'bs58' )
7
7
const CID = require ( 'cids' )
8
8
const withIs = require ( 'class-is' )
9
+ const inspect = Symbol . for ( 'nodejs.util.inspect.custom' )
9
10
10
11
/**
11
12
* Creates a [multiaddr](https://github.com/multiformats/multiaddr) from
@@ -86,7 +87,25 @@ Multiaddr.prototype.toOptions = function toOptions () {
86
87
}
87
88
88
89
/**
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
90
109
*
91
110
* @returns {String }
92
111
* @example
You can’t perform that action at this time.
0 commit comments