UNPKG

@onesy/utils

Version:
24 lines (23 loc) 1.04 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const is_1 = __importDefault(require("./is")); 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 (0, is_1.default)('string', value_) && ['localhost', '127.0.0.1'].some(value__ => value_.indexOf(value__) > -1); default: return false; } } exports.default = isEnvironment;