
Security News
ECMAScript 2025 Finalized with Iterator Helpers, Set Methods, RegExp.escape, and More
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
@livepixie-open/device-detector
Advanced tools
A Server-Side Rendering (SSR) library to detect Material UI breakpoints from user agent.
π Framework-agnostic device detection for Node.js with Material UI breakpoint mapping for SSR and client-side usage.
xs
, sm
, md
, etc.) for responsive design.ua-parser-js
for minimal overhead and high performance.Install the package using your preferred package manager:
# Using pnpm
pnpm add @livepixie-open/device-detector
# Using npm
npm install @livepixie-open/device-detector
# Using yarn
yarn add @livepixie-open/device-detector
import { detectDevice } from "@livepixie-open/device-detector";
const userAgent = "Mozilla/5.0 (iPhone; CPU iPhone OS 15_0 like Mac OS X)";
const device = detectDevice(userAgent);
console.log(device);
// Output:
// {
// type: "mobile",
// breakpoint: "xs",
// userAgent: "Mozilla/5.0 (iPhone; CPU iPhone OS 15_0 like Mac OS X)",
// model: "iPhone"
// }
The library supports detection for a wide range of devices. Here are some examples:
// Desktop
console.log(detectDevice("Mozilla/5.0 (Windows NT 10.0; Win64; x64)"));
// Output: { type: "desktop", breakpoint: "md", userAgent: "...", model: undefined }
// Tablet
console.log(detectDevice("Mozilla/5.0 (iPad; CPU OS 15_0 like Mac OS X)"));
// Output: { type: "tablet", breakpoint: "sm", userAgent: "...", model: "iPad" }
// Mobile
console.log(detectDevice("Mozilla/5.0 (Linux; Android 12; Samsung Galaxy Z Fold3)"));
// Output: { type: "mobile", breakpoint: "sm", userAgent: "...", model: "Samsung Galaxy Z Fold3" }
import { detectDevice } from "@livepixie-open/device-detector";
export const getServerSideProps = (context) => {
const userAgent = context.req.headers["user-agent"] || "";
const device = detectDevice(userAgent);
return {
props: {
device,
},
};
};
export default function Home({ device }) {
return (
<div>
<h1>Your device: {device.type}</h1>
<p>Breakpoint: {device.breakpoint}</p>
</div>
);
}
import express from "express";
import { detectDevice } from "@livepixie-open/device-detector";
const app = express();
app.use((req, res, next) => {
const userAgent = req.headers["user-agent"] || "";
req.device = detectDevice(userAgent);
next();
});
app.get("/", (req, res) => {
res.send(`Your device: ${req.device.type}, Breakpoint: ${req.device.breakpoint}`);
});
app.listen(3000, () => console.log("Server running on http://localhost:3000"));
pnpm install
pnpm lint
pnpm test
pnpm build
pnpm publish --access public
detectDevice(userAgent: string): DeviceInfo
Detects the device type and maps it to a Material UI breakpoint.
userAgent
: The user-agent string to analyze.An object with the following properties:
type
: The device type ("mobile"
, "tablet"
, or "desktop"
).breakpoint
: The corresponding Material UI breakpoint ("xs"
, "sm"
, "md"
, etc.).userAgent
: The original user-agent string.model
: The device model (if available).If the library encounters an unknown or unsupported user-agent string, it will default to:
{ "type": "desktop", "breakpoint": "md", "userAgent": "..." }
You can extend the library to support custom breakpoint mappings by modifying the source code or opening a feature request.
MIT License Β© 2025 Live Pixie Open Source
We welcome contributions! Hereβs how you can help:
Weβd love to hear your feedback! Reach out to us via:
π₯ Happy Coding! π
detectDevice
function.FAQs
A Server-Side Rendering (SSR) library to detect Material UI breakpoints from user agent.
We found that @livepixie-open/device-detector demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.Β It has 0 open source maintainers 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
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.
Research
North Korean threat actors linked to the Contagious Interview campaign return with 35 new malicious npm packages using a stealthy multi-stage malware loader.