# import-lazy

> Import a module lazily

Latest version **4.0.0** (published 2019-04-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install import-lazy
pnpm add import-lazy
yarn add import-lazy
bun add import-lazy
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.0.0 |
| Published | 2019-04-27 |
| First published | 2017-05-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=8 |
| Dependencies | 0 |
| Unpacked size | 4.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 248 |
| Author | Sindre Sorhus |
| Maintainers | sindresorhus |
| Keywords | import, require, load, module, modules, lazy, lazily, defer, deferred, proxy, proxies |

## Links

- npm: https://www.npmjs.com/package/import-lazy
- Repository: https://github.com/sindresorhus/import-lazy
- Homepage: https://github.com/sindresorhus/import-lazy#readme
- Issues: https://github.com/sindresorhus/import-lazy/issues
- npm.io page: https://npm.io/package/import-lazy

## Recent versions

- 4.0.0 (latest) — 2019-04-27
- 3.1.0 — 2017-11-03
- 3.0.0 — 2017-06-14
- 2.1.0 — 2017-05-21

## README

# import-lazy [![Build Status](https://travis-ci.org/sindresorhus/import-lazy.svg?branch=master)](https://travis-ci.org/sindresorhus/import-lazy)

> Import a module lazily


## Install

```
$ npm install import-lazy
```


## Usage

```js
// 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:

```js
const {isNumber, isString} = importLazy('lodash');
```

Note that this will cause immediate property access, negating the lazy loading, and is equivalent to:

```js
import {isNumber, isString} from 'lodash';
```

## Related

- [resolve-from](https://github.com/sindresorhus/resolve-from) - Resolve the path of a module from a given path
- [import-from](https://github.com/sindresorhus/import-from) - Import a module from a given path
- [resolve-pkg](https://github.com/sindresorhus/resolve-pkg) - Resolve the path of a package regardless of it having an entry point
- [lazy-value](https://github.com/sindresorhus/lazy-value) - Create a lazily evaluated value
- [define-lazy-prop](https://github.com/sindresorhus/define-lazy-prop) - Define a lazily evaluated property on an object


## License

MIT © [Sindre Sorhus](https://sindresorhus.com)

---
_Source: https://npm.io/package/import-lazy · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
