UNPKG

@techmely/utils

Version:

Collection of helpful JavaScript / TypeScript utils

36 lines (31 loc) 743 B
/*! * @techmely/utils * Copyright(c) 2021-2024 Techmely <techmely.creation@gmail.com> * MIT Licensed */ // src/cache.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; }; } var cacheStringFunction = (fn) => { const cache = /* @__PURE__ */ Object.create(null); return (str) => { const hit = cache[str]; return hit || (cache[str] = fn(str)); }; }; export { createCachedImport, cacheStringFunction };