UNPKG

@jswork/runtime-env

Version:

Runtime-env is a JS library for detecting environments like Web, WeChat MiniProgram, and JSSDK.

51 lines 1.94 kB
/*! * 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 */ // 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"; }; var index_default = runtimeEnv; export { index_default as default }; //# sourceMappingURL=index.esm.js.map