From ae862966db1a2d4336dbf4811f9dc68755e6b67d Mon Sep 17 00:00:00 2001 From: Rishat Gabaydullov Date: Mon, 8 Jul 2019 02:55:11 +0300 Subject: [PATCH] add ability to pass useragent string to the detect function (#114) --- src/index.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 502cefd..f0c67ab 100644 --- a/src/index.ts +++ b/src/index.ts @@ -153,7 +153,11 @@ const operatingSystemRules: OperatingSystemRule[] = [ ['Search Bot', SEARCHBOT_OS_REGEX], ]; -export function detect(): BrowserInfo | BotInfo | NodeInfo | null { +export function detect(userAgent?: string): BrowserInfo | BotInfo | NodeInfo | null { + if (!!userAgent) { + return parseUserAgent(userAgent); + } + if (typeof navigator !== 'undefined') { return parseUserAgent(navigator.userAgent); }