{"size": 1781, "ext": "js", "max_stars_repo_path": "core/utils/memoize.js", "max_stars_repo_name": "pecuniafinance/gateway-api", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "core/utils/memoize.js", "max_issues_repo_name": "pecuniafinance/gateway-api", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "core/utils/memoize.js", "max_forks_repo_name": "pecuniafinance/gateway-api", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 32.9814814815, "max_line_length": 79, "alphanum_fraction": 0.5115103874}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.memoizeSuccessfulPromise = exports.memoize = void 0;
function memoize(func, resolver) {
    if (typeof func != "function" ||
        (resolver != null && typeof resolver != "function")) {
        throw new TypeError("Invalid memo");
    }
    const cache = new Map();
    let memoized = (...args) => {
        let fn = (...args) => {
            const key = resolver ? resolver(...args) : args[0];
            if (cache.has(key)) {
                return cache.get(key);
            }
            const result = func(...args);
            cache.set(key, result);
            return result;
        };
        memoized = fn;
        return fn(...args);
    };
    return memoized;
}
exports.memoize = memoize;
function memoizeSuccessfulPromise(func, resolver) {
    if (typeof func != "function" ||
        (resolver != null && typeof resolver != "function")) {
        throw new TypeError("Invalid memo");
    }
    const cache = new Map();
    let memoized = (...args) => {
        let fn = (...args) => {
            const key = resolver ? resolver(...args) : args[0];
            if (cache.has(key)) {
                return cache.get(key);
            }
            const result = func(...args);
            cache.set(key, result);
            if (result === null || result === void 0 ? void 0 : result.catch) {
                result.catch((error) => {
                    cache.delete(key);
                    return Promise.reject(error);
                });
            }
            return result;
        };
        memoized = fn;
        return fn(...args);
    };
    return memoized;
}
exports.memoizeSuccessfulPromise = memoizeSuccessfulPromise;
//# sourceMappingURL=memoize.js.map