npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

google-robotstxt-parser

v1.2.0

Published

Pure JavaScript port of Google's robots.txt parser (google/robotstxt). Works in Node.js and the browser.

Readme

google-robotstxt-parser

npm version npm downloads license

Live Demo

A pure JavaScript port of Google's official robotstxt C++ library. Runs in both Node.js and the browser with no dependencies.

Implements the same parsing rules, typo tolerance, and URL-matching logic that Google's own crawler uses to evaluate robots.txt files.

Installation

npm install google-robotstxt-parser

Usage

import { RobotsMatcher } from 'google-robotstxt-parser';

const matcher = new RobotsMatcher();
const robotsContent = `
User-agent: *
Dissallow: /secret/   # Typo accepted by Google!
`;

const isAllowed = matcher.allowedByRobots(robotsContent, ['Googlebot'], 'https://example.com/secret/page');
console.log(isAllowed); // false

Check a single user-agent

const allowed = matcher.oneAgentAllowedByRobots(robotsContent, 'Googlebot', 'https://example.com/public/');
console.log(allowed); // true

Check multiple user-agents at once

allowedByRobots accepts an array — the URL is blocked if any of the agents is disallowed.

const allowed = matcher.allowedByRobots(robotsContent, ['Googlebot', 'Bingbot'], 'https://example.com/page');

API

RobotsMatcher

| Method | Description | |---|---| | allowedByRobots(robotsTxt, userAgents, url) | Returns true if the URL is accessible to at least one of the given user-agents. | | oneAgentAllowedByRobots(robotsTxt, userAgent, url) | Convenience wrapper for a single user-agent string. | | disallow() | Returns the raw disallow decision after a parse (useful after calling allowedByRobots). | | everSeenSpecificAgent() | true if the parsed file contained a rule group for the queried agent specifically. | | matchingLine() | Line number of the winning allow/disallow rule, or 0 if none matched. |

parseRobotsTxt(robotsBody, handler)

Low-level parser. Pass a RobotsParseHandler subclass to react to individual directives without running the full matcher.

import { parseRobotsTxt, RobotsParseHandler } from 'google-robotstxt-parser';

class MyHandler extends RobotsParseHandler {
  handleDisallow(lineNum, value) {
    console.log(`Line ${lineNum}: Disallow ${value}`);
  }
}

parseRobotsTxt(robotsContent, new MyHandler());

Compatibility with Google's parser

This library matches Google's behaviour in several ways that differ from a naive implementation:

  • Typo tolerance — common misspellings like Dissallow, Disalow, User agent are accepted.
  • Pattern priority — longer patterns win over shorter ones, regardless of order.
  • Specific agent beats wildcard — if the robots.txt contains a group for the queried agent, the User-agent: * group is ignored entirely for that agent.
  • URL normalisation — non-ASCII characters in allow/disallow patterns are percent-encoded to match Google's canonicalisation.
  • UTF-8 BOM — silently stripped at the start of the file.
  • Line length cap — lines longer than ~16 KB are truncated, matching the C++ implementation.

/index.html and /index.htm normalisation

When an Allow pattern ends in /index.html or /index.htm but does not match the requested URL, Google's parser applies a Google-specific fallback: the pattern is re-evaluated as the parent directory path anchored with $ — i.e. /dir/index.html is re-tried as /dir/$. This means the rule grants access to the exact directory URL (/dir/) but not to arbitrary paths beneath it or to /dir/index.htm (without the trailing l). It is therefore more precise than a plain Allow: /dir/ prefix match. This behaviour is inherited directly from the upstream C++ implementation (robots.cc) and is verified by the GoogleOnly_IndexHTMLisDirectory test.

Browser usage

The library is a standard ES module with no Node.js-specific APIs, so it works directly in the browser:

<script type="module">
  import { RobotsMatcher } from './robots.js';

  const matcher = new RobotsMatcher();
  console.log(matcher.oneAgentAllowedByRobots('User-agent: *\nDisallow: /', 'MyBot', 'https://example.com/'));
</script>

License

Apache 2.0 — same as the upstream google/robotstxt repository.