@amaui/utils
Version:
22 lines (17 loc) • 702 B
JavaScript
import is from './is';
export default function isEnvironment(type, value) {
let value_;
switch (type) {
case 'browser':
return typeof window !== 'undefined' && typeof window.document !== 'undefined';
case 'worker':
return typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope;
case 'nodejs':
return new Function('try {return this===global;}catch(e){return false;}')();
case 'localhost':
value_ = value !== undefined ? value : isEnvironment('browser') && window.location.hostname;
return is('string', value_) && ['localhost', '127.0.0.1'].some(value__ => value_.indexOf(value__) > -1);
default:
return false;
}
}