aboutsummaryrefslogtreecommitdiffstats
path: root/packages/utils/src/configured_bignumber.ts
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-11-12 05:11:10 +0800
committerFabio Berger <me@fabioberger.com>2018-11-12 05:11:10 +0800
commit0391f93490cffdc69f6cb32f11762d174ed04e37 (patch)
tree3a8b30a04de1193aa21e5b84bd572db24979a8bf /packages/utils/src/configured_bignumber.ts
parent399a7d5fec9af4f3491a77f0c2d46738f3d8ffa7 (diff)
parent397b4e289015f9bb0831c1a0ce6fee601670b487 (diff)
downloaddexon-sol-tools-0391f93490cffdc69f6cb32f11762d174ed04e37.tar
dexon-sol-tools-0391f93490cffdc69f6cb32f11762d174ed04e37.tar.gz
dexon-sol-tools-0391f93490cffdc69f6cb32f11762d174ed04e37.tar.bz2
dexon-sol-tools-0391f93490cffdc69f6cb32f11762d174ed04e37.tar.lz
dexon-sol-tools-0391f93490cffdc69f6cb32f11762d174ed04e37.tar.xz
dexon-sol-tools-0391f93490cffdc69f6cb32f11762d174ed04e37.tar.zst
dexon-sol-tools-0391f93490cffdc69f6cb32f11762d174ed04e37.zip
merge development
Diffstat (limited to 'packages/utils/src/configured_bignumber.ts')
-rw-r--r--packages/utils/src/configured_bignumber.ts23
1 files changed, 23 insertions, 0 deletions
diff --git a/packages/utils/src/configured_bignumber.ts b/packages/utils/src/configured_bignumber.ts
index 2b22b6938..34b57d303 100644
--- a/packages/utils/src/configured_bignumber.ts
+++ b/packages/utils/src/configured_bignumber.ts
@@ -11,4 +11,27 @@ BigNumber.config({
DECIMAL_PLACES: 78,
});
+// Set a debug print function for NodeJS
+// Upstream issue: https://github.com/MikeMcl/bignumber.js/issues/188
+import isNode = require('detect-node');
+if (isNode) {
+ // Dynamically load a NodeJS specific module.
+ // Typescript requires all imports to be global, so we need to use
+ // `const` here and disable the tslint warning.
+ // tslint:disable-next-line: no-var-requires
+ const util = require('util');
+
+ // Set a custom util.inspect function
+ // HACK: We add a function to the BigNumber class by assigning to the
+ // prototype. The function name is a symbol provided by Node.
+ (BigNumber.prototype as any)[util.inspect.custom] = function(): string {
+ // HACK: When executed, `this` will refer to the BigNumber instance.
+ // This is also why we need a function expression instead of an
+ // arrow function, as the latter does not have a `this`.
+ // Return the readable string representation
+ // tslint:disable-next-line: no-invalid-this
+ return this.toString();
+ };
+}
+
export { BigNumber };