$ show nuxt-modules/device
This is a Nuxt module for device detection that provides a reactive `$device` object and `useDevice()` composable. It determines device type (mobile, tablet, desktop), operating system (iOS, Android, Windows, macOS, Linux), browser (Chrome, Firefox, Edge, Safari, Samsung), and crawler status by parsing the User-Agent header and/or CDN-provided headers (Amazon CloudFront, Cloudflare). The core detection logic is encapsulated in `src/runtime/generateFlags.ts`, which is a standalone, well-tested function. The module is built for Nuxt 3+ (ESM-only) and uses `crawler-user-agents` for crawler detection with a build-time generated regex for performance. The codebase is small, focused, and demonstrates good engineering practices with clean separation of concerns, comprehensive tests, and proper use of Nuxt module APIs.
The LLM identified 1 files worth highlighting for reuse:
A self-contained function `generateFlags(userAgent, headers)` that takes a User-Agent string and optional HTTP headers and returns a `Device` object with all boolean flags (isMobile, isTablet, isDesktop, isAndroid, isIos, isWindows, isMacOS, isLinux, isApple, isSafari, isFirefox, isEdge, isChrome, isSamsung, isCrawler). It implements logic for standard UA regex matching, Amazon CloudFront headers, Cloudflare device type headers, and browser detection. This function has zero internal dependencies aside from a build-time generated regex, making it easily extractable into a standalone npm package for device detection in any JavaScript environment.