@prosary/core 0.0.0-stage → 0.0.0
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/.dist/THIRD-PARTY-LICENSES.md.gz +0 -0
- package/.dist/_chunks/libs/@formatjs/fast-memoize.mjs +65 -0
- package/.dist/_chunks/libs/@formatjs/icu-messageformat-parser.mjs +2285 -0
- package/.dist/_chunks/libs/intl-messageformat.mjs +305 -0
- package/.dist/index.d.mts +289 -0
- package/.dist/index.mjs +325 -0
- package/README.md +2 -2
- package/package.json +36 -4
|
Binary file
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
function memoize(fn, options) {
|
|
2
|
+
const cache = options && options.cache ? options.cache : cacheDefault;
|
|
3
|
+
const serializer = options && options.serializer ? options.serializer : serializerDefault;
|
|
4
|
+
return (options && options.strategy ? options.strategy : strategyDefault)(fn, {
|
|
5
|
+
cache,
|
|
6
|
+
serializer
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
function isPrimitive(value) {
|
|
10
|
+
return value == null || typeof value === "number" || typeof value === "boolean";
|
|
11
|
+
}
|
|
12
|
+
function monadic(fn, cache, serializer, arg) {
|
|
13
|
+
const cacheKey = isPrimitive(arg) ? arg : serializer(arg);
|
|
14
|
+
let computedValue = cache.get(cacheKey);
|
|
15
|
+
if (typeof computedValue === "undefined") {
|
|
16
|
+
computedValue = fn.call(this, arg);
|
|
17
|
+
cache.set(cacheKey, computedValue);
|
|
18
|
+
}
|
|
19
|
+
return computedValue;
|
|
20
|
+
}
|
|
21
|
+
function variadic(fn, cache, serializer) {
|
|
22
|
+
const args = Array.prototype.slice.call(arguments, 3);
|
|
23
|
+
const cacheKey = serializer(args);
|
|
24
|
+
let computedValue = cache.get(cacheKey);
|
|
25
|
+
if (typeof computedValue === "undefined") {
|
|
26
|
+
computedValue = fn.apply(this, args);
|
|
27
|
+
cache.set(cacheKey, computedValue);
|
|
28
|
+
}
|
|
29
|
+
return computedValue;
|
|
30
|
+
}
|
|
31
|
+
function assemble(fn, context, strategy, cache, serialize) {
|
|
32
|
+
return strategy.bind(context, fn, cache, serialize);
|
|
33
|
+
}
|
|
34
|
+
function strategyDefault(fn, options) {
|
|
35
|
+
const strategy = fn.length === 1 ? monadic : variadic;
|
|
36
|
+
return assemble(fn, this, strategy, options.cache.create(), options.serializer);
|
|
37
|
+
}
|
|
38
|
+
function strategyVariadic(fn, options) {
|
|
39
|
+
return assemble(fn, this, variadic, options.cache.create(), options.serializer);
|
|
40
|
+
}
|
|
41
|
+
function strategyMonadic(fn, options) {
|
|
42
|
+
return assemble(fn, this, monadic, options.cache.create(), options.serializer);
|
|
43
|
+
}
|
|
44
|
+
const serializerDefault = function() {
|
|
45
|
+
return JSON.stringify(arguments);
|
|
46
|
+
};
|
|
47
|
+
var ObjectWithoutPrototypeCache = class {
|
|
48
|
+
constructor() {
|
|
49
|
+
this.cache = Object.create(null);
|
|
50
|
+
}
|
|
51
|
+
get(key) {
|
|
52
|
+
return this.cache[key];
|
|
53
|
+
}
|
|
54
|
+
set(key, value) {
|
|
55
|
+
this.cache[key] = value;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
const cacheDefault = { create: function create() {
|
|
59
|
+
return new ObjectWithoutPrototypeCache();
|
|
60
|
+
} };
|
|
61
|
+
const strategies = {
|
|
62
|
+
variadic: strategyVariadic,
|
|
63
|
+
monadic: strategyMonadic
|
|
64
|
+
};
|
|
65
|
+
export { memoize, strategies };
|