diff --git a/.eslintrc.yaml b/.eslintrc.yaml index 8e3e593..c869a9a 100644 --- a/.eslintrc.yaml +++ b/.eslintrc.yaml @@ -7,6 +7,7 @@ env: globals: Set: false Symbol: false + BigInt: false plugins: - ie11 diff --git a/lib/formatio.js b/lib/formatio.js index e8d26b8..04dd004 100644 --- a/lib/formatio.js +++ b/lib/formatio.js @@ -66,6 +66,13 @@ function ascii(f, object, processed, indent) { return ascii.func(object); } + // eslint supports bigint as of version 6.0.0 + // https://github.com/eslint/eslint/commit/e4ab0531c4e44c23494c6a802aa2329d15ac90e5 + // eslint-disable-next-line + if (typeOf(object) === "bigint") { + return object.toString(); + } + processed = processed || []; if (isCircular(object, processed)) { return "[Circular]"; } diff --git a/lib/formatio.test.js b/lib/formatio.test.js index 84f4733..90707e8 100644 --- a/lib/formatio.test.js +++ b/lib/formatio.test.js @@ -525,4 +525,31 @@ describe("formatio.ascii", function () { assert.equals(str, "[object global]"); }); }); + + describe("BigInt", function () { + before(function () { + if (typeof BigInt === "undefined") { + this.skip(); + } + }); + + // Note: We cannot use 0n, 1n, -1n here because not all + // browsers and node versions support BigInt at the moment + // and this will result in a SyntaxError + + it("formats 0n", function () { + // eslint-disable-next-line + assert.equals(formatio.ascii(BigInt("0")), "0"); + }); + + it("formats positive values", function () { + // eslint-disable-next-line + assert.equals(formatio.ascii(BigInt("1")), "1"); + }); + + it("formats negative values", function () { + // eslint-disable-next-line + assert.equals(formatio.ascii(BigInt("-1")), "-1"); + }); + }); });