Skip to content

oxidized-world/svgo-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

64 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

svgo-rs

svgo-rs is a high-performance SVG optimizer written in Rust, designed to process and optimize SVG files efficiently. It provides bindings for Node.js through NAPI-RS, making it accessible for JavaScript and TypeScript developers.

Features

  • Written in Rust for high performance.
  • Provides plugins for various SVG optimizations, such as removing metadata, comments, and unnecessary elements.
  • Supports multiple platforms with precompiled binaries.
  • Easy integration with Node.js projects.

Installation

Install the package via npm:

npm install @svg-rs/svgo

Usage

Node.js

const { optimize } = require('@svg-rs/svgo')

const inputSvg = `<svg xmlns="http://www.w3.org/2000/svg">
  <g attr1="val1">
    <desc>Example</desc>
    <circle cx="50" cy="50" r="40"/>
  </g>
</svg>`

const optimizedSvg = optimize(inputSvg)
console.log(optimizedSvg)

Plugins

  • addAttributesToSVGElement
  • addClassesToSVGElement
  • cleanupAttrs
  • cleanupEnableBackground
  • cleanupIds
  • cleanupListOfValues
  • cleanupNumericValues
  • collapseGroups
  • convertColors
  • convertEllipseToCircle
  • convertOneStopGradients
  • convertPathData
  • convertShapeToPath
  • convertStyleToAttrs
  • convertTransform
  • inlineStyles
  • mergePaths
  • mergeStyles
  • minifyStyles
  • moveElemsAttrsToGroup
  • moveGroupAttrsToElems
  • prefixIds
  • removeAttributesBySelector
  • removeAttrs
  • removeComments
  • removeDeprecatedAttrs
  • removeDesc
  • removeDimensions
  • removeDoctype
  • removeEditorsNSData
  • removeElementsByAttr
  • removeEmptyAttrs
  • removeEmptyContainers
  • removeEmptyText
  • removeHiddenElems
  • removeMetadata
  • removeNonInheritableGroupAttrs
  • removeOffCanvasPaths
  • removeRasterImages
  • removeScripts
  • removeStyleElement
  • removeTitle
  • removeUnknownsAndDefaults
  • removeUnusedNS
  • removeUselessDefs
  • removeUselessStrokeAndFill
  • removeViewBox
  • removeXMLNS
  • removeXMLProcInst
  • removeXlink
  • reusePaths
  • sortAttrs
  • sortDefsChildren

Benchmarks

svgo-rs provides significant performance improvements over JavaScript-based SVG optimizers. Run the benchmarks in the benchmark/ directory to compare:

yarn bench

License

This project is licensed under the MIT License. See the LICENSE file for details.

Contributing

Contributions are welcome! Please open an issue or submit a pull request on GitHub.