Debian Codegraph @

node/@xterm/xterm/src/common/Platform.ts

raw
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 declare const process: unknown;
16
17 export const isNode = (typeof process !== 'undefined' && 'title' in (process as any)) ? true : false;
18 const userAgent = (isNode) ? 'node' : navigator.userAgent;
19 const platform = (isNode) ? 'node' : navigator.platform;
20
21 export const isFirefox = userAgent.includes('Firefox');
22 export const isLegacyEdge = userAgent.includes('Edge');
23 export const isSafari = /^((?!chrome|android).)*safari/i.test(userAgent);
24 export function getSafariVersion(): number {
25 if (!isSafari) {
26 return 0;
27 }
28 const majorVersion = userAgent.match(/Version\/(\d+)/);
29 if (majorVersion === null || majorVersion.length < 2) {
30 return 0;
31 }
32 return parseInt(majorVersion[1]);
33 }
34
35 // Find the users platform. We use this to interpret the meta key
36 // and ISO third level shifts.
37 // http://stackoverflow.com/q/19877924/577598
38 export const isMac = ['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K'].includes(platform);
39 export const isIpad = platform === 'iPad';
40 export const isIphone = platform === 'iPhone';
41 export const isWindows = ['Windows', 'Win16', 'Win32', 'WinCE'].includes(platform);
42 export const isLinux = platform.indexOf('Linux') >= 0;
43 // Note that when this is true, isLinux will also be true.
44 export const isChromeOS = /\bCrOS\b/.test(userAgent);