forked from nativescript-community/expo-nativescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlatform.ts
31 lines (27 loc) · 1.05 KB
/
Platform.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { isIOS, isAndroid, platformNames } from "@nativescript/core";
export type PlatformSelectOSType = keyof typeof platformNames | 'native' | 'electron' | 'default';
export type PlatformSelect = <T>(specifics: { [platform in PlatformSelectOSType]?: T }) => T;
const Platform = {
/**
* Denotes the currently running platform.
* Can be one of ios, android, web.
*/
OS: isIOS ? "iOS" : isAndroid ? "Android" : "<unknown platform>",
/**
* Returns the value with the matching platform.
* Object keys can be any of ios, android, native, web, default.
*
* @ios ios, native, default
* @android android, native, default
* @web web, default
*/
select: <T>(specifics: { [platform in PlatformSelectOSType]?: T }): T => {
return "ios" in specifics ? specifics.ios : "native" in specifics ? specifics.native : specifics.default;
},
/**
* Denotes if the DOM API is available in the current environment.
* The DOM is not available in native React runtimes and Node.js.
*/
isDOMAvailable: false,
};
export default Platform;