Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
json-bignum
Advanced tools
Node.js JSON replacement which handles 64-bit integers and arbitrary-precision decimals.
Node.js JSON replacement which handles 64-bit integers and arbitrary-precision decimals. It is a modified version of Douglas Crockford's JSON library. Although it can handle 64-bit integers and arbitrary-precision decimals, it is slower than the built-in JSON functions.
$ npm install json-bignum
var bignumJSON = require('json-bignum');
var obj = bignumJSON.parse('{ "decimal": -9223372036854775807.4237482374983253298159 }');
var bignumJSON = require('json-bignum');
var obj = {
bigint: new bignumJSON.BigNumber('92233720368547758074237482374983253298159'),
decimal: new bignumJSON.BigNumber('-9223372036854775807.4237482374983253298159'),
};
console.log(bignumJSON.stringify(obj));
The BigNumber
class simply stores the number as a string. It does not support arithmetic, but if you need that here are some excellent libraries.
BigInteger
and BigDecimal
classes.// example using BigDecimal.js
var bignumJSON = require('json-bignum');
var bigdecimal = require('bigdecimal');
var jsonStr = '{"normal":-922337203.234,"big":-9223372036854775807.4237482374983253298159}';
var jsonObj = bignumJSON.parse(jsonStr);
var a = new bigdecimal.BigDecimal(jsonObj.normal.toString());
var b = new bigdecimal.BigDecimal(jsonObj.big.toString());
var sum = a.add(b);
jsonObj.sum = new bignumJSON.BigNumber(sum.toString());
console.log(bignumJSON.stringify(jsonObj));
It is not recommended to mix calls to JSON
and bignumJSON
. For example, JSON.stringify()
does not know how to parse BigNumber
.
Below shows the result of the benchmark on my machine.
$ node benchmark.js
10000 calls of JSON.parse(): 26.746847 ms
10000 calls of JSON.stringify(): 20.824071 ms
10000 calls of bignumJSON.parse() with bignums in JSON: 221.945307 ms
10000 calls of bignumJSON.parse() without bignums in JSON: 150.626292 ms
10000 calls of bignumJSON.stringify() with bignums in JSON: 64.166056 ms
10000 calls of bignumJSON.stringify() without bignums in JSON: 61.860016 ms
FAQs
Node.js JSON replacement which handles 64-bit integers and arbitrary-precision decimals.
The npm package json-bignum receives a total of 229,762 weekly downloads. As such, json-bignum popularity was classified as popular.
We found that json-bignum demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.