0.2.1 • Published 2 months ago

@stdlib/number-float64-reviver v0.2.1

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
2 months ago

reviveNumber

NPM version Build Status Coverage Status

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


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

Chat


License

See LICENSE.

Copyright

Copyright © 2016-2024. The Stdlib Authors.