index.d.ts 640 B

1234567891011121314151617181920212223242526
  1. /**
  2. Import a module lazily.
  3. @example
  4. ```
  5. // Pass in `require` or a custom import function
  6. import importLazy = require('import-lazy');
  7. const _ = importLazy(require)('lodash');
  8. // Instead of referring to its exported properties directly…
  9. _.isNumber(2);
  10. // …it's cached on consecutive calls
  11. _.isNumber('unicorn');
  12. // Works out of the box for functions and regular properties
  13. const stuff = importLazy(require)('./math-lib');
  14. console.log(stuff.sum(1, 2)); // => 3
  15. console.log(stuff.PHI); // => 1.618033
  16. ```
  17. */
  18. declare function importLazy<T = unknown>(
  19. importFn: (moduleId: string) => T
  20. ): (moduleId: string) => T;
  21. export = importLazy;