'use strict';
/** A way to detect platform from window.navigator.userAgent and window.navigator.platform.
* Inspired from https://stackoverflow.com/questions/38241480/detect-macos-ios-windows-android-and-linux-os-with-js
*/
class Platform {
/** Whether the platform is Windows
* @type {boolean}
*/
isWin = null;
/** Whether the platform is Mac
* @type {boolean}
*/
isMac = null;
/** Whether the platform is Android
* @type {boolean}
*/
isAndroid = null;
/** Whether the platform is iOS
* @type {boolean}
*/
isIOS = null;
/** Whether the platform is Linux
* @type {boolean}
*/
isLinux = null;
/** Whether the platform is unidentified
* @type {boolean}
*/
isUnidentified = null;
/** Sets userAgent and platform
*/
constructor() {
this.userAgent = window.navigator.userAgent;
this.navigatorPlatform = window.navigator.platform;
this.isWin = ['Win32', 'Win64', 'Windows', 'WinCE'].includes(this.navigatorPlatform);
this.isMac = ['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K'].includes(this.navigatorPlatform);
this.isAndroid = /Android/.test(this.userAgent);
this.isIOS = ['iPhone', 'iPad', 'iPod'].includes(this.navigatorPlatform);
this.isLinux = !(this.isWin || this.isMac || this.isAndroid || this.isIOS) && /Linux/.test(this.navigatorPlatform);
this.isUnidentified = !this.isWin && !this.isMac && !this.isAndroid && !this.isIOS && !this.isLinux;
}
}
/** Instance of the class of this module
* @type {module:platform~Platform}
*/
export const platform = new Platform();