index.d.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. declare const importCwd: {
  2. /**
  3. Import a module like with [`require()`](https://nodejs.org/api/globals.html#globals_require) but from the current working directory.
  4. @param moduleId - What you would use in `require()`.
  5. @throws Like `require()`, throws when the module can't be found.
  6. @example
  7. ```
  8. import importCwd = require('import-cwd');
  9. // Target module is at '/Users/sindresorhus/unicorn/foo.js'
  10. console.log(__dirname);
  11. //=> '/Users/sindresorhus/rainbow'
  12. console.log(process.cwd());
  13. //=> '/Users/sindresorhus/unicorn'
  14. const foo = importCwd('./foo');
  15. ```
  16. */
  17. (moduleId: string): unknown;
  18. /**
  19. Import a module like with [`require()`](https://nodejs.org/api/globals.html#globals_require) but from the current working directory.
  20. @param moduleId - What you would use in `require()`.
  21. @returns `undefined` instead of throwing when the module can't be found.
  22. @example
  23. ```
  24. import importCwd = require('import-cwd');
  25. // '/Users/sindresorhus/empty/' is empty
  26. console.log(__dirname);
  27. //=> '/Users/sindresorhus/rainbow'
  28. console.log(process.cwd());
  29. //=> '/Users/sindresorhus/empty'
  30. const foo = importCwd.silent('./nonexistent');
  31. //=> undefined
  32. ```
  33. */
  34. silent(moduleId: string): unknown;
  35. };
  36. export = importCwd;