Provides utility methods for working with user agent strings.





  • Determines whether a given user agent string belongs to a bot.

    This method checks the user agent string for common bot-related keywords such as 'bot', 'crawl', 'spider', and 'slurp'. It's a simple heuristic approach and may not cover all cases or be 100% accurate.


    • userAgent: string

      The user agent string to check. This is typically the value of the User-Agent HTTP header sent by browsers, crawlers, or other HTTP clients.

    Returns boolean

    true if the user agent string contains any of the bot-related keywords, indicating it might be a bot; false otherwise.

    Example usage:

    if (UserAgents.isBot(request.headers['user-agent'])) {
    console.log('This request is likely from a bot');
    } else {
    console.log('This request is likely from a human user');