From 350f9d5b19e83633e048c0da56cfcb3d4e9b0814 Mon Sep 17 00:00:00 2001 From: Sam Carlton Date: Sun, 4 Sep 2022 10:13:37 -0500 Subject: [PATCH] Add isLinux helper --- helpers/environment.js | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/helpers/environment.js b/helpers/environment.js index 9910283..5b081a5 100644 --- a/helpers/environment.js +++ b/helpers/environment.js @@ -5,11 +5,37 @@ export function isNuxt( VueThis ) { return has( VueThis, [ '$nuxt' ]) } +export function isBrowserContext () { + if ( typeof navigator === 'undefined' ) return false + + return true +} + +export function hasProcesGlobal () { + if ( typeof process === 'undefined' ) return false + + return true +} + + // https://stackoverflow.com/a/8684009/1397641 export function isDarwin () { - if ( typeof navigator !== 'undefined' ) return false + if ( isBrowserContext() ) return false - if ( typeof process === 'undefined' ) return false + if ( !hasProcesGlobal() ) return false return process.platform === 'darwin' } + + +export function isLinux () { + if ( isBrowserContext() ) return false + + if ( !hasProcesGlobal() ) return false + + if ( process.platform === 'linux' ) return true + + if ( process.platform === 'openbsd' ) return true + + return false +}