Skip to content

Commit

Permalink
Add replacer for bigint on json formatter (#84)
Browse files Browse the repository at this point in the history
* Add replacer for bigint

* fix: fix for older node versions
  • Loading branch information
adrianhopebailie authored and DABH committed Mar 27, 2019
1 parent 4c4d1e3 commit 432d7a8
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions json.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ const jsonStringify = require('fast-safe-stringify');

/*
* function replacer (key, value)
* Handles proper stringification of Buffer output.
* Handles proper stringification of Buffer and bigint output.
*/
function replacer(key, value) {
return value instanceof Buffer
? value.toString('base64')
: value;
if (value instanceof Buffer)
return value.toString('base64');
// eslint-disable-next-line valid-typeof
if (typeof value === 'bigint')
return value.toString();
return value;
}

/*
Expand Down

0 comments on commit 432d7a8

Please sign in to comment.