@techmely/utils
Version:
Collection of helpful JavaScript / TypeScript utils
17 lines (13 loc) • 315 B
JavaScript
/*!
* @techmely/utils
* Copyright(c) 2021-2024 Techmely <techmely.creation@gmail.com>
* MIT Licensed
*/
// src/singleton.ts
function singleton(name, valueFactory) {
const g = global;
g.__singletons ??= {};
g.__singletons[name] ??= valueFactory();
return g.__singletons[name];
}
export { singleton };