Home Manual Reference Source Test Repository
import ESComplex from 'typhonjs-escomplex/src/ESComplex.js'
public class | source

ESComplex

Next generation code complexity reporting for Javascript abstract syntax trees (AST). ESComplex exposes all methods available via ESComplexModule & ESComplexProject modules which process AST. Several methods available below accept source code which is translated via Babylon w/ all plugins enabled allowing any ES6/ES7/edge JS to be parsed. Asynchronous versions with the Async suffix of all methods are available as well.

See:

Constructor Summary

Public Constructor
public

constructor(options: object)

Initializes ESComplex.

Member Summary

Private Members
private

_escomplexModule: ESComplexModule

An instance of ESComplexModule.

private

_escomplexProject: ESComplexProject

An instance of ESComplexProject.

Method Summary

Public Methods
public

analyzeModule(source: string, options: object, parserOptions: object): object

Parses the given source code then processes the generated AST and calculates metrics via plugins.

public

Processes the given ast and calculates metrics via plugins.

public

Wraps in a Promise processing the given ast and calculates metrics via plugins.

public

analyzeModuleAsync(source: string, options: object, parserOptions: object): object

Wraps in a Promise parsing of the given source code then processes the generated AST and calculates metrics via plugins.

public

analyzeProject(sources: Array<object>, options: object, parserOptions: object): {reports: Array<{}>}

Processes the given sources and calculates project metrics via plugins.

public

analyzeProjectAST(modules: Array<object>, options: object): {reports: Array<{}>}

Processes the given modules and calculates project metrics via plugins.

public

analyzeProjectASTAsync(modules: Array, options: object): Promise<{reports: Array<{}>}>

Wraps in a Promise processing the given modules and calculates project metrics via plugins.

public

analyzeProjectAsync(sources: Array<object>, options: object, parserOptions: object): Promise<{reports: Array<{}>}>

Wraps in a Promise processing the given sources and calculates project metrics via plugins.

public

parse(source: string, parserOptions: object): object

Provides a convenience method to parse the given source code and return the babylon AST.

public

parseAsync(source: string, parserOptions: object): Promise<object>

Wraps in a Promise a convenience method to parse the given source code and return the babylon AST.

public

processProject(results: object, options: object): {reports: Array<{}>}

Processes existing project results and calculates metrics via plugins.

public

processProjectAsync(results: object, options: object): Promise<{reports: Array<{}>}>

Wraps in a Promise processing existing project results and calculates metrics via plugins.

Public Constructors

public constructor(options: object) source

Initializes ESComplex.

Params:

NameTypeAttributeDescription
options object

module and project options including user plugins to load including:

(object)             module - Provides an object hash of the following options for the module runtime:
   (boolean)         loadDefaultPlugins - When false ESComplexProject will not load any default plugins.
   (Array<Object>)   plugins - A list of ESComplexModule plugins that have already been instantiated.

(object)             project - Provides an object hash of the following options for the project runtime:
   (boolean)         loadDefaultPlugins - When false ESComplexProject will not load any default plugins.
   (Array<Object>)   plugins - A list of ESComplexProject plugins that have already been instantiated.

Private Members

private _escomplexModule: ESComplexModule source

An instance of ESComplexModule.

private _escomplexProject: ESComplexProject source

An instance of ESComplexProject.

Public Methods

public analyzeModule(source: string, options: object, parserOptions: object): object source

Parses the given source code then processes the generated AST and calculates metrics via plugins.

Params:

NameTypeAttributeDescription
source string

Javascript source code.

options object

(Optional) module analyze options.

parserOptions object

(Optional) overrides default babylon parser options.

Return:

object

A single module report.

public analyzeModuleAST(ast: object | Array, options: object): object source

Processes the given ast and calculates metrics via plugins.

Params:

NameTypeAttributeDescription
ast object | Array

Javascript AST.

options object

(Optional) module analyze options.

Return:

object

