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-libraryfirst-app-lyfucifn-lib-examplefmslfluent.adflow.reactnativesdkfluent.adflow.reactnativesdk-alphaframework_test_library_sixdeeframework_test_library_sixdee_newframework_test_library_sixdee_new_newgamification-integration-newkhaled-salem-custom-componentshomebridge-zigbee2mqtt-embeddedhong1-utilshubot-budahw9miracle-webpack-tree-shakinglightning-jetmkcp-solarpunkng-search-dropdownnpm-custom-lib-resueover-armour-masterpg-utlpayutestingnpmtest-05041npm_one_12_34_1_npm_one_1_2_3npm_one_2_2npm_qwertyone-app-cliokapi-plaid-cliopea-bootstrapori-bot-react-nativejeuxuijesh-calculationjordy-frijters-test-libjrennsoh88-react-native-scroll-indicatorm2m-chartjs-plugin-crosshairmakyomama-exporternative-apple-loginnative-google-loginnative-date-picker-modulenative-kakao-loginnative-modal-damage-vehiclempesa-cookiempesa-cookie-jarmpass-climypluginlolneural_compressor_ext_lab_customizedneural_compressor_ext_lab_customized_2new-awesome-4321@idas1/ui-component-lib@innodata/vue-v3-ya-metrika@imrtoy/homebridge-night-light@labiebhn_/react-native-multiplier@lehuyaa/my-assets@livecycle.io/rrweb-snapshot@lofcz/sweetalert2-neutral@ltryy/ubox-cli@lywzx/rollup-build-scripts@mathu01/gdpr-consent@microsoft/rush-stack-compiler-2.4@microsoft/rush-stack-compiler-2.7@microsoft/rush-stack-compiler-2.8
4.0.0

6 years ago

3.1.0

7 years ago

3.0.0

7 years ago

2.1.0

7 years ago