Summarize

Perform a static summary analysis for a list of JavaScript files.

Usage

var analyze = require( '@stdlib/_tools/static-analysis/js/summarize-file-list' );

analyze( files, [options,] clbk )

Performs a static summary analysis for a list of JavaScript files.

var files = [ './beep.js', './boop.js' ];

analyze( files, clbk );

function clbk( error, results ) {
    if ( error ) {
        throw error;
    }
    console.log( JSON.stringify( results ) );
}

The function accepts the following options:

  • cumulative: boolean indicating whether to perform a cumulative analysis. Default: true.

By default, the function performs a cumulative static summary analysis. To return a separate program summary for each file in files, set the cumulative option to false.

var files = [ './beep.js', './boop.js' ];

var opts = {
    'cumulative': false
};
analyze( files, opts, clbk );

function clbk( error, results ) {
    if ( error ) {
        throw error;
    }
    console.log( JSON.stringify( results ) );
}

analyze.sync( files[, options] )

Synchronously performs a static summary analysis for a list of JavaScript files.

var files = [ './beep.js', './boop.js' ];

var results = analyze( files );
if ( results instanceof Error ) {
    throw results;
}
console.log( JSON.stringify( results ) );

The function accepts the same options as analyze() above.

Notes

  • File paths are resolved relative to the current working directory of the calling process.

Examples

var join = require( 'path' ).join;
var analyze = require( '@stdlib/_tools/static-analysis/js/summarize-file-list' );

var files = [
    join( __dirname, 'examples', 'index.js' ),
    join( __dirname, 'lib', 'index.js' ),
    join( __dirname, 'lib', 'main.js' ),
    join( __dirname, 'lib', 'sync.js' ),
    join( __dirname, 'test', 'test.js' ),
    join( __dirname, 'bin', 'cli' )
];

analyze( files, clbk );

function clbk( error, results ) {
    if ( error ) {
        return console.error( 'Error: %s', error.message );
    }
    console.log( JSON.stringify( results ) );
}

CLI

Usage

Usage: js-summarize-file-list [options] [<file> <file> ...]

Options:

  -h,  --help            Print this message.
  -V,  --version         Print the package version.
       --split sep       Separator used to split stdin data. Default: /\\r?\\n/.
       --no-cumulative   Generate separate program summaries and print results
                         as newline-delimited JSON (NDJSON).

Notes

Examples

$ js-summarize-file-list ./examples/index.js
{...}

To use as a standard stream,

$ echo -n $'./examples/index.js\n./lib/index.js\n' | js-summarize-file-list
{...}

To generate a separate program summary for each input file, set the no-cumulative flag.

$ echo -n $'./examples/index.js\n./lib/index.js\n' | js-summarize-file-list --no-cumulative
{...}
{...}