diff --git a/index.js b/index.js index ab82742..ef54077 100644 --- a/index.js +++ b/index.js @@ -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; } diff --git a/test/unit/serialize.js b/test/unit/serialize.js index 6510ec2..6062910 100644 --- a/test/unit/serialize.js +++ b/test/unit/serialize.js @@ -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');