Modules@robinpath/robots
robots

@robinpath/robots

0.1.1Node.jsPublic

robots.txt parsing, generation, URL permission checking, and crawl configuration

Robots

robots.txt parsing, generation, URL permission checking, and crawl configuration

Package: @robinpath/robots | Category: Web | Type: Utility

Authentication

No authentication required. All functions are available immediately.

Use Cases

Use the robots module when you need to:

  • Parse robots.txt content -- Use robots.parse to perform this operation
  • Generate robots.txt -- Use robots.create to perform this operation
  • Check if URL is allowed -- Use robots.isAllowed to perform this operation
  • Check if URL is disallowed -- Use robots.isDisallowed to perform this operation
  • Get crawl delay for agent -- Use robots.getCrawlDelay to perform this operation

Quick Reference

FunctionDescriptionReturns
parseParse robots.txt content{rules[], sitemaps[], host}
createGenerate robots.txtrobots.txt content
isAllowedCheck if URL is allowedtrue if allowed
isDisallowedCheck if URL is disallowedtrue if disallowed
getCrawlDelayGet crawl delay for agentDelay in seconds or null
getSitemapsGet sitemap URLsSitemap URLs
getRulesGet rules for agentMatching rules
addRuleAdd rule to robots configUpdated config
removeRuleRemove rule by user agentUpdated config
addSitemapAdd sitemap URLUpdated config
allowAllGenerate allow-all robots.txtrobots.txt
disallowAllGenerate disallow-all robots.txtrobots.txt
fetchFetch and parse robots.txt from URL{found, status, parsed, raw}

Functions

parse

Parse robots.txt content

Module: robots | Returns: object -- {rules[], sitemaps[], host}

robots.parse $text
ParameterTypeRequiredDescription
textstringYesrobots.txt content

create

Generate robots.txt

Module: robots | Returns: string -- robots.txt content

robots.create {"rules": [{"userAgent": "*", "disallow": ["/admin"]}]}
ParameterTypeRequiredDescription
configobjectYes{rules[], sitemaps[], host}

isAllowed

Check if URL is allowed

Module: robots | Returns: boolean -- true if allowed

robots.isAllowed $robots "/page" "Googlebot"
ParameterTypeRequiredDescription
robotsobjectYesParsed robots or raw text
urlstringYesURL or path
userAgentstringNoBot name (default *)

isDisallowed

Check if URL is disallowed

Module: robots | Returns: boolean -- true if disallowed

robots.isDisallowed $robots "/admin"
ParameterTypeRequiredDescription
robotsobjectYesParsed robots or raw text
urlstringYesURL or path
userAgentstringNoBot name

getCrawlDelay

Get crawl delay for agent

Module: robots | Returns: number -- Delay in seconds or null

robots.getCrawlDelay $robots "Googlebot"
ParameterTypeRequiredDescription
robotsobjectYesParsed robots
userAgentstringNoBot name

getSitemaps

Get sitemap URLs

Module: robots | Returns: array -- Sitemap URLs

robots.getSitemaps $robots
ParameterTypeRequiredDescription
robotsobjectYesParsed robots

getRules

Get rules for agent

Module: robots | Returns: array -- Matching rules

robots.getRules $robots "Googlebot"
ParameterTypeRequiredDescription
robotsobjectYesParsed robots
userAgentstringNoBot name (all if omitted)

addRule

Add rule to robots config

Module: robots | Returns: object -- Updated config

robots.addRule $robots {"userAgent": "BadBot", "disallow": ["/"]}
ParameterTypeRequiredDescription
robotsobjectYesParsed robots
ruleobjectYes{userAgent, allow[], disallow[], crawlDelay}

removeRule

Remove rule by user agent

Module: robots | Returns: object -- Updated config

robots.removeRule $robots "BadBot"
ParameterTypeRequiredDescription
robotsobjectYesParsed robots
userAgentstringYesBot name

addSitemap

Add sitemap URL

Module: robots | Returns: object -- Updated config

robots.addSitemap $robots "https://example.com/sitemap.xml"
ParameterTypeRequiredDescription
robotsobjectYesParsed robots
urlstringYesSitemap URL

allowAll

Generate allow-all robots.txt

Module: robots | Returns: string -- robots.txt

robots.allowAll
ParameterTypeRequiredDescription
userAgentstringNoBot name (default *)

disallowAll

Generate disallow-all robots.txt

Module: robots | Returns: string -- robots.txt

robots.disallowAll
ParameterTypeRequiredDescription
userAgentstringNoBot name (default *)

fetch

Fetch and parse robots.txt from URL

Module: robots | Returns: object -- {found, status, parsed, raw}

robots.fetch "https://example.com"
ParameterTypeRequiredDescription
urlstringYesSite URL

Error Handling

All functions throw on failure. Common errors:

ErrorCause
(standard errors)Check function parameters and authentication
@desc "Parse and validate result"
do
  set $result as robots.parse $text
  if $result != null
    print "Success"
  else
    print "No result"
  end
enddo

Recipes

1. List and iterate CrawlDelay

Retrieve all items and loop through them.

@desc "Get crawl delay and iterate results"
do
  set $result as robots.getCrawlDelay $robots "Googlebot"
  each $item in $result
    print $item
  end
enddo

2. Create a new item with create

Create a new resource and capture the result.

set $result as robots.create {"rules": [{"userAgent": "*", "disallow": ["/admin"]}]}
print "Created: " + $result

3. Check before creating

List existing items and only create if needed.

@desc "Get crawl delay and create"
do
  set $existing as robots.getCrawlDelay $robots "Googlebot"
  if $existing == null
    robots.create {"rules": [{"userAgent": "*", "disallow": ["/admin"]}]}
    print "Item created"
  else
    print "Item already exists"
  end
enddo

4. Multi-step Robots workflow

Chain multiple robots operations together.

@desc "Parse, create, and more"
do
  set $r_parse as robots.parse $text
  set $r_create as robots.create {"rules": [{"userAgent": "*", "disallow": ["/admin"]}]}
  set $r_isAllowed as robots.isAllowed $robots "/page" "Googlebot"
  print "All operations complete"
enddo

5. Safe parse with validation

Check results before proceeding.

@desc "Parse and validate result"
do
  set $result as robots.parse $text
  if $result != null
    print "Success: " + $result
  else
    print "Operation returned no data"
  end
enddo

Related Modules

  • json -- JSON module for complementary functionality

Versions (1)

VersionTagPublished
0.1.1latest1 months ago
Install
$ robinpath add @robinpath/robots

Collaborators

Dumitru Balaban
Dumitru Balaban
@dumitru
View all @robinpath modules
Version0.1.1
LicenseMIT
Unpacked Size5.5 KB
Versions1
Weekly Downloads21
Total Downloads21
Stars0
Last Publish1 months ago
Created1 months ago

Keywords

Category

web