Changeset View
Changeset View
Standalone View
Standalone View
lib/types/device-types.js
// @flow | // @flow | ||||
import invariant from 'invariant'; | import invariant from 'invariant'; | ||||
export type DeviceType = 'ios' | 'android'; | import { values } from '../utils/objects.js'; | ||||
const deviceTypesObj = Object.freeze({ | |||||
ios: 'ios', | |||||
android: 'android', | |||||
}); | |||||
export type DeviceType = $Values<typeof deviceTypesObj>; | |||||
export type Platform = DeviceType | 'web' | 'windows' | 'macos'; | export type Platform = DeviceType | 'web' | 'windows' | 'macos'; | ||||
export const deviceTypes: $ReadOnlyArray<DeviceType> = values(deviceTypesObj); | |||||
export function isDeviceType(platform: ?string): boolean { | export function isDeviceType(platform: ?string): boolean { | ||||
return platform === 'ios' || platform === 'android'; | return platform === 'ios' || platform === 'android'; | ||||
} | } | ||||
export function assertDeviceType(deviceType: ?string): DeviceType { | export function assertDeviceType(deviceType: ?string): DeviceType { | ||||
invariant( | invariant( | ||||
deviceType === 'ios' || deviceType === 'android', | deviceType === 'ios' || deviceType === 'android', | ||||
'string is not DeviceType enum', | 'string is not DeviceType enum', | ||||
Show All 19 Lines |