@techmely/utils
Version:
Collection of helpful JavaScript / TypeScript utils
25 lines (21 loc) • 542 B
JavaScript
/*!
* @techmely/utils
* Copyright(c) 2021-2024 Techmely <techmely.creation@gmail.com>
* MIT Licensed
*/
// src/cacheImportModule.ts
var lazyImportCache = /* @__PURE__ */ new Map();
function createCachedImport(name, imp) {
return () => {
const cached = lazyImportCache.get(name);
if (cached)
return cached;
const promise = imp().then((module) => {
lazyImportCache.set(name, module);
return module;
});
lazyImportCache.set(name, promise);
return promise;
};
}
export { createCachedImport };