sidorares / json-bigint

JSON.parse/stringify with bigints support
MIT License
790 stars 189 forks source link

Support alwaysParseAsBig with storeAsString #72

Open ronmrdechai opened 2 years ago

ronmrdechai commented 2 years ago

When alwaysParseAsBig is set to true, and json-bigint encounters a safe number, it doesn't check whether storeAsString is true as well. This PR adds a check for storeAsString, similar to the ternary check when the encountered number is not safe.

I am using json-bigint to parse responses from an API server which passes down raw IDs via an HTTP API. No arithmetic is performed on these IDs, and they're passed back to the server on subsequent HTTP calls. This means storing numbers in the API server's responses as strings is very convenient, and just works when interoping with Node JS's native HTTP module, or with the request module.

A unit tests was also added to ensure this works correctly.