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 🙏

© 2025 – Pkg Stats / Ryan Hefner

robots-txt-editor

v0.0.1

Published

Robots txt editor for react

Downloads

4

Readme

robots-txt-editor

CodeMirror-based robots.txt editor with RFC 9309 validation for React

npm version npm downloads License: MIT

A professional robots.txt editor component for React applications with real-time validation, syntax highlighting, and auto-completion.

✨ Features

  • Real-time validation - RFC 9309 compliant
  • Syntax highlighting - Color-coded directives
  • Auto-completion - Press Ctrl+Space for suggestions
  • Error detection - Red squiggly lines for errors
  • Warning detection - Orange lines for warnings
  • Line numbers - Easy navigation
  • TypeScript support - Full type definitions
  • Lightweight - ~300KB bundled

📦 Installation

npm install robots-txt-editor
# or
pnpm add robots-txt-editor
# or
yarn add robots-txt-editor

🚀 Quick Start

import { useState } from 'react';
import RobotsTxtEditor from 'robots-txt-editor';

function App() {
  const [content, setContent] = useState(`User-agent: *
Disallow: /admin/
Allow: /admin/public

Sitemap: https://example.com/sitemap.xml
`);
  
  const [isValid, setIsValid] = useState(true);

  return (
    <div>
      <RobotsTxtEditor
        initialValue={content}
        onChange={setContent}
        onValidation={setIsValid}
        height="500px"
      />
      
      <div>
        {isValid ? '✅ Valid' : '❌ Has Errors'}
      </div>
    </div>
  );
}

📖 API Reference

Props

| Prop | Type | Default | Description | |------|------|---------|-------------| | initialValue | string | '' | Initial robots.txt content | | onChange | (value: string) => void | - | Called when content changes | | onValidation | (isValid: boolean) => void | - | Called when validation state changes | | height | string | '600px' | Editor height (CSS value) | | readOnly | boolean | false | Make editor read-only |

Example with All Props

<RobotsTxtEditor
  initialValue="User-agent: *\nDisallow: /admin/"
  onChange={(value) => console.log(value)}
  onValidation={(isValid) => console.log(isValid)}
  height="400px"
  readOnly={false}
/>

🎨 Advanced Usage

With Save Functionality

import { useState } from 'react';
import RobotsTxtEditor from 'robots-txt-editor';

function RobotsEditor() {
  const [content, setContent] = useState('');
  const [isValid, setIsValid] = useState(true);

  const handleSave = async () => {
    if (!isValid) {
      alert('Please fix errors before saving');
      return;
    }

    await fetch('/api/robots-txt', {
      method: 'PUT',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({ content }),
    });
    
    alert('Saved!');
  };

  return (
    <div>
      <RobotsTxtEditor
        initialValue={content}
        onChange={setContent}
        onValidation={setIsValid}
        height="500px"
      />
      
      <button onClick={handleSave} disabled={!isValid}>
        Save
      </button>
    </div>
  );
}

Using the Validator Separately

import { validateRobotsTxt } from 'robots-txt-editor/validator';

const result = validateRobotsTxt('User-agent: *\nDisallow: /admin/');

console.log(result.isValid); // true
console.log(result.errors);  // []
console.log(result.warnings); // []

🎯 Validation Rules (RFC 9309)

The editor validates according to the official RFC 9309 standard:

  • ✅ Proper directive syntax
  • ✅ User-agent requirements
  • ✅ Path formatting
  • ✅ Sitemap URL validation
  • ✅ Special characters handling
  • ⚠️ Non-standard directives warnings

⌨️ Keyboard Shortcuts

  • Ctrl+Space - Trigger auto-completion
  • Ctrl+Z - Undo
  • Ctrl+Y / Ctrl+Shift+Z - Redo
  • Ctrl+A - Select all
  • Ctrl+F - Find

🎨 Styling

The editor uses CodeMirror 6 and can be customized via CSS:

/* Custom theme example */
.cm-editor {
  font-family: 'Fira Code', monospace;
  font-size: 16px;
}

.cm-gutters {
  background-color: #f5f5f5;
}

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

📝 License

MIT © Najmus Sakib

🙏 Acknowledgments

📧 Support


Made with ❤️ by Najmus Sakib