json-bigint
Advanced tools
Comparing version 0.1.4 to 0.2.0
@@ -78,3 +78,4 @@ var BigNumber = null; | ||
var _options = { | ||
"strict": false // not being strict means do not generate syntax errors for "duplicate key" | ||
"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 | ||
}; | ||
@@ -88,2 +89,5 @@ | ||
} | ||
if (options.storeAsString === true) { | ||
_options.storeAsString = true; | ||
} | ||
} | ||
@@ -175,3 +179,3 @@ | ||
if (string.length > 15) | ||
return new BigNumber(string); | ||
return (_options.storeAsString === true) ? string : new BigNumber(string); | ||
return number; | ||
@@ -178,0 +182,0 @@ } |
{ | ||
"name": "json-bigint", | ||
"version": "0.1.4", | ||
"version": "0.2.0", | ||
"description": "JSON.parse with bigints support", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -84,3 +84,29 @@ json-bigint | ||
#### options.storeAsString, boolean, default false | ||
Specifies if BigInts should be stored in the object as a string, rather than the default BigNumber. | ||
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}); | ||
var key = '{ "key": 1234567890123456789 }'; | ||
console.log('\n\nStoring the BigInt as a string, instead of a BigNumber'); | ||
console.log('Input:', key); | ||
var withInt = JSONbig.parse(key); | ||
var withString = JSONbigString.parse(key); | ||
console.log('Default type: %s, With option type: %s', typeof withInt.key, typeof withString.key); | ||
``` | ||
Output | ||
``` | ||
Storing the BigInt as a string, instead of a BigNumber | ||
Input: { "key": 1234567890123456789 } | ||
Default type: object, With option type: string | ||
``` | ||
### Links: | ||
@@ -87,0 +113,0 @@ - [RFC4627: The application/json Media Type for JavaScript Object Notation (JSON)](http://www.ietf.org/rfc/rfc4627.txt) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
35526
11
699
118