Skip to content

Commit

Permalink
Resolved Cannot convert a BigInt value to a number (#723)
Browse files Browse the repository at this point in the history
* Resolved Cannot convert a BigInt value to a number

Signed-off-by: Camillo Positano <59197708+camillo-positano@users.noreply.github.com>

* added test for asNumber throwing exception

Exception thrown was  Cannot convert a BigInt value to a number.

This test verifies that it can convert a big int

Signed-off-by: Camillo Positano <59197708+camillo-positano@users.noreply.github.com>

---------

Signed-off-by: Camillo Positano <59197708+camillo-positano@users.noreply.github.com>
  • Loading branch information
camillo-positano committed Jun 19, 2024
1 parent cf5c0d0 commit 85e1f07
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ module.exports = class Serializer {

asNumber (i) {
// fast cast to number
const num = +i
const num = Number(i)
// check if number is NaN
// eslint-disable-next-line no-self-compare
if (num !== num) {
Expand Down
13 changes: 13 additions & 0 deletions test/asNumber.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict'

const test = require('tap').test

test('asNumber should convert BigInt', (t) => {
t.plan(1)
const Serializer = require('../lib/serializer')
const serializer = new Serializer()

const number = serializer.asNumber(11753021440n)

t.equal(number, '11753021440')
})

0 comments on commit 85e1f07

Please sign in to comment.