Repository URL to install this package:
|
Version:
2.2.1 ▾
|
import { isObj, isFunction } from 'exotic'
/**
* also available from 'fbjs'
*/
const canUseDOM =
typeof window === 'object' &&
isObj(window.document) &&
isFunction(window.document.createElement)
/**
* @description sometimes this throws, so we wrap this one function and scope the easily-deopted of trycatch
*/
function removeElement(element: Element) {
try {
document.body.removeChild(element)
return true
} catch (objectOrDomException) {
//
return false
}
}
function getElementOrCreate(id: string) {
return document.getElementById(id) || document.createElement('div')
}
export { canUseDOM, removeElement, getElementOrCreate }