Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@skava/ui / src / components / features / Portal / deps.ts
Size: Mime:
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 }