@stacc/clear-module
TypeScript icon, indicating that this package has built-in type declarations

4.3.2 • Public • Published

clear-module

Clear a module from the cache

Useful for testing purposes when you need to freshly import a module.

Install

$ npm install clear-module

Usage

// foo.js
let i = 0;
module.exports = () => ++i;
const clearModule = require('clear-module');

require('./foo')();
//=> 1

require('./foo')();
//=> 2

clearModule('./foo');

require('./foo')();
//=> 1

API

clearModule(moduleId)

moduleId

Type: string

What you would use with require().

clearModule.all()

Clear all modules from the cache.

clearModule.match(regex)

Clear all matching modules from the cache.

regex

Type: RegExp

Regex to match against the module IDs.

clearModule.single(moduleId)

Clear a single module from the cache non-recursively. No parent or children modules will be affected.

This is mostly only useful if you use singletons, where you would want to clear a specific module without causing any side effects.

moduleId

Type: string

What you would use with require().

Related

Package Sidebar

Install

npm i @stacc/clear-module

Weekly Downloads

62

Version

4.3.2

License

MIT

Unpacked Size

7.04 kB

Total Files

5

Last publish

Collaborators

  • karolined
  • gawdfrey
  • bjarnehelland
  • robingrundvag
  • anderseidestacc
  • oyvindfanebust
  • slem