@naturalcycles/js-lib
Version:
Standard library for universal (browser + Node.js) javascript
20 lines (19 loc) • 490 B
JavaScript
/**
* Use it to detect SSR/Node.js environment.
*
* Will return `true` in Node.js.
* Will return `false` in the Browser.
*/
export function isServerSide() {
return !isClientSide();
}
/**
* Use it to detect Browser (not SSR/Node) environment.
*
* Will return `true` in the Browser.
* Will return `false` in Node.js.
*/
export function isClientSide() {
// eslint-disable-next-line unicorn/prefer-global-this
return typeof window !== 'undefined' && !!window?.document;
}