From 5e4280d8e0f9dd73245433d86063e3b218cf4fd9 Mon Sep 17 00:00:00 2001 From: rshtg Date: Thu, 13 Jun 2019 17:35:27 +0300 Subject: [PATCH 1/3] add argument to the detect --- src/index.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 502cefd..a1e8b9e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -153,11 +153,15 @@ const operatingSystemRules: OperatingSystemRule[] = [ ['Search Bot', SEARCHBOT_OS_REGEX], ]; -export function detect(): BrowserInfo | BotInfo | NodeInfo | null { +export function detect(userAgent: string | null = null): BrowserInfo | BotInfo | NodeInfo | null { if (typeof navigator !== 'undefined') { return parseUserAgent(navigator.userAgent); } + if (userAgent) { + return parseUserAgent(userAgent); + } + return getNodeVersion(); } From 9736d62970978571196c74729c23dbd420d6d636 Mon Sep 17 00:00:00 2001 From: rshtg Date: Mon, 1 Jul 2019 16:40:29 +0300 Subject: [PATCH 2/3] add not specified userAgent for detect method --- src/index.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/index.ts b/src/index.ts index a1e8b9e..3b8d32c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -153,15 +153,15 @@ const operatingSystemRules: OperatingSystemRule[] = [ ['Search Bot', SEARCHBOT_OS_REGEX], ]; -export function detect(userAgent: string | null = null): 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); } - if (userAgent) { - return parseUserAgent(userAgent); - } - return getNodeVersion(); } From 815cf7dc4e7de9f7bc18a09146d3f152c24d7def Mon Sep 17 00:00:00 2001 From: rshtg Date: Mon, 1 Jul 2019 16:50:23 +0300 Subject: [PATCH 3/3] remove traling whitespace --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 3b8d32c..f0c67ab 100644 --- a/src/index.ts +++ b/src/index.ts @@ -157,7 +157,7 @@ export function detect(userAgent?: string): BrowserInfo | BotInfo | NodeInfo | n if (!!userAgent) { return parseUserAgent(userAgent); } - + if (typeof navigator !== 'undefined') { return parseUserAgent(navigator.userAgent); }