Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

json-bigint

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-bigint - npm Package Compare versions

Comparing version 0.1.4 to 0.2.0

test/string-option-test.js

8

lib/parse.js

@@ -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)

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc