From 79dccc4d3274ffae17cfb54ce08703a98b1d4fe0 Mon Sep 17 00:00:00 2001 From: Kirill Fomichev Date: Sat, 10 Aug 2019 19:36:47 +0300 Subject: [PATCH] Update BN#inspect for Symbols (#225) --- lib/bn.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/bn.js b/lib/bn.js index 2be2c25..bba8981 100644 --- a/lib/bn.js +++ b/lib/bn.js @@ -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 ? ''; - }; + } /*