1import { Platform as ReactNativePlatform, PlatformOSType } from 'react-native';
2
3import {
4  isDOMAvailable,
5  canUseEventListeners,
6  canUseViewport,
7  isAsyncDebugging,
8} from './environment/browser';
9
10export type PlatformSelectOSType = PlatformOSType | 'native' | 'electron' | 'default';
11
12export type PlatformSelect = <T>(specifics: { [platform in PlatformSelectOSType]?: T }) => T;
13
14const Platform = {
15  /**
16   * Denotes the currently running platform.
17   * Can be one of ios, android, web.
18   */
19  OS: ReactNativePlatform.OS,
20  /**
21   * Returns the value with the matching platform.
22   * Object keys can be any of ios, android, native, web, default.
23   *
24   * @ios ios, native, default
25   * @android android, native, default
26   * @web web, default
27   */
28  select: ReactNativePlatform.select as PlatformSelect,
29  /**
30   * Denotes if the DOM API is available in the current environment.
31   * The DOM is not available in native React runtimes and Node.js.
32   */
33  isDOMAvailable,
34  /**
35   * Denotes if the current environment can attach event listeners
36   * to the window. This will return false in native React
37   * runtimes and Node.js.
38   */
39  canUseEventListeners,
40  /**
41   * Denotes if the current environment can inspect properties of the
42   * screen on which the current window is being rendered. This will
43   * return false in native React runtimes and Node.js.
44   */
45  canUseViewport,
46  /**
47   * If the JavaScript is being executed in a remote JavaScript environment.
48   * When `true`, synchronous native invocations cannot be executed.
49   */
50  isAsyncDebugging,
51};
52
53export default Platform;
54