Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Inspect deprecation warning #109

Merged
merged 1 commit into from
Feb 13, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const varint = require('varint')
const bs58 = require('bs58')
const CID = require('cids')
const withIs = require('class-is')
const inspect = Symbol.for('nodejs.util.inspect.custom')

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

/**
* Returns Multiaddr as a human-readable string
* Returns Multiaddr as a human-readable string.
* For post Node.js v10.0.0.
* https://nodejs.org/api/deprecations.html#deprecations_dep0079_custom_inspection_function_on_objects_via_inspect
*
* @returns {String}
* @example
* console.log(Multiaddr('/ip4/127.0.0.1/tcp/4001'))
* // '<Multiaddr 047f000001060fa1 - /ip4/127.0.0.1/tcp/4001>'
*/
Multiaddr.prototype[inspect] = function inspectCustom () {
return '<Multiaddr ' +
this.buffer.toString('hex') + ' - ' +
codec.bufferToString(this.buffer) + '>'
}

/**
* Returns Multiaddr as a human-readable string.
* Fallback for pre Node.js v10.0.0.
* https://nodejs.org/api/deprecations.html#deprecations_dep0079_custom_inspection_function_on_objects_via_inspect
*
* @returns {String}
* @example
Expand Down