
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
true-device
Advanced tools
npm install true-device
import { getDevice } from 'true-device';
const device = getDevice();
console.log(device);
// {
// type: 'desktop',
// os: { name: 'Windows', version: '10' },
// browser: { name: 'Edge', version: '142.0.0.0' },
// isTouchDevice: false,
// screenWidth: 1920,
// screenHeight: 1080,
// userAgent: '...'
// }
import { getDevice } from 'true-device';
const device = getDevice();
if (device.type === 'mobile') {
document.body.classList.add('mobile-layout');
} else if (device.type === 'tablet') {
document.body.classList.add('tablet-layout');
} else {
document.body.classList.add('desktop-layout');
}
import { getDevice } from 'true-device';
const device = getDevice();
if (device.isTouchDevice) {
document.addEventListener('touchstart', handleTouchStart);
} else {
document.addEventListener('mousedown', handleMouseDown);
}
import { getDevice } from 'true-device';
const device = getDevice();
if (device.os.name === 'iOS') {
showIOSInstallPrompt();
} else if (device.os.name === 'Android') {
showAndroidInstallPrompt();
}
getDevice(): DeviceInfoส่งคืนข้อมูลอุปกรณ์ทั้งหมด
interface DeviceInfo {
type: 'mobile' | 'tablet' | 'desktop';
os: { name: string; version: string; };
browser: { name: string; version: string; };
isTouchDevice: boolean;
screenWidth: number;
screenHeight: number;
userAgent: string;
}
import { checkPlatform, checkOS, checkBrowser, checkTouch } from 'true-device';
const type = checkPlatform(); // 'mobile' | 'tablet' | 'desktop'
const os = checkOS(); // { name: 'iOS', version: '17.0' }
const browser = checkBrowser(); // { name: 'Chrome', version: '142.0' }
const hasTouch = checkTouch(); // true | false
true-device ใช้หลายวิธีร่วมกัน:
'ontouchstart' in window, navigator.maxTouchPointswindow.screen.width/heightnavigator.platform// iPad (iOS 13+) รายงาน platform เป็น "MacIntel" แต่มี maxTouchPoints > 1
const isIPad = navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1;
import { getDevice } from 'true-device';
import { useState, useEffect } from 'react';
function App() {
const [device, setDevice] = useState(getDevice());
useEffect(() => {
const handleResize = () => setDevice(getDevice());
window.addEventListener('resize', handleResize);
return () => window.removeEventListener('resize', handleResize);
}, []);
return (
<div className={`app app--${device.type}`}>
{device.type === 'mobile' ? <MobileNav /> : <DesktopNav />}
</div>
);
}
MIT © rratchapol
FAQs
Accurate device detection library that goes beyond user-agent string
The npm package true-device receives a total of 2 weekly downloads. As such, true-device popularity was classified as not popular.
We found that true-device demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.