or run

npx @tessl/cli init
Log in

Version

Files

tile.json

task.mdevals/scenario-3/

Device Information Analyzer

Build a device information analyzer that processes user agent strings to extract and categorize platform details for analytics purposes.

Requirements

Create a module that exports a function analyzeDevice(userAgent) which:

  1. Extracts Platform Details: Parse the user agent string to determine the device's platform type (desktop, mobile, tablet, tv, or bot)

  2. Identifies Device Vendor and Model: When available, extract the device vendor (e.g., Apple, Huawei, Samsung) and specific device model (e.g., iPhone, iPad, Kindle Fire)

  3. Returns Structured Data: Return an object containing:

    • platformType: The platform type as a string
    • vendor: The device vendor (or null if not detected)
    • model: The device model (or null if not detected)
    • isBot: A boolean indicating if the device is a bot/crawler
  4. Handles Invalid Input: Return null for invalid or empty user agent strings

Test Cases

  • When given an iPhone user agent string, it returns platform type "mobile", vendor "Apple", and model "iPhone" @test

  • When given an iPad user agent string, it returns platform type "tablet", vendor "Apple", and model "iPad" @test

  • When given a desktop Chrome user agent string, it returns platform type "desktop" with vendor and model as null @test

  • When given a bot user agent string (e.g., Googlebot), it returns isBot as true and platform type "bot" @test

Implementation

@generates

API

/**
 * Analyzes a user agent string to extract device platform information
 * @param {string} userAgent - The user agent string to analyze
 * @returns {Object|null} Device information object or null if invalid
 */
function analyzeDevice(userAgent) {
  // Implementation here
}

module.exports = { analyzeDevice };

Dependencies { .dependencies }

bowser { .dependency }

Provides browser and device detection support