Skip to content

Commit

Permalink
Serialize BigInt.
Browse files Browse the repository at this point in the history
Closes #22.
  • Loading branch information
flatheadmill committed Jul 30, 2021
1 parent 28ebd77 commit 009dc5c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion test/verbatim.t.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
require('proof')(20, okay => {
require('proof')(21, okay => {
const Verbatim = require('..')

function cycle (value) {
return Verbatim.deserialize(Verbatim.serialize(value))
}

okay(cycle(1), 1, 'number')
okay(cycle(1n), 1n, 'bigint')
okay(cycle(Infinity), Infinity, 'infinity')
okay(cycle(-Infinity), -Infinity, 'negative infinity')
okay(cycle(true), true, 'true')
Expand Down
4 changes: 4 additions & 0 deletions verbatim.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ exports.serialize = function (object) {
default:
return value
}
case 'bigint':
return [ '_bigint', String(value) ]
default:
return value
}
Expand Down Expand Up @@ -74,6 +76,8 @@ exports.deserialize = function (buffers) {
return buffers[value[1]]
case '_undefined':
return function () {} ()
case '_bigint':
return BigInt(value[1])
}
}
if (value == null) {
Expand Down

0 comments on commit 009dc5c

Please sign in to comment.