"Fossies" - the Fresh Open Source Software Archive

Member "node-v12.18.4-win-x64/node_modules/npm/node_modules/import-lazy/readme.md" (14 Feb 2020, 2015 Bytes) of package /windows/www/node-v12.18.4-win-x64.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format (assuming markdown format). Alternatively you can here view or download the uninterpreted source code file. A member file download can also be achieved by clicking within a package contents listing on the according byte size field.

import-lazy Build Status

Import modules lazily

Install

$ npm install --save import-lazy

Usage

// Pass in `require` or a custom import function
const importLazy = require('import-lazy')(require);
const _ = importLazy('lodash');

// Where you would normally do
_.isNumber(2);

// You now instead call it as a function
_().isNumber(2);

// It's cached on consecutive calls
_().isString('unicorn');

// Extract lazy variations of the props you need
const members = importLazy('lodash')('isNumber', 'isString');

// Useful when using destructuring assignment in ES2015
const {isNumber, isString} = importLazy('lodash')('isNumber', 'isString');

// Works out of the box for functions and regular properties
const stuff = importLazy('./math-lib')('sum', 'PHI');
console.log(stuff.sum(1, 2)); // => 3
console.log(stuff.PHI); // => 1.618033

Proxy support in Node.js 6 or later

If you use Node.js 6 or later, you can take advantage of ES2015 proxies and don’t need to call it as a function.

const importLazy = require('import-lazy').proxy(require);
const _ = importLazy('lodash');

// No need to call it as a function but still lazily imported
_.isNumber(2);

License

MIT © Sindre Sorhus