npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

typescript-coverage

v1.0.0

Published

A dead-simple criteria to track your Typescript migration

Downloads

245

Readme

Typescript Coverage

Intro

A dead-simple criteria to track your Typescript migration.

To measure Typescript coverage, we simply divide the total number of lines in TS by the total number of lines in the project. That's it, nothing more. Easy, huh?

Example output

An output example when run in terminal

Our approach

  • We locate all the files according to the include and exclude options.
  • If the file extension belongs to tsExtensions, we consider the whole file written in TS. Its line number is added to "lines in TS".
  • In any case, its line number is added to "all lines".
  • We divide "lines in TS" by "all lines" to get the final percentage.

Installation

Install the package alongside its peer dependencies (chalk and glob) with your favorite package manager:

npm install --save-dev typescript-coverage chalk glob
yarn add --dev typescript-coverage chalk glob
pnpm install --save-dev typescript-coverage chalk glob

Using in your project

  1. Add a new script to your package.json:
{
  "scripts": {
    "typescript-coverage": "typescript-coverage"
  }
}
  1. Create a typescript-coverage.config.json file in the root of your project to customize the coverage calculation (optional). When no config was found, the following defaults will be used:
{
  // how to find the files to analyze (glob syntax)
  include: 'src/**/*.{ts,tsx,js,jsx}',
  // the files or the folders to ignore: mocks, tests, etc. (glob syntax)
  exclude: ['**/__tests__/**'],
  // whether to ignore empty lines
  ignoreEmptyLines: false,
  // the files that are consider written in TS (could be .ts, .tsx, .mts, .cts, etc)
  tsExtensions: ['.ts', '.tsx'],
}

System requirements

  • The project uses top-level await with ES modules and thus requires Node v14.8.0 or higher (tested on Node 18 and 20).
  • To run the tests locally, the PNPM package manager must be installed. Note: this requirement only applies if you are contributing to the project.

Caveats

  • For simplicity, we are only looking at the file extension but the content isn't validated. A linter or a Typescript compiler will take care of that.
  • If the file has a .ts extension but the content is not a valid TS code, it will still be treated as TS.
  • No type inference is taken into account.
  • If the file is a mixture of JS and TS code but has a .ts extension, all the lines will be counted as TS.
  • We don't ignore comments. Taking different comments into account (inline, multiline) would further complicate it.

Our story

At Prose, we've been migrating two projects to Typescript. We needed the simplest way to track our progress, so we created typescript-coverage — a minimalistic tool focused on this sole goal. Instead of copying and pasting it into every project, we decided to make it an open-source package for anyone facing the same challenge 💚