1.4.1 • Published 1 year ago

tsmetrics-core v1.4.1

Weekly downloads
748
License
MIT
Repository
github
Last release
1 year ago

TS Metrics - Core

Computes complexity in TypeScript / JavaScript files.

Complexity calculation

The steps of the calculation:

  • create an AST from the input source file
  • walk through each and every node of it
  • depending on the type of the node and the configuration associated with it create a new entry about the node. This entry contains everything necessary for further use (e.g. a textual representation for the node, complexity increment, child nodes etc.)
  • The returned tree can be traversed to collect the complexity information.

Please note that it is not a standard metric, but it is a close approximation of Cyclomatic complexity.

Please also note that it is possible to balance the complexity calculation for the project / team / personal taste by adjusting the relevant configuration entries.

Packages / extensions built on top of this package

Example usage:

import * as ts from 'typescript';
import { IMetricsModel, IMetricsParseResult, MetricsParser, MetricsConfiguration } from 'tsmetrics-core';

export class ExampleUsage {

    public getMetrics(filePath: string) {
        var metricsForFile: IMetricsParseResult = MetricsParser.getMetrics(filePath, MetricsConfiguration, ts.ScriptTarget.ES5);
        this.log(metricsForFile.metrics, "");
    }

    private log(model: IMetricsModel, level: string) {
        console.log(model.toLogString(level));
        model.children.forEach(element => {
            this.log(element, level + "  ");
        });
    }
}

License

Licensed under MIT

1.4.1

1 year ago

1.4.0

1 year ago

1.3.1

1 year ago

1.3.0

1 year ago

1.2.2

4 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.0

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

6 years ago

0.4.3

6 years ago

0.4.2

7 years ago

0.4.1

7 years ago

0.4.0

7 years ago

0.3.3

7 years ago

0.3.2

8 years ago

0.3.1

8 years ago

0.3.0

8 years ago

0.2.0

8 years ago

0.1.0

8 years ago

0.0.1

8 years ago