UNPKG

@techmely/utils

Version:

Collection of helpful JavaScript / TypeScript utils

26 lines (20 loc) 466 B
'use strict'; /*! * @techmely/utils * Copyright(c) 2021-2024 Techmely <techmely.creation@gmail.com> * MIT Licensed */ // src/isServer.ts function isServer() { return typeof window === "undefined"; } // src/onClickOutside/index.ts function onClickOutside(element, callback) { if (isServer()) return; document.addEventListener("click", (e) => { if (!element.contains(e.target)) callback(); }); } exports.onClickOutside = onClickOutside;