@stdlib/number-float64-reviver
v0.2.2
Published
Revive a JSON-serialized number.
Downloads
32
Readme
reviveNumber
Revive a JSON-serialized number.
Installation
npm install @stdlib/number-float64-reviver
Usage
var reviveNumber = require( '@stdlib/number-float64-reviver' );
reviveNumber( key, value )
Revives a JSON-serialized number.
var parseJSON = require( '@stdlib/utils-parse-json' );
var str = '{"type":"float64","value":"NaN"}';
var buf = parseJSON( str, reviveNumber );
// returns NaN
For details on the JSON serialization format, see @stdlib/number-float64/to-json
.
Examples
var parseJSON = require( '@stdlib/utils-parse-json' );
var number2json = require( '@stdlib/number-float64-to-json' );
var reviveNumber = require( '@stdlib/number-float64-reviver' );
var str = JSON.stringify( number2json( NaN ) );
console.log( str );
// => '{"type":"float64","value":"NaN"}'
var out = parseJSON( str, reviveNumber );
if ( out instanceof Error ) {
throw out;
}
console.log( out );
// => NaN
See Also
@stdlib/number-float64/to-json
: return a JSON representation of a number.
Notice
This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.
Community
License
See LICENSE.
Copyright
Copyright © 2016-2024. The Stdlib Authors.