hexo-adsense 1.0.21 → 1.0.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/README.md +20 -6
  3. package/lib/index.js +8 -1
  4. package/lib/source/adblock.css +2 -83
  5. package/lib/source/adblock.js +1 -31
  6. package/lib/source/article-ads.css +2 -11
  7. package/lib/source/article-ads.js +1 -270
  8. package/lib/source/blogger-redirect.html +1 -14
  9. package/lib/source/https.js +1 -4
  10. package/lib/src/article-ads.d.ts +1 -1
  11. package/lib/src/article-ads.js +6 -6
  12. package/lib/src/config.d.ts +12 -19
  13. package/lib/src/config.js +3 -5
  14. package/lib/src/utils.d.ts +9 -1
  15. package/lib/src/utils.js +2 -2
  16. package/package.json +20 -5
  17. package/packages/hexo-cli-extras/.eslintrc +13 -0
  18. package/packages/hexo-cli-extras/LICENSE.md +20 -0
  19. package/packages/hexo-cli-extras/README.md +146 -0
  20. package/packages/hexo-cli-extras/docs/basic.gif +0 -0
  21. package/packages/hexo-cli-extras/docs/gui.gif +0 -0
  22. package/packages/hexo-cli-extras/docs/remove.png +0 -0
  23. package/packages/hexo-cli-extras/docs/rename.png +0 -0
  24. package/packages/hexo-cli-extras/index.js +48 -0
  25. package/packages/hexo-cli-extras/lib/edit.js +209 -0
  26. package/packages/hexo-cli-extras/lib/env.js +52 -0
  27. package/packages/hexo-cli-extras/lib/extensions.js +23 -0
  28. package/packages/hexo-cli-extras/lib/integrate.js +87 -0
  29. package/packages/hexo-cli-extras/lib/isolate.js +179 -0
  30. package/packages/hexo-cli-extras/lib/remove.js +145 -0
  31. package/packages/hexo-cli-extras/lib/rename.js +171 -0
  32. package/packages/hexo-cli-extras/package.json +34 -0
  33. package/packages/hexo-extend-injector2/.eslintrc +4 -0
  34. package/packages/hexo-extend-injector2/.github/workflows/linter.yml +27 -0
  35. package/packages/hexo-extend-injector2/.github/workflows/tester.yml +24 -0
  36. package/packages/hexo-extend-injector2/.vscode/settings.json +10 -0
  37. package/packages/hexo-extend-injector2/LICENSE +165 -0
  38. package/packages/hexo-extend-injector2/README-ZH.md +189 -0
  39. package/packages/hexo-extend-injector2/README.md +191 -0
  40. package/packages/hexo-extend-injector2/USAGE.md +38 -0
  41. package/packages/hexo-extend-injector2/index.js +13 -0
  42. package/packages/hexo-extend-injector2/lib/bundle/css-bundle.js +79 -0
  43. package/packages/hexo-extend-injector2/lib/bundle/css-generator.js +13 -0
  44. package/packages/hexo-extend-injector2/lib/bundle/handle-data-pre.js +29 -0
  45. package/packages/hexo-extend-injector2/lib/bundle/js-bundle.js +42 -0
  46. package/packages/hexo-extend-injector2/lib/bundle/js-generator.js +10 -0
  47. package/packages/hexo-extend-injector2/lib/default-config.js +52 -0
  48. package/packages/hexo-extend-injector2/lib/filter.js +24 -0
  49. package/packages/hexo-extend-injector2/lib/helper/injector.js +6 -0
  50. package/packages/hexo-extend-injector2/lib/helper/next-inject.js +14 -0
  51. package/packages/hexo-extend-injector2/lib/injector.js +128 -0
  52. package/packages/hexo-extend-injector2/lib/load.js +45 -0
  53. package/packages/hexo-extend-injector2/lib/next-point.js +19 -0
  54. package/packages/hexo-extend-injector2/lib/next.js +87 -0
  55. package/packages/hexo-extend-injector2/lib/order.js +9 -0
  56. package/packages/hexo-extend-injector2/package.json +49 -0
  57. package/packages/hexo-extend-injector2/renovate.json +6 -0
  58. package/packages/hexo-extend-injector2/test/.eslintrc +3 -0
  59. package/packages/hexo-extend-injector2/test/index.js +18 -0
  60. package/packages/hexo-extend-injector2/test/lib/bundle/bundle-css.js +86 -0
  61. package/packages/hexo-extend-injector2/test/lib/bundle/bundle-js.js +36 -0
  62. package/packages/hexo-extend-injector2/test/lib/bundle/test.css +3 -0
  63. package/packages/hexo-extend-injector2/test/lib/bundle/test.js +5 -0
  64. package/packages/hexo-extend-injector2/test/lib/helper/injector.js +45 -0
  65. package/packages/hexo-extend-injector2/test/lib/helper/next-inject.js +69 -0
  66. package/packages/hexo-extend-injector2/test/lib/hexo-compatible.js +250 -0
  67. package/packages/hexo-extend-injector2/test/lib/hexo-injector.js +37 -0
  68. package/packages/hexo-extend-injector2/test/lib/injector.js +93 -0
  69. package/packages/memoize/CHANGELOG.md +82 -0
  70. package/packages/memoize/CHANGES +124 -0
  71. package/packages/memoize/LICENSE +15 -0
  72. package/packages/memoize/README.md +503 -0
  73. package/packages/memoize/ext/async.js +154 -0
  74. package/packages/memoize/ext/dispose.js +33 -0
  75. package/packages/memoize/ext/max-age.js +90 -0
  76. package/packages/memoize/ext/max.js +27 -0
  77. package/packages/memoize/ext/promise.js +147 -0
  78. package/packages/memoize/ext/ref-counter.js +48 -0
  79. package/packages/memoize/index.js +34 -0
  80. package/packages/memoize/lib/configure-map.js +182 -0
  81. package/packages/memoize/lib/methods.js +32 -0
  82. package/packages/memoize/lib/registered-extensions.js +1 -0
  83. package/packages/memoize/lib/resolve-length.js +15 -0
  84. package/packages/memoize/lib/resolve-normalize.js +17 -0
  85. package/packages/memoize/lib/resolve-resolve.js +21 -0
  86. package/packages/memoize/lib/weak.js +134 -0
  87. package/packages/memoize/methods-plain.js +3 -0
  88. package/packages/memoize/methods.js +3 -0
  89. package/packages/memoize/normalizers/get-1.js +29 -0
  90. package/packages/memoize/normalizers/get-fixed.js +71 -0
  91. package/packages/memoize/normalizers/get-primitive-fixed.js +16 -0
  92. package/packages/memoize/normalizers/get.js +90 -0
  93. package/packages/memoize/normalizers/primitive.js +9 -0
  94. package/packages/memoize/package.json +60 -0
  95. package/packages/memoize/plain.js +37 -0
  96. package/packages/memoize/profile.js +107 -0
  97. package/packages/memoize/repository.md +1 -0
  98. package/packages/memoize/weak-plain.js +3 -0
  99. package/packages/memoize/weak.js +3 -0
