Add electron option when detecting environment

This commit is contained in:
jeromewu
2019-12-27 09:03:54 +00:00
parent c506475a76
commit 1bacf193d9
3 changed files with 20 additions and 3 deletions

View File

@@ -1,10 +1,21 @@
const isElectron = require('is-electron');
module.exports = (key) => {
const env = {
type: (typeof window !== 'undefined') && (typeof window.document !== 'undefined') ? 'browser' : 'node',
};
const env = {};
if (isElectron()) {
env.type = 'electron';
} else if (typeof window === 'object') {
env.type = 'browser';
} else if (typeof importScripts === 'function') {
env.type = 'webworker';
} else if (typeof process === 'object' && typeof require === 'function') {
env.type = 'node';
}
if (typeof key === 'undefined') {
return env;
}
return env[key];
};