Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

WW-Digital/stringify-with-floats

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

stringify-with-floats

An extended JSON.stringify with the ability to force float data type

Build Status

Install

npm i stringify-with-floats

Usage

const stringify = StringifyWithFloats( schema )
  • schema {Object} the property names that need data type coercion
stringify( value [, replacer [, space ]] )

Example

  const value = {
    a: 1,
    b: {
      c: 1.0, // regular JSON.stringify drops the decimal... but we want to keep it!
      d: 1.20
    }
  }
  const stringify = StringifyWithFloats({ c: 'float' })
  stringify(value) // {"a":1,"b":{"c":1.0,"d":1.2}}

Known issues

  • Inability to distinguish between obj.a and obj.nested.a (#3)

License

MIT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published