which-bot
TypeScript icon, indicating that this package has built-in type declarations

1.1.3 • Public • Published

which-spider

detect which spider is from user-agent

Usage

npm install which-bot
# OR
yarn add which-bot
import { parse } from 'which-bot';

parse(
    'Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; Googlebot/2.1; +http://www.google.com/bot.html) Chrome/W.X.Y.Z Safari/537.36'
) // => { name: 'googlebot', compant: 'google', mobile: false }

parse(
    'Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5X Build/MMB29P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/W.X.Y.Z Mobile Safari/537.36 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)'
) // => { name: 'googlebot', compant: 'google', mobile: true }

await parse(
    'Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; Googlebot/2.1; +http://www.google.com/bot.html) Chrome/W.X.Y.Z Safari/537.36',
    '66.249.66.1'
) // => { name: 'googlebot', compant: 'google', mobile: false, valid: true }

await parse(
    'Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; Googlebot/2.1; +http://www.google.com/bot.html) Chrome/W.X.Y.Z Safari/537.36',
    '1.1.1.1'
) // => { name: 'googlebot', compant: 'google', mobile: false, valid: false }

API Reference

const RULES

type RULES = Array<{
    company: string;
    pattern: RegExp;
    hosts?: string[];
    bots: Array<{
        name: string;
        pattern: RegExp;
    }>
}>

parse(ua: string)

interface BotItem {
    name: string;
    company: string;
    mobile: boolean;
}

async parse(ua: string, ip: string)

{
    name: string;
    company: string;
    mobile: boolean;
    valid: boolean;
}

is(company: string, us: string)

interface BotItem {
    name: string;
    company: string;
    mobile: boolean;
}

async is(name: string, ua: string, ip: string)

{
    name: string;
    company: string;
    mobile: boolean;
    valid: boolean;
}

Package Sidebar

Install

npm i which-bot

Weekly Downloads

18

Version

1.1.3

License

MIT

Unpacked Size

32 kB

Total Files

15

Last publish

Collaborators

  • yeliex