Skip to content

Commit

Permalink
Update BN#inspect for Symbols (#225)
Browse files Browse the repository at this point in the history
  • Loading branch information
fanatid authored Aug 10, 2019
1 parent b28644b commit 79dccc4
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/bn.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,17 @@
return this;
};

BN.prototype.inspect = function inspect () {
// Check Symbol.for because not everywhere where Symbol defined
// See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol#Browser_compatibility
if (typeof Symbol !== 'undefined' && typeof Symbol.for === 'function') {
BN.prototype[Symbol.for('nodejs.util.inspect.custom')] = inspect;
} else {
BN.prototype.inspect = inspect;
}

function inspect () {
return (this.red ? '<BN-R: ' : '<BN: ') + this.toString(16) + '>';
};
}

/*
Expand Down

0 comments on commit 79dccc4

Please sign in to comment.