oslllo/svg-fixer
Sobre
Converts SVG Strokes To Fill.
Design e mídiaCrescimento medido de estrelas
- em 24 h
- 0
- em 7 dias
- 0
- em 15 dias
- 0
- em 1 mês
- Coletando histórico
Variações líquidas em períodos sobrepostos, não totais diários. Medições ausentes ficam em branco. Estrelas indicam interesse, não qualidade.
README.md
Original
SVG Fixer
Convert SVG strokes and shapes into a single filled path for icon fonts and other tools that require path outlines.
🎉 v3.0.0 is now 11x faster thanks to @ericfennis. See PR #89.

Contents
- Installation
- Quick start
- Files and directories
- SVG strings and Buffers
- Options
- Command line
- How conversion works
- Development
- Changelog and license
Installation
Requires Node.js 22.12 or later. CI tests Node.js 22 and 24 on Linux, macOS, and Windows.
npm install oslllo-svg-fixer
# Or:
yarn add oslllo-svg-fixer
This README describes the current source on master. Check the release's requirements when using an older package version.
Quick start
const fs = require("node:fs");
const SVGFixer = require("oslllo-svg-fixer");
async function main() {
fs.mkdirSync("fixed", { recursive: true });
await SVGFixer("icons", "fixed").fix();
console.log("Saved fixed icons");
}
main().catch(console.error);
The following examples use the same SVGFixer import. Examples containing await belong inside an async function.
Files and directories
SVGFixer(source, destination, options?) creates an instance, with or without new.
| Parameter | Meaning |
|---|---|
source |
Path to one .svg file or a directory containing .svg files |
destination |
Output directory; must already exist by default |
options |
Optional conversion settings described below |
Directory discovery processes lowercase *.svg files directly inside the source directory; it does not recurse into subdirectories. Output files keep their original basenames. Existing output files with the same names are overwritten, so choose a separate destination when retaining the originals.
// One file; destination is still a directory.
const fixer = await SVGFixer("icons/example.svg", "fixed").fix();
// All SVGs immediately inside a directory.
await SVGFixer("icons", "fixed", { traceResolution: 1200 }).fix();
.fix() returns a Promise resolving to the fixer instance. With a callback, it returns the instance immediately and calls callback(err, fixer) when processing finishes:
SVGFixer("icons", "fixed").fix((err, fixer) => {
if (err) {
console.error(err);
return;
}
console.log(`Saved ${fixer.source.length} icons`);
});
Constructor validation can throw synchronously, including when paths are invalid. Handle conversion failures through Promise rejections or callback errors.
SVG strings and Buffers
SVGFixer.fixString(svg, resolution = 600) accepts SVG markup as a string or Buffer and returns a Promise resolving to fixed SVG markup. It does not read a file path, write files, or use a callback.
const source = '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><circle cx="12" cy="12" r="9" fill="none" stroke="black" stroke-width="2"/></svg>';
const fixed = await SVGFixer.fixString(source);
const higherResolution = await SVGFixer.fixString(Buffer.from(source), 1200);
Invalid input types throw synchronously; rendering and tracing errors reject the returned Promise.
Options
| Option | Default | Meaning |
|---|---|---|
showProgressBar |
false |
Show progress while processing files |
throwIfDestinationDoesNotExist |
true |
Throw when the output directory is missing |
traceResolution |
600 |
Width in pixels of the raster image used for tracing; height follows the original aspect ratio |
A larger trace resolution can improve detail at the cost of processing time and memory. Use a positive resolution. This value controls the intermediate image, not the final SVG's intended dimensions.
await SVGFixer("icons", "fixed", {
showProgressBar: true,
throwIfDestinationDoesNotExist: false,
traceResolution: 600,
}).fix();
With throwIfDestinationDoesNotExist: false, the destination directory is created if missing. Its parent directory must already exist; creation is not recursive.
Command line
Use the locally installed binary:
npx oslllo-svg-fixer --source icons --destination fixed
npx oslllo-svg-fixer -s icons/example.svg -d fixed --trace-resolution 1200
npx oslllo-svg-fixer -s icons -d fixed --strict-destination=false --show-progress=false
npx oslllo-svg-fixer --help
Or install globally:
npm install --global oslllo-svg-fixer
oslllo-svg-fixer -s icons -d fixed
| Flag | Alias | Default | Meaning |
|---|---|---|---|
--source |
-s |
Required | Source file or directory |
--destination |
-d |
Required | Output directory |
--strict-destination |
--sd |
true |
Require the destination to exist |
--show-progress |
--sp |
true |
Show progress; enabled by default in the CLI |
--trace-resolution |
--tr |
600 |
Intermediate raster width |
--help |
Show usage | ||
--version |
Show package version |
Pass source and destination as named flags. Exit code 0 means success; 1 means failure.
How conversion works
SVG Fixer uses SVG2 to render an enlarged SVG as a PNG, then Potrace to trace the image into one path containing the outlines. File conversions run through a Piscina worker pool. fixString() calls the conversion pipeline directly.
This is rasterization followed by tracing, so curves and fine details can change. The result is intended for monochrome icon outlines, rather than preserving multicolor artwork, text, filters, or SVG structure. The generated path uses stroke="none" and fill-rule="evenodd".
The converter restores original root attributes and selected attributes from the first original path. It normalizes the root viewBox origin to 0 0; do not assume every attribute or coordinate system is preserved exactly. Review the output for artwork with unusual fills, multiple colors, or offset view boxes.
The current package depends on the published SVG2 v6 and Potrace v6 releases, even though their sibling repositories may contain newer changes. Editing a sibling checkout does not automatically change the installed dependencies used here.
Development
CI runs on pull requests targeting master, pushes to master, and manual dispatch. Tests cover Node.js 22 and 24 on Linux, macOS, and Windows, plus Node.js 22.12.0 on Linux to verify the minimum supported version.
The dependency overrides select patched glob and minimatch versions for the test tooling. Keep these overrides until upstream dependencies adopt the patched versions.
npm ci
npm test
npm test runs the main tests, output checks, and ESLint with coverage collection. Main tests include file and string conversion, options, paths, callbacks, progress, and the CLI. Output tests compare rendering and inspect paths and attributes.
npm run test:all # Main tests followed by output checks, without lint
npm run test:cli # CLI tests only
npm run lint
npm run coverage # Generate LCOV after collecting coverage
Changelog and license
See CHANGELOG.md for release history and LICENSE for the MIT license of SVG Fixer. Its tracing dependency, oslllo-potrace, is licensed separately under GPL-2.0.
Created by oslllo. The project was built to prepare icons for tools such as IcoMoon, Fontello, and webfont. Conversion uses SVG2 and Potrace; worker processing uses Piscina.
Explore projetos relacionados
Carregando…