node-lib

@wtasnorg/node-lib


@wtasnorg/node-lib / parseUserAgent

Function: parseUserAgent()

parseUserAgent(ua): UserAgentInfo

Defined in: user-agent.ts:48

Parses a user-agent string into a UserAgentInfo object.

Parameters

ua

string

The user-agent string to parse.

Returns

UserAgentInfo

An object containing the extracted information.

Examples

// Success Example (Chrome on Windows)
const ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36";
const info = parseUserAgent(ua);
// { browser: "Chrome", version: "120.0.0.0", os: "Windows", device: "Desktop", engine: "Blink" }
// Error/Fallback Example (Empty string)
const info = parseUserAgent("");
// { browser: "Other", version: "0", os: "Other", device: "Desktop", engine: "Other" }