This package has been deprecated

Author message:

Renamed to `clear-module`.

clear-require
DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/clear-require package

3.0.0 • Public • Published

clear-require Build Status

Clear a module from the require cache

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

Install

$ npm install --save clear-require

Usage

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

API

clearRequire(moduleId)

moduleId

Type: string

What you would use with require().

clearRequire.all()

Clear all modules from the require cache.

clearRequire.match(regex)

Clear all matching modules from the require cache.

regex

Type: RegExp

Regex to match against the module ID's.

Related

License

MIT © Sindre Sorhus

Package Sidebar

Install

npm i clear-require

Weekly Downloads

2,720

Version

3.0.0

License

MIT

Unpacked Size

3.61 kB

Total Files

4

Last publish

Collaborators

  • sindresorhus