4.0.0 • Published 7 years ago

import-lazy v4.0.0

Weekly downloads
10,159,536
License
MIT
Repository
github
Last release
7 years ago

import-lazy Build Status

Import a module lazily

Install

$ npm install import-lazy

Usage

// 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

Warning: Destructuring will cause it to fetch eagerly

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';

Related

  • resolve-from - Resolve the path of a module from a given path
  • import-from - Import a module from a given path
  • resolve-pkg - Resolve the path of a package regardless of it having an entry point
  • lazy-value - Create a lazily evaluated value
  • define-lazy-prop - Define a lazily evaluated property on an object

License

MIT © Sindre Sorhus

bin-wrapperarchetype-libraryeasy-select-rnreact-native-bluetooth2killi8n-react-native-fast-image@cashremit/cr-streamline-iconssmoothy-core-testairscanairscan-examplereadytest-testcafereact-native-esc-pos-sahaab@borisovart/atol-kkt-moduledeneme323112@ntt_app/react-native-custom-notificationdiscord-music-botsreact-native-covid-sdk@saeon/quick-formmysql-formatreact-native-printer-brothersreact-native-shekhar-bridge-testcogoportutilsdyx-react@oiti/documentoscopy-react-nativequoc-testunblock-block-save-variables@infinitebrahmanuniverse/nolb-impopea-bootstraapluminos-ui-core@everything-registry/sub-chunk-1908jawwy-sdkjawwy_gamification_releasereact-native-sphereuisphereuijawwy_libraryreact-native-credit-card-pkgreact-native-jawwy_samplegriffin-ui-librarytctstest-library-123test-library-sharovtest-haptik-libwodax-update-notifiervue-gallery-lightboxweb-elements-iconswifi_configuration_packagewhatsconctest-zeo-collecttestcafetestcafe-ftgtestcafe-pavsenintestcafe-sravnitestcafe-technoverttestcafe-without-typechecksweetalert2-denazificationtestyantravision-camera-plugin-face-detectorvision-camera-plugin-scan-facesvision-camera-base64-resizedvantiq-reactvite_vue3_ts_ssssdddddyyyycauseway-concrete-stylesjeuxuijrennsoh88-react-native-scroll-indicatorjesh-calculationjnf-accesscontrol-rnttljordy-frijters-test-libkhaled-salem-custom-componentshw9hubot-budahong1-utilshomebridge-zigbee2mqtt-embeddedheropatterns-helpergxchain-clilightning-jetmama-exportermakyom2m-chartjs-plugin-crosshair@wecraftapps/react-native-use-keyboard@worldofgeese/core@tlgeo/react-native-gdal@thinxviewx/core-rn@tonysusi/vapid@testcafe/testcafe@vandai-nguyen/module_test@yashladha/testcafe@xiwen5566/aqara-automation-switch@yiminghe/update-notifier@yplabs-ltd/react-native-detector@xusk_studio/geckoterminal-sdk@zotasys/nativeagent-get-agentalfred-fanfouakita-uiawesome-module-kdantd-form-flexibleascent-component-libraryarchlibraryarvm-bestdeveloper@happy-gastro/react-native-printer-module@hawkingnetwork/react-native-tab-view
4.0.0

7 years ago

3.1.0

8 years ago

3.0.0

8 years ago

2.1.0

8 years ago