@@ -0,0 +1,124 @@
1
+ -- For new changelog see CHANGELOG.md
2
+
3
+ v0.4.4 -- 2017.03.15
4
+ * Expose _get and _has methods. It provides temporary means for better cache inspection until
5
+ v1 is delivered
6
+
7
+ v0.4.3 -- 2017.02.20
8
+ * Fix normalization resolver, so it validates already normalized resolvers (reported at #70)
9
+
10
+ v0.4.2 -- 2017.02.17
11
+ * Guard proper promise resolution in promise mode
12
+ * Improve documentation
13
+ * Improve npm scripts configuration
14
+ * Improve CI configuration
15
+
16
+ v0.4.1 -- 2016.07.13
17
+ * Fix promise mode to not use `then` and `finally` pair. Thanks @Kovensky
18
+ * Add 'done' mode to 'promise' mode (so now callbacks can be registered through `done` but no
19
+ `finally` event if it's implemented)
20
+
21
+ v0.4.0 -- 2016.07.07
22
+ * Introduce 'promise' mode
23
+ * Change signature of internal events for 'async' case
24
+ * Document 'normalizer' option
25
+
26
+ v0.3.10 -- 2016.04.21
27
+ * Fix resolvers bug (#12)
28
+ * Fix arguments support for weak mode
29
+ * Update repository address after rename
30
+
31
+ v0.3.9 -- 2015.08.04
32
+ * Update dependencies
33
+ * Improve documentation
34
+ * FIx spelling of LICENSE
35
+
36
+ v0.3.8 -- 2014.10.08
37
+ * Introduce WeakMap based `weak` mode
38
+
39
+ v0.3.7 -- 2014.08.14
40
+ * Fix prefetch support for asynchronous functions (#19)
41
+ * Configure lint scripts
42
+
43
+ v0.3.6 -- 2014.07.28
44
+ * Fix race condition issue related to clear/delete calls and returning id's (#18)
45
+ * Fix maxAge major cache handling issue (on timeout instead of individual record whole cache was
46
+ cleared)
47
+
48
+ v0.3.5 -- 2014.07.07
49
+ * Fix internal id genaration, for primitive, length = 1 case.
50
+ Ids were not serialized to strings, and that caused issues with other
51
+ internal logiv, which e.g. treated `null` case specifically.
52
+ Fixes #15 (Thanks @isaacg for reporting)
53
+
54
+ v0.3.4 -- 2014.06.22
55
+ * Fix async handling in case of clear between two async calls
56
+ (assurance of unique cache ids solves that). Fixes #13
57
+
58
+ v0.3.3 -- 2014.05.12
59
+ * Fix profiler special property definition
60
+
61
+ v0.3.2 -- 2014.05.01
62
+ * Provide no-arguments memoization out of a box
63
+ (no need to provide normalizer to `memoizee/plain`)
64
+
65
+ v0.3.1 -- 2014.04.27
66
+ * Update package.json to use latest 'tad' engine (fixes tests evaluation)
67
+
68
+ v0.3.0 -- 2014.04.27
69
+ Major reorganization and partial refactoring
70
+ * Move out main modules from lib folder
71
+ * Introduce normalizer based memoization. Primitive and regular handlers were converted into
72
+ dedicated normalizers (located in lib/normalizers folder). Custom normalizers can be provided at
73
+ run time via `normalizer` option.
74
+ * Provide 'plain' module which does not import (require) any extensions or normalizers. Thanks to
75
+ that it's lighter for e.g. client-side bundle. Any extensions that are expected to be used should
76
+ be required upfront, normalizers should be provided via `normalizer` option.
77
+ * Rename `memoized.clear` into `memoized.delete`, and `memoized.clearAll` into `memoized.clear`
78
+ * Rename `memoized.clearRef` into `memoized.deleteRef` (applies to 'refCounter' option)
79
+ * Remove 'method' option. Instead 'methods' and 'methods-plan' modules are provided which generate
80
+ descriptors for lazy created memoized methods.
81
+ * 'profile' is no longer an extension. It's provided as dedicated module.
82
+ * Clean up logic for `async` handling
83
+ * Take out 'max' extension's LRU logic into external `lru-queue` package.
84
+ See https://github.com/medikoo/lru-queue
85
+ * Remove possibility to access original arguments when resolvers are used
86
+ * Assure expected length of memoized functions
87
+ * Remove Makefile (it's environment agnostic package)
88
+
89
+ v0.2.6 -- 2013.10.08
90
+ * Fix internal events propagation when handling async calls that
91
+ resolve with errors. `asyncpurge` was emitted for values that had no
92
+ `asyncinit` emitted. Issue #9
93
+
94
+ v0.2.5 -- 2013.06.21
95
+ * Fix primitive handling for dynamic arguments length
96
+
97
+ v0.2.4 -- 2013.03.23
98
+ * Throw on circular invocations, they cannot be memoized as intended.
99
+
100
+ v0.2.3 -- 2012.10.04
101
+ * Fixed serious bug related to not properly cleared cache when working in
102
+ regular mode
103
+
104
+ v0.2.2 -- 2012.10.03
105
+ * preFetch functionality for maxAge variant
106
+ * Prevent memoization of already memoized functions
107
+
108
+ v0.2.1 -- 2012.09.21
109
+ * Fix missing global reference in method option logic
110
+ * Fix variable visibility in async option logic
111
+ * Lint cleanup
112
+
113
+ v0.2.0 -- 2012.09.21
114
+ * Modularization and general algorithm cleanup
115
+ * Cache is limited (max option) using LRU instead of FIFO algorithm
116
+ * Improved async mode, and its handling by other options
117
+
118
+ v0.1.1 -- 2012.09.19
119
+ * Fix dispose invocations for no arguments call
120
+ * Small documentation improvements
121
+
122
+ v0.1.0 -- 2012.09.18
123
+ * Initial. Derived from es5-ext package and added `async`, `maxAge`,
124
+ `refCounter`, `max` and `dispose` options.
@@ -0,0 +1,15 @@
1
+ ISC License
2
+
3
+ Copyright (c) 2012-2018, Mariusz Nowak, @medikoo, medikoo.com
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted, provided that the above
7
+ copyright notice and this permission notice appear in all copies.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14
+ OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15
+ PERFORMANCE OF THIS SOFTWARE.
@@ -0,0 +1,503 @@
1
+ [![*nix build status][nix-build-image]][nix-build-url]
2
+ [![Windows build status][win-build-image]][win-build-url]
3
+ ![Transpilation status][transpilation-image]
4
+ [![npm version][npm-image]][npm-url]
5
+
6
+ # Memoizee
7
+
8
+ ## Complete memoize/cache solution for JavaScript
9
+
10
+ _Originally derived from [es5-ext](https://github.com/medikoo/es5-ext) package._
11
+
12
+ Memoization is best technique to save on memory or CPU cycles when we deal with repeated operations. For detailed insight see: http://en.wikipedia.org/wiki/Memoization
13
+
14
+ ### Features
15
+
16
+ * Works with any type of function arguments – **no serialization is needed**
17
+ * Works with [**any length of function arguments**](#arguments-length). Length can be set as fixed or dynamic.
18
+ * One of the [**fastest**](#benchmarks) available solutions.
19
+ * Support for [**promises**](#promise-returning-functions) and [**asynchronous functions**](#nodejs-callback-style-functions)
20
+ * [**Primitive mode**](#primitive-mode) which assures fast performance when arguments are convertible to strings.
21
+ * [**WeakMap based mode**](#weakmap-based-configurations) for garbage collection friendly configuration
22
+ * Can be configured [**for methods**](#memoizing-methods) (when `this` counts in)
23
+ * Cache [**can be cleared manually**](#manual-clean-up) or [**after specified timeout**](#expire-cache-after-given-period-of-time)
24
+ * Cache size can be **[limited on LRU basis](#limiting-cache-size)**
25
+ * Optionally [**accepts resolvers**](#argument-resolvers) that normalize function arguments before passing them to underlying function.
26
+ * Optional [**reference counter mode**](#reference-counter), that allows more sophisticated cache management
27
+ * [**Profile tool**](#profiling--statistics) that provides valuable usage statistics
28
+ * Covered by [**over 500 unit tests**](#tests)
29
+
30
+ ### Installation
31
+
32
+ In your project path — **note the two `e`'s in `memoizee`:**
33
+
34
+ $ npm install memoizee
35
+
36
+ _`memoize` name was already taken, therefore project is published as `memoizee` on NPM._
37
+
38
+ To port it to Browser or any other (non CJS) environment, use your favorite CJS bundler. No favorite yet? Try: [Browserify](http://browserify.org/), [Webmake](https://github.com/medikoo/modules-webmake) or [Webpack](http://webpack.github.io/)
39
+
40
+ ### Usage
41
+
42
+ ```javascript
43
+ var memoize = require("memoizee");
44
+
45
+ var fn = function(one, two, three) {
46
+ /* ... */
47
+ };
48
+
49
+ memoized = memoize(fn);
50
+
51
+ memoized("foo", 3, "bar");
52
+ memoized("foo", 3, "bar"); // Cache hit
53
+ ```
54
+
55
+ __Note__: Invocations that throw exceptions are not cached.
56
+
57
+ ### Configuration
58
+
59
+ All below options can be applied in any combination
60
+
61
+ #### Arguments length
62
+
63
+ By default fixed number of arguments that function take is assumed (it's read from function's `length` property) this can be overridden:
64
+
65
+ ```javascript
66
+ memoized = memoize(fn, { length: 2 });
67
+
68
+ memoized("foo"); // Assumed: 'foo', undefined
69
+ memoized("foo", undefined); // Cache hit
70
+
71
+ memoized("foo", 3, {}); // Third argument is ignored (but passed to underlying function)
72
+ memoized("foo", 3, 13); // Cache hit
73
+ ```
74
+
75
+ __Note:__ [Parameters predefined with default values (ES2015+ feature)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Default_parameters) are not reflected in function's `length`, therefore if you want to memoize them as well, you need to tweak `length` setting accordingly
76
+
77
+ Dynamic _length_ behavior can be forced by setting _length_ to `false`, that means memoize will work with any number of arguments.
78
+
79
+ ```javascript
80
+ memoized = memoize(fn, { length: false });
81
+
82
+ memoized("foo");
83
+ memoized("foo"); // Cache hit
84
+ memoized("foo", undefined);
85
+ memoized("foo", undefined); // Cache hit
86
+
87
+ memoized("foo", 3, {});
88
+ memoized("foo", 3, 13);
89
+ memoized("foo", 3, 13); // Cache hit
90
+ ```
91
+
92
+ #### Primitive mode
93
+
94
+ If we work with large result sets, or memoize hot functions, default mode may not perform as fast as we expect. In that case it's good to run memoization in _primitive_ mode. To provide fast access, results are saved in hash instead of an array. Generated hash ids are result of arguments to string conversion. **Mind that this mode will work correctly only if stringified arguments produce unique strings.**
95
+
96
+ ```javascript
97
+ memoized = memoize(fn, { primitive: true });
98
+
99
+ memoized("/path/one");
100
+ memoized("/path/one"); // Cache hit
101
+ ```
102
+
103
+ #### Cache id resolution (normalization)
104
+
105
+ By default cache id for given call is resolved either by:
106
+
107
+ * Direct Comparison of values passed in arguments as they are. In such case two different objects, even if their characteristics is exactly same (e.g. `var a = { foo: 'bar' }, b = { foo: 'bar' }`) will be treated as two different values.
108
+ * Comparison of stringified values of given arguments (`primitive` mode), which serves well, when arguments are expected to be primitive values, or objects that stringify naturally do unique values (e.g. arrays)
109
+
110
+ Still above two methods do not serve all cases, e.g. if we want to memoize function where arguments are hash objects which we do not want to compare by instance but by its content.
111
+
112
+ ##### Writing custom cache id normalizers
113
+
114
+ There's a `normalizer` option through which we can pass custom cache id normalization function
115
+ e.g. if we want to memoize a function where argument is a hash object which we do not want to compare by instance but by its content, then we can achieve it as following:
116
+
117
+ ```javascript
118
+ var mfn = memoize(
119
+ function(hash) {
120
+ // body of memoized function
121
+ },
122
+ {
123
+ normalizer: function(args) {
124
+ // args is arguments object as accessible in memoized function
125
+ return JSON.stringify(args[0]);
126
+ }
127
+ }
128
+ );
129
+
130
+ mfn({ foo: "bar" });
131
+ mfn({ foo: "bar" }); // Cache hit
132
+ ```
133
+
134
+ #### Argument resolvers
135
+
136
+ When we're expecting arguments of certain type it's good to coerce them before doing memoization. We can do that by passing additional resolvers array:
137
+
138
+ ```javascript
139
+ memoized = memoize(fn, { length: 2, resolvers: [String, Boolean] });
140
+
141
+ memoized(12, [1, 2, 3].length);
142
+ memoized("12", true); // Cache hit
143
+ memoized(
144
+ {
145
+ toString: function() {
146
+ return "12";
147
+ }
148
+ },
149
+ {}
150
+ ); // Cache hit
151
+ ```
152
+
153
+ **Note. If your arguments are collections (arrays or hashes) that you want to memoize by content (not by self objects), you need to cast them to strings**, for it's best to just use [primitive mode](#primitive-mode). Arrays have standard string representation and work with primitive mode out of a box, for hashes you need to define `toString` method, that will produce unique string descriptions, or rely on `JSON.stringify`.
154
+
155
+ Similarly **if you want to memoize functions by their code representation not by their objects, you should use primitive mode**.
156
+
157
+ #### Memoizing asynchronous functions
158
+
159
+ ##### Promise returning functions
160
+
161
+ With _promise_ option we indicate that we memoize a function that returns promise.
162
+
163
+ The difference from natural behavior is that in case when promise was rejected with exception,
164
+ the result is immediately removed from memoize cache, and not kept as further reusable result.
165
+
166
+ ```javascript
167
+ var afn = function(a, b) {
168
+ return new Promise(function(res) {
169
+ res(a + b);
170
+ });
171
+ };
172
+ memoized = memoize(afn, { promise: true });
173
+
174
+ memoized(3, 7);
175
+ memoized(3, 7); // Cache hit
176
+ ```
177
+
178
+ ###### Important notice on internal promises handling
179
+
180
+ Default handling stands purely on _then_ which has side-effect of muting eventual unhandled rejection notifications.
181
+ Alternatively we can other (explained below), by stating with `promise` option desired mode:
182
+
183
+ ```javascript
184
+ memoized = memoize(afn, { promise: "done:finally" });
185
+ ```
186
+
187
+ Supported modes
188
+
189
+ * `then` _(default)_. Values are resolved purely by passing callbacks to `promise.then`. **Side effect is that eventual unhandled rejection on given promise
190
+ come with no logged warning!**, and that to avoid implied error swallowing both states are resolved tick after callbacks were invoked
191
+
192
+ * `done` Values are resolved purely by passing callback to `done` method. **Side effect is that eventual unhandled rejection on given promise come with no logged warning!**.
193
+
194
+ * `done:finally` The only method that may work with no side-effects assuming that promise implementaion does not throw unconditionally
195
+ if no _onFailure_ callback was passed to `done`, and promise error was handled by other consumer (this is not commonly implemented _done_ behavior). Otherwise side-effect is that exception is thrown on promise rejection (highly not recommended)
196
+
197
+ ##### Node.js callback style functions
198
+
199
+ With _async_ option we indicate that we memoize asynchronous (Node.js style) function
200
+ Operations that result with an error are not cached.
201
+
202
+ ```javascript
203
+ afn = function(a, b, cb) {
204
+ setTimeout(function() {
205
+ cb(null, a + b);
206
+ }, 200);
207
+ };
208
+ memoized = memoize(afn, { async: true });
209
+
210
+ memoized(3, 7, function(err, res) {
211
+ memoized(3, 7, function(err, res) {
212
+ // Cache hit
213
+ });
214
+ });
215
+
216
+ memoized(3, 7, function(err, res) {
217
+ // Cache hit
218
+ });
219
+ ```
220
+
221
+ #### Memoizing methods
222
+
223
+ When we are defining a prototype, we may want to define a method that will memoize it's results in relation to each instance. A basic way to obtain that would be:
224
+
225
+ ```javascript
226
+ var Foo = function() {
227
+ this.bar = memoize(this.bar.bind(this), { someOption: true });
228
+ // ... constructor logic
229
+ };
230
+ Foo.prototype.bar = function() {
231
+ // ... method logic
232
+ };
233
+ ```
234
+
235
+ There's a lazy methods descriptor generator provided:
236
+
237
+ ```javascript
238
+ var d = require("d");
239
+ var memoizeMethods = require("memoizee/methods");
240
+
241
+ var Foo = function() {
242
+ // ... constructor logic
243
+ };
244
+ Object.defineProperties(
245
+ Foo.prototype,
246
+ memoizeMethods({
247
+ bar: d(
248
+ function() {
249
+ // ... method logic
250
+ },
251
+ { someOption: true }
252
+ )
253
+ })
254
+ );
255
+ ```
256
+
257
+ #### WeakMap based configurations
258
+
259
+ In this case memoization cache is not bound to memoized function (which we may want to keep forever), but to objects for which given results were generated.
260
+
261
+ This mode works only for functions of which first argument is expected to be an object.
262
+ It can be combined with other options mentioned across documentation. However due to WeakMap specificity global clear is not possible.
263
+
264
+ ```javascript
265
+ var memoize = require("memoizee/weak");
266
+
267
+ var memoized = memoize(function(obj) {
268
+ return Object.keys(obj);
269
+ });
270
+
271
+ var obj = { foo: true, bar: false };
272
+ memoized(obj);
273
+ memoized(obj); // Cache hit
274
+ ```
275
+
276
+ #### Cache handling
277
+
278
+ ##### Manual clean up:
279
+
280
+ Delete data for particular call.
281
+
282
+ ```javascript
283
+ memoized.delete("foo", true);
284
+ ```
285
+
286
+ Arguments passed to `delete` are treated with same rules as input arguments passed to function
287
+
288
+ Clear all cached data:
289
+
290
+ ```javascript
291
+ memoized.clear();
292
+ ```
293
+
294
+ ##### Expire cache after given period of time
295
+
296
+ With _maxAge_ option we can ensure that cache for given call is cleared after predefined period of time (in milliseconds)
297
+
298
+ ```javascript
299
+ memoized = memoize(fn, { maxAge: 1000 }); // 1 second
300
+
301
+ memoized("foo", 3);
302
+ memoized("foo", 3); // Cache hit
303
+ setTimeout(function() {
304
+ memoized("foo", 3); // No longer in cache, re-executed
305
+ memoized("foo", 3); // Cache hit
306
+ }, 2000);
307
+ ```
308
+
309
+ Additionally we may ask to _pre-fetch_ in a background a value that is about to expire. _Pre-fetch_ is invoked only if value is accessed close to its expiry date. By default it needs to be within at least 33% of _maxAge_ timespan before expire:
310
+
311
+ ```javascript
312
+ memoized = memoize(fn, { maxAge: 1000, preFetch: true }); // Defaults to 0.33
313
+
314
+ memoized("foo", 3);
315
+ memoized("foo", 3); // Cache hit
316
+
317
+ setTimeout(function() {
318
+ memoized("foo", 3); // Cache hit
319
+ }, 500);
320
+
321
+ setTimeout(function() {
322
+ memoized("foo", 3); // Cache hit, silently pre-fetched in next tick
323
+ }, 800);
324
+
325
+ setTimeout(function() {
326
+ memoized("foo", 3); // Cache hit
327
+ }, 1300);
328
+ ```
329
+
330
+ _Pre-fetch_ timespan can be customized:
331
+
332
+ ```javascript
333
+ memoized = memoize(fn, { maxAge: 1000, preFetch: 0.6 });
334
+
335
+ memoized("foo", 3);
336
+ memoized("foo", 3); // Cache hit
337
+
338
+ setTimeout(function() {
339
+ memoized("foo", 3); // Cache hit, silently pre-fetched in next tick
340
+ }, 500);
341
+
342
+ setTimeout(function() {
343
+ memoized("foo", 3); // Cache hit
344
+ }, 1300);
345
+ ```
346
+
347
+ _Thanks [@puzrin](https://github.com/puzrin) for helpful suggestions concerning this functionality_
348
+
349
+ ##### Reference counter
350
+
351
+ We can track number of references returned from cache, and manually delete them. When the last reference is cleared, the cache is purged automatically:
352
+
353
+ ```javascript
354
+ memoized = memoize(fn, { refCounter: true });
355
+
356
+ memoized("foo", 3); // refs: 1
357
+ memoized("foo", 3); // Cache hit, refs: 2
358
+ memoized("foo", 3); // Cache hit, refs: 3
359
+ memoized.deleteRef("foo", 3); // refs: 2
360
+ memoized.deleteRef("foo", 3); // refs: 1
361
+ memoized.deleteRef("foo", 3); // refs: 0, Cache purged for 'foo', 3
362
+ memoized("foo", 3); // Re-executed, refs: 1
363
+ ```
364
+
365
+ ##### Limiting cache size
366
+
367
+ With _max_ option you can limit cache size, it's backed with [LRU algorithm](http://en.wikipedia.org/wiki/Cache_algorithms#Least_Recently_Used), provided by low-level [lru-queue](https://github.com/medikoo/lru-queue) utility.
368
+
369
+ The _size_ relates purely to count of results we want to keep in cache, it doesn't relate to memory cost associated with cache value (but such feature is likely to be introduced with next version of memoizee).
370
+
371
+ ```javascript
372
+ memoized = memoize(fn, { max: 2 });
373
+
374
+ memoized("foo", 3);
375
+ memoized("bar", 7);
376
+ memoized("foo", 3); // Cache hit
377
+ memoized("bar", 7); // Cache hit
378
+ memoized("lorem", 11); // Cache cleared for 'foo', 3
379
+ memoized("bar", 7); // Cache hit
380
+ memoized("foo", 3); // Re-executed, Cache cleared for 'lorem', 11
381
+ memoized("lorem", 11); // Re-executed, Cache cleared for 'bar', 7
382
+ memoized("foo", 3); // Cache hit
383
+ memoized("bar", 7); // Re-executed, Cache cleared for 'lorem', 11
384
+ ```
385
+
386
+ ##### Registering dispose callback
387
+
388
+ You can register a callback to be called on each value removed from the cache:
389
+
390
+ ```javascript
391
+ memoized = memoize(fn, {
392
+ dispose: function(value) {
393
+ /*…*/
394
+ }
395
+ });
396
+
397
+ var foo3 = memoized("foo", 3);
398
+ var bar7 = memoized("bar", 7);
399
+ memoized.clear("foo", 3); // Dispose called with foo3 value
400
+ memoized.clear("bar", 7); // Dispose called with bar7 value
401
+ ```
402
+
403
+ ### Benchmarks
404
+
405
+ Simple benchmark tests can be found in _benchmark_ folder. Currently it's just plain simple calculation of fibonacci sequences. To run it you need to install other test candidates:
406
+
407
+ $ npm install underscore lodash lru-cache secondary-cache
408
+
409
+ Example output taken under Node v0.10.35 on 2011 MBP Pro:
410
+
411
+ ```
412
+ Fibonacci 3000 x10:
413
+
414
+ 1: 15ms Memoizee (primitive mode)
415
+ 2: 15ms Underscore
416
+ 3: 18ms lru-cache LRU (max: 1000)
417
+ 4: 21ms secondary-cache LRU (max: 1000)
418
+ 5: 37ms Lo-dash
419
+ 6: 62ms Memoizee (primitive mode) LRU (max: 1000)
420
+ 7: 163ms Memoizee (object mode) LRU (max: 1000)
421
+ 8: 195ms Memoizee (object mode)
422
+ ```
423
+
424
+ ### Profiling & Statistics
425
+
426
+ If you want to make sure how much you benefit from memoization or just check if memoization works as expected, loading profile module will give access to all valuable information.
427
+
428
+ **Module needs to be imported before any memoization (that we want to track) is configured. Mind also that running profile module affects performance, it's best not to use it in production environment**
429
+
430
+ ```javascript
431
+ var memProfile = require('memoizee/profile');
432
+ ...
433
+ ...
434
+ memoize(fn);
435
+ ...
436
+ memoize(fn, { profileName: 'Some Function' })
437
+ ...
438
+ memoize(fn, { profileName: 'Another Function' })
439
+ ```
440
+
441
+ Access statistics at any time:
442
+
443
+ ```javascript
444
+ memProfile.statistics; // Statistics accessible for programmatic use
445
+ console.log(memProfile.log()); // Output statistics data in readable form
446
+ ```
447
+
448
+ Example console output:
449
+
450
+ ```
451
+ ------------------------------------------------------------
452
+ Memoize statistics:
453
+
454
+ Init Cache %Cache Source location
455
+ 11604 35682 75.46 (all)
456
+ 2112 19901 90.41 Some Function, at /Users/medikoo/Projects/_packages/next/lib/fs/is-ignored.js:276:12
457
+ 2108 9087 81.17 Another Function, at /Users/medikoo/Projects/_packages/next/lib/fs/is-ignored.js:293:10
458
+ 6687 2772 29.31 at /Users/medikoo/Projects/_packages/next/lib/fs/watch.js:125:9
459
+ 697 3922 84.91 at /Users/medikoo/Projects/_packages/next/lib/fs/is-ignored.js:277:15
460
+ ------------------------------------------------------------
461
+ ```
462
+
463
+ * _Init_ – Initial hits
464
+ * _Cache_ – Cache hits
465
+ * _%Cache_ – What's the percentage of cache hits (of all function calls)
466
+ * _Source location_ – Where in the source code given memoization was initialized
467
+
468
+ ### Tests
469
+
470
+ $ npm test
471
+
472
+ Project cross-browser compatibility to be supported by:
473
+
474
+ <a href="https://browserstack.com"><img src="https://bstacksupport.zendesk.com/attachments/token/Pj5uf2x5GU9BvWErqAr51Jh2R/?name=browserstack-logo-600x315.png" height="150" /></a>
475
+
476
+ ## Security contact information
477
+
478
+ To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure.
479
+
480
+ ---
481
+
482
+ <div align="center">
483
+ <b>
484
+ <a href="https://tidelift.com/subscription/pkg/npm-memoizee?utm_source=npm-memoizee&utm_medium=referral&utm_campaign=readme">Get professional support for d with a Tidelift subscription</a>
485
+ </b>
486
+ <br>
487
+ <sub>
488
+ Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
489
+ </sub>
490
+ </div>
491
+
492
+ ### Contributors
493
+
494
+ * [@puzrin](https://github.com/puzrin) (Vitaly Puzrin)
495
+ * Proposal and help with coining right _pre-fetch_ logic for [_maxAge_](https://github.com/medikoo/memoize#expire-cache-after-given-period-of-time) variant
496
+
497
+ [nix-build-image]: https://semaphoreci.com/api/v1/medikoo-org/memoizee/branches/master/shields_badge.svg
498
+ [nix-build-url]: https://semaphoreci.com/medikoo-org/memoizee
499
+ [win-build-image]: https://ci.appveyor.com/api/projects/status/hsxubnbwe89c26bu?svg=true
500
+ [win-build-url]: https://ci.appveyor.com/project/medikoo/memoizee
501
+ [transpilation-image]: https://img.shields.io/badge/transpilation-free-brightgreen.svg
502
+ [npm-image]: https://img.shields.io/npm/v/memoizee.svg
503
+ [npm-url]: https://www.npmjs.com/package/memoizee