lib/index.js
function stringify(opts, callback) {
    assert.object(opts, 'opts');
    assert.func(callback, 'callback');

    let stringified = '';
    const stringifyStream = createStringifyStream(opts);
    const passthroughStream = new stream.PassThrough();
    const cb = once(callback);

    // setup the passthrough stream as a sink
    passthroughStream.on('data', function(chunk) {
        stringified += chunk;
    });

    passthroughStream.on('end', function() {
        return cb(null, stringified);
    });

    // don't know what errors stringify stream may emit, but pass them back
    // up.
    stringifyStream.on('error', function(err) {
        return cb(err);
    });

    stringifyStream.pipe(passthroughStream);
}
function stringify(opts, callback) {
    assert.object(opts, 'opts');
    assert.func(callback, 'callback');

    let stringified = '';
    const stringifyStream = createStringifyStream(opts);
    const passthroughStream = new stream.PassThrough();
    const cb = once(callback);

    // setup the passthrough stream as a sink
    passthroughStream.on('data', function(chunk) {
        stringified += chunk;
    });

    passthroughStream.on('end', function() {
        return cb(null, stringified);
    });

    // don't know what errors stringify stream may emit, but pass them back
    // up.
    stringifyStream.on('error', function(err) {
        return cb(err);
    });

    stringifyStream.pipe(passthroughStream);
}
function stringify ( opts , callback ) { assert . object ( opts , 'opts' ) ; assert . func ( callback , 'callback' ) ; let stringified = '' ; const stringifyStream = createStringifyStream ( opts ) ; const passthroughStream = new stream . PassThrough ( ) ; const cb = once ( callback ) ; // setup the passthrough stream as a sink passthroughStream . on ( 'data' , function ( chunk ) { stringified += chunk ; } ) ; passthroughStream . on ( 'end' , function ( ) { return cb ( null , stringified ) ; } ) ; // don't know what errors stringify stream may emit, but pass them back // up. stringifyStream . on ( 'error' , function ( err ) { return cb ( err ) ; } ) ; stringifyStream . pipe ( passthroughStream ) ; }
stream based JSON.stringify. async function signature to abstract over
streams.
@public
@param {Object} opts options to pass to stringify stream
@param {Function} callback a callback function
@function stringify
@return {Object} the parsed JSON object
stream based JSON . stringify . async function signature to abstract over streams .