{"id":43961680,"url":"https://github.com/vnykmshr/imguri","last_synced_at":"2026-02-07T05:33:36.378Z","repository":{"id":12326425,"uuid":"14963938","full_name":"vnykmshr/imguri","owner":"vnykmshr","description":"Convert images to data URIs for inline embedding. Supports local files and HTTP URLs with concurrent processing. Node.js 18+, ES modules, native fetch.","archived":false,"fork":false,"pushed_at":"2025-11-18T15:38:23.000Z","size":222,"stargazers_count":1,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-11-18T16:45:15.735Z","etag":null,"topics":["base64-encoding","build-tools","data-uri","email-templates","esm","fetch-api","image-processing","inline-images","mime-types","nodejs"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vnykmshr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-12-05T19:48:07.000Z","updated_at":"2025-11-18T15:23:30.000Z","dependencies_parsed_at":"2022-08-02T19:01:12.818Z","dependency_job_id":null,"html_url":"https://github.com/vnykmshr/imguri","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/vnykmshr/imguri","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vnykmshr%2Fimguri","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vnykmshr%2Fimguri/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vnykmshr%2Fimguri/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vnykmshr%2Fimguri/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vnykmshr","download_url":"https://codeload.github.com/vnykmshr/imguri/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vnykmshr%2Fimguri/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29187224,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-07T05:07:31.176Z","status":"ssl_error","status_checked_at":"2026-02-07T05:06:15.227Z","response_time":63,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["base64-encoding","build-tools","data-uri","email-templates","esm","fetch-api","image-processing","inline-images","mime-types","nodejs"],"created_at":"2026-02-07T05:33:35.845Z","updated_at":"2026-02-07T05:33:36.373Z","avatar_url":"https://github.com/vnykmshr.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# imguri\n\nConvert local and remote images to data URI scheme for inline embedding.\n\n[![CI](https://github.com/vnykmshr/imguri/workflows/CI/badge.svg)](https://github.com/vnykmshr/imguri/actions)\n[![npm version](https://img.shields.io/npm/v/imguri.svg)](https://www.npmjs.com/package/imguri)\n[![npm downloads](https://img.shields.io/npm/dm/imguri.svg)](https://www.npmjs.com/package/imguri)\n[![Node version](https://img.shields.io/node/v/imguri.svg)](https://nodejs.org)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n## Features\n\n- ES modules with dual CJS/ESM support\n- Local files and HTTP/HTTPS URLs\n- Concurrent batch processing\n- Path traversal protection\n- Native fetch API, no deprecated dependencies\n\n**Requirements:** Node.js \u003e= 18.0.0\n\n## Installation\n\n```bash\nnpm install imguri\n```\n\n## Usage\n\n### Single File\n\n```javascript\nimport { encodeSingle } from 'imguri';\n\n// Local file\nconst uri = await encodeSingle('logo.png');\nconsole.log(uri); // data:image/png;base64,...\n\n// Remote URL\nconst uri = await encodeSingle('https://example.com/image.jpg');\n\n// With options\nconst uri = await encodeSingle('large.png', {\n  sizeLimit: 256000, // 250KB\n  force: true, // override limit\n});\n```\n\n### Batch Processing\n\n```javascript\nimport { encode } from 'imguri';\n\nconst results = await encode(['icon1.png', 'icon2.png', 'https://example.com/logo.jpg'], {\n  concurrency: 5,\n});\n\nfor (const [path, result] of results) {\n  if (result.error) {\n    console.error(path, result.error.message);\n  } else {\n    console.log(path, result.data.substring(0, 50) + '...');\n  }\n}\n```\n\n### CommonJS\n\n```javascript\nconst { encodeSingle } = require('imguri');\n\n(async () =\u003e {\n  const uri = await encodeSingle('image.png');\n  console.log(uri);\n})();\n```\n\n## API\n\n### encodeSingle(path, options?)\n\nEncodes a single file or URL to data URI.\n\n- **path** `string` - File path or HTTP/HTTPS URL\n- **options** `object`\n  - `sizeLimit` `number` - Max bytes (default: 131072 / 128KB)\n  - `force` `boolean` - Override size limit (default: false)\n  - `timeout` `number` - HTTP timeout ms (default: 20000)\n\nReturns `Promise\u003cstring\u003e` - Data URI string\n\nThrows if file not found, size exceeded, or network error.\n\n### encode(paths, options?)\n\nEncodes multiple files/URLs with concurrent processing.\n\n- **paths** `string | string[]` - Path(s) to encode\n- **options** `object` - Same as encodeSingle, plus:\n  - `concurrency` `number` - Max parallel ops (default: 10)\n\nReturns `Promise\u003cMap\u003cstring, EncodeResult\u003e\u003e` where EncodeResult is:\n\n```javascript\n{\n  data: string | null,  // Data URI or null if error\n  error: Error | null   // Error or null if success\n}\n```\n\n### encodeLegacy(paths, options, callback)\n\nCallback-based API for v0.x compatibility. Deprecated, will be removed in v2.0.\n\n## Configuration\n\n| Option      | Type    | Default | Description                    |\n| ----------- | ------- | ------- | ------------------------------ |\n| sizeLimit   | number  | 131072  | Max file size in bytes (128KB) |\n| timeout     | number  | 20000   | HTTP timeout in milliseconds   |\n| concurrency | number  | 10      | Max concurrent operations      |\n| force       | boolean | false   | Override size limit            |\n\n## Security\n\nPath validation prevents directory traversal attacks (`../` is blocked). Absolute paths are allowed but can access any readable file - validate user input in production.\n\nFor HTTP URLs, content-type validation ensures only images are processed. Size limits prevent memory exhaustion.\n\n## Migration from v0.x\n\nv1.0 replaces callbacks with promises and changes result format from object to Map. Use `encodeLegacy()` for backward compatibility or update to promise-based API:\n\n```javascript\n// v0.x\nimguri.encode(['file.png'], opts, (err, results) =\u003e { ... });\n\n// v1.0\nconst results = await encode(['file.png'], opts);\nfor (const [path, result] of results) { ... }\n```\n\nSee [CHANGELOG.md](CHANGELOG.md) for complete migration guide.\n\n## How It Works\n\nTwo-layer architecture separates business logic from I/O:\n\n- **Core layer:** Base64 encoding and data URI formatting\n- **Adapter layer:** File system operations and HTTP client\n- **Main module:** Coordinates adapters, validates paths, manages concurrency\n\nData flows: Adapter → Validation → Encoder → Data URI string\n\n## Development\n\n```bash\nnpm install      # Install dependencies\nnpm test         # Run tests (54 tests, 89% coverage)\nnpm run lint     # Check code style\nnpm run build    # Build CJS/ESM bundles\n```\n\n## Documentation\n\n- [Technical Blog](docs/TECHNICAL_BLOG.md) - Architecture deep dive\n- [Changelog](CHANGELOG.md) - Version history\n- [Security Policy](.github/SECURITY.md) - Vulnerability reporting\n\n## License\n\nMIT License\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvnykmshr%2Fimguri","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvnykmshr%2Fimguri","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvnykmshr%2Fimguri/lists"}