1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | var __spreadArrays = (this && this.__spreadArrays) || function () {
|
8 | for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
9 | for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
10 | for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
11 | r[k] = a[j];
|
12 | return r;
|
13 | };
|
14 | Object.defineProperty(exports, "__esModule", { value: true });
|
15 |
|
16 | function getCacheId(inputs) {
|
17 | return JSON.stringify(inputs.map(function (input) {
|
18 | return input && typeof input === 'object' ? orderedProps(input) : input;
|
19 | }));
|
20 | }
|
21 | function orderedProps(obj) {
|
22 | return Object.keys(obj)
|
23 | .sort()
|
24 | .map(function (k) {
|
25 | var _a;
|
26 | return (_a = {}, _a[k] = obj[k], _a);
|
27 | });
|
28 | }
|
29 | var memoizeFormatConstructor = function (FormatConstructor, cache) {
|
30 | if (cache === void 0) { cache = {}; }
|
31 | return function () {
|
32 | var _a;
|
33 | var args = [];
|
34 | for (var _i = 0; _i < arguments.length; _i++) {
|
35 | args[_i] = arguments[_i];
|
36 | }
|
37 | var cacheId = getCacheId(args);
|
38 | var format = cacheId && cache[cacheId];
|
39 | if (!format) {
|
40 | format = new ((_a = FormatConstructor).bind.apply(_a, __spreadArrays([void 0], args)))();
|
41 | if (cacheId) {
|
42 | cache[cacheId] = format;
|
43 | }
|
44 | }
|
45 | return format;
|
46 | };
|
47 | };
|
48 | exports.default = memoizeFormatConstructor;
|