Skip to content
This repository has been archived by the owner on Jan 6, 2021. It is now read-only.

Commit

Permalink
Merge pull request #31 from sinonjs/support-bigint
Browse files Browse the repository at this point in the history
add support for bigint formatting
  • Loading branch information
fatso83 committed Aug 6, 2019
2 parents b9a00b4 + 88290c6 commit 2af0cdb
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions .eslintrc.yaml
Expand Up @@ -7,6 +7,7 @@ env:
globals:
Set: false
Symbol: false
BigInt: false

plugins:
- ie11
Expand Down
7 changes: 7 additions & 0 deletions lib/formatio.js
Expand Up @@ -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]"; }
Expand Down
27 changes: 27 additions & 0 deletions lib/formatio.test.js
Expand Up @@ -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");
});
});
});

0 comments on commit 2af0cdb

Please sign in to comment.