xterm
[VSoRC/.git] / node_modules / xterm / src / common / Platform.ts
1 /**
2  * Copyright (c) 2016 The xterm.js authors. All rights reserved.
3  * @license MIT
4  */
5
6 interface INavigator {
7   userAgent: string;
8   language: string;
9   platform: string;
10 }
11
12 // We're declaring a navigator global here as we expect it in all runtimes (node and browser), but
13 // we want this module to live in common.
14 declare const navigator: INavigator;
15
16 const isNode = (typeof navigator === 'undefined') ? true : false;
17 const userAgent = (isNode) ? 'node' : navigator.userAgent;
18 const platform = (isNode) ? 'node' : navigator.platform;
19
20 export const isFirefox = !!~userAgent.indexOf('Firefox');
21 export const isSafari = /^((?!chrome|android).)*safari/i.test(userAgent);
22
23 // Find the users platform. We use this to interpret the meta key
24 // and ISO third level shifts.
25 // http://stackoverflow.com/q/19877924/577598
26 export const isMac = contains(['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K'], platform);
27 export const isIpad = platform === 'iPad';
28 export const isIphone = platform === 'iPhone';
29 export const isWindows = contains(['Windows', 'Win16', 'Win32', 'WinCE'], platform);
30 export const isLinux = platform.indexOf('Linux') >= 0;
31
32 /**
33  * Return if the given array contains the given element
34  * @param arr The array to search for the given element.
35  * @param el The element to look for into the array
36  */
37 function contains(arr: any[], el: any): boolean {
38   return arr.indexOf(el) >= 0;
39 }