1 # lazy-cache [![NPM version](https://img.shields.io/npm/v/lazy-cache.svg?style=flat)](https://www.npmjs.com/package/lazy-cache) [![NPM downloads](https://img.shields.io/npm/dm/lazy-cache.svg?style=flat)](https://npmjs.org/package/lazy-cache) [![Build Status](https://img.shields.io/travis/jonschlinkert/lazy-cache.svg?style=flat)](https://travis-ci.org/jonschlinkert/lazy-cache)
3 > Cache requires to be lazy-loaded when needed.
7 Install with [npm](https://www.npmjs.com/):
10 $ npm install lazy-cache --save
13 If you use webpack and are experiencing issues, try using [unlazy-loader](https://github.com/doowb/unlazy-loader), a webpack loader that fixes the bug that prevents webpack from working with native javascript getters.
18 var utils = require('lazy-cache')(require);
21 **Use as a property on `lazy`**
23 The module is also added as a property to the `lazy` function
24 so it can be called without having to call a function first.
27 var utils = require('lazy-cache')(require);
33 console.log(utils.glob.sync('*.js'));
36 utils.glob('*.js', function (err, files) {
44 var utils = require('lazy-cache')(require);
45 var glob = utils('glob');
47 // `glob` is a now a function that may be called when needed
48 glob().sync('foo/*.js');
53 An alias may be passed as the second argument if you don't want to use the automatically camel-cased variable name.
58 var utils = require('lazy-cache')(require);
60 // alias `ansi-yellow` as `yellow`
61 utils('ansi-yellow', 'yellow');
62 console.log(utils.yellow('foo'));
70 var utils = require('lazy-cache')(require);
71 // temporarily re-assign `require` to trick browserify
74 // list module dependencies (here, `require` is actually `lazy-cache`)
76 require = fn; // restore the native `require` function
79 * Now you can use glob with the `utils.glob` variable
83 console.log(utils.glob.sync('*.js'));
86 utils.glob('*.js', function (err, files) {
87 console.log(files.join('\n'));
93 In certain rare edge cases it may be necessary to unlazy all lazy-cached dependencies (5 reported cases after ~30 million downloads).
95 To force lazy-cache to immediately invoke all dependencies, do:
98 process.env.UNLAZY = true;
103 You might also be interested in these projects:
105 [lint-deps](https://www.npmjs.com/package/lint-deps): CLI tool that tells you when dependencies are missing from package.json and offers you a… [more](https://www.npmjs.com/package/lint-deps) | [homepage](https://github.com/jonschlinkert/lint-deps)
109 Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/lazy-cache/issues/new).
113 Generate readme and API documentation with [verb](https://github.com/verbose/verb):
116 $ npm install verb && npm run docs
119 Or, if [verb](https://github.com/verbose/verb) is installed globally:
127 Install dev dependencies:
130 $ npm install -d && npm test
137 * [github/jonschlinkert](https://github.com/jonschlinkert)
138 * [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
142 Copyright © 2016, [Jon Schlinkert](https://github.com/jonschlinkert).
143 Released under the [MIT license](https://github.com/jonschlinkert/lazy-cache/blob/master/LICENSE).
147 _This file was generated by [verb](https://github.com/verbose/verb), v0.9.0, on April 22, 2016._