hexo-adsense 1.1.1 → 2.0.2
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.
- package/CHANGELOG.md +0 -0
- package/LICENSE +0 -0
- package/dist/index.cjs +12799 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.js +12782 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +12782 -0
- package/dist/index.mjs.map +1 -0
- package/dist/source/adblock.css +2 -0
- package/dist/source/adblock.js +1 -0
- package/{lib → dist}/source/article-ads.css +0 -0
- package/dist/source/article-ads.js +1 -0
- package/dist/source/article-ads.old.js +1 -0
- package/{lib → dist}/source/blogger-redirect.html +0 -0
- package/dist/source/https.js +1 -0
- package/{lib → dist}/source/in_article_ads_test.html +0 -0
- package/package.json +122 -38
- package/{README.md → readme.md} +27 -8
- package/gulpfile.ts +0 -100
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -91
- package/lib/packages/hexo-cli-extras/lib/env.d.ts +0 -3
- package/lib/packages/hexo-cli-extras/lib/env.js +0 -49
- package/lib/packages/hexo-extend-injector2/index.d.ts +0 -2
- package/lib/packages/hexo-extend-injector2/index.js +0 -12
- package/lib/packages/hexo-extend-injector2/lib/bundle/css-bundle.d.ts +0 -2
- package/lib/packages/hexo-extend-injector2/lib/bundle/css-bundle.js +0 -64
- package/lib/packages/hexo-extend-injector2/lib/bundle/css-generator.d.ts +0 -2
- package/lib/packages/hexo-extend-injector2/lib/bundle/css-generator.js +0 -12
- package/lib/packages/hexo-extend-injector2/lib/bundle/handle-data-pre.d.ts +0 -2
- package/lib/packages/hexo-extend-injector2/lib/bundle/handle-data-pre.js +0 -28
- package/lib/packages/hexo-extend-injector2/lib/bundle/js-bundle.d.ts +0 -2
- package/lib/packages/hexo-extend-injector2/lib/bundle/js-bundle.js +0 -32
- package/lib/packages/hexo-extend-injector2/lib/bundle/js-generator.d.ts +0 -2
- package/lib/packages/hexo-extend-injector2/lib/bundle/js-generator.js +0 -8
- package/lib/packages/hexo-extend-injector2/lib/default-config.d.ts +0 -39
- package/lib/packages/hexo-extend-injector2/lib/default-config.js +0 -46
- package/lib/packages/hexo-extend-injector2/lib/filter.d.ts +0 -2
- package/lib/packages/hexo-extend-injector2/lib/filter.js +0 -22
- package/lib/packages/hexo-extend-injector2/lib/helper/injector.d.ts +0 -2
- package/lib/packages/hexo-extend-injector2/lib/helper/injector.js +0 -5
- package/lib/packages/hexo-extend-injector2/lib/helper/next-inject.d.ts +0 -2
- package/lib/packages/hexo-extend-injector2/lib/helper/next-inject.js +0 -12
- package/lib/packages/hexo-extend-injector2/lib/injector.d.ts +0 -29
- package/lib/packages/hexo-extend-injector2/lib/injector.js +0 -125
- package/lib/packages/hexo-extend-injector2/lib/load.d.ts +0 -3
- package/lib/packages/hexo-extend-injector2/lib/load.js +0 -37
- package/lib/packages/hexo-extend-injector2/lib/next-point.d.ts +0 -2
- package/lib/packages/hexo-extend-injector2/lib/next-point.js +0 -18
- package/lib/packages/hexo-extend-injector2/lib/next.d.ts +0 -2
- package/lib/packages/hexo-extend-injector2/lib/next.js +0 -99
- package/lib/packages/hexo-extend-injector2/lib/order.d.ts +0 -5
- package/lib/packages/hexo-extend-injector2/lib/order.js +0 -8
- package/lib/source/adblock.css +0 -2
- package/lib/source/adblock.js +0 -1
- package/lib/source/article-ads.js +0 -1
- package/lib/source/article-ads.old.js +0 -1
- package/lib/source/https.js +0 -1
- package/lib/src/article-ads.d.ts +0 -20
- package/lib/src/article-ads.js +0 -310
- package/lib/src/checkLocalHost.d.ts +0 -10
- package/lib/src/checkLocalHost.js +0 -37
- package/lib/src/config.d.ts +0 -14
- package/lib/src/config.js +0 -50
- package/lib/src/html-parser.d.ts +0 -8
- package/lib/src/html-parser.js +0 -26
- package/lib/src/log.d.ts +0 -1
- package/lib/src/log.js +0 -11
- package/lib/src/logger.d.ts +0 -3
- package/lib/src/logger.js +0 -25
- package/lib/src/md5.d.ts +0 -7
- package/lib/src/md5.js +0 -30
- package/lib/src/safestringify.d.ts +0 -2
- package/lib/src/safestringify.js +0 -125
- package/lib/src/utils.d.ts +0 -31
- package/lib/src/utils.js +0 -160
- package/lib/src/versionParser.d.ts +0 -27
- package/lib/src/versionParser.js +0 -40
- package/packages/@types/.gitmodules +0 -8
- package/packages/@types/LICENSE +0 -21
- package/packages/@types/README.md +0 -27
- package/packages/@types/hexo/HexoConfig.d.ts +0 -216
- package/packages/@types/hexo/LICENSE +0 -21
- package/packages/@types/hexo/README.md +0 -16
- package/packages/@types/hexo/index.d.ts +0 -849
- package/packages/@types/hexo/package.json +0 -34
- package/packages/@types/hexo-bunyan/LICENSE +0 -21
- package/packages/@types/hexo-bunyan/README.md +0 -16
- package/packages/@types/hexo-bunyan/index.d.ts +0 -9
- package/packages/@types/hexo-bunyan/package.json +0 -24
- package/packages/@types/hexo-log/LICENSE +0 -21
- package/packages/@types/hexo-log/README.md +0 -16
- package/packages/@types/hexo-log/index.d.ts +0 -159
- package/packages/@types/hexo-log/package.json +0 -28
- package/packages/@types/index.js +0 -2
- package/packages/@types/package.json +0 -30
- package/packages/@types/test/package.json +0 -15
- package/packages/@types/test/through2.ts +0 -6
- package/packages/@types/tsconfig.json +0 -14
- package/packages/@types/typings/index.d.ts +0 -7
- package/packages/@types/typings/kill-port.d.ts +0 -3
- package/packages/@types/typings/markdown-it-abbr.d.ts +0 -4
- package/packages/@types/typings/markdown-it-footnote.d.ts +0 -4
- package/packages/@types/typings/markdown-it-image-figures.d.ts +0 -4
- package/packages/@types/typings/markdown-it-mark.d.ts +0 -4
- package/packages/@types/typings/markdown-it-sub.d.ts +0 -7
- package/packages/@types/typings/markdown-it-sup.d.ts +0 -7
- package/packages/hexo-cli-extras/.eslintrc +0 -13
- package/packages/hexo-cli-extras/LICENSE.md +0 -20
- package/packages/hexo-cli-extras/README.md +0 -146
- package/packages/hexo-cli-extras/docs/basic.gif +0 -0
- package/packages/hexo-cli-extras/docs/gui.gif +0 -0
- package/packages/hexo-cli-extras/docs/remove.png +0 -0
- package/packages/hexo-cli-extras/docs/rename.png +0 -0
- package/packages/hexo-cli-extras/index.js +0 -48
- package/packages/hexo-cli-extras/lib/edit.js +0 -209
- package/packages/hexo-cli-extras/lib/env.js +0 -52
- package/packages/hexo-cli-extras/lib/extensions.js +0 -23
- package/packages/hexo-cli-extras/lib/integrate.js +0 -87
- package/packages/hexo-cli-extras/lib/isolate.js +0 -179
- package/packages/hexo-cli-extras/lib/remove.js +0 -145
- package/packages/hexo-cli-extras/lib/rename.js +0 -171
- package/packages/hexo-cli-extras/package.json +0 -34
- package/packages/hexo-extend-injector2/.eslintrc +0 -4
- package/packages/hexo-extend-injector2/.github/workflows/linter.yml +0 -27
- package/packages/hexo-extend-injector2/.github/workflows/tester.yml +0 -24
- package/packages/hexo-extend-injector2/.vscode/settings.json +0 -10
- package/packages/hexo-extend-injector2/LICENSE +0 -165
- package/packages/hexo-extend-injector2/README-ZH.md +0 -189
- package/packages/hexo-extend-injector2/README.md +0 -191
- package/packages/hexo-extend-injector2/USAGE.md +0 -38
- package/packages/hexo-extend-injector2/index.js +0 -14
- package/packages/hexo-extend-injector2/lib/bundle/css-bundle.js +0 -79
- package/packages/hexo-extend-injector2/lib/bundle/css-generator.js +0 -13
- package/packages/hexo-extend-injector2/lib/bundle/handle-data-pre.js +0 -29
- package/packages/hexo-extend-injector2/lib/bundle/js-bundle.js +0 -42
- package/packages/hexo-extend-injector2/lib/bundle/js-generator.js +0 -10
- package/packages/hexo-extend-injector2/lib/default-config.js +0 -52
- package/packages/hexo-extend-injector2/lib/filter.js +0 -24
- package/packages/hexo-extend-injector2/lib/helper/injector.js +0 -6
- package/packages/hexo-extend-injector2/lib/helper/next-inject.js +0 -14
- package/packages/hexo-extend-injector2/lib/injector.js +0 -128
- package/packages/hexo-extend-injector2/lib/load.js +0 -45
- package/packages/hexo-extend-injector2/lib/next-point.js +0 -19
- package/packages/hexo-extend-injector2/lib/next.js +0 -87
- package/packages/hexo-extend-injector2/lib/order.js +0 -9
- package/packages/hexo-extend-injector2/package.json +0 -49
- package/packages/hexo-extend-injector2/renovate.json +0 -6
- package/packages/hexo-extend-injector2/test/.eslintrc +0 -3
- package/packages/hexo-extend-injector2/test/index.js +0 -18
- package/packages/hexo-extend-injector2/test/lib/bundle/bundle-css.js +0 -86
- package/packages/hexo-extend-injector2/test/lib/bundle/bundle-js.js +0 -36
- package/packages/hexo-extend-injector2/test/lib/bundle/test.css +0 -3
- package/packages/hexo-extend-injector2/test/lib/bundle/test.js +0 -5
- package/packages/hexo-extend-injector2/test/lib/helper/injector.js +0 -45
- package/packages/hexo-extend-injector2/test/lib/helper/next-inject.js +0 -69
- package/packages/hexo-extend-injector2/test/lib/hexo-compatible.js +0 -250
- package/packages/hexo-extend-injector2/test/lib/hexo-injector.js +0 -37
- package/packages/hexo-extend-injector2/test/lib/injector.js +0 -93
- package/packages/memoize/CHANGELOG.md +0 -82
- package/packages/memoize/CHANGES +0 -124
- package/packages/memoize/LICENSE +0 -15
- package/packages/memoize/README.md +0 -503
- package/packages/memoize/ext/async.js +0 -154
- package/packages/memoize/ext/dispose.js +0 -33
- package/packages/memoize/ext/max-age.js +0 -90
- package/packages/memoize/ext/max.js +0 -27
- package/packages/memoize/ext/promise.js +0 -147
- package/packages/memoize/ext/ref-counter.js +0 -48
- package/packages/memoize/index.js +0 -34
- package/packages/memoize/lib/configure-map.js +0 -182
- package/packages/memoize/lib/methods.js +0 -32
- package/packages/memoize/lib/registered-extensions.js +0 -1
- package/packages/memoize/lib/resolve-length.js +0 -15
- package/packages/memoize/lib/resolve-normalize.js +0 -17
- package/packages/memoize/lib/resolve-resolve.js +0 -21
- package/packages/memoize/lib/weak.js +0 -134
- package/packages/memoize/methods-plain.js +0 -3
- package/packages/memoize/methods.js +0 -3
- package/packages/memoize/normalizers/get-1.js +0 -29
- package/packages/memoize/normalizers/get-fixed.js +0 -71
- package/packages/memoize/normalizers/get-primitive-fixed.js +0 -16
- package/packages/memoize/normalizers/get.js +0 -90
- package/packages/memoize/normalizers/primitive.js +0 -9
- package/packages/memoize/package.json +0 -60
- package/packages/memoize/plain.js +0 -37
- package/packages/memoize/profile.js +0 -107
- package/packages/memoize/repository.md +0 -1
- package/packages/memoize/weak-plain.js +0 -3
- package/packages/memoize/weak.js +0 -3
- package/tsconfig.json +0 -39
- package/unused.md +0 -11
|
@@ -1,90 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,27 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,147 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,48 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,34 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
/* eslint no-eq-null: 0, eqeqeq: 0, no-unused-vars: 0 */
|
|
2
|
-
|
|
3
|
-
"use strict";
|
|
4
|
-
|
|
5
|
-
var customError = require("es5-ext/error/custom")
|
|
6
|
-
, defineLength = require("es5-ext/function/_define-length")
|
|
7
|
-
, d = require("d")
|
|
8
|
-
, ee = require("event-emitter").methods
|
|
9
|
-
, resolveResolve = require("./resolve-resolve")
|
|
10
|
-
, resolveNormalize = require("./resolve-normalize");
|
|
11
|
-
|
|
12
|
-
var apply = Function.prototype.apply
|
|
13
|
-
, call = Function.prototype.call
|
|
14
|
-
, create = Object.create
|
|
15
|
-
, defineProperties = Object.defineProperties
|
|
16
|
-
, on = ee.on
|
|
17
|
-
, emit = ee.emit;
|
|
18
|
-
|
|
19
|
-
module.exports = function (original, length, options) {
|
|
20
|
-
var cache = create(null)
|
|
21
|
-
, conf
|
|
22
|
-
, memLength
|
|
23
|
-
, get
|
|
24
|
-
, set
|
|
25
|
-
, del
|
|
26
|
-
, clear
|
|
27
|
-
, extDel
|
|
28
|
-
, extGet
|
|
29
|
-
, extHas
|
|
30
|
-
, normalizer
|
|
31
|
-
, getListeners
|
|
32
|
-
, setListeners
|
|
33
|
-
, deleteListeners
|
|
34
|
-
, memoized
|
|
35
|
-
, resolve;
|
|
36
|
-
if (length !== false) memLength = length;
|
|
37
|
-
else if (isNaN(original.length)) memLength = 1;
|
|
38
|
-
else memLength = original.length;
|
|
39
|
-
|
|
40
|
-
if (options.normalizer) {
|
|
41
|
-
normalizer = resolveNormalize(options.normalizer);
|
|
42
|
-
get = normalizer.get;
|
|
43
|
-
set = normalizer.set;
|
|
44
|
-
del = normalizer.delete;
|
|
45
|
-
clear = normalizer.clear;
|
|
46
|
-
}
|
|
47
|
-
if (options.resolvers != null) resolve = resolveResolve(options.resolvers);
|
|
48
|
-
|
|
49
|
-
if (get) {
|
|
50
|
-
memoized = defineLength(function (arg) {
|
|
51
|
-
var id, result, args = arguments;
|
|
52
|
-
if (resolve) args = resolve(args);
|
|
53
|
-
id = get(args);
|
|
54
|
-
if (id !== null) {
|
|
55
|
-
if (hasOwnProperty.call(cache, id)) {
|
|
56
|
-
if (getListeners) conf.emit("get", id, args, this);
|
|
57
|
-
return cache[id];
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
if (args.length === 1) result = call.call(original, this, args[0]);
|
|
61
|
-
else result = apply.call(original, this, args);
|
|
62
|
-
if (id === null) {
|
|
63
|
-
id = get(args);
|
|
64
|
-
if (id !== null) throw customError("Circular invocation", "CIRCULAR_INVOCATION");
|
|
65
|
-
id = set(args);
|
|
66
|
-
} else if (hasOwnProperty.call(cache, id)) {
|
|
67
|
-
throw customError("Circular invocation", "CIRCULAR_INVOCATION");
|
|
68
|
-
}
|
|
69
|
-
cache[id] = result;
|
|
70
|
-
if (setListeners) conf.emit("set", id, null, result);
|
|
71
|
-
return result;
|
|
72
|
-
}, memLength);
|
|
73
|
-
} else if (length === 0) {
|
|
74
|
-
memoized = function () {
|
|
75
|
-
var result;
|
|
76
|
-
if (hasOwnProperty.call(cache, "data")) {
|
|
77
|
-
if (getListeners) conf.emit("get", "data", arguments, this);
|
|
78
|
-
return cache.data;
|
|
79
|
-
}
|
|
80
|
-
if (arguments.length) result = apply.call(original, this, arguments);
|
|
81
|
-
else result = call.call(original, this);
|
|
82
|
-
if (hasOwnProperty.call(cache, "data")) {
|
|
83
|
-
throw customError("Circular invocation", "CIRCULAR_INVOCATION");
|
|
84
|
-
}
|
|
85
|
-
cache.data = result;
|
|
86
|
-
if (setListeners) conf.emit("set", "data", null, result);
|
|
87
|
-
return result;
|
|
88
|
-
};
|
|
89
|
-
} else {
|
|
90
|
-
memoized = function (arg) {
|
|
91
|
-
var result, args = arguments, id;
|
|
92
|
-
if (resolve) args = resolve(arguments);
|
|
93
|
-
id = String(args[0]);
|
|
94
|
-
if (hasOwnProperty.call(cache, id)) {
|
|
95
|
-
if (getListeners) conf.emit("get", id, args, this);
|
|
96
|
-
return cache[id];
|
|
97
|
-
}
|
|
98
|
-
if (args.length === 1) result = call.call(original, this, args[0]);
|
|
99
|
-
else result = apply.call(original, this, args);
|
|
100
|
-
if (hasOwnProperty.call(cache, id)) {
|
|
101
|
-
throw customError("Circular invocation", "CIRCULAR_INVOCATION");
|
|
102
|
-
}
|
|
103
|
-
cache[id] = result;
|
|
104
|
-
if (setListeners) conf.emit("set", id, null, result);
|
|
105
|
-
return result;
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
conf = {
|
|
109
|
-
original: original,
|
|
110
|
-
memoized: memoized,
|
|
111
|
-
profileName: options.profileName,
|
|
112
|
-
get: function (args) {
|
|
113
|
-
if (resolve) args = resolve(args);
|
|
114
|
-
if (get) return get(args);
|
|
115
|
-
return String(args[0]);
|
|
116
|
-
},
|
|
117
|
-
has: function (id) { return hasOwnProperty.call(cache, id); },
|
|
118
|
-
delete: function (id) {
|
|
119
|
-
var result;
|
|
120
|
-
if (!hasOwnProperty.call(cache, id)) return;
|
|
121
|
-
if (del) del(id);
|
|
122
|
-
result = cache[id];
|
|
123
|
-
delete cache[id];
|
|
124
|
-
if (deleteListeners) conf.emit("delete", id, result);
|
|
125
|
-
},
|
|
126
|
-
clear: function () {
|
|
127
|
-
var oldCache = cache;
|
|
128
|
-
if (clear) clear();
|
|
129
|
-
cache = create(null);
|
|
130
|
-
conf.emit("clear", oldCache);
|
|
131
|
-
},
|
|
132
|
-
on: function (type, listener) {
|
|
133
|
-
if (type === "get") getListeners = true;
|
|
134
|
-
else if (type === "set") setListeners = true;
|
|
135
|
-
else if (type === "delete") deleteListeners = true;
|
|
136
|
-
return on.call(this, type, listener);
|
|
137
|
-
},
|
|
138
|
-
emit: emit,
|
|
139
|
-
updateEnv: function () { original = conf.original; }
|
|
140
|
-
};
|
|
141
|
-
if (get) {
|
|
142
|
-
extDel = defineLength(function (arg) {
|
|
143
|
-
var id, args = arguments;
|
|
144
|
-
if (resolve) args = resolve(args);
|
|
145
|
-
id = get(args);
|
|
146
|
-
if (id === null) return;
|
|
147
|
-
conf.delete(id);
|
|
148
|
-
}, memLength);
|
|
149
|
-
} else if (length === 0) {
|
|
150
|
-
extDel = function () { return conf.delete("data"); };
|
|
151
|
-
} else {
|
|
152
|
-
extDel = function (arg) {
|
|
153
|
-
if (resolve) arg = resolve(arguments)[0];
|
|
154
|
-
return conf.delete(arg);
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
extGet = defineLength(function () {
|
|
158
|
-
var id, args = arguments;
|
|
159
|
-
if (length === 0) return cache.data;
|
|
160
|
-
if (resolve) args = resolve(args);
|
|
161
|
-
if (get) id = get(args);
|
|
162
|
-
else id = String(args[0]);
|
|
163
|
-
return cache[id];
|
|
164
|
-
});
|
|
165
|
-
extHas = defineLength(function () {
|
|
166
|
-
var id, args = arguments;
|
|
167
|
-
if (length === 0) return conf.has("data");
|
|
168
|
-
if (resolve) args = resolve(args);
|
|
169
|
-
if (get) id = get(args);
|
|
170
|
-
else id = String(args[0]);
|
|
171
|
-
if (id === null) return false;
|
|
172
|
-
return conf.has(id);
|
|
173
|
-
});
|
|
174
|
-
defineProperties(memoized, {
|
|
175
|
-
__memoized__: d(true),
|
|
176
|
-
delete: d(extDel),
|
|
177
|
-
clear: d(conf.clear),
|
|
178
|
-
_get: d(extGet),
|
|
179
|
-
_has: d(extHas)
|
|
180
|
-
});
|
|
181
|
-
return conf;
|
|
182
|
-
};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var forEach = require("es5-ext/object/for-each")
|
|
4
|
-
, normalizeOpts = require("es5-ext/object/normalize-options")
|
|
5
|
-
, callable = require("es5-ext/object/valid-callable")
|
|
6
|
-
, lazy = require("d/lazy")
|
|
7
|
-
, resolveLength = require("./resolve-length")
|
|
8
|
-
, extensions = require("./registered-extensions");
|
|
9
|
-
|
|
10
|
-
module.exports = function (memoize) {
|
|
11
|
-
return function (props) {
|
|
12
|
-
forEach(props, function (desc) {
|
|
13
|
-
var fn = callable(desc.value), length;
|
|
14
|
-
desc.value = function (options) {
|
|
15
|
-
if (options.getNormalizer) {
|
|
16
|
-
options = normalizeOpts(options);
|
|
17
|
-
if (length === undefined) {
|
|
18
|
-
length = resolveLength(
|
|
19
|
-
options.length,
|
|
20
|
-
fn.length,
|
|
21
|
-
options.async && extensions.async
|
|
22
|
-
);
|
|
23
|
-
}
|
|
24
|
-
options.normalizer = options.getNormalizer(length);
|
|
25
|
-
delete options.getNormalizer;
|
|
26
|
-
}
|
|
27
|
-
return memoize(fn.bind(this), options);
|
|
28
|
-
};
|
|
29
|
-
});
|
|
30
|
-
return lazy(props);
|
|
31
|
-
};
|
|
32
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var toPosInt = require("es5-ext/number/to-pos-integer");
|
|
4
|
-
|
|
5
|
-
module.exports = function (optsLength, fnLength, isAsync) {
|
|
6
|
-
var length;
|
|
7
|
-
if (isNaN(optsLength)) {
|
|
8
|
-
length = fnLength;
|
|
9
|
-
if (!(length >= 0)) return 1;
|
|
10
|
-
if (isAsync && length) return length - 1;
|
|
11
|
-
return length;
|
|
12
|
-
}
|
|
13
|
-
if (optsLength === false) return false;
|
|
14
|
-
return toPosInt(optsLength);
|
|
15
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var callable = require("es5-ext/object/valid-callable");
|
|
4
|
-
|
|
5
|
-
module.exports = function (userNormalizer) {
|
|
6
|
-
var normalizer;
|
|
7
|
-
if (typeof userNormalizer === "function") return { set: userNormalizer, get: userNormalizer };
|
|
8
|
-
normalizer = { get: callable(userNormalizer.get) };
|
|
9
|
-
if (userNormalizer.set !== undefined) {
|
|
10
|
-
normalizer.set = callable(userNormalizer.set);
|
|
11
|
-
if (userNormalizer.delete) normalizer.delete = callable(userNormalizer.delete);
|
|
12
|
-
if (userNormalizer.clear) normalizer.clear = callable(userNormalizer.clear);
|
|
13
|
-
return normalizer;
|
|
14
|
-
}
|
|
15
|
-
normalizer.set = normalizer.get;
|
|
16
|
-
return normalizer;
|
|
17
|
-
};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var toArray = require("es5-ext/array/to-array")
|
|
4
|
-
, isValue = require("es5-ext/object/is-value")
|
|
5
|
-
, callable = require("es5-ext/object/valid-callable");
|
|
6
|
-
|
|
7
|
-
var slice = Array.prototype.slice, resolveArgs;
|
|
8
|
-
|
|
9
|
-
resolveArgs = function (args) {
|
|
10
|
-
return this.map(function (resolve, i) {
|
|
11
|
-
return resolve ? resolve(args[i]) : args[i];
|
|
12
|
-
}).concat(slice.call(args, this.length));
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
module.exports = function (resolvers) {
|
|
16
|
-
resolvers = toArray(resolvers);
|
|
17
|
-
resolvers.forEach(function (resolve) {
|
|
18
|
-
if (isValue(resolve)) callable(resolve);
|
|
19
|
-
});
|
|
20
|
-
return resolveArgs.bind(resolvers);
|
|
21
|
-
};
|