The `robot-directives` package (current stable version 0.4.0) provides a focused utility for parsing and interpreting robot directives found within HTML `<meta name="robots">` tags and `X-Robots-Tag` HTTP headers. It allows developers to programmatically determine a crawler's allowed or disallowed actions based on these instructions, such as `noindex`, `nofollow`, `noarchive`, and `unavailable_after`. The library handles the cascading logic of multiple directives, user-agent specific rules, and resolves conflicts based on a `restrictive` default (mimicking Googlebot's behavior). It explicitly differentiates itself by not handling the underlying HTML parsing, requiring users to extract meta tag content themselves. While not on a rapid release cycle, the package offers a stable API for its specialized parsing tasks, including a comprehensive set of constants for all standard robot directives and static methods for general utility.
npm install robot-directivesVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to instantiate `RobotDirectives`, add directives from HTTP headers and HTML meta tags, and then query their state using `is()` with specific user agents and time overrides. It also shows the usage of the static `isBot()` helper.
If you require 'all' to be an absolute override, set `allIsReadonly: false` in the constructor options. Be aware this deviates from common crawler behavior.
If your target crawler doesn't follow restrictive conflict resolution, set `restrictive: false` in the constructor options. You may then need to implement custom conflict resolution logic.
Ensure `currentTime` in the constructor options or `is()` method options accurately reflects the desired current time, especially when dealing with dates and time zones.
Use a dedicated HTML parser (e.g., `cheerio`, `jsdom`) to extract the meta tag content before passing it to `robot-directives`.
For CommonJS, use `const RobotDirectives = require('robot-directives');`. For ESM, use `import RobotDirectives from 'robot-directives';`.If in an ESM file (e.g., `type: module` in `package.json`), use `import RobotDirectives from 'robot-directives';` instead of `const RobotDirectives = require('robot-directives');`.Review the constructor options for `allIsReadonly` (default `true`) and `restrictive` (default `true`). Adjust them in the `new RobotDirectives(options)` call if the default behavior doesn't match your expectations.
No dependency data recorded yet.