svg-to-data-uri-lite
v1.0.0
Published
Ultra-fast, zero-dependency utility to encode raw SVG strings into compact, optimized Data URIs for inline CSS and HTML.
Maintainers
Readme
🖼️ svg-to-data-uri-lite
Ultra-fast, zero-dependency utility to encode raw SVG strings into compact, optimized Data URIs for inline CSS and HTML.
🚀 Quick Start
import { svgToDataUri } from 'svg-to-data-uri-lite';
const iconSvg = '<svg viewBox="0 0 24 24"><path d="M5 12h14" fill="#3b82f6"/></svg>';
// 1. Optimized UTF-8 Data URI (readable & compact for CSS):
const cssUri = svgToDataUri(iconSvg);
console.log(cssUri);
// "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M5 12h14' fill='%233b82f6'/%3E%3C/svg%3E"
// 2. Base64 format if required:
const base64Uri = svgToDataUri(iconSvg, { base64: true });
console.log(base64Uri);
// "data:image/svg+xml;base64,PHN2ZyB2aWV3..."💖 Support the Project
If you find this package useful, consider sponsoring its ongoing development: 👉 Sponsor @Piratha97 on GitHub Sponsors
📄 License
MIT © 2026 Pirapaakaran Pirathapan
