Skip to content

Commit

Permalink
Fix serialization issue for 0n. (#156)
Browse files Browse the repository at this point in the history
Fix #125
Fix #154
  • Loading branch information
momocow authored Jan 15, 2023
1 parent 343abd9 commit 7e23ae8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ module.exports = function serialize(obj, options) {
deleteFunctions(value);
}

if (!value && value !== undefined) {
if (!value && value !== undefined && value !== BigInt(0)) {
return value;
}

Expand Down
6 changes: 6 additions & 0 deletions test/unit/serialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,12 @@ describe('serialize( obj )', function () {
expect(serialize({t: [b]})).to.be.a('string').equal('{"t":[BigInt("9999")]}');
});

it('should serialize 0n', function () {
var b = BigInt(0);
expect(serialize(b)).to.equal('BigInt("0")');
expect(serialize({t: [b]})).to.be.a('string').equal('{"t":[BigInt("0")]}');
});

it('should deserialize BigInt', function () {
var d = eval(serialize(BigInt(9999)));
expect(d).to.be.a('BigInt');
Expand Down

0 comments on commit 7e23ae8

Please sign in to comment.