UNPKG

@sandlada/vue-mdc

Version:

![Vue MDC Logo](https://raw.githubusercontent.com/sandlada/vue-mdc/refs/heads/main/docs/vue-mdc-cover.png)

63 lines (62 loc) 1.61 kB
/** * @license * Copyright 2024 glare-labs & bre97-web * SPDX-License-Identifier: MIT */ function detectPlatform(uaString) { const ua = (uaString || (typeof navigator !== "undefined" ? navigator.userAgent : "")).toLowerCase(); let type = "unknown"; let isMobile = false; let isDesktop = false; if (!ua) { return { type, isMobile, isDesktop, userAgent: ua }; } if (/\b(iphone|ipad|ipod)/.test(ua) || ua.includes("macintosh") && typeof navigator !== "undefined" && navigator.maxTouchPoints > 1) { type = "ios"; isMobile = true; } else if (/\bandroid\b/.test(ua)) { type = "android"; isMobile = true; } else if (/\b(windows|linux|macintosh|cros)\b/.test(ua) && // Added cros for Chrome OS !/\bandroid\b/.test(ua)) { if (!/\b(iphone|ipad|ipod|tablet|mobile|opera mini|iemobile|wpdesktop|windows phone)\b/.test(ua)) { type = "desktop"; isDesktop = true; } else { if (/\b(tablet|mobile|opera mini|iemobile|wpdesktop|windows phone)\b/.test(ua)) { isMobile = true; } else { type = "desktop"; isDesktop = true; } } } if (isMobile) { isDesktop = false; } else if (isDesktop) { isMobile = false; } if (type === "unknown" && /\bmobile\b/.test(ua)) { isMobile = true; isDesktop = false; } if (type === "unknown" && !isMobile && typeof navigator !== "undefined") { type = "desktop"; isDesktop = true; } return { type, isMobile, isDesktop, userAgent: ua }; } export { detectPlatform }; //# sourceMappingURL=platform.js.map