import-lazy
Advanced tools
Import a module lazily
Weekly downloads
Changelog
Breaking:
Enhancements:
https://github.com/sindresorhus/import-lazy/compare/v3.1.0...v4.0.0
Readme
Import a module lazily
$ npm install import-lazy
// Pass in `require` or a custom import function
const importLazy = require('import-lazy')(require);
const _ = importLazy('lodash');
// Instead of referring to its exported properties directly…
_.isNumber(2);
// …it's cached on consecutive calls
_.isNumber('unicorn');
// Works out of the box for functions and regular properties
const stuff = importLazy('./math-lib');
console.log(stuff.sum(1, 2)); // => 3
console.log(stuff.PHI); // => 1.618033
While you may be tempted to do leverage destructuring, like this:
const {isNumber, isString} = importLazy('lodash');
Note that this will cause immediate property access, negating the lazy loading, and is equivalent to:
import {isNumber, isString} from 'lodash';
MIT © Sindre Sorhus
Import a module lazily
The npm package import-lazy receives a total of 9,585,256 weekly downloads. As such, import-lazy popularity was classified as popular.
We found that import-lazy demonstrated a not healthy version release cadence and project activity because the last version was released a year ago.It has 1 open source maintainer collaborating on the project.