Skip to content

Commit 85e1f07

Browse files
Resolved Cannot convert a BigInt value to a number (#723)
* 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>
1 parent cf5c0d0 commit 85e1f07

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/serializer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ module.exports = class Serializer {
4141

4242
asNumber (i) {
4343
// fast cast to number
44-
const num = +i
44+
const num = Number(i)
4545
// check if number is NaN
4646
// eslint-disable-next-line no-self-compare
4747
if (num !== num) {

test/asNumber.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use strict'
2+
3+
const test = require('tap').test
4+
5+
test('asNumber should convert BigInt', (t) => {
6+
t.plan(1)
7+
const Serializer = require('../lib/serializer')
8+
const serializer = new Serializer()
9+
10+
const number = serializer.asNumber(11753021440n)
11+
12+
t.equal(number, '11753021440')
13+
})

0 commit comments

Comments
 (0)