🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

istanbul-api

Package Overview
Dependencies
Maintainers
3
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

istanbul-api

High level API for istanbul features

1.3.7
Source
npm
Version published
Weekly downloads
1.2M
83.2%
Maintainers
3
Weekly downloads
 
Created

What is istanbul-api?

The 'istanbul-api' npm package provides a set of APIs for working with code coverage in JavaScript projects. It is part of the Istanbul toolset, which is widely used for measuring code coverage in JavaScript applications. The package allows you to create coverage reports, manage coverage data, and instrument code for coverage analysis.

What are istanbul-api's main functionalities?

Creating Coverage Reports

This feature allows you to create coverage reports in various formats such as HTML. The code sample demonstrates how to create an HTML coverage report using the 'istanbul-api' package.

const istanbul = require('istanbul-api');
const reports = istanbul.reports;
const collector = new istanbul.Collector();
const reporter = reports.create('html', { dir: './coverage' });

collector.add(global.__coverage__);
reporter.writeReport(collector, true);

Managing Coverage Data

This feature allows you to manage and manipulate coverage data. The code sample shows how to create a coverage map and add file coverage data to it.

const istanbul = require('istanbul-api');
const coverageMap = istanbul.libCoverage.createCoverageMap();

coverageMap.addFileCoverage(global.__coverage__);
console.log(coverageMap.toJSON());

Instrumenting Code for Coverage

This feature allows you to instrument code for coverage analysis. The code sample demonstrates how to read a JavaScript file, instrument it for coverage, and write the instrumented code to a new file.

const istanbul = require('istanbul-api');
const instrumenter = istanbul.libInstrument.createInstrumenter();
const fs = require('fs');

const code = fs.readFileSync('path/to/your/file.js', 'utf8');
const instrumentedCode = instrumenter.instrumentSync(code, 'path/to/your/file.js');

fs.writeFileSync('path/to/your/instrumented-file.js', instrumentedCode);

Other packages similar to istanbul-api

Keywords

istanbul

FAQs

Package last updated on 05 Sep 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts