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,154 @@
1
+ /* eslint consistent-this: 0, no-shadow:0, no-eq-null: 0, eqeqeq: 0, no-unused-vars: 0 */
2
+
3
+ // Support for asynchronous functions
4
+
5
+ "use strict";
6
+
7
+ var aFrom = require("es5-ext/array/from")
8
+ , objectMap = require("es5-ext/object/map")
9
+ , mixin = require("es5-ext/object/mixin")
10
+ , defineLength = require("es5-ext/function/_define-length")
11
+ , nextTick = require("next-tick");
12
+
13
+ var slice = Array.prototype.slice, apply = Function.prototype.apply, create = Object.create;
14
+
15
+ require("../lib/registered-extensions").async = function (tbi, conf) {
16
+ var waiting = create(null)
17
+ , cache = create(null)
18
+ , base = conf.memoized
19
+ , original = conf.original
20
+ , currentCallback
21
+ , currentContext
22
+ , currentArgs;
23
+
24
+ // Initial
25
+ conf.memoized = defineLength(function (arg) {
26
+ var args = arguments, last = args[args.length - 1];
27
+ if (typeof last === "function") {
28
+ currentCallback = last;
29
+ args = slice.call(args, 0, -1);
30
+ }
31
+ return base.apply(currentContext = this, currentArgs = args);
32
+ }, base);
33
+ try { mixin(conf.memoized, base); }
34
+ catch (ignore) {}
35
+
36
+ // From cache (sync)
37
+ conf.on("get", function (id) {
38
+ var cb, context, args;
39
+ if (!currentCallback) return;
40
+
41
+ // Unresolved
42
+ if (waiting[id]) {
43
+ if (typeof waiting[id] === "function") waiting[id] = [waiting[id], currentCallback];
44
+ else waiting[id].push(currentCallback);
45
+ currentCallback = null;
46
+ return;
47
+ }
48
+
49
+ // Resolved, assure next tick invocation
50
+ cb = currentCallback;
51
+ context = currentContext;
52
+ args = currentArgs;
53
+ currentCallback = currentContext = currentArgs = null;
54
+ nextTick(function () {
55
+ var data;
56
+ if (hasOwnProperty.call(cache, id)) {
57
+ data = cache[id];
58
+ conf.emit("getasync", id, args, context);
59
+ apply.call(cb, data.context, data.args);
60
+ } else {
61
+ // Purged in a meantime, we shouldn't rely on cached value, recall
62
+ currentCallback = cb;
63
+ currentContext = context;
64
+ currentArgs = args;
65
+ base.apply(context, args);
66
+ }
67
+ });
68
+ });
69
+
70
+ // Not from cache
71
+ conf.original = function () {
72
+ var args, cb, origCb, result;
73
+ if (!currentCallback) return apply.call(original, this, arguments);
74
+ args = aFrom(arguments);
75
+ cb = function self(err) {
76
+ var cb, args, id = self.id;
77
+ if (id == null) {
78
+ // Shouldn't happen, means async callback was called sync way
79
+ nextTick(apply.bind(self, this, arguments));
80
+ return undefined;
81
+ }
82
+ delete self.id;
83
+ cb = waiting[id];
84
+ delete waiting[id];
85
+ if (!cb) {
86
+ // Already processed,
87
+ // outcome of race condition: asyncFn(1, cb), asyncFn.clear(), asyncFn(1, cb)
88
+ return undefined;
89
+ }
90
+ args = aFrom(arguments);
91
+ if (conf.has(id)) {
92
+ if (err) {
93
+ conf.delete(id);
94
+ } else {
95
+ cache[id] = { context: this, args: args };
96
+ conf.emit("setasync", id, typeof cb === "function" ? 1 : cb.length);
97
+ }
98
+ }
99
+ if (typeof cb === "function") {
100
+ result = apply.call(cb, this, args);
101
+ } else {
102
+ cb.forEach(function (cb) { result = apply.call(cb, this, args); }, this);
103
+ }
104
+ return result;
105
+ };
106
+ origCb = currentCallback;
107
+ currentCallback = currentContext = currentArgs = null;
108
+ args.push(cb);
109
+ result = apply.call(original, this, args);
110
+ cb.cb = origCb;
111
+ currentCallback = cb;
112
+ return result;
113
+ };
114
+
115
+ // After not from cache call
116
+ conf.on("set", function (id) {
117
+ if (!currentCallback) {
118
+ conf.delete(id);
119
+ return;
120
+ }
121
+ if (waiting[id]) {
122
+ // Race condition: asyncFn(1, cb), asyncFn.clear(), asyncFn(1, cb)
123
+ if (typeof waiting[id] === "function") waiting[id] = [waiting[id], currentCallback.cb];
124
+ else waiting[id].push(currentCallback.cb);
125
+ } else {
126
+ waiting[id] = currentCallback.cb;
127
+ }
128
+ delete currentCallback.cb;
129
+ currentCallback.id = id;
130
+ currentCallback = null;
131
+ });
132
+
133
+ // On delete
134
+ conf.on("delete", function (id) {
135
+ var result;
136
+ // If false, we don't have value yet, so we assume that intention is not
137
+ // to memoize this call. After value is obtained we don't cache it but
138
+ // gracefully pass to callback
139
+ if (hasOwnProperty.call(waiting, id)) return;
140
+ if (!cache[id]) return;
141
+ result = cache[id];
142
+ delete cache[id];
143
+ conf.emit("deleteasync", id, slice.call(result.args, 1));
144
+ });
145
+
146
+ // On clear
147
+ conf.on("clear", function () {
148
+ var oldCache = cache;
149
+ cache = create(null);
150
+ conf.emit(
151
+ "clearasync", objectMap(oldCache, function (data) { return slice.call(data.args, 1); })
152
+ );
153
+ });
154
+ };
@@ -0,0 +1,33 @@
1
+ // Call dispose callback on each cache purge
2
+
3
+ "use strict";
4
+
5
+ var callable = require("es5-ext/object/valid-callable")
6
+ , forEach = require("es5-ext/object/for-each")
7
+ , extensions = require("../lib/registered-extensions")
8
+
9
+ , apply = Function.prototype.apply;
10
+
11
+ extensions.dispose = function (dispose, conf, options) {
12
+ var del;
13
+ callable(dispose);
14
+ if ((options.async && extensions.async) || (options.promise && extensions.promise)) {
15
+ conf.on("deleteasync", del = function (id, resultArray) {
16
+ apply.call(dispose, null, resultArray);
17
+ });
18
+ conf.on("clearasync", function (cache) {
19
+ forEach(cache, function (result, id) {
20
+ del(id, result);
21
+ });
22
+ });
23
+ return;
24
+ }
25
+ conf.on("delete", del = function (id, result) {
26
+ dispose(result);
27
+ });
28
+ conf.on("clear", function (cache) {
29
+ forEach(cache, function (result, id) {
30
+ del(id, result);
31
+ });
32
+ });
33
+ };
@@ -0,0 +1,90 @@
1
+ /* eslint consistent-this: 0 */
2
+
3
+ // Timeout cached values
4
+
5
+ "use strict";
6
+
7
+ var aFrom = require("es5-ext/array/from")
8
+ , forEach = require("es5-ext/object/for-each")
9
+ , nextTick = require("next-tick")
10
+ , isPromise = require("is-promise")
11
+ , timeout = require("timers-ext/valid-timeout")
12
+ , extensions = require("../lib/registered-extensions");
13
+
14
+ var noop = Function.prototype, max = Math.max, min = Math.min, create = Object.create;
15
+
16
+ extensions.maxAge = function (maxAge, conf, options) {
17
+ var timeouts, postfix, preFetchAge, preFetchTimeouts;
18
+
19
+ maxAge = timeout(maxAge);
20
+ if (!maxAge) return;
21
+
22
+ timeouts = create(null);
23
+ postfix =
24
+ (options.async && extensions.async) || (options.promise && extensions.promise)
25
+ ? "async"
26
+ : "";
27
+ conf.on("set" + postfix, function (id) {
28
+ timeouts[id] = setTimeout(function () { conf.delete(id); }, maxAge);
29
+ if (typeof timeouts[id].unref === "function") timeouts[id].unref();
30
+ if (!preFetchTimeouts) return;
31
+ if (preFetchTimeouts[id]) {
32
+ if (preFetchTimeouts[id] !== "nextTick") clearTimeout(preFetchTimeouts[id]);
33
+ }
34
+ preFetchTimeouts[id] = setTimeout(function () {
35
+ delete preFetchTimeouts[id];
36
+ }, preFetchAge);
37
+ if (typeof preFetchTimeouts[id].unref === "function") preFetchTimeouts[id].unref();
38
+ });
39
+ conf.on("delete" + postfix, function (id) {
40
+ clearTimeout(timeouts[id]);
41
+ delete timeouts[id];
42
+ if (!preFetchTimeouts) return;
43
+ if (preFetchTimeouts[id] !== "nextTick") clearTimeout(preFetchTimeouts[id]);
44
+ delete preFetchTimeouts[id];
45
+ });
46
+
47
+ if (options.preFetch) {
48
+ if (options.preFetch === true || isNaN(options.preFetch)) {
49
+ preFetchAge = 0.333;
50
+ } else {
51
+ preFetchAge = max(min(Number(options.preFetch), 1), 0);
52
+ }
53
+ if (preFetchAge) {
54
+ preFetchTimeouts = {};
55
+ preFetchAge = (1 - preFetchAge) * maxAge;
56
+ conf.on("get" + postfix, function (id, args, context) {
57
+ if (!preFetchTimeouts[id]) {
58
+ preFetchTimeouts[id] = "nextTick";
59
+ nextTick(function () {
60
+ var result;
61
+ if (preFetchTimeouts[id] !== "nextTick") return;
62
+ delete preFetchTimeouts[id];
63
+ conf.delete(id);
64
+ if (options.async) {
65
+ args = aFrom(args);
66
+ args.push(noop);
67
+ }
68
+ result = conf.memoized.apply(context, args);
69
+ if (options.promise) {
70
+ // Supress eventual error warnings
71
+ if (isPromise(result)) {
72
+ if (typeof result.done === "function") result.done(noop, noop);
73
+ else result.then(noop, noop);
74
+ }
75
+ }
76
+ });
77
+ }
78
+ });
79
+ }
80
+ }
81
+
82
+ conf.on("clear" + postfix, function () {
83
+ forEach(timeouts, function (id) { clearTimeout(id); });
84
+ timeouts = {};
85
+ if (preFetchTimeouts) {
86
+ forEach(preFetchTimeouts, function (id) { if (id !== "nextTick") clearTimeout(id); });
87
+ preFetchTimeouts = {};
88
+ }
89
+ });
90
+ };
@@ -0,0 +1,27 @@
1
+ // Limit cache size, LRU (least recently used) algorithm.
2
+
3
+ "use strict";
4
+
5
+ var toPosInteger = require("es5-ext/number/to-pos-integer")
6
+ , lruQueue = require("lru-queue")
7
+ , extensions = require("../lib/registered-extensions");
8
+
9
+ extensions.max = function (max, conf, options) {
10
+ var postfix, queue, hit;
11
+
12
+ max = toPosInteger(max);
13
+ if (!max) return;
14
+
15
+ queue = lruQueue(max);
16
+ postfix = (options.async && extensions.async) || (options.promise && extensions.promise)
17
+ ? "async" : "";
18
+
19
+ conf.on("set" + postfix, hit = function (id) {
20
+ id = queue.hit(id);
21
+ if (id === undefined) return;
22
+ conf.delete(id);
23
+ });
24
+ conf.on("get" + postfix, hit);
25
+ conf.on("delete" + postfix, queue.delete);
26
+ conf.on("clear" + postfix, queue.clear);
27
+ };
@@ -0,0 +1,147 @@
1
+ /* eslint max-statements: 0 */
2
+
3
+ // Support for functions returning promise
4
+
5
+ "use strict";
6
+
7
+ var objectMap = require("es5-ext/object/map")
8
+ , primitiveSet = require("es5-ext/object/primitive-set")
9
+ , ensureString = require("es5-ext/object/validate-stringifiable-value")
10
+ , toShortString = require("es5-ext/to-short-string-representation")
11
+ , isPromise = require("is-promise")
12
+ , nextTick = require("next-tick");
13
+
14
+ var create = Object.create
15
+ , supportedModes = primitiveSet("then", "then:finally", "done", "done:finally");
16
+
17
+ require("../lib/registered-extensions").promise = function (mode, conf) {
18
+ var waiting = create(null), cache = create(null), promises = create(null);
19
+
20
+ if (mode === true) {
21
+ mode = null;
22
+ } else {
23
+ mode = ensureString(mode);
24
+ if (!supportedModes[mode]) {
25
+ throw new TypeError("'" + toShortString(mode) + "' is not valid promise mode");
26
+ }
27
+ }
28
+
29
+ // After not from cache call
30
+ conf.on("set", function (id, ignore, promise) {
31
+ var isFailed = false;
32
+
33
+ if (!isPromise(promise)) {
34
+ // Non promise result
35
+ cache[id] = promise;
36
+ conf.emit("setasync", id, 1);
37
+ return;
38
+ }
39
+ waiting[id] = 1;
40
+ promises[id] = promise;
41
+ var onSuccess = function (result) {
42
+ var count = waiting[id];
43
+ if (isFailed) {
44
+ throw new Error(
45
+ "Memoizee error: Detected unordered then|done & finally resolution, which " +
46
+ "in turn makes proper detection of success/failure impossible (when in " +
47
+ "'done:finally' mode)\n" +
48
+ "Consider to rely on 'then' or 'done' mode instead."
49
+ );
50
+ }
51
+ if (!count) return; // Deleted from cache before resolved
52
+ delete waiting[id];
53
+ cache[id] = result;
54
+ conf.emit("setasync", id, count);
55
+ };
56
+ var onFailure = function () {
57
+ isFailed = true;
58
+ if (!waiting[id]) return; // Deleted from cache (or succeed in case of finally)
59
+ delete waiting[id];
60
+ delete promises[id];
61
+ conf.delete(id);
62
+ };
63
+
64
+ var resolvedMode = mode;
65
+ if (!resolvedMode) resolvedMode = "then";
66
+
67
+ if (resolvedMode === "then") {
68
+ var nextTickFailure = function () { nextTick(onFailure); };
69
+ // Eventual finally needs to be attached to non rejected promise
70
+ // (so we not force propagation of unhandled rejection)
71
+ promise = promise.then(function (result) {
72
+ nextTick(onSuccess.bind(this, result));
73
+ }, nextTickFailure);
74
+ // If `finally` is a function we attach to it to remove cancelled promises.
75
+ if (typeof promise.finally === "function") {
76
+ promise.finally(nextTickFailure);
77
+ }
78
+ } else if (resolvedMode === "done") {
79
+ // Not recommended, as it may mute any eventual "Unhandled error" events
80
+ if (typeof promise.done !== "function") {
81
+ throw new Error(
82
+ "Memoizee error: Retrieved promise does not implement 'done' " +
83
+ "in 'done' mode"
84
+ );
85
+ }
86
+ promise.done(onSuccess, onFailure);
87
+ } else if (resolvedMode === "done:finally") {
88
+ // The only mode with no side effects assuming library does not throw unconditionally
89
+ // for rejected promises.
90
+ if (typeof promise.done !== "function") {
91
+ throw new Error(
92
+ "Memoizee error: Retrieved promise does not implement 'done' " +
93
+ "in 'done:finally' mode"
94
+ );
95
+ }
96
+ if (typeof promise.finally !== "function") {
97
+ throw new Error(
98
+ "Memoizee error: Retrieved promise does not implement 'finally' " +
99
+ "in 'done:finally' mode"
100
+ );
101
+ }
102
+ promise.done(onSuccess);
103
+ promise.finally(onFailure);
104
+ }
105
+ });
106
+
107
+ // From cache (sync)
108
+ conf.on("get", function (id, args, context) {
109
+ var promise;
110
+ if (waiting[id]) {
111
+ ++waiting[id]; // Still waiting
112
+ return;
113
+ }
114
+ promise = promises[id];
115
+ var emit = function () { conf.emit("getasync", id, args, context); };
116
+ if (isPromise(promise)) {
117
+ if (typeof promise.done === "function") promise.done(emit);
118
+ else {
119
+ promise.then(function () { nextTick(emit); });
120
+ }
121
+ } else {
122
+ emit();
123
+ }
124
+ });
125
+
126
+ // On delete
127
+ conf.on("delete", function (id) {
128
+ delete promises[id];
129
+ if (waiting[id]) {
130
+ delete waiting[id];
131
+ return; // Not yet resolved
132
+ }
133
+ if (!hasOwnProperty.call(cache, id)) return;
134
+ var result = cache[id];
135
+ delete cache[id];
136
+ conf.emit("deleteasync", id, [result]);
137
+ });
138
+
139
+ // On clear
140
+ conf.on("clear", function () {
141
+ var oldCache = cache;
142
+ cache = create(null);
143
+ waiting = create(null);
144
+ promises = create(null);
145
+ conf.emit("clearasync", objectMap(oldCache, function (data) { return [data]; }));
146
+ });
147
+ };
@@ -0,0 +1,48 @@
1
+ // Reference counter, useful for garbage collector like functionality
2
+
3
+ "use strict";
4
+
5
+ var d = require("d")
6
+ , extensions = require("../lib/registered-extensions")
7
+
8
+ , create = Object.create, defineProperties = Object.defineProperties;
9
+
10
+ extensions.refCounter = function (ignore, conf, options) {
11
+ var cache, postfix;
12
+
13
+ cache = create(null);
14
+ postfix = (options.async && extensions.async) || (options.promise && extensions.promise)
15
+ ? "async" : "";
16
+
17
+ conf.on("set" + postfix, function (id, length) {
18
+ cache[id] = length || 1;
19
+ });
20
+ conf.on("get" + postfix, function (id) {
21
+ ++cache[id];
22
+ });
23
+ conf.on("delete" + postfix, function (id) {
24
+ delete cache[id];
25
+ });
26
+ conf.on("clear" + postfix, function () {
27
+ cache = {};
28
+ });
29
+
30
+ defineProperties(conf.memoized, {
31
+ deleteRef: d(function () {
32
+ var id = conf.get(arguments);
33
+ if (id === null) return null;
34
+ if (!cache[id]) return null;
35
+ if (!--cache[id]) {
36
+ conf.delete(id);
37
+ return true;
38
+ }
39
+ return false;
40
+ }),
41
+ getRefCount: d(function () {
42
+ var id = conf.get(arguments);
43
+ if (id === null) return 0;
44
+ if (!cache[id]) return 0;
45
+ return cache[id];
46
+ })
47
+ });
48
+ };
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+
3
+ var normalizeOpts = require("es5-ext/object/normalize-options")
4
+ , resolveLength = require("./lib/resolve-length")
5
+ , plain = require("./plain");
6
+
7
+ module.exports = function (fn/*, options*/) {
8
+ var options = normalizeOpts(arguments[1]), length;
9
+
10
+ if (!options.normalizer) {
11
+ length = options.length = resolveLength(options.length, fn.length, options.async);
12
+ if (length !== 0) {
13
+ if (options.primitive) {
14
+ if (length === false) {
15
+ options.normalizer = require("./normalizers/primitive");
16
+ } else if (length > 1) {
17
+ options.normalizer = require("./normalizers/get-primitive-fixed")(length);
18
+ }
19
+ } else if (length === false) options.normalizer = require("./normalizers/get")();
20
+ else if (length === 1) options.normalizer = require("./normalizers/get-1")();
21
+ else options.normalizer = require("./normalizers/get-fixed")(length);
22
+ }
23
+ }
24
+
25
+ // Assure extensions
26
+ if (options.async) require("./ext/async");
27
+ if (options.promise) require("./ext/promise");
28
+ if (options.dispose) require("./ext/dispose");
29
+ if (options.maxAge) require("./ext/max-age");
30
+ if (options.max) require("./ext/max");
31
+ if (options.refCounter) require("./ext/ref-counter");
32
+
33
+ return plain(fn, options);
34
+ };