Recognise bots/crawlers/spiders using the user agent string.
82
Build utilities that let callers create lightweight bot detectors from custom patterns using the bot-detection dependency.
createBotDetector accepts a regex string "CrawlerX|TestBot" and returns a detector returning true for "Mozilla/5.0 TestBot/1.0" and false for "Mozilla/5.0 Safari/537.36". @testRegExp object works the same way, matching the provided pattern against the user agent. @testcreateDetectorFromList accepts ["FooBot","ScanAPI"] and returns a detector returning true for "ScanAPI Monitor" and false for "Mozilla/5.0 Chrome/114.0". @testfalse when invoked with an empty string, undefined, or null instead of throwing. @test@generates
/**
* Builds a detector from a regex string or RegExp that is evaluated against user agent strings.
*
* @param {string|RegExp} patternSource
* @returns {(userAgent: string | null | undefined) => boolean}
*/
export function createBotDetector(patternSource);
/**
* Builds a detector from an array of pattern strings that are combined into a regex.
*
* @param {string[]} patterns
* @returns {(userAgent: string | null | undefined) => boolean}
*/
export function createDetectorFromList(patterns);Provides bot detection helpers for compiling custom bot matchers from regex inputs.
Install with Tessl CLI
npx tessl i tessl/npm-isbot