From 66b41c6589a928fe09f753edffe7dd330307e458 Mon Sep 17 00:00:00 2001 From: Alastair Brayne Date: Thu, 23 Nov 2017 14:21:30 +0000 Subject: [PATCH 1/3] Allow decimals to be used as hints for converting to floats, with options. --- README.md | 45 +++++++++++++++ lib/parse.js | 10 +++- test.js | 8 +++ test/bigint-test.js | 23 ++++++++ test/strict-floats-test.js | 49 ++++++++++++++++ yarn.lock | 112 +++++++++++++++++++++++++++++++++++++ 6 files changed, 245 insertions(+), 2 deletions(-) create mode 100644 test.js create mode 100644 test/strict-floats-test.js create mode 100644 yarn.lock diff --git a/README.md b/README.md index 17421b8..0e844c6 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,18 @@ big number JSON: JSON.parse(input).value : 9223372036854775807 JSON.stringify(JSON.parse(input)): {"value":9223372036854775807,"v2":123} ``` + +### A Note on Parsing Floats + +This library now checks if numbers have a decimal point and a non-zero mantissa (the part after a decimal point). + +If there is a mantissa and it is non-zero, then the number is parsed as a float (with precision maintained or not as defined by the in-built javascript float interpreter). e.g. `'123.45'` will parse as `123.45` and `12345678901234567890123.456` will convert to `1.2345678901234568e+22`. + +If there is a mantissa and it is only a series of zeros, then it is stripped and only the integer part is used to calculate whether a BigNumber conversion is required. i.e. `'123.000'` will parse as `123` and `12345678901234567890123.000` will convert to `BigNumber('12345678901234567890123')`. + +Why not always use a decimal point as a hint for float in all cases? Well, you can if you want to. Simply use the `strictFloatHints` option described below. + + ### Options The behaviour of the parser is somewhat configurable through 'options' @@ -54,6 +66,7 @@ The default follows what is allowed in standard json and resembles the behavior Setting options.strict = true will fail-fast on such duplicate-key occurances and thus warn you upfront of possible lost information. example: + ```js var JSONbig = require('json-bigint'); var JSONstrict = require('json-bigint')({"strict": true}); @@ -73,6 +86,7 @@ try { ``` Output + ``` Duplicate Key test with big number JSON Input: { "dupkey": "value 1", "dupkey": "value 2"} @@ -87,6 +101,7 @@ Specifies if BigInts should be stored in the object as a string, rather than the Note that this is a dangerous behavior as it breaks the default functionality of being able to convert back-and-forth without data type changes (as this will convert all BigInts to be-and-stay strings). example: + ```js var JSONbig = require('json-bigint'); var JSONbigString = require('json-bigint')({"storeAsString": true}); @@ -100,6 +115,7 @@ console.log('Default type: %s, With option type: %s', typeof withInt.key, typeof ``` Output + ``` Storing the BigInt as a string, instead of a BigNumber Input: { "key": 1234567890123456789 } @@ -108,6 +124,35 @@ Default type: object, With option type: string ``` +#### options.strictFloatHints, boolean, default false + +Always interpret the presence of a decimal point as an instruction to parse the number using the in-built javascript float interpreter. + +example: + +```js +var JSONbig = require('json-bigint'); +var JSONbigFloats = require('json-bigint')({"strictFloatHints": true}); +var key = '{ "key": '1234567890123456789012345.000' }'; +console.log('\n\nAlways interpreting decimal numbers as floats, instead of a BigNumber'); +console.log('Input:', key); +var withStrictFloatHints = JSONbigFloats.parse(key); +var asNormal = JSONbig.parse(key); +console.log('Default type: %s, With option type: %s', typeof asNormal.key, typeof withStrictFloatHints.key); + +``` + +Output + +``` +Always interpreting decimal numbers as floats, instead of a BigNumber +Input: { "key": "1234567890123456789012345.000" } +Default type: object, With option type: number + +``` + + + ### Links: - [RFC4627: The application/json Media Type for JavaScript Object Notation (JSON)](http://www.ietf.org/rfc/rfc4627.txt) - [Re: \[Json\] Limitations on number size?](http://www.ietf.org/mail-archive/web/json/current/msg00297.html) diff --git a/lib/parse.js b/lib/parse.js index 2941c81..a051eae 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -76,7 +76,8 @@ var json_parse = function (options) { // Default options one can override by passing options to the parse() var _options = { "strict": false, // not being strict means do not generate syntax errors for "duplicate key" - "storeAsString": false // toggles whether the values should be stored as BigNumber (default) or a string + "storeAsString": false, // toggles whether the values should be stored as BigNumber (default) or a string + "strictFloatHints": false // toggles whether to always parse numbers with decimals as flaots }; @@ -88,6 +89,9 @@ var json_parse = function (options) { if (options.storeAsString === true) { _options.storeAsString = true; } + if(options.strictFloatHints === true) { + _options.strictFloatHints = true; + } } @@ -173,8 +177,10 @@ var json_parse = function (options) { BigNumber = require('bignumber.js'); //if (number > 9007199254740992 || number < -9007199254740992) // Bignumber has stricter check: everything with length > 15 digits disallowed - if (string.length > 15) + var test = (_options.strictFloatHints) ? string.indexOf('.') === -1 : !/\..*[^0]/.test(string); + if (test && string.length > 15 ) { return (_options.storeAsString === true) ? string : new BigNumber(string); + } return number; } }, diff --git a/test.js b/test.js new file mode 100644 index 0000000..0e65ea0 --- /dev/null +++ b/test.js @@ -0,0 +1,8 @@ +var JSONbig = require('./index'); +var JSONbigFloats = require('./index')({"strictFloatHints": true}); +var key = '{ "key": '1234567890123456789012345.000' }'; +console.log('\n\nAlways interpreting decimal numbers as floats, instead of a BigNumber'); +console.log('Input:', key); +var withStrictFloatHints = JSONbigFloats.parse(key); +var asNormal = JSONbig.parse(key); +console.log('Default type: %s, With option type: %s', typeof asNormal.key, typeof withStrictFloatHints.key); diff --git a/test/bigint-test.js b/test/bigint-test.js index 5f5e1a3..b632d27 100644 --- a/test/bigint-test.js +++ b/test/bigint-test.js @@ -28,4 +28,27 @@ describe("Testing bigint support", function(){ expect(output).to.equal(input); done(); }); + + it('should leave numbers with non-zero mantissa as floats', function(done){ + var JSONbig = require('../index'); + var obj = JSONbig.parse('12345678912345.123'); + expect(typeof obj).to.equal('number'); + done(); + }); + + it('should convert numbers with a zero mantissa to ints if the integer part is longer than 15 chars', function(done){ + var inputLong = '9223372036854775807.00000'; + var inputShort = '75807.00000'; + var JSONbig = require('../index'); + + var objLong = JSONbig.parse(inputLong); + expect(objLong, "instanceof big int").to.be.instanceof(BigNumber); + expect(objLong.toString(), "string from big int").to.equal("9223372036854775807"); + + var objShort = JSONbig.parse(inputShort); + expect(objShort).to.be.a('number'); + expect(objShort).to.equal(75807); + + done(); + }); }); diff --git a/test/strict-floats-test.js b/test/strict-floats-test.js new file mode 100644 index 0000000..ff2f4d1 --- /dev/null +++ b/test/strict-floats-test.js @@ -0,0 +1,49 @@ +var mocha = require('mocha') + , assert = require('chai').assert + , expect = require('chai').expect + , BigNumber = require('bignumber.js') + ; + +describe("Testing 'strictFloatHints' option", function(){ + + [ + '123.123', + '12345678901234567890.000', + '12345678901234567890.123', + '00000000000000000000.000' + ].forEach(function(input) { + it("Should treat input " + input + " as a float", function(done){ + var JSONbig = require('../index')({"strictFloatHints": true}); + var result = JSONbig.parse(input); + expect(result).to.be.a('number'); + done(); + }); + }); + + [ + '12345678901234567890', + '12345678901234567890', + '00000000000000000000' + ].forEach(function(input) { + it("Should treat input " + input + " as a BigNumber", function(done){ + var JSONbig = require('../index')({"strictFloatHints": true}); + var result = JSONbig.parse(input); + expect(result).to.be.instanceof(BigNumber); + done(); + }); + }); + + + [ + '123', + '0' + ].forEach(function(input) { + it("Should treat input " + input + " as an ordinary number", function(done){ + var JSONbig = require('../index')({"strictFloatHints": true}); + var result = JSONbig.parse(input); + expect(result).to.be.a('number'); + done(); + }); + }); + +}); diff --git a/yarn.lock b/yarn.lock new file mode 100644 index 0000000..55c9454 --- /dev/null +++ b/yarn.lock @@ -0,0 +1,112 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +assertion-error@1.0.0: + version "1.0.0" + resolved "http://nexus3.dgcsdev.com/repository/npm/assertion-error/-/assertion-error-1.0.0.tgz#c7f85438fdd466bc7ca16ab90c81513797a5d23b" + +bignumber.js@^4.0.0: + version "4.1.0" + resolved "http://nexus3.dgcsdev.com/repository/npm/bignumber.js/-/bignumber.js-4.1.0.tgz#db6f14067c140bd46624815a7916c92d9b6c24b1" + +chai@~1.9.1: + version "1.9.2" + resolved "http://nexus3.dgcsdev.com/repository/npm/chai/-/chai-1.9.2.tgz#3f1a20f82b0b9d7437577d24d6f12b1a69d3b590" + dependencies: + assertion-error "1.0.0" + deep-eql "0.1.3" + +commander@0.6.1: + version "0.6.1" + resolved "http://nexus3.dgcsdev.com/repository/npm/commander/-/commander-0.6.1.tgz#fa68a14f6a945d54dbbe50d8cdb3320e9e3b1a06" + +commander@2.0.0: + version "2.0.0" + resolved "http://nexus3.dgcsdev.com/repository/npm/commander/-/commander-2.0.0.tgz#d1b86f901f8b64bd941bdeadaf924530393be928" + +debug@*: + version "3.1.0" + resolved "http://nexus3.dgcsdev.com/repository/npm/debug/-/debug-3.1.0.tgz#5bb5a0672628b64149566ba16819e61518c67261" + dependencies: + ms "2.0.0" + +deep-eql@0.1.3: + version "0.1.3" + resolved "http://nexus3.dgcsdev.com/repository/npm/deep-eql/-/deep-eql-0.1.3.tgz#ef558acab8de25206cd713906d74e56930eb69f2" + dependencies: + type-detect "0.1.1" + +diff@1.0.7: + version "1.0.7" + resolved "http://nexus3.dgcsdev.com/repository/npm/diff/-/diff-1.0.7.tgz#24bbb001c4a7d5522169e7cabdb2c2814ed91cf4" + +glob@3.2.3: + version "3.2.3" + resolved "http://nexus3.dgcsdev.com/repository/npm/glob/-/glob-3.2.3.tgz#e313eeb249c7affaa5c475286b0e115b59839467" + dependencies: + graceful-fs "~2.0.0" + inherits "2" + minimatch "~0.2.11" + +graceful-fs@~2.0.0: + version "2.0.3" + resolved "http://nexus3.dgcsdev.com/repository/npm/graceful-fs/-/graceful-fs-2.0.3.tgz#7cd2cdb228a4a3f36e95efa6cc142de7d1a136d0" + +growl@1.7.x: + version "1.7.0" + resolved "http://nexus3.dgcsdev.com/repository/npm/growl/-/growl-1.7.0.tgz#de2d66136d002e112ba70f3f10c31cf7c350b2da" + +inherits@2: + version "2.0.3" + resolved "http://nexus3.dgcsdev.com/repository/npm/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de" + +jade@0.26.3: + version "0.26.3" + resolved "http://nexus3.dgcsdev.com/repository/npm/jade/-/jade-0.26.3.tgz#8f10d7977d8d79f2f6ff862a81b0513ccb25686c" + dependencies: + commander "0.6.1" + mkdirp "0.3.0" + +lru-cache@2: + version "2.7.3" + resolved "http://nexus3.dgcsdev.com/repository/npm/lru-cache/-/lru-cache-2.7.3.tgz#6d4524e8b955f95d4f5b58851ce21dd72fb4e952" + +minimatch@~0.2.11: + version "0.2.14" + resolved "http://nexus3.dgcsdev.com/repository/npm/minimatch/-/minimatch-0.2.14.tgz#c74e780574f63c6f9a090e90efbe6ef53a6a756a" + dependencies: + lru-cache "2" + sigmund "~1.0.0" + +mkdirp@0.3.0: + version "0.3.0" + resolved "http://nexus3.dgcsdev.com/repository/npm/mkdirp/-/mkdirp-0.3.0.tgz#1bbf5ab1ba827af23575143490426455f481fe1e" + +mkdirp@0.3.5: + version "0.3.5" + resolved "http://nexus3.dgcsdev.com/repository/npm/mkdirp/-/mkdirp-0.3.5.tgz#de3e5f8961c88c787ee1368df849ac4413eca8d7" + +mocha@~1.20.1: + version "1.20.1" + resolved "http://nexus3.dgcsdev.com/repository/npm/mocha/-/mocha-1.20.1.tgz#f343832d9fe0c7d97c64fc70448f5136df9fed5b" + dependencies: + commander "2.0.0" + debug "*" + diff "1.0.7" + glob "3.2.3" + growl "1.7.x" + jade "0.26.3" + mkdirp "0.3.5" + +ms@2.0.0: + version "2.0.0" + resolved "http://nexus3.dgcsdev.com/repository/npm/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8" + +sigmund@~1.0.0: + version "1.0.1" + resolved "http://nexus3.dgcsdev.com/repository/npm/sigmund/-/sigmund-1.0.1.tgz#3ff21f198cad2175f9f3b781853fd94d0d19b590" + +type-detect@0.1.1: + version "0.1.1" + resolved "http://nexus3.dgcsdev.com/repository/npm/type-detect/-/type-detect-0.1.1.tgz#0ba5ec2a885640e470ea4e8505971900dac58822" From 0706ad2c4fba070947cb98125b6db5fb1516ba8a Mon Sep 17 00:00:00 2001 From: Alastair Brayne Date: Thu, 23 Nov 2017 14:41:24 +0000 Subject: [PATCH 2/3] Made backwards compatible by moving all new float interpretations to options --- README.md | 23 ++++++------ lib/parse.js | 16 +++++++-- test/bigint-test.js | 36 ++++++++----------- test/float-hints-test.js | 33 +++++++++++++++++ ...ats-test.js => strict-float-hints-test.js} | 34 +++++++++--------- 5 files changed, 89 insertions(+), 53 deletions(-) create mode 100644 test/float-hints-test.js rename test/{strict-floats-test.js => strict-float-hints-test.js} (60%) diff --git a/README.md b/README.md index 0e844c6..1d3734e 100644 --- a/README.md +++ b/README.md @@ -45,17 +45,6 @@ JSON.parse(input).value : 9223372036854775807 JSON.stringify(JSON.parse(input)): {"value":9223372036854775807,"v2":123} ``` -### A Note on Parsing Floats - -This library now checks if numbers have a decimal point and a non-zero mantissa (the part after a decimal point). - -If there is a mantissa and it is non-zero, then the number is parsed as a float (with precision maintained or not as defined by the in-built javascript float interpreter). e.g. `'123.45'` will parse as `123.45` and `12345678901234567890123.456` will convert to `1.2345678901234568e+22`. - -If there is a mantissa and it is only a series of zeros, then it is stripped and only the integer part is used to calculate whether a BigNumber conversion is required. i.e. `'123.000'` will parse as `123` and `12345678901234567890123.000` will convert to `BigNumber('12345678901234567890123')`. - -Why not always use a decimal point as a hint for float in all cases? Well, you can if you want to. Simply use the `strictFloatHints` option described below. - - ### Options The behaviour of the parser is somewhat configurable through 'options' @@ -123,6 +112,15 @@ Default type: object, With option type: string ``` +#### options.floatHints, boolean, default false + +Interpret the presence of a decimal point as a loose hint that this number should be treated as a float. + +If there is a mantissa and it is non-zero, then the number is parsed as a float (with precision maintained or not as defined by the in-built javascript float interpreter). e.g. `'123.45'` will parse as `123.45` and `12345678901234567890123.456` will convert to `1.2345678901234568e+22`. + +If there is a mantissa and it is only a series of zeros, then it is stripped and only the integer part is used to calculate whether a BigNumber conversion is required. i.e. `'123.000'` will parse as `123` and `12345678901234567890123.000` will convert to `BigNumber('12345678901234567890123')`. + + #### options.strictFloatHints, boolean, default false @@ -150,7 +148,8 @@ Input: { "key": "1234567890123456789012345.000" } Default type: object, With option type: number ``` - + + ### Links: diff --git a/lib/parse.js b/lib/parse.js index a051eae..8b32e6c 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -77,7 +77,8 @@ var json_parse = function (options) { var _options = { "strict": false, // not being strict means do not generate syntax errors for "duplicate key" "storeAsString": false, // toggles whether the values should be stored as BigNumber (default) or a string - "strictFloatHints": false // toggles whether to always parse numbers with decimals as flaots + "floatHints": false, // toggles whether to parse numbers with non-zero mantissas as floats + "strictFloatHints": false // toggles whether to always parse numbers with mantissas as floats }; @@ -89,6 +90,9 @@ var json_parse = function (options) { if (options.storeAsString === true) { _options.storeAsString = true; } + if(options.floatHints === true) { + _options.floatHints = true; + } if(options.strictFloatHints === true) { _options.strictFloatHints = true; } @@ -175,10 +179,16 @@ var json_parse = function (options) { } else { if (BigNumber == null) BigNumber = require('bignumber.js'); + + if (_options.strictFloatHints && string.indexOf('.') !== -1) { + return parseFloat(number); + } + + var testForBigNum = (_options.floatHints) ? !/\..*[^0]/.test(string) : true; + //if (number > 9007199254740992 || number < -9007199254740992) // Bignumber has stricter check: everything with length > 15 digits disallowed - var test = (_options.strictFloatHints) ? string.indexOf('.') === -1 : !/\..*[^0]/.test(string); - if (test && string.length > 15 ) { + if (testForBigNum && string.length > 15 ) { return (_options.storeAsString === true) ? string : new BigNumber(string); } return number; diff --git a/test/bigint-test.js b/test/bigint-test.js index b632d27..078f46a 100644 --- a/test/bigint-test.js +++ b/test/bigint-test.js @@ -29,26 +29,20 @@ describe("Testing bigint support", function(){ done(); }); - it('should leave numbers with non-zero mantissa as floats', function(done){ - var JSONbig = require('../index'); - var obj = JSONbig.parse('12345678912345.123'); - expect(typeof obj).to.equal('number'); - done(); - }); - - it('should convert numbers with a zero mantissa to ints if the integer part is longer than 15 chars', function(done){ - var inputLong = '9223372036854775807.00000'; - var inputShort = '75807.00000'; - var JSONbig = require('../index'); + [ + ['1.23456789012345678901', '1.23456789012345678901'], + ['12345678901234.5678901', '12345678901234.5678901'], + ['00000000000000.0000000', '0'] + ].forEach((data) => { + var input = data[0]; + var expected = data[1]; + it('should convert any number longer than 15 chars to bignumber, even floats like' + input, function(done){ + var JSONbig = require('../index'); + var result = JSONbig.parse(input); + expect(result).to.be.instanceof(BigNumber); + expect(result.toString()).to.equal(expected); + done(); + }); + }) - var objLong = JSONbig.parse(inputLong); - expect(objLong, "instanceof big int").to.be.instanceof(BigNumber); - expect(objLong.toString(), "string from big int").to.equal("9223372036854775807"); - - var objShort = JSONbig.parse(inputShort); - expect(objShort).to.be.a('number'); - expect(objShort).to.equal(75807); - - done(); - }); }); diff --git a/test/float-hints-test.js b/test/float-hints-test.js new file mode 100644 index 0000000..c1ffb85 --- /dev/null +++ b/test/float-hints-test.js @@ -0,0 +1,33 @@ +var mocha = require('mocha') + , assert = require('chai').assert + , expect = require('chai').expect + , BigNumber = require('bignumber.js') +; + +describe("Testing 'strictFloatHints' option", function() { + + + it('should leave numbers with non-zero mantissa as floats', function(done) { + var JSONbig = require('../index')({floatHints: true}); + var obj = JSONbig.parse('12345678912345.123'); + expect(typeof obj).to.equal('number'); + done(); + }); + + it('should convert numbers with a zero mantissa to ints if the integer part is longer than 15 chars', function(done) { + var inputLong = '9223372036854775807.00000'; + var inputShort = '75807.00000'; + var JSONbig = require('../index')({floatHints: true}); + + var objLong = JSONbig.parse(inputLong); + expect(objLong, "instanceof big int").to.be.instanceof(BigNumber); + expect(objLong.toString(), "string from big int").to.equal("9223372036854775807"); + + var objShort = JSONbig.parse(inputShort); + expect(objShort).to.be.a('number'); + expect(objShort).to.equal(75807); + + done(); + }); + +}); diff --git a/test/strict-floats-test.js b/test/strict-float-hints-test.js similarity index 60% rename from test/strict-floats-test.js rename to test/strict-float-hints-test.js index ff2f4d1..c4c0189 100644 --- a/test/strict-floats-test.js +++ b/test/strict-float-hints-test.js @@ -1,31 +1,31 @@ -var mocha = require('mocha') +var mocha = require('mocha') , assert = require('chai').assert , expect = require('chai').expect , BigNumber = require('bignumber.js') - ; +; -describe("Testing 'strictFloatHints' option", function(){ +describe("Testing 'strictFloatHints' option", function() { - [ - '123.123', - '12345678901234567890.000', - '12345678901234567890.123', - '00000000000000000000.000' - ].forEach(function(input) { - it("Should treat input " + input + " as a float", function(done){ - var JSONbig = require('../index')({"strictFloatHints": true}); - var result = JSONbig.parse(input); - expect(result).to.be.a('number'); - done(); - }); + [ + '123.123', + '12345678901234567890.000', + '12345678901234567890.123', + '00000000000000000000.000' + ].forEach(function(input) { + it("Should treat input " + input + " as a float", function(done) { + var JSONbig = require('../index')({"strictFloatHints": true}); + var result = JSONbig.parse(input); + expect(result).to.be.a('number'); + done(); }); + }); [ '12345678901234567890', '12345678901234567890', '00000000000000000000' ].forEach(function(input) { - it("Should treat input " + input + " as a BigNumber", function(done){ + it("Should treat input " + input + " as a BigNumber", function(done) { var JSONbig = require('../index')({"strictFloatHints": true}); var result = JSONbig.parse(input); expect(result).to.be.instanceof(BigNumber); @@ -38,7 +38,7 @@ describe("Testing 'strictFloatHints' option", function(){ '123', '0' ].forEach(function(input) { - it("Should treat input " + input + " as an ordinary number", function(done){ + it("Should treat input " + input + " as an ordinary number", function(done) { var JSONbig = require('../index')({"strictFloatHints": true}); var result = JSONbig.parse(input); expect(result).to.be.a('number'); From 455fa8365f829f8a679bcad31eec719fa953fc15 Mon Sep 17 00:00:00 2001 From: Alastair Brayne Date: Thu, 23 Nov 2017 14:51:34 +0000 Subject: [PATCH 3/3] Fixing for legacy nodejs environments --- package-lock.json | 167 ++++++++++++++++++++++++++++++++++++++++++++ test.js | 8 --- test/bigint-test.js | 2 +- yarn.lock | 112 ----------------------------- 4 files changed, 168 insertions(+), 121 deletions(-) create mode 100644 package-lock.json delete mode 100644 test.js delete mode 100644 yarn.lock diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..a1d03f7 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,167 @@ +{ + "name": "json-bigint", + "version": "0.2.3", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "assertion-error": { + "version": "1.0.0", + "resolved": "http://nexus3.dgcsdev.com/repository/npm/assertion-error/-/assertion-error-1.0.0.tgz", + "integrity": "sha1-x/hUOP3UZrx8oWq5DIFRN5el0js=", + "dev": true + }, + "bignumber.js": { + "version": "4.1.0", + "resolved": "http://nexus3.dgcsdev.com/repository/npm/bignumber.js/-/bignumber.js-4.1.0.tgz", + "integrity": "sha512-eJzYkFYy9L4JzXsbymsFn3p54D+llV27oTQ+ziJG7WFRheJcNZilgVXMG0LoZtlQSKBsJdWtLFqOD0u+U0jZKA==" + }, + "chai": { + "version": "1.9.2", + "resolved": "http://nexus3.dgcsdev.com/repository/npm/chai/-/chai-1.9.2.tgz", + "integrity": "sha1-Pxog+CsLnXQ3V30k1vErGmnTtZA=", + "dev": true, + "requires": { + "assertion-error": "1.0.0", + "deep-eql": "0.1.3" + } + }, + "commander": { + "version": "2.0.0", + "resolved": "http://nexus3.dgcsdev.com/repository/npm/commander/-/commander-2.0.0.tgz", + "integrity": "sha1-0bhvkB+LZL2UG96tr5JFMDk76Sg=", + "dev": true + }, + "debug": { + "version": "3.1.0", + "resolved": "http://nexus3.dgcsdev.com/repository/npm/debug/-/debug-3.1.0.tgz", + "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", + "dev": true, + "requires": { + "ms": "2.0.0" + } + }, + "deep-eql": { + "version": "0.1.3", + "resolved": "http://nexus3.dgcsdev.com/repository/npm/deep-eql/-/deep-eql-0.1.3.tgz", + "integrity": "sha1-71WKyrjeJSBs1xOQbXTlaTDrafI=", + "dev": true, + "requires": { + "type-detect": "0.1.1" + } + }, + "diff": { + "version": "1.0.7", + "resolved": "http://nexus3.dgcsdev.com/repository/npm/diff/-/diff-1.0.7.tgz", + "integrity": "sha1-JLuwAcSn1VIhaefKvbLCgU7ZHPQ=", + "dev": true + }, + "glob": { + "version": "3.2.3", + "resolved": "http://nexus3.dgcsdev.com/repository/npm/glob/-/glob-3.2.3.tgz", + "integrity": "sha1-4xPusknHr/qlxHUoaw4RW1mDlGc=", + "dev": true, + "requires": { + "graceful-fs": "2.0.3", + "inherits": "2.0.3", + "minimatch": "0.2.14" + } + }, + "graceful-fs": { + "version": "2.0.3", + "resolved": "http://nexus3.dgcsdev.com/repository/npm/graceful-fs/-/graceful-fs-2.0.3.tgz", + "integrity": "sha1-fNLNsiiko/Nule+mzBQt59GhNtA=", + "dev": true + }, + "growl": { + "version": "1.7.0", + "resolved": "http://nexus3.dgcsdev.com/repository/npm/growl/-/growl-1.7.0.tgz", + "integrity": "sha1-3i1mE20ALhErpw8/EMMc98NQsto=", + "dev": true + }, + "inherits": { + "version": "2.0.3", + "resolved": "http://nexus3.dgcsdev.com/repository/npm/inherits/-/inherits-2.0.3.tgz", + "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=", + "dev": true + }, + "jade": { + "version": "0.26.3", + "resolved": "http://nexus3.dgcsdev.com/repository/npm/jade/-/jade-0.26.3.tgz", + "integrity": "sha1-jxDXl32NefL2/4YqgbBRPMslaGw=", + "dev": true, + "requires": { + "commander": "0.6.1", + "mkdirp": "0.3.0" + }, + "dependencies": { + "commander": { + "version": "0.6.1", + "resolved": "http://nexus3.dgcsdev.com/repository/npm/commander/-/commander-0.6.1.tgz", + "integrity": "sha1-+mihT2qUXVTbvlDYzbMyDp47GgY=", + "dev": true + }, + "mkdirp": { + "version": "0.3.0", + "resolved": "http://nexus3.dgcsdev.com/repository/npm/mkdirp/-/mkdirp-0.3.0.tgz", + "integrity": "sha1-G79asbqCevI1dRQ0kEJkVfSB/h4=", + "dev": true + } + } + }, + "lru-cache": { + "version": "2.7.3", + "resolved": "http://nexus3.dgcsdev.com/repository/npm/lru-cache/-/lru-cache-2.7.3.tgz", + "integrity": "sha1-bUUk6LlV+V1PW1iFHOId1y+06VI=", + "dev": true + }, + "minimatch": { + "version": "0.2.14", + "resolved": "http://nexus3.dgcsdev.com/repository/npm/minimatch/-/minimatch-0.2.14.tgz", + "integrity": "sha1-x054BXT2PG+aCQ6Q775u9TpqdWo=", + "dev": true, + "requires": { + "lru-cache": "2.7.3", + "sigmund": "1.0.1" + } + }, + "mkdirp": { + "version": "0.3.5", + "resolved": "http://nexus3.dgcsdev.com/repository/npm/mkdirp/-/mkdirp-0.3.5.tgz", + "integrity": "sha1-3j5fiWHIjHh+4TaN+EmsRBPsqNc=", + "dev": true + }, + "mocha": { + "version": "1.20.1", + "resolved": "http://nexus3.dgcsdev.com/repository/npm/mocha/-/mocha-1.20.1.tgz", + "integrity": "sha1-80ODLZ/gx9l8ZPxwRI9RNt+f7Vs=", + "dev": true, + "requires": { + "commander": "2.0.0", + "debug": "3.1.0", + "diff": "1.0.7", + "glob": "3.2.3", + "growl": "1.7.0", + "jade": "0.26.3", + "mkdirp": "0.3.5" + } + }, + "ms": { + "version": "2.0.0", + "resolved": "http://nexus3.dgcsdev.com/repository/npm/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", + "dev": true + }, + "sigmund": { + "version": "1.0.1", + "resolved": "http://nexus3.dgcsdev.com/repository/npm/sigmund/-/sigmund-1.0.1.tgz", + "integrity": "sha1-P/IfGYytIXX587eBhT/ZTQ0ZtZA=", + "dev": true + }, + "type-detect": { + "version": "0.1.1", + "resolved": "http://nexus3.dgcsdev.com/repository/npm/type-detect/-/type-detect-0.1.1.tgz", + "integrity": "sha1-C6XsKohWQORw6k6FBZcZANrFiCI=", + "dev": true + } + } +} diff --git a/test.js b/test.js deleted file mode 100644 index 0e65ea0..0000000 --- a/test.js +++ /dev/null @@ -1,8 +0,0 @@ -var JSONbig = require('./index'); -var JSONbigFloats = require('./index')({"strictFloatHints": true}); -var key = '{ "key": '1234567890123456789012345.000' }'; -console.log('\n\nAlways interpreting decimal numbers as floats, instead of a BigNumber'); -console.log('Input:', key); -var withStrictFloatHints = JSONbigFloats.parse(key); -var asNormal = JSONbig.parse(key); -console.log('Default type: %s, With option type: %s', typeof asNormal.key, typeof withStrictFloatHints.key); diff --git a/test/bigint-test.js b/test/bigint-test.js index 078f46a..78b92e4 100644 --- a/test/bigint-test.js +++ b/test/bigint-test.js @@ -33,7 +33,7 @@ describe("Testing bigint support", function(){ ['1.23456789012345678901', '1.23456789012345678901'], ['12345678901234.5678901', '12345678901234.5678901'], ['00000000000000.0000000', '0'] - ].forEach((data) => { + ].forEach(function (data) { var input = data[0]; var expected = data[1]; it('should convert any number longer than 15 chars to bignumber, even floats like' + input, function(done){ diff --git a/yarn.lock b/yarn.lock deleted file mode 100644 index 55c9454..0000000 --- a/yarn.lock +++ /dev/null @@ -1,112 +0,0 @@ -# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. -# yarn lockfile v1 - - -assertion-error@1.0.0: - version "1.0.0" - resolved "http://nexus3.dgcsdev.com/repository/npm/assertion-error/-/assertion-error-1.0.0.tgz#c7f85438fdd466bc7ca16ab90c81513797a5d23b" - -bignumber.js@^4.0.0: - version "4.1.0" - resolved "http://nexus3.dgcsdev.com/repository/npm/bignumber.js/-/bignumber.js-4.1.0.tgz#db6f14067c140bd46624815a7916c92d9b6c24b1" - -chai@~1.9.1: - version "1.9.2" - resolved "http://nexus3.dgcsdev.com/repository/npm/chai/-/chai-1.9.2.tgz#3f1a20f82b0b9d7437577d24d6f12b1a69d3b590" - dependencies: - assertion-error "1.0.0" - deep-eql "0.1.3" - -commander@0.6.1: - version "0.6.1" - resolved "http://nexus3.dgcsdev.com/repository/npm/commander/-/commander-0.6.1.tgz#fa68a14f6a945d54dbbe50d8cdb3320e9e3b1a06" - -commander@2.0.0: - version "2.0.0" - resolved "http://nexus3.dgcsdev.com/repository/npm/commander/-/commander-2.0.0.tgz#d1b86f901f8b64bd941bdeadaf924530393be928" - -debug@*: - version "3.1.0" - resolved "http://nexus3.dgcsdev.com/repository/npm/debug/-/debug-3.1.0.tgz#5bb5a0672628b64149566ba16819e61518c67261" - dependencies: - ms "2.0.0" - -deep-eql@0.1.3: - version "0.1.3" - resolved "http://nexus3.dgcsdev.com/repository/npm/deep-eql/-/deep-eql-0.1.3.tgz#ef558acab8de25206cd713906d74e56930eb69f2" - dependencies: - type-detect "0.1.1" - -diff@1.0.7: - version "1.0.7" - resolved "http://nexus3.dgcsdev.com/repository/npm/diff/-/diff-1.0.7.tgz#24bbb001c4a7d5522169e7cabdb2c2814ed91cf4" - -glob@3.2.3: - version "3.2.3" - resolved "http://nexus3.dgcsdev.com/repository/npm/glob/-/glob-3.2.3.tgz#e313eeb249c7affaa5c475286b0e115b59839467" - dependencies: - graceful-fs "~2.0.0" - inherits "2" - minimatch "~0.2.11" - -graceful-fs@~2.0.0: - version "2.0.3" - resolved "http://nexus3.dgcsdev.com/repository/npm/graceful-fs/-/graceful-fs-2.0.3.tgz#7cd2cdb228a4a3f36e95efa6cc142de7d1a136d0" - -growl@1.7.x: - version "1.7.0" - resolved "http://nexus3.dgcsdev.com/repository/npm/growl/-/growl-1.7.0.tgz#de2d66136d002e112ba70f3f10c31cf7c350b2da" - -inherits@2: - version "2.0.3" - resolved "http://nexus3.dgcsdev.com/repository/npm/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de" - -jade@0.26.3: - version "0.26.3" - resolved "http://nexus3.dgcsdev.com/repository/npm/jade/-/jade-0.26.3.tgz#8f10d7977d8d79f2f6ff862a81b0513ccb25686c" - dependencies: - commander "0.6.1" - mkdirp "0.3.0" - -lru-cache@2: - version "2.7.3" - resolved "http://nexus3.dgcsdev.com/repository/npm/lru-cache/-/lru-cache-2.7.3.tgz#6d4524e8b955f95d4f5b58851ce21dd72fb4e952" - -minimatch@~0.2.11: - version "0.2.14" - resolved "http://nexus3.dgcsdev.com/repository/npm/minimatch/-/minimatch-0.2.14.tgz#c74e780574f63c6f9a090e90efbe6ef53a6a756a" - dependencies: - lru-cache "2" - sigmund "~1.0.0" - -mkdirp@0.3.0: - version "0.3.0" - resolved "http://nexus3.dgcsdev.com/repository/npm/mkdirp/-/mkdirp-0.3.0.tgz#1bbf5ab1ba827af23575143490426455f481fe1e" - -mkdirp@0.3.5: - version "0.3.5" - resolved "http://nexus3.dgcsdev.com/repository/npm/mkdirp/-/mkdirp-0.3.5.tgz#de3e5f8961c88c787ee1368df849ac4413eca8d7" - -mocha@~1.20.1: - version "1.20.1" - resolved "http://nexus3.dgcsdev.com/repository/npm/mocha/-/mocha-1.20.1.tgz#f343832d9fe0c7d97c64fc70448f5136df9fed5b" - dependencies: - commander "2.0.0" - debug "*" - diff "1.0.7" - glob "3.2.3" - growl "1.7.x" - jade "0.26.3" - mkdirp "0.3.5" - -ms@2.0.0: - version "2.0.0" - resolved "http://nexus3.dgcsdev.com/repository/npm/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8" - -sigmund@~1.0.0: - version "1.0.1" - resolved "http://nexus3.dgcsdev.com/repository/npm/sigmund/-/sigmund-1.0.1.tgz#3ff21f198cad2175f9f3b781853fd94d0d19b590" - -type-detect@0.1.1: - version "0.1.1" - resolved "http://nexus3.dgcsdev.com/repository/npm/type-detect/-/type-detect-0.1.1.tgz#0ba5ec2a885640e470ea4e8505971900dac58822"