aboutsummaryrefslogtreecommitdiff
path: root/node_modules/lazy-cache/README.md
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2017-08-14 05:01:11 +0200
committerFlorian Dold <florian.dold@gmail.com>2017-08-14 05:02:09 +0200
commit363723fc84f7b8477592e0105aeb331ec9a017af (patch)
tree29f92724f34131bac64d6a318dd7e30612e631c7 /node_modules/lazy-cache/README.md
parent5634e77ad96bfe1818f6b6ee70b7379652e5487f (diff)
downloadwallet-core-363723fc84f7b8477592e0105aeb331ec9a017af.tar.xz
node_modules
Diffstat (limited to 'node_modules/lazy-cache/README.md')
-rw-r--r--node_modules/lazy-cache/README.md94
1 files changed, 71 insertions, 23 deletions
diff --git a/node_modules/lazy-cache/README.md b/node_modules/lazy-cache/README.md
index 33b5a4dde..14463180c 100644
--- a/node_modules/lazy-cache/README.md
+++ b/node_modules/lazy-cache/README.md
@@ -1,4 +1,4 @@
-# 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)
+# lazy-cache [![NPM version](https://img.shields.io/npm/v/lazy-cache.svg?style=flat)](https://www.npmjs.com/package/lazy-cache) [![NPM monthly downloads](https://img.shields.io/npm/dm/lazy-cache.svg?style=flat)](https://npmjs.org/package/lazy-cache) [![NPM total downloads](https://img.shields.io/npm/dt/lazy-cache.svg?style=flat)](https://npmjs.org/package/lazy-cache) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/lazy-cache.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/lazy-cache)
> Cache requires to be lazy-loaded when needed.
@@ -7,10 +7,44 @@
Install with [npm](https://www.npmjs.com/):
```sh
-$ npm install lazy-cache --save
+$ npm install --save lazy-cache
```
-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.
+## Heads up!
+
+It's suprising how many libraries are in the average dependency tree that don't belong there for one reason or another. Either because they were accidentally listed as `dependencies` instead of `devDepedencies`, or they are required in a file as variables, but the variable is never actually used (poor linting), and so on. Or because the maintainer made the decision to add the deps, even though they will never ([or can't ever](https://github.com/felixge/node-dateformat/issues/36)) be used by 99.9% of users.
+
+Worse, many libraries like chalk and [shelljs](https://github.com/eslint/eslint/issues/7316) actually execute code when `require()` is called!? (shelljs was modifying the `String.prototype`, and chalk loops over some objects to dynamically create methods). In other words, they do something like this:
+
+```js
+// in the main export of a library, if you do this it will
+// automatically modify the String.prototype _globally_,
+// the moment node.js loads the dependency tree
+String.prototype.foo = function() {};
+
+// same if you do something like this
+// (dont' do this, ever. wrap this kind of code in a function
+// and allow implementors to decide when to call it)
+while (foo) {
+ // do stuff
+}
+```
+
+In any case, just having these libraries in your dependency tree somewhere means that their code will excecute the moment you run your application _even if the libraries are never called by your application or any other code anywhere in the tree_.
+
+**solution**
+
+lazy-cache doesn't use any "magic", it uses native, plain-vanilla, tried and true javascript getters to call node's `require()` system.
+
+**Faster, safer code**
+
+There main advantage to this, the main is that `require`s are loaded on demand, so only code that is actually used will ever be loaded. As a result, applications will load faster (sometimes much faster - we've seen load times drop from ~1 second to less than 50 milliseconds).
+
+Moreover, in some cases this also avoids inadvertently loading libraries that execute code or modifies globals, etc.
+
+**webpack users**
+
+If you use webpack and are experiencing issues with lazy-cache, this is a known bug caused by webpack, not lazy-cache. There is a solution though, you can use [unlazy-loader](https://github.com/doowb/unlazy-loader), a webpack loader that _fixes the webpack bug_.
## Usage
@@ -20,8 +54,7 @@ var utils = require('lazy-cache')(require);
**Use as a property on `lazy`**
-The module is also added as a property to the `lazy` function
-so it can be called without having to call a function first.
+The module is also added as a property to the `lazy` function so it can be called without having to call a function first.
```js
var utils = require('lazy-cache')(require);
@@ -62,6 +95,20 @@ utils('ansi-yellow', 'yellow');
console.log(utils.yellow('foo'));
```
+Dot notation may also be used in the alias to create an object hierarchy.
+
+**Example**
+
+```js
+var utils = require('lazy-cache')(require);
+utils('ansi-cyan', 'color.cyan');
+utils('ansi-yellow', 'color.yellow');
+utils('ansi-magenta', 'color.magenta');
+console.log(utils.color.cyan('foo'));
+console.log(utils.color.yellow('bar'));
+console.log(utils.color.magenta('baz'));
+```
+
## Browserify usage
**Example**
@@ -90,39 +137,40 @@ utils.glob('*.js', function (err, files) {
## Kill switch
-In certain rare edge cases it may be necessary to unlazy all lazy-cached dependencies (5 reported cases after ~30 million downloads).
-
To force lazy-cache to immediately invoke all dependencies, do:
```js
process.env.UNLAZY = true;
```
-## Related projects
+## About
-You might also be interested in these projects:
+### Related projects
-[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)
+[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://github.com/jonschlinkert/lint-deps) | [homepage](https://github.com/jonschlinkert/lint-deps "CLI tool that tells you when dependencies are missing from package.json and offers you a choice to install them. Also tells you when dependencies are listed in package.json but are not being used anywhere in your project. Node.js command line tool and API")
-## Contributing
+### Contributing
-Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/lazy-cache/issues/new).
+Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
-## Building docs
+### Contributors
-Generate readme and API documentation with [verb](https://github.com/verbose/verb):
+| **Commits** | **Contributor**<br/> |
+| --- | --- |
+| 31 | [jonschlinkert](https://github.com/jonschlinkert) |
+| 27 | [doowb](https://github.com/doowb) |
-```sh
-$ npm install verb && npm run docs
-```
+### Building docs
+
+_(This document was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme) (a [verb](https://github.com/verbose/verb) generator), please don't edit the readme directly. Any changes to the readme must be made in [.verb.md](.verb.md).)_
-Or, if [verb](https://github.com/verbose/verb) is installed globally:
+To generate the readme and API documentation with [verb](https://github.com/verbose/verb):
```sh
-$ verb
+$ npm install -g verb verb-generate-readme && verb
```
-## Running tests
+### Running tests
Install dev dependencies:
@@ -130,18 +178,18 @@ Install dev dependencies:
$ npm install -d && npm test
```
-## Author
+### Author
**Jon Schlinkert**
* [github/jonschlinkert](https://github.com/jonschlinkert)
* [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
-## License
+### License
Copyright © 2016, [Jon Schlinkert](https://github.com/jonschlinkert).
Released under the [MIT license](https://github.com/jonschlinkert/lazy-cache/blob/master/LICENSE).
***
-_This file was generated by [verb](https://github.com/verbose/verb), v0.9.0, on April 22, 2016._ \ No newline at end of file
+_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.2.0, on November 07, 2016._ \ No newline at end of file