@eternaljs/user-agent
Version:
A user agent request is a string of text that identifies the client software requesting online content.
19 lines (17 loc) • 594 B
text/typescript
const useragent = require('express-useragent')
function getRequestType(userAgent: Record<string, any>) {
if (userAgent?.isMobile) return "mobile"
if (userAgent?.isTablet) return "tablet"
return "web"
}
export function userAgent(agent: string) {
const userAgent = useragent.parse(agent)
return {
browser: userAgent?.browser || "",
version: userAgent?.version || "",
os: userAgent?.os || "",
platform: userAgent?.platform || "",
source: userAgent?.source || "",
type: getRequestType(userAgent) || "",
}
}