From 7cb82a7959fe0455392bcbf2519c6a9b2360594b Mon Sep 17 00:00:00 2001 From: qishibo Date: Thu, 11 Mar 2021 20:40:41 +0800 Subject: [PATCH 1/3] Fix bignumber is not a constructor --- lib/parse.js | 2 +- lib/stringify.js | 2 +- test/bigint-parse-test.js | 4 ++-- test/bigint-stringify-test.js | 4 ++-- test/bigint-test.js | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/parse.js b/lib/parse.js index bb4e5eb..cba1054 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -205,7 +205,7 @@ var json_parse = function (options) { if (!isFinite(number)) { error('Bad number'); } else { - if (BigNumber == null) BigNumber = require('bignumber.js'); + if (BigNumber == null) BigNumber = require('bignumber.js').BigNumber; //if (number > 9007199254740992 || number < -9007199254740992) // Bignumber has stricter check: everything with length > 15 digits disallowed if (string.length > 15) diff --git a/lib/stringify.js b/lib/stringify.js index 3bd5269..f62b820 100644 --- a/lib/stringify.js +++ b/lib/stringify.js @@ -1,4 +1,4 @@ -var BigNumber = require('bignumber.js'); +var BigNumber = require('bignumber.js').BigNumber; /* json2.js diff --git a/test/bigint-parse-test.js b/test/bigint-parse-test.js index e9755ff..3e286c4 100644 --- a/test/bigint-parse-test.js +++ b/test/bigint-parse-test.js @@ -1,7 +1,7 @@ var mocha = require('mocha') , assert = require('chai').assert , expect = require('chai').expect - , BigNumber = require('bignumber.js') + , BigNumber = require('bignumber.js').BigNumber ; describe("Testing native BigInt support: parse", function () { @@ -56,4 +56,4 @@ describe("Testing native BigInt support: parse", function () { expect(output).to.equal(input); done(); }); -}); \ No newline at end of file +}); diff --git a/test/bigint-stringify-test.js b/test/bigint-stringify-test.js index bef4670..ea50613 100644 --- a/test/bigint-stringify-test.js +++ b/test/bigint-stringify-test.js @@ -1,7 +1,7 @@ var mocha = require('mocha') , assert = require('chai').assert , expect = require('chai').expect - , BigNumber = require('bignumber.js') + , BigNumber = require('bignumber.js').BigNumber ; describe("Testing native BigInt support: stringify", function () { @@ -33,4 +33,4 @@ describe("Testing native BigInt support: stringify", function () { ); done(); }); -}); \ No newline at end of file +}); diff --git a/test/bigint-test.js b/test/bigint-test.js index 046aa5b..752e160 100644 --- a/test/bigint-test.js +++ b/test/bigint-test.js @@ -1,7 +1,7 @@ var mocha = require('mocha') , assert = require('chai').assert , expect = require('chai').expect - , BigNumber = require('bignumber.js') + , BigNumber = require('bignumber.js').BigNumber ; describe("Testing bigint support", function(){ From 6e5cb091c79dd6e2d57fb7fc885abdcf97b83bb4 Mon Sep 17 00:00:00 2001 From: qishibo Date: Mon, 29 Nov 2021 15:54:00 +0800 Subject: [PATCH 2/3] bigint stringify as raw number instead of scientific counting --- lib/stringify.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/stringify.js b/lib/stringify.js index f62b820..fcec50f 100644 --- a/lib/stringify.js +++ b/lib/stringify.js @@ -217,6 +217,11 @@ var JSON = module.exports; value = holder[key], isBigNumber = value != null && (value instanceof BigNumber || BigNumber.isBigNumber(value)); + // return big int to raw instead of scientific counting such as 1.11e8 + if (value instanceof BigNumber) { + return value.toFixed(); + } + // If the value has a toJSON method, call it to obtain a replacement value. if (value && typeof value === 'object' && From b14cd42eb4226b12f065852055cf34720623829a Mon Sep 17 00:00:00 2001 From: qishibo Date: Wed, 19 Jan 2022 10:06:27 +0800 Subject: [PATCH 3/3] npm pub info --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 9309f6b..5428c93 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { - "name": "json-bigint", + "name": "@qii404/json-bigint", "version": "1.0.0", - "description": "JSON.parse with bigints support", + "description": "JSON.parse with bigints support, forked from sidorares/json-bigint by qii404", "main": "index.js", "files": [ "index.js", @@ -13,7 +13,7 @@ }, "repository": { "type": "git", - "url": "git@github.com:sidorares/json-bigint.git" + "url": "git@github.com:qishibo/json-bigint.git" }, "keywords": [ "JSON",