Skip to content

Commit 7e23ae8

Browse files
authoredJan 15, 2023
Fix serialization issue for 0n. (#156)
Fix #125 Fix #154
1 parent 343abd9 commit 7e23ae8

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed
 

‎index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ module.exports = function serialize(obj, options) {
8383
deleteFunctions(value);
8484
}
8585

86-
if (!value && value !== undefined) {
86+
if (!value && value !== undefined && value !== BigInt(0)) {
8787
return value;
8888
}
8989

‎test/unit/serialize.js

+6
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,12 @@ describe('serialize( obj )', function () {
441441
expect(serialize({t: [b]})).to.be.a('string').equal('{"t":[BigInt("9999")]}');
442442
});
443443

444+
it('should serialize 0n', function () {
445+
var b = BigInt(0);
446+
expect(serialize(b)).to.equal('BigInt("0")');
447+
expect(serialize({t: [b]})).to.be.a('string').equal('{"t":[BigInt("0")]}');
448+
});
449+
444450
it('should deserialize BigInt', function () {
445451
var d = eval(serialize(BigInt(9999)));
446452
expect(d).to.be.a('BigInt');

0 commit comments

Comments
 (0)
Please sign in to comment.