A single module report.

public analyzeModuleASTAsync(ast: object | Array, options: object): Promise<object> source

Wraps in a Promise processing the given ast and calculates metrics via plugins.

Params:

NameTypeAttributeDescription
ast object | Array

Javascript AST.

options object

(Optional) module analyze options.

Return:

Promise<object>

A single module report.

public analyzeModuleAsync(source: string, options: object, parserOptions: object): object source

Wraps in a Promise parsing of the given source code then processes the generated AST and calculates metrics via plugins.

Params:

NameTypeAttributeDescription
source string

Javascript source code.

options object

(Optional) module analyze options.

parserOptions object

(Optional) overrides default babylon parser options.

Return:

object

A single module report.

public analyzeProject(sources: Array<object>, options: object, parserOptions: object): {reports: Array<{}>} source

Processes the given sources and calculates project metrics via plugins.

Params:

NameTypeAttributeDescription
sources Array<object>

Array of object hashes containing code and srcPath entries with optional entries include filePath and srcPathAlias.

options object

(Optional) project processing options.

parserOptions object

(Optional) overrides default babylon parser options.

Return:

{reports: Array<{}>}

An object hash with a reports entry that is an Array of module results.

public analyzeProjectAST(modules: Array<object>, options: object): {reports: Array<{}>} source

Processes the given modules and calculates project metrics via plugins.

Params:

NameTypeAttributeDescription
modules Array<object>

Array of object hashes containing ast and srcPath entries with optional entries include filePath and srcPathAlias.

options object

(Optional) project processing options.

Return:

{reports: Array<{}>}

An object hash with a reports entry that is an Array of module results.

public analyzeProjectASTAsync(modules: Array, options: object): Promise<{reports: Array<{}>}> source

Wraps in a Promise processing the given modules and calculates project metrics via plugins.

Params:

NameTypeAttributeDescription
modules Array

Array of object hashes containing ast and path entries.

options object

(Optional) project processing options.

Return:

Promise<{reports: Array<{}>}>

An object hash with a reports entry that is an Array of module results.

public analyzeProjectAsync(sources: Array<object>, options: object, parserOptions: object): Promise<{reports: Array<{}>}> source

Wraps in a Promise processing the given sources and calculates project metrics via plugins.

Params:

NameTypeAttributeDescription
sources Array<object>

Array of object hashes containing code and path entries.

options object

(Optional) project processing options.

parserOptions object

(Optional) overrides default babylon parser options.

Return:

Promise<{reports: Array<{}>}>

An object hash with a reports entry that is an Array of module results.

public parse(source: string, parserOptions: object): object source

Provides a convenience method to parse the given source code and return the babylon AST.

Params:

NameTypeAttributeDescription
source string

Javascript source code.

parserOptions object

(Optional) overrides default babylon parser options.

Return:

object

babylon generated AST.

public parseAsync(source: string, parserOptions: object): Promise<object> source

Wraps in a Promise a convenience method to parse the given source code and return the babylon AST.

Params:

NameTypeAttributeDescription
source string

Javascript source code.

parserOptions object

(Optional) overrides default babylon parser options.

Return:

Promise<object>

babylon generated AST.

public processProject(results: object, options: object): {reports: Array<{}>} source

Processes existing project results and calculates metrics via plugins.

Params:

NameTypeAttributeDescription
results object

An object hash with a reports entry that is an Array of module results.

options object

(Optional) project processing options.

Return:

{reports: Array<{}>}

An object hash with a reports entry that is an Array of module results.

public processProjectAsync(results: object, options: object): Promise<{reports: Array<{}>}> source

Wraps in a Promise processing existing project results and calculates metrics via plugins.

Params:

NameTypeAttributeDescription
results object

An object hash with a reports entry that is an Array of module results.

options object

(Optional) project processing options.

Return:

Promise<{reports: Array<{}>}>

An object hash with a reports entry that is an Array of module results.