UNPKG

@primer/react

Version:

An implementation of GitHub's Primer Design System using React

25 lines (21 loc) 1.05 kB
import { version } from 'react'; /** * Indicate whether current execution environment can access the DOM. * * @see https://github.com/facebook/fbjs/blob/4d1751311d3f67af2dcce2e40df8512a23c7b9c6/packages/fbjs/src/core/ExecutionEnvironment.js#L12 */ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition,ssr-friendly/no-dom-globals-in-module-scope const canUseDOM = !!(typeof window !== 'undefined' && window.document && window.document.createElement); // Grab the major version from react. This could be formatted as any valid // semver version, e.g.: // // - 19.0.0 // - 19.0.0-rc.1 // - 0.0.0-{channel}-{commit}-{time} // // So we only pull the first part of the version and parse it. const reactVersion = version.split('.'); const reactMajorVersion = parseInt(reactVersion[0], 10); const EXPERIMENTAL_REACT_VERSION_REGEX = /^0\.0\.0-experimental-[a-f0-9]{8}-\d{8}$/; const isExperimentalReactVersion = EXPERIMENTAL_REACT_VERSION_REGEX.test(version); export { canUseDOM, isExperimentalReactVersion, reactMajorVersion };