This function creates a Singleton in your application. it adds a singleton to global and checks whether it exist, and if it doesn’t, it runs the function passed as a parameter, and returns it.
function singleton<T>(name: string, value(()=>T) {
const yolo = global
const yolo.__singleton ??= {}
const yolo.__singleton[name] ??= value()
return yolo__singleton[name]
}