Socket
Socket
Sign inDemoInstall

istanbul-lib-hook

Package Overview
Dependencies
Maintainers
3
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


Version published
Weekly downloads
4.2M
increased by4.1%
Maintainers
3
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 20 Dec 2019

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