Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[No QA] [TS migration] Migrate 'getOperatingSystem' lib to TypeScript #27517

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {Platform} from 'react-native';
import CONST from '../../CONST';
import GetOperatingSystem from './types';

/**
* Reads the current operating system for native platforms.
* @return {String | null}
*/
export default () => {
const getOperatingSystem: GetOperatingSystem = () => {
switch (Platform.OS) {
case 'ios':
return CONST.OS.IOS;
Expand All @@ -15,3 +15,5 @@ export default () => {
return CONST.OS.NATIVE;
}
};

export default getOperatingSystem;
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
import _ from 'underscore';
import CONST from '../../CONST';
import GetOperatingSystem from './types';

/**
* Reads the current operating system when running on Web/Mobile-Web/Desktop
* @return {String | null}
*/
export default () => {
const getOperatingSystem: GetOperatingSystem = () => {
const {userAgent, platform} = window.navigator;
const macosPlatforms = ['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K'];
const windowsPlatforms = ['Win32', 'Win64', 'Windows', 'WinCE'];
const iosPlatforms = ['iPhone', 'iPad', 'iPod'];

let os = null;
if (_.contains(macosPlatforms, platform)) {
if (macosPlatforms.includes(platform)) {
os = CONST.OS.MAC_OS;
} else if (_.contains(iosPlatforms, platform)) {
} else if (iosPlatforms.includes(platform)) {
os = CONST.OS.IOS;
} else if (_.contains(windowsPlatforms, platform)) {
} else if (windowsPlatforms.includes(platform)) {
os = CONST.OS.WINDOWS;
} else if (/Android/.test(userAgent)) {
os = CONST.OS.ANDROID;
Expand All @@ -25,3 +24,5 @@ export default () => {
}
return os;
};

export default getOperatingSystem;
7 changes: 7 additions & 0 deletions src/libs/getOperatingSystem/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {ValueOf} from 'type-fest';
import CONST from '../../CONST';

type OS = ValueOf<typeof CONST.OS> | null;
type GetOperatingSystem = () => OS;

export default GetOperatingSystem;
Loading