Files
2026-01-09 14:52:46 +00:00

22 lines
986 B
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.isBrowser = void 0;
var isNode = typeof process !== 'undefined' && process.versions != null && process.versions.node != null;
/**
* 用于判断当前是否在浏览器环境中。
* 首先会判断当前是否处于测试环境中(通过 process.env.NODE_ENV === 'TEST' 判断),
* 如果是,则返回 true。否则会进一步判断是否存在 window 对象、document 对象以及 matchMedia 方法
* 同时通过 !isNode 判断当前不是在服务器Node.js环境下执行
* 如果都符合,则返回 true 表示当前处于浏览器环境中。
* @returns boolean
*/
var isBrowser = exports.isBrowser = function isBrowser() {
if (typeof process !== 'undefined' && process.env.NODE_ENV === 'TEST') {
return true;
}
return typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.matchMedia !== 'undefined' && !isNode;
};