From 6040eadb575604e623df4e8f3484fef60b3dedf2 Mon Sep 17 00:00:00 2001 From: Nathan Rashleigh Date: Fri, 12 Mar 2021 17:34:23 +1000 Subject: [PATCH] Stringify BigInts I ran into issues using https://github.com/trentm/node-bunyan which makes use of this library. This PR simply converts BigInts to strings, which I think is reasonable because ``` > BigInt('11111111111111111111111111111111111'); 11111111111111111111111111111111111n ``` BigNumber.js similarly uses strings as an intermediate representation. --- index.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/index.js b/index.js index d04a1a9..7a83736 100644 --- a/index.js +++ b/index.js @@ -21,6 +21,10 @@ function ensureProperties(obj) { var seen = [ ]; // store references to objects we have seen before function visit(obj) { + if (typeof obj === 'bigint') { + return obj.toString(); + } + if (obj === null || typeof obj !== 'object') { return obj; }