Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

istanbul-lib-hook

Package Overview
Dependencies
Maintainers
2
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

istanbul-lib-hook

Hooks for require, vm and script used in istanbul

  • 1.0.6
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5.3M
increased by25.07%
Maintainers
2
Weekly downloads
 
Created

What is istanbul-lib-hook?

The 'istanbul-lib-hook' package is part of the Istanbul code coverage tool suite. It provides utilities to hook into JavaScript code execution, allowing you to intercept and modify code at runtime. This is particularly useful for code coverage analysis, where you need to track which parts of your code are being executed during tests.

What are istanbul-lib-hook's main functionalities?

Hooking into require

This feature allows you to hook into the Node.js require function. You can specify a matcher function to determine which files to hook into and a transformer function to modify the code of those files before they are executed.

const hook = require('istanbul-lib-hook');
const matcher = (file) => file.endsWith('.js');
const transformer = (code, { filename }) => {
  // Modify the code here
  return code;
};

hook.hookRequire(matcher, transformer);

Hooking into vm.runInThisContext

This feature allows you to hook into the vm.runInThisContext function. Similar to hooking into require, you can specify a matcher and a transformer to modify the code before it is executed in the current context.

const hook = require('istanbul-lib-hook');
const matcher = (file) => file.endsWith('.js');
const transformer = (code, { filename }) => {
  // Modify the code here
  return code;
};

hook.hookRunInThisContext(matcher, transformer);

Unhooking

This feature allows you to unhook from the require or vm.runInThisContext functions. This is useful for cleaning up and restoring the original behavior after you are done with your modifications.

const hook = require('istanbul-lib-hook');

// Hook into require
const matcher = (file) => file.endsWith('.js');
const transformer = (code, { filename }) => {
  // Modify the code here
  return code;
};

const unhook = hook.hookRequire(matcher, transformer);

// Later, unhook
unhook();

Other packages similar to istanbul-lib-hook

Keywords

FAQs

Package last updated on 29 Apr 2017

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc