{"id":51075988,"url":"https://github.com/letieu/svgcap","last_synced_at":"2026-06-23T14:04:26.848Z","repository":{"id":363823851,"uuid":"1265076759","full_name":"letieu/svgcap","owner":"letieu","description":"solve svg captcha","archived":false,"fork":false,"pushed_at":"2026-06-10T13:05:46.000Z","size":452,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-10T15:07:23.709Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/letieu.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":"2026-06-10T12:50:18.000Z","updated_at":"2026-06-10T13:06:33.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/letieu/svgcap","commit_stats":null,"previous_names":["letieu/svgcap"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/letieu/svgcap","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/letieu%2Fsvgcap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/letieu%2Fsvgcap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/letieu%2Fsvgcap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/letieu%2Fsvgcap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/letieu","download_url":"https://codeload.github.com/letieu/svgcap/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/letieu%2Fsvgcap/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34692803,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-23T02:00:07.161Z","response_time":65,"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":[],"created_at":"2026-06-23T14:04:25.958Z","updated_at":"2026-06-23T14:04:26.837Z","avatar_url":"https://github.com/letieu.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @letieu/svgcap\n\nA lightweight, zero-dependency JavaScript package and Command Line Interface (CLI) to **solve** and **train** SVG captchas.\n\n## Features\n\n- **Solve Captchas**: Extract character codes from SVG captcha strings using a pattern-recognition model.\n- **Train Models**: Generate custom pattern-recognition models from a directory of labeled SVG captchas.\n- **Lightweight**: Zero external dependencies (only uses `@xmldom/xmldom` to parse SVG documents).\n- **Dual Package (ESM \u0026 CommonJS)**: Fully supports both `import` and `require()` natively in Node.js.\n- **CLI Support**: Use it as a library in your JavaScript code or run it directly from your terminal.\n\n---\n\n## Installation\n\nInstall via `npm`:\n\n```bash\nnpm install @letieu/svgcap\n```\n\n---\n\n## Programmatic Usage\n\n`@letieu/svgcap` supports both ES Modules (ESM) and CommonJS (CJS) natively out of the box.\n\n### 1. Solve a Captcha\n\nBy default, `solve` uses a built-in pre-trained model (`defaultModel`) that resolves characters based on their SVG path patterns.\n\n#### ES Modules (ESM)\n```javascript\nimport { solve } from '@letieu/svgcap';\n\n// Your SVG captcha source string\nconst svgString = `\u003csvg ...\u003e ... \u003c/svg\u003e`;\n\n// Solve using the default model\nconst code = solve(svgString);\nconsole.log('Solved Captcha:', code);\n```\n\n#### CommonJS (CJS)\n```javascript\nconst { solve } = require('@letieu/svgcap');\n\n// Your SVG captcha source string\nconst svgString = `\u003csvg ...\u003e ... \u003c/svg\u003e`;\n\n// Solve using the default model\nconst code = solve(svgString);\nconsole.log('Solved Captcha:', code);\n```\n\n---\n\n### 2. Solve with a Custom Model\n\nIf you have trained a custom model and saved it as a JSON file, you can pass it to the `solve` function:\n\n#### ES Modules (ESM)\n```javascript\nimport fs from 'fs/promises';\nimport { solve } from '@letieu/svgcap';\n\nconst svgString = `\u003csvg ...\u003e ... \u003c/svg\u003e`;\n\n// Load custom model\nconst modelData = await fs.readFile('./my-model.json', 'utf8');\nconst customModel = JSON.parse(modelData);\n\n// Solve using custom model\nconst code = solve(svgString, customModel);\nconsole.log('Solved Captcha:', code);\n```\n\n#### CommonJS (CJS)\n```javascript\nconst fs = require('fs/promises');\nconst { solve } = require('@letieu/svgcap');\n\nconst svgString = `\u003csvg ...\u003e ... \u003c/svg\u003e`;\n\nasync function run() {\n  // Load custom model\n  const modelData = await fs.readFile('./my-model.json', 'utf8');\n  const customModel = JSON.parse(modelData);\n\n  // Solve using custom model\n  const code = solve(svgString, customModel);\n  console.log('Solved Captcha:', code);\n}\nrun();\n```\n\n---\n\n### 3. Train a Model\n\nYou can train a model programmatically by pointing the `train` function to a folder of labeled captcha SVGs. The name of each SVG file in the directory should be the exact text of the captcha (e.g. `3EDK9P.svg`).\n\n#### ES Modules (ESM)\n```javascript\nimport fs from 'fs/promises';\nimport { train } from '@letieu/svgcap';\n\n// Train a model from the folder containing labeled SVGs\nconst newModel = await train('./path/to/captchas');\n\n// Save the trained model to a file\nawait fs.writeFile('my-model.json', JSON.stringify(newModel, null, 2));\nconsole.log('Model trained and saved successfully!');\n```\n\n#### CommonJS (CJS)\n```javascript\nconst fs = require('fs/promises');\nconst { train } = require('@letieu/svgcap');\n\nasync function run() {\n  // Train a model from the folder containing labeled SVGs\n  const newModel = await train('./path/to/captchas');\n\n  // Save the trained model to a file\n  await fs.writeFile('my-model.json', JSON.stringify(newModel, null, 2));\n  console.log('Model trained and saved successfully!');\n}\nrun();\n```\n\n---\n\n### 4. Train a Single SVG\n\nIf you want to map characters of a single SVG captcha to a known answer:\n\n```javascript\n// ESM\nimport { trainSvg } from '@letieu/svgcap';\n// CJS: const { trainSvg } = require('@letieu/svgcap');\n\nconst svgString = `\u003csvg ...\u003e ... \u003c/svg\u003e`;\nconst answer = '3EDK9P';\n\nconst singleModelPart = trainSvg(svgString, answer);\n// Returns an object mapping SVG path patterns to characters\nconsole.log(singleModelPart);\n```\n\n---\n\n## Command Line Interface (CLI)\n\nYou can run the CLI directly without installing it globally using `npx`.\n\n### 1. Solve an SVG Captcha\n\nSolve a single SVG file using the default model:\n\n```bash\nnpx @letieu/svgcap solve captcha.svg\n```\n\nSolve using a custom model file:\n\n```bash\nnpx @letieu/svgcap solve captcha.svg my-model.json\n```\n\n### 2. Train a Model\n\nGenerate a pattern model from a directory of labeled SVG captchas:\n\n```bash\nnpx @letieu/svgcap train ./path/to/captchas [output-model.json]\n```\n\n*If no output path is provided, it defaults to saving as `MODEL.json` in the current working directory.*\n\n---\n\n## File Labeled Captchas Example\n\nTo train a model, compile a folder of captchas named after their answers, for example:\n```\ncaptchas/\n├── 3EDK9P.svg\n├── 4AB7CD.svg\n└── 9XYZ12.svg\n```\n\n---\n\n## License\n\n[ISC](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fletieu%2Fsvgcap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fletieu%2Fsvgcap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fletieu%2Fsvgcap/lists"}