Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

před 3 roky
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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)
  2. > Cache requires to be lazy-loaded when needed.
  3. ## Install
  4. Install with [npm](https://www.npmjs.com/):
  5. ```sh
  6. $ npm install lazy-cache --save
  7. ```
  8. 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.
  9. ## Usage
  10. ```js
  11. var utils = require('lazy-cache')(require);
  12. ```
  13. **Use as a property on `lazy`**
  14. The module is also added as a property to the `lazy` function
  15. so it can be called without having to call a function first.
  16. ```js
  17. var utils = require('lazy-cache')(require);
  18. // `npm install glob`
  19. utils('glob');
  20. // glob sync
  21. console.log(utils.glob.sync('*.js'));
  22. // glob async
  23. utils.glob('*.js', function (err, files) {
  24. console.log(files);
  25. });
  26. ```
  27. **Use as a function**
  28. ```js
  29. var utils = require('lazy-cache')(require);
  30. var glob = utils('glob');
  31. // `glob` is a now a function that may be called when needed
  32. glob().sync('foo/*.js');
  33. ```
  34. ## Aliases
  35. An alias may be passed as the second argument if you don't want to use the automatically camel-cased variable name.
  36. **Example**
  37. ```js
  38. var utils = require('lazy-cache')(require);
  39. // alias `ansi-yellow` as `yellow`
  40. utils('ansi-yellow', 'yellow');
  41. console.log(utils.yellow('foo'));
  42. ```
  43. ## Browserify usage
  44. **Example**
  45. ```js
  46. var utils = require('lazy-cache')(require);
  47. // temporarily re-assign `require` to trick browserify
  48. var fn = require;
  49. require = utils;
  50. // list module dependencies (here, `require` is actually `lazy-cache`)
  51. require('glob');
  52. require = fn; // restore the native `require` function
  53. /**
  54. * Now you can use glob with the `utils.glob` variable
  55. */
  56. // sync
  57. console.log(utils.glob.sync('*.js'));
  58. // async
  59. utils.glob('*.js', function (err, files) {
  60. console.log(files.join('\n'));
  61. });
  62. ```
  63. ## Kill switch
  64. In certain rare edge cases it may be necessary to unlazy all lazy-cached dependencies (5 reported cases after ~30 million downloads).
  65. To force lazy-cache to immediately invoke all dependencies, do:
  66. ```js
  67. process.env.UNLAZY = true;
  68. ```
  69. ## Related projects
  70. You might also be interested in these projects:
  71. [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)
  72. ## Contributing
  73. Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/lazy-cache/issues/new).
  74. ## Building docs
  75. Generate readme and API documentation with [verb](https://github.com/verbose/verb):
  76. ```sh
  77. $ npm install verb && npm run docs
  78. ```
  79. Or, if [verb](https://github.com/verbose/verb) is installed globally:
  80. ```sh
  81. $ verb
  82. ```
  83. ## Running tests
  84. Install dev dependencies:
  85. ```sh
  86. $ npm install -d && npm test
  87. ```
  88. ## Author
  89. **Jon Schlinkert**
  90. * [github/jonschlinkert](https://github.com/jonschlinkert)
  91. * [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
  92. ## License
  93. Copyright © 2016, [Jon Schlinkert](https://github.com/jonschlinkert).
  94. Released under the [MIT license](https://github.com/jonschlinkert/lazy-cache/blob/master/LICENSE).
  95. ***
  96. _This file was generated by [verb](https://github.com/verbose/verb), v0.9.0, on April 22, 2016._