Giter VIP home page Giter VIP logo

ts-complex's Introduction

ts-complex

Inspired from 'typhonjs-escomplex', this module helps to find the Halstead Complexity Matrices, Cyclomatic Complexity and Maintainability for typescript.

Features

  • Calculates function wise Halstead Complexity Matrices.
  • Calculates function wise Cyclomatic Complexity.
  • Calculates file wise Average Maintainability and Minimum Maintainability.

Installing

npm install ts-complex

Usage

Maintainability

const tscomplex = require('ts-complex');

const path = './test.ts'; // Finding maintainability of this file
const maintainability = tscomplex.calculateMaintainability(path);
console.log(maintainability); // { averageMaintainability: 56.14, minMaintainability: 46.19 }

Halstead Complexity Matrices

const tscomplex = require('ts-complex');

const path = './test.ts'; // Finding maintainability of this file
const halstead = tscomplex.calculateHalstead(path);
console.log(halstead); // object with function name as keys and Halstead Complexity Matrices as value

Cyclomatic Complexity

const tscomplex = require('ts-complex');

const path = './test.ts'; // Finding maintainability of this file
const complexity = tscomplex.calculateCyclomaticComplexity(path);
console.log(complexity); // object with function name as keys and cyclomatic complexity as value

How is the Maintainability calculated

The formula to calculate the maintainability for a file is

Maintainability = 171 - 5.2 * log_2(HV) - 0.23 * CC - 16.2 * log_2(SLoC)

Where, HV = Halstead Volume CC = Cyclomatic Complexity SLoC = Lines of Code

We calculate Halstead Complexity Matrices and Cyclomatic Complexity for each function in the given file. And aggregate them by two methods; considering the average and considering the maximum.

Thus, average maintainability is calculated using average halstead volume and average cyclomatic complexity. And minimum maintainability is calculated using maximum halstead volume and maximum cyclomatic complexity.

Contributing

Pull Requests are welcome!

Authors

License

This project is licensed under the MIT License - see the LICENSE.md file for details

ts-complex's People

Contributors

anandundavia avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.