4.0.0 • Published 5 years ago

import-lazy v4.0.0

Weekly downloads
10,159,536
License
MIT
Repository
github
Last release
5 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

update-notifierbin-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-coretestcafe@everything-registry/sub-chunk-1908jawwy-sdkjawwy_gamification_releasereact-native-sphereuisphereuijawwy_libraryreact-native-credit-card-pkgreact-native-jawwy_sample@gabrielgodoy/testcafeweb-elements-iconszeo-collectzhihu-daily-clizubtesttoday@geeky-apo/react-native-advanced-clipboardwifi_configuration_packagewodax-update-notifierwangyaling-1ayangtao-jsupdate-notifier-cjsupdate-notifier-gitupdate-notifier-newupdate-notifier-webpackupdate-notifier2vue-v3-yandex-metrikavite_vue3_ts_ssssdddddyyyyvue-gallery-lightbox@hemith/react-native-tnkfluent.adflow.reactnativesdk-alphafluent.adflow.reactnativesdkfmslfn-lib-example@lywzx/rollup-build-scriptsjawwy_library_newjawy_library_v1gamification-jawwy-libraryframework_test_library_sixdee_new_jawwytest_lib_module_aarreact-native-create-video-thumbnailreact-native-android-video-player-viewreact-native-animate-textreact-native-additionreact-native-pulsator-nativereact-native-plugpag-wrapperreact-native-rom-componentsreact-native-rtn-ips-poslin-testreact-native-savczuk-feature-libraryreact-native-sandycomponentreact-native-shared-gesturereact-native-recent-framework-updatereact-native-reanimated-sortable-listreact-native-omental-frameworkreact-native-onrampreact-native-screen-idle-timerreact-native-scroll-tab-to-indexreact-native-progress-arrowreact-native-simple-timelinereact-native-sixdee_test_libreact-native-sp-test-commonreact-native-tilt-blereact-native-ticker-tapereact-native-ytximkitreact-native-volume-phisicalreact-native-ui-components-libraryreact-native-teads-sdk-modulereact-native-tejab41097-sample-libraryreact-native-teknoctrl-componentsreact-native-syan-photo-pickerreact-native-transtracker-libraryreact-native-tone-frameworkreact-native-test-view
4.0.0

5 years ago

3.1.0

6 years ago

3.0.0

7 years ago

2.1.0

7 years ago