🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

svg-unjunk

Package Overview
Dependencies
Maintainers
0
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

svg-unjunk

Removes invisible and useless stuff from SVG code

latest
Source
npmnpm
Version
0.2.2
Version published
Weekly downloads
8
-50%
Maintainers
0
Weekly downloads
 
Created
Source

svg-unjunk

Removes invisible and useless stuff from SVG code. It uses real Chromium to render and compare rasterized SVGs.

Command line usage

npx svg-unjunk [OPTIONS] FILE [FILE...]
npx svg-unjunk svgfile.svg anothersvgfile.svg

--lossless

Use only transformations that makes the rasterized image look exactly, pixel perfect, the same.

Chromim SVG rasterizer may leave barely noticeable rendering artifacts that aren't visible to the naked eye. In --lossless mode these transfromations will be rejected.

Typically running in near-lossless (without --lossless) mode is good enough.

--parallel

Use several Chromium pages for raserization and optimization at once.

Defaults to the # of CPUs on your machine.

--scale

Upscale the image # times when rasterizing.

Ex: If the SVG image is 50 Ă— 50 and --scale is 2, it will be rasterized (and compared) as 100 Ă— 100.

Default is 2 ("retina").

--debug

Shows the Chromium window and probably some additional debug info.

Node.js module usage

const { SvgUnjunk } = require('svg-unjunk');
const unjunk = new SvgUnjunk(/* options */);

const newSvgCode1 = await unjunk.process(oldSvgCode1 /*, options */);
const newSvgCode2 = await unjunk.process(oldSvgCode2 /*, options */);
// ...

unjunk.destroy();

Please refer the index.d.ts for the full interface documentation.

.destroy() it!

svg-unjunk uses puppeteer and it opens a real Chromium browser. Unfortunately, there's no way to .unref() it so far. If you don't call destroy the node.js script will not exit clean: It will wait util the browser process end at it will never happen.

new SvgUjunk() is heavy!

Reuse the same instance as much as you can! Each new SvgUnjunk instance starts a new browser and it's really not a fast thing to do.

In fact, if you reuse the same instance you can benefit from the parallel processing.

FAQs

Package last updated on 26 Jun 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts