index.d.ts
1 /* (c) 2015 Ari Porad (@ariporad) <http://ariporad.com>. License: ariporad.mit-license.org */ 2 3 declare type Hook = (code: string, filename: string) => string; 4 declare type Matcher = (code: string) => boolean; 5 declare type RevertFunction = () => void; 6 interface Options { 7 /** A matcher function, will be called with path to a file. Should return truthy if the file should be hooked, falsy otherwise. */ 8 matcher?: Matcher; 9 /** 10 * The extensions to hook. Should start with '.' (ex. ['.js']). 11 * 12 * @default ['.js'] 13 */ 14 exts?: Array<string>; 15 /** 16 * Auto-ignore node_modules. Independent of any matcher. 17 * 18 * @default true 19 */ 20 ignoreNodeModules?: boolean; 21 } 22 /** 23 * Add a require hook. 24 * 25 * @param {Hook} hook - The hook. Accepts the code of the module and the filename. Required. 26 * @param {Options} [opts] - Options 27 * @returns {RevertFunction} revert - Reverts the hooks. 28 */ 29 export declare function addHook(hook: Hook, opts?: Options): RevertFunction; 30 export {};