index.d.ts 991 B

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