diff --git a/src/libs/getOperatingSystem/index.native.js b/src/libs/getOperatingSystem/index.native.ts similarity index 72% rename from src/libs/getOperatingSystem/index.native.js rename to src/libs/getOperatingSystem/index.native.ts index fce2857548f1..38b87f4983b7 100644 --- a/src/libs/getOperatingSystem/index.native.js +++ b/src/libs/getOperatingSystem/index.native.ts @@ -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; @@ -15,3 +15,5 @@ export default () => { return CONST.OS.NATIVE; } }; + +export default getOperatingSystem; diff --git a/src/libs/getOperatingSystem/index.js b/src/libs/getOperatingSystem/index.ts similarity index 69% rename from src/libs/getOperatingSystem/index.js rename to src/libs/getOperatingSystem/index.ts index d1ffac6defa7..7adfa27c45fc 100644 --- a/src/libs/getOperatingSystem/index.js +++ b/src/libs/getOperatingSystem/index.ts @@ -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; @@ -25,3 +24,5 @@ export default () => { } return os; }; + +export default getOperatingSystem; diff --git a/src/libs/getOperatingSystem/types.ts b/src/libs/getOperatingSystem/types.ts new file mode 100644 index 000000000000..64bb103db083 --- /dev/null +++ b/src/libs/getOperatingSystem/types.ts @@ -0,0 +1,7 @@ +import {ValueOf} from 'type-fest'; +import CONST from '../../CONST'; + +type OS = ValueOf | null; +type GetOperatingSystem = () => OS; + +export default GetOperatingSystem;