LLOC

Calculate the logical lines of code (LLOC) in a JavaScript program.

Usage

var lloc = require( '@stdlib/_tools/static-analysis/js/lloc' );

lloc( src )

Returns the logical lines of code (LLOC) in a JavaScript program, where src may be either an input string or Buffer.

var n = lloc( 'var beep = "boop";\n' );
// returns 1

Notes

  • Counting methodology is biased toward the coding conventions of stdlib.

  • Logical lines of code (LLOC) is defined as the number of executable statements. In comparison to the metric source lines of code (SLOC), calculating LLOC is not sensitive to stylistic forms. In the following example,

    var x = -5.0;
    
    // Shorthand:
    if ( x < 0.0 ) x *= -1;
    
    // "Verbose":
    if ( x < 0.0 ) {
        x *= -1;
    }
    

    the shorthand and "verbose" form both correspond to 2 LLOC (1 LLOC for the if statement and 1 LLOC for the if block content).

  • For further details regarding how LLOC is calculated, see program-summary.

Examples

var readFile = require( '@stdlib/fs/read-file' );
var lloc = require( '@stdlib/_tools/static-analysis/js/lloc' );

readFile( __filename, onFile );

function onFile( error, data ) {
    if ( error ) {
        throw error;
    }
    console.log( lloc( data ) );
}

CLI

Usage

Usage: js-lloc [options] [<string>]

Options:

  -h,    --help                Print this message.
  -V,    --version             Print the package version.

Examples

$ js-lloc 'var beep = "boop";\n'
1

To use as a standard stream,

$ echo -n $'var beep = "boop";\n' | js-lloc
1