stringify-with-floats
An extended JSON.stringify with the ability to force float data type
Install
npm i stringify-with-floats
Usage
const stringify =
schema
{Object} the property names that need data type coercion
stringify( value [, replacer [, space ]] )
value
The value to convert to a JSON stringreplacer
{Function|Array} see JSON.stringify documentationspace
{Number|String} see JSON.stringify documentation
Example
const value = a: 1 b: c: 10 // regular JSON.stringify drops the decimal... but we want to keep it! d: 120 const stringify = // {"a":1,"b":{"c":1.0,"d":1.2}}
Known issues
- Inability to distinguish between
obj.a
andobj.nested.a
(#3)
License
MIT