{"id":31956336,"url":"https://github.com/profullstack/text-type-detection","last_synced_at":"2026-01-20T16:57:12.898Z","repository":{"id":318242259,"uuid":"1070500553","full_name":"profullstack/text-type-detection","owner":"profullstack","description":"A lightweight, zero-dependency Node.js module for detecting text format types from strings. Accurately identifies plain text, markdown, ASCII art, code blocks, HTML, JSON, and XML.","archived":false,"fork":false,"pushed_at":"2025-10-06T03:35:06.000Z","size":29,"stargazers_count":1,"open_issues_count":2,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-10-23T19:52:02.820Z","etag":null,"topics":["hacktoberfest"],"latest_commit_sha":null,"homepage":"https://profullstack.com","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/profullstack.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-10-06T02:54:04.000Z","updated_at":"2025-10-17T17:02:51.000Z","dependencies_parsed_at":null,"dependency_job_id":"346cf66d-7e52-4f07-b018-d4ef7f13a777","html_url":"https://github.com/profullstack/text-type-detection","commit_stats":null,"previous_names":["profullstack/text-type-detection"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/profullstack/text-type-detection","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/profullstack%2Ftext-type-detection","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/profullstack%2Ftext-type-detection/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/profullstack%2Ftext-type-detection/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/profullstack%2Ftext-type-detection/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/profullstack","download_url":"https://codeload.github.com/profullstack/text-type-detection/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/profullstack%2Ftext-type-detection/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280810441,"owners_count":26395239,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-24T02:00:06.418Z","response_time":73,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hacktoberfest"],"created_at":"2025-10-14T14:48:33.608Z","updated_at":"2025-10-24T14:35:07.044Z","avatar_url":"https://github.com/profullstack.png","language":"JavaScript","readme":"# @profullstack/text-type-detection\n\nA lightweight, zero-dependency Node.js module for detecting text format types from strings. Accurately identifies plain text, markdown, ASCII art, code blocks, HTML, JSON, and XML.\n\n## Features\n\n- 🎯 **Accurate Detection**: Uses multiple heuristics to identify text formats\n- 🚀 **Zero Dependencies**: Pure JavaScript implementation\n- 📦 **ESM Support**: Modern ES Module syntax\n- 🧪 **Well Tested**: Comprehensive test coverage with Mocha and Chai\n- 🎨 **ASCII Art Detection**: Recognizes box drawing, Unicode art, ANSI sequences\n- 📝 **Markdown Support**: Detects headings, lists, links, code blocks, and more\n- 🔍 **Multiple Formats**: Supports plain, markdown, ascii, code, html, json, xml\n\n## Installation\n\n```bash\npnpm add @profullstack/text-type-detection\n```\n\nOr with npm:\n\n```bash\nnpm install @profullstack/text-type-detection\n```\n\n## Usage\n\n### Basic Example\n\n```javascript\nimport { detectTextFormat } from '@profullstack/text-type-detection';\n\nconst text = '# Hello World\\n\\nThis is a markdown document.';\nconst result = detectTextFormat(text);\n\nconsole.log(result);\n// {\n//   text_format: 'markdown',\n//   asciiArt: 0.000,\n//   markdown: 0.180,\n//   reasons: {\n//     ascii: [],\n//     markdown: ['heading'],\n//     codePenaltyApplied: false\n//   },\n//   stats: { lines: 3, mean: 20.67, std: 12.34, symD: 0.05, alpha: 0.75 }\n// }\n```\n\n### Detecting Different Formats\n\n#### Plain Text\n\n```javascript\nconst plainText = 'This is just a simple sentence.';\nconst result = detectTextFormat(plainText);\nconsole.log(result.text_format); // 'plain'\n```\n\n#### Markdown\n\n```javascript\nconst markdown = `# Title\n\n## Subtitle\n\n- Item 1\n- Item 2\n\n[Link](https://example.com)`;\n\nconst result = detectTextFormat(markdown);\nconsole.log(result.text_format); // 'markdown'\nconsole.log(result.reasons.markdown); // ['heading', 'list', 'link']\n```\n\n#### ASCII Art\n\n```javascript\nconst asciiArt = `┌─────────────┐\n│   Hello     │\n│   World     │\n└─────────────┘`;\n\nconst result = detectTextFormat(asciiArt);\nconsole.log(result.text_format); // 'ascii'\nconsole.log(result.asciiArt); // 0.680 (high score)\n```\n\n#### Code Block\n\n```javascript\nconst code = `\\`\\`\\`javascript\nfunction hello() {\n  console.log(\"Hello\");\n}\n\\`\\`\\``;\n\nconst result = detectTextFormat(code);\nconsole.log(result.text_format); // 'code'\n```\n\n#### HTML\n\n```javascript\nconst html = '\u003cdiv class=\"container\"\u003e\u003cp\u003eHello World\u003c/p\u003e\u003c/div\u003e';\nconst result = detectTextFormat(html);\nconsole.log(result.text_format); // 'html'\n```\n\n#### JSON\n\n```javascript\nconst json = '{\"name\": \"John\", \"age\": 30}';\nconst result = detectTextFormat(json);\nconsole.log(result.text_format); // 'json'\n```\n\n#### XML\n\n```javascript\nconst xml = '\u003c?xml version=\"1.0\"?\u003e\u003croot\u003e\u003citem\u003etest\u003c/item\u003e\u003c/root\u003e';\nconst result = detectTextFormat(xml);\nconsole.log(result.text_format); // 'xml'\n```\n\n## API\n\n### `detectTextFormat(text: string): DetectionResult`\n\nAnalyzes the input text and returns a detection result object.\n\n#### Parameters\n\n- `text` (string): The text to analyze\n\n#### Returns\n\nAn object with the following properties:\n\n- `text_format` (string): The detected format type\n  - `'plain'` - Plain text\n  - `'markdown'` - Markdown formatted text\n  - `'ascii'` - ASCII art or box drawing\n  - `'code'` - Code block (fenced)\n  - `'html'` - HTML markup\n  - `'json'` - JSON data\n  - `'xml'` - XML document\n\n- `asciiArt` (number): ASCII art confidence score (0.000 - 1.000)\n\n- `markdown` (number): Markdown confidence score (0.000 - 1.000)\n\n- `reasons` (object): Detailed detection reasons\n  - `ascii` (array): List of ASCII art indicators found\n  - `markdown` (array): List of markdown features found\n  - `codePenaltyApplied` (boolean): Whether code penalty was applied\n\n- `stats` (object): Statistical analysis of the text\n  - `lines` (number): Number of lines\n  - `mean` (number): Mean line length\n  - `std` (number): Standard deviation of line lengths\n  - `symD` (number): Symbol density ratio\n  - `alpha` (number): Alphanumeric character ratio\n\n## Detection Heuristics\n\n### ASCII Art Detection\n\nThe module detects ASCII art using multiple indicators:\n\n- **Unicode Art Characters**: Box drawing (U+2500-U+257F), block elements (U+2580-U+259F), Braille patterns (U+2800-U+28FF), geometric shapes (U+25A0-U+25FF)\n- **Border Lines**: Lines composed primarily of border characters (+, -, |, _, =, etc.)\n- **Consistent Width**: Lines with similar lengths (low standard deviation)\n- **Symbol Density**: High ratio of symbols to alphanumeric characters\n- **Character Runs**: Repeated sequences of the same character\n- **ANSI Sequences**: Terminal color codes and formatting\n- **Trailing Spaces**: Intentional spacing for alignment\n\n### Markdown Detection\n\nMarkdown features detected include:\n\n- **Headings**: ATX-style (#) and Setext-style (underlined)\n- **Lists**: Unordered (-/*/+) and ordered (1.)\n- **Links**: `[text](url)` format\n- **Images**: `![alt](url)` format\n- **Code**: Inline backticks and fenced code blocks\n- **Blockquotes**: Lines starting with \u003e\n- **Tables**: Pipe-separated columns\n- **Emphasis**: Bold (**) and italic (*)\n- **Horizontal Rules**: ---, ***, ___\n- **Front Matter**: YAML metadata blocks\n\n### Code Detection\n\nCode blocks are identified by:\n\n- Fenced code blocks (``` or ~~~)\n- Indentation patterns\n- Programming language keywords\n- Syntax characters (semicolons, braces, brackets)\n\n## Development\n\n### Setup\n\n```bash\n# Clone the repository\ngit clone https://github.com/profullstack/text-type-detection.git\ncd text-type-detection\n\n# Install dependencies\npnpm install\n```\n\n### Running Tests\n\n```bash\n# Run all tests\npnpm test\n\n# Run tests in watch mode\npnpm run test:watch\n```\n\n### Linting and Formatting\n\n```bash\n# Run ESLint\npnpm run lint\n\n# Fix linting issues\npnpm run lint:fix\n\n# Format code with Prettier\npnpm run format\n```\n\n## Requirements\n\n- Node.js \u003e= 20.0.0\n- ESM support\n\n## License\n\nMIT\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n## Author\n\nProfullstack, Inc. https://profullstack.com\n\n## Repository\n\nhttps://github.com/profullstack/text-type-detection\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprofullstack%2Ftext-type-detection","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprofullstack%2Ftext-type-detection","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprofullstack%2Ftext-type-detection/lists"}