File: index.d.ts

package info (click to toggle)
node-import-lazy 4.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 152 kB
  • sloc: javascript: 82; makefile: 2
file content (26 lines) | stat: -rw-r--r-- 640 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/**
Import a module lazily.

@example
```
// Pass in `require` or a custom import function
import importLazy = require('import-lazy');
const _ = importLazy(require)('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(require)('./math-lib');
console.log(stuff.sum(1, 2)); // => 3
console.log(stuff.PHI); // => 1.618033
```
*/
declare function importLazy<T = unknown>(
	importFn: (moduleId: string) => T
): (moduleId: string) => T;

export = importLazy;