index.d.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. declare const importFrom: {
  2. /**
  3. Import a module like with [`require()`](https://nodejs.org/api/modules.html#modules_require_id) but from a given path.
  4. @param fromDirectory - Directory to import from.
  5. @param moduleId - What you would use in `require()`.
  6. @throws Like `require()`, throws when the module can't be found.
  7. @example
  8. ```
  9. import importFrom = require('import-from');
  10. try {
  11. const bar = importFrom('foo', './bar');
  12. // Do something with `bar`
  13. } catch (error) {
  14. // `error` is thrown when `./bar` can't be found
  15. }
  16. ```
  17. */
  18. (fromDirectory: string, moduleId: string): unknown;
  19. /**
  20. Import a module like with [`require()`](https://nodejs.org/api/modules.html#modules_require_id) but from a given path.
  21. @param fromDirectory - Directory to import from.
  22. @param moduleId - What you would use in `require()`.
  23. @returns `undefined` instead of throwing when the module can't be found.
  24. @example
  25. ```
  26. import importFrom = require('import-from');
  27. const bar = importFrom.silent('foo', './bar');
  28. // Do something with `bar`, may be `undefined` when `./bar` can't be found
  29. ```
  30. */
  31. silent(fromDirectory: string, moduleId: string): unknown;
  32. };
  33. export = importFrom;