fn

testUserAgentPlatform

v0.0.5tested

Tests navigator.platform against a regular expression, guarding for non-browser environments. Returns undefined when there is no navigator (e.g. during SSR) so callers can distinguish "no" from "unknown".

Example

ts
const onMac = testUserAgentPlatform(/^Mac/);

Signature

ts
export function testUserAgentPlatform(re: RegExp): boolean | undefined{ ... }

Parameters

ParameterTypeDescription
reRegExpThe pattern to test navigator.platform against

Returns

boolean | undefinedThe match result, or undefined outside a browser