docs
evals
scenario-1
scenario-10
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
Build a device information analyzer that processes user agent strings to extract and categorize platform details for analytics purposes.
Create a module that exports a function analyzeDevice(userAgent) which:
Extracts Platform Details: Parse the user agent string to determine the device's platform type (desktop, mobile, tablet, tv, or bot)
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)
Returns Structured Data: Return an object containing:
platformType: The platform type as a stringvendor: 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/crawlerHandles Invalid Input: Return null for invalid or empty user agent strings
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
/**
* 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 };Provides browser and device detection support