From 133ba04810b11a03c660e13be8427ebff38b0189 Mon Sep 17 00:00:00 2001 From: Camillo Positano <59197708+camillo-positano@users.noreply.github.com> Date: Wed, 19 Jun 2024 11:51:44 +0200 Subject: [PATCH 1/2] Resolved Cannot convert a BigInt value to a number Signed-off-by: Camillo Positano <59197708+camillo-positano@users.noreply.github.com> --- lib/serializer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/serializer.js b/lib/serializer.js index 24917433..1a006d5f 100644 --- a/lib/serializer.js +++ b/lib/serializer.js @@ -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) { From 21a3d93d60203db0402486ed7415e37d6cad774f Mon Sep 17 00:00:00 2001 From: Camillo Positano <59197708+camillo-positano@users.noreply.github.com> Date: Wed, 19 Jun 2024 12:41:03 +0200 Subject: [PATCH 2/2] 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> --- test/asNumber.test.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 test/asNumber.test.js diff --git a/test/asNumber.test.js b/test/asNumber.test.js new file mode 100644 index 00000000..5e68b922 --- /dev/null +++ b/test/asNumber.test.js @@ -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') +})