Device detection library that analyzes User-Agent strings to identify mobile devices, tablets, phones, operating systems, browsers, and device capabilities
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Core device identification functionality for determining device types and manufacturers through User-Agent string analysis.
Detects if the User-Agent represents a mobile device and returns the manufacturer/family name.
/**
* Returns the detected mobile device type/family string or null
* @returns The mobile device manufacturer (e.g., 'Sony', 'Samsung', 'iPhone') or null if not mobile
* Possible values: Any phone or tablet key, 'UnknownPhone', 'UnknownTablet', 'UnknownMobile', or null
*/
mobile(): string | null;Usage Examples:
const MobileDetect = require('mobile-detect');
// iPhone detection
const iphoneMd = new MobileDetect('Mozilla/5.0 (iPhone; CPU iPhone OS 14_0 like Mac OS X)');
console.log(iphoneMd.mobile()); // 'iPhone'
// Samsung Android detection
const samsungMd = new MobileDetect('Mozilla/5.0 (Linux; Android 11; SM-G991B)');
console.log(samsungMd.mobile()); // 'Samsung'
// Desktop detection
const desktopMd = new MobileDetect('Mozilla/5.0 (Windows NT 10.0; Win64; x64)');
console.log(desktopMd.mobile()); // nullSpecifically detects phone devices (excluding tablets) and returns the manufacturer/family.
/**
* Returns the detected phone type/family string or null
* @returns The phone manufacturer (e.g., 'iPhone', 'Samsung', 'HTC') or null if not a phone
*/
phone(): string | null;Detected Phone Families:
Usage Examples:
// iPhone detection
const md1 = new MobileDetect('Mozilla/5.0 (iPhone; CPU iPhone OS 15_0 like Mac OS X)');
console.log(md1.phone()); // 'iPhone'
// Samsung phone detection
const md2 = new MobileDetect('Mozilla/5.0 (Linux; Android 12; SM-G998B)');
console.log(md2.phone()); // 'Samsung'
// iPad (tablet, not phone)
const md3 = new MobileDetect('Mozilla/5.0 (iPad; CPU OS 15_0 like Mac OS X)');
console.log(md3.phone()); // null
console.log(md3.tablet()); // 'iPad'Detects tablet devices and returns the manufacturer/family name.
/**
* Returns the detected tablet type/family string or null
* @returns The tablet manufacturer (e.g., 'iPad', 'Samsung', 'Nexus') or null if not a tablet
*/
tablet(): string | null;Detected Tablet Families:
Usage Examples:
// iPad detection
const md1 = new MobileDetect('Mozilla/5.0 (iPad; CPU OS 15_0 like Mac OS X)');
console.log(md1.tablet()); // 'iPad'
// Samsung tablet detection
const md2 = new MobileDetect('Mozilla/5.0 (Linux; Android 12; SM-T870)');
console.log(md2.tablet()); // 'SamsungTablet'
// Phone (not tablet)
const md3 = new MobileDetect('Mozilla/5.0 (iPhone; CPU iPhone OS 15_0 like Mac OS X)');
console.log(md3.tablet()); // null
console.log(md3.phone()); // 'iPhone'Determines if a device should be considered phone-sized based on screen dimensions (browser environments only).
/**
* Checks whether the mobile device can be considered as phone regarding screen width
* @param maxPhoneWidth - Optional maximum logical pixels to be considered as phone.
* If not provided, uses constructor maxPhoneWidth (default: 600)
* @returns true if screen width <= maxPhoneWidth, false otherwise,
* undefined if screen size not detectable (server-side environments)
*/
isPhoneSized(maxPhoneWidth?: number): boolean | undefined;
/**
* Static version of isPhoneSized method for current screen
* @param maxPhoneWidth - Maximum logical pixels to be considered as phone (required for static version)
* @returns true if current screen width <= maxPhoneWidth, false otherwise,
* undefined in server-side environments (no window.screen access)
*/
static isPhoneSized(maxPhoneWidth?: number): boolean | undefined;Usage Examples:
// Instance method - uses constructor maxPhoneWidth or 600px default
const md = new MobileDetect(navigator.userAgent, 768);
console.log(md.isPhoneSized()); // true/false/undefined
// Instance method - override maxPhoneWidth
console.log(md.isPhoneSized(480)); // true/false/undefined
// Static method - check current screen
console.log(MobileDetect.isPhoneSized(600)); // true/false/undefined
// Server-side usage
const serverMd = new MobileDetect(req.headers['user-agent']);
console.log(serverMd.isPhoneSized()); // undefined (no screen access)The library detects devices across these major categories: