You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

readme.md 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # import-lazy [![Build Status](https://travis-ci.org/sindresorhus/import-lazy.svg?branch=master)](https://travis-ci.org/sindresorhus/import-lazy)
  2. > Import a module lazily
  3. Note: Version 3 is exclusively `Proxy`-based and requires Node.js 6+. Use [version 2](https://github.com/sindresorhus/import-lazy/tree/ed6c2fac31aaf8a7d91a27295756383487f3965d) if you need Node.js <=5 support.
  4. ## Install
  5. ```
  6. $ npm install import-lazy
  7. ```
  8. ## Usage
  9. ```js
  10. // Pass in `require` or a custom import function
  11. const importLazy = require('import-lazy')(require);
  12. const _ = importLazy('lodash');
  13. // Instead of referring to its exported properties directly…
  14. _.isNumber(2);
  15. // …it's cached on consecutive calls
  16. _.isNumber('unicorn');
  17. // It also works using destructuring assignment in ES2015
  18. const {isNumber, isString} = importLazy('lodash');
  19. // Works out of the box for functions and regular properties
  20. const stuff = importLazy('./math-lib');
  21. console.log(stuff.sum(1, 2)); // => 3
  22. console.log(stuff.PHI); // => 1.618033
  23. ```
  24. ## Related
  25. - [resolve-from](https://github.com/sindresorhus/resolve-from) - Resolve the path of a module from a given path
  26. - [import-from](https://github.com/sindresorhus/import-from) - Import a module from a given path
  27. - [resolve-pkg](https://github.com/sindresorhus/resolve-pkg) - Resolve the path of a package regardless of it having an entry point
  28. - [lazy-value](https://github.com/sindresorhus/lazy-value) - Create a lazily evaluated value
  29. - [define-lazy-prop](https://github.com/sindresorhus/define-lazy-prop) - Define a lazily evaluated property on an object
  30. ## License
  31. MIT © [Sindre Sorhus](https://sindresorhus.com)