4.0.0 • Published 6 years ago

import-lazy v4.0.0

Weekly downloads
10,159,536
License
MIT
Repository
github
Last release
6 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_ssssdddddyyyy@digitalrakesh/jsui@cs6/react-native-test-native-view-library@con-test/react-native-concent-common@damruravihara/react-native-testing-package@corelmax/react-native-my2c2p-sdk@praella/localisationistcauseway-concrete-stylesjeuxuijrennsoh88-react-native-scroll-indicatorjesh-calculationjnf-accesscontrol-rnttljordy-frijters-test-libkhaled-salem-custom-componentsjawwy_library_newjawy_library_v1gamification-jawwy-libraryframework_test_library_sixdee_new_jawwytest_lib_module_aardfeuk-frontenddfeuk-frontend-manualquickcapture_react_nativern-agora-ios-mreact-native-omental-frameworkreact-native-sixdee_test_libtingzi-vuepresstittlestldrawlignintimplatwine-libtwine-library@aidc/chrome@amiruldev/wajs@amirdiafi/react-native-ios-haptics@apardellass/react-native-audio-stream@arman-ab/solarinsure-stickersheet@ankitfxz/params-ui@aviinash_jha/react-native-test_multiply@ali5049/react-native-buttons@bee-icons/qwik@aysea/react-native-ui-library
4.0.0

6 years ago

3.1.0

8 years ago

3.0.0

8 years ago

2.1.0

8 years ago