@jswork/runtime-env
Version:
Runtime-env is a JS library for detecting environments like Web, WeChat MiniProgram, and JSSDK.
72 lines • 2.98 kB
JavaScript
function _type_of(obj) {
"@swc/helpers - typeof";
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
}
/*!
* name: @jswork/runtime-env
* description: Runtime-env is a JS library for detecting environments like Web, WeChat MiniProgram, and JSSDK.
* homepage: https://js.work
* version: 1.0.2
* date: 2025-05-23 13:42:53
* license: MIT
*/ (function(g, f) {
if ((typeof exports === "undefined" ? "undefined" : _type_of(exports)) == "object" && (typeof module === "undefined" ? "undefined" : _type_of(module)) < "u") {
module.exports = f();
} else if ("function" == typeof define && define.amd) {
define("runtimeEnv", f);
} else {
g["runtimeEnv"] = f();
}
})((typeof globalThis === "undefined" ? "undefined" : _type_of(globalThis)) < "u" ? globalThis : (typeof self === "undefined" ? "undefined" : _type_of(self)) < "u" ? self : this, function() {
var exports1 = {};
var __exports = exports1;
var module1 = {
exports: exports1
};
"use strict";
// src/index.ts
var IOS_REGEX = /(iphone|ipad|ipod)/;
var ANDROID_REGEX = /android(?!.*chrome\/[.\d]* mobile)/;
var runtimeEnv = function() {
var isIOS = false;
var isAndroid = false;
var isStudent = false;
var isTeacher = false;
var isWX = false;
if (typeof wx !== "undefined") isWX = true;
if (typeof navigator !== "undefined" && navigator.userAgent) {
var ua = navigator.userAgent.toLowerCase();
isIOS = IOS_REGEX.test(ua);
isAndroid = ANDROID_REGEX.test(ua);
isStudent = ua.indexOf("alo7student") !== -1;
isTeacher = ua.indexOf("axt_teacher") !== -1;
}
if (isIOS) {
if (isStudent) return "ALO7_APP_STUDENT_IOS";
if (isTeacher) return "ALO7_APP_TEACHER_IOS";
}
if (isAndroid) {
if (isStudent) return "ALO7_APP_STUDENT_ANDROID";
if (isTeacher) return "ALO7_APP_TEACHER_ANDROID";
}
if (isWX && wx.getSystemInfoSync) {
var systemInfo = wx.getSystemInfoSync();
if (systemInfo && systemInfo.platform === "devtools") {
return "WX_DEVTOOLS";
} else if (systemInfo && (systemInfo.platform === "ios" || systemInfo.platform === "android")) {
return "WX_MINI_PROGRAM";
}
}
if (isWX && wx.qy) return "WX_WXWORK";
if (isWX && global.__wxjs_environment === "miniprogram") return "WX_MINI_PROGRAM_WEBVIEW";
if (isWX && typeof wx.miniProgram !== "undefined") return "WX_WEB";
if (typeof window !== "undefined" && typeof document !== "undefined") {
return "WEB";
}
return "UNKNOWN";
};
module1.exports = runtimeEnv;
if (__exports != exports1) module1.exports = exports1;
return module1.exports;
});
//# sourceMappingURL=index.umd.js.map