To check if your TypeScript application is running on a desktop platform, you can use the navigator
object which provides information about the browser environment. Here's an example code snippet that you can use to check if your application is running on a desktop:
index.ts184 chars7 lines
The navigator.platform
property returns a string that represents the platform of the browser (i.e. the operating system). We convert the platform string to lowercase and then use a regular expression to check if it matches any mobile platform (i.e. iPhone, iPad, Android, or mobile).
If the platform doesn't match any mobile platform, it means that the application is running on a desktop. The isDesktop
function returns true
in this case, and false
otherwise. The above code snippet logs the result of the isDesktop
function to the console.
gistlibby LogSnag