New:Microsoft Teams Notifications Are Now Available in Socket.Learn more
Get Started

svg-format

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

svg-format

Structural formatter for SVG documents.

latest
Source
npmnpm
Version
0.3.0
Version published
Maintainers
1
Created
Source

svg-format

NPM

Structural formatter for SVG documents.

npm install -g svg-format                 # unscoped alias
npm install -g @svg-toolkit/svg-format    # canonical package
svg-format icon.svg
npx svg-format icon.svg

@svg-toolkit/svg-format is the canonical package; unscoped svg-format is a thin alias that depends on it. Either install gives you the same bin. Or grab the whole toolkit at once with @kjanat/svg-toolkit.

The package resolves a prebuilt native binary for your platform via optionalDependencies — no postinstall step, no network access at runtime.

On Linux, the binary is picked by the host's libc: musl hosts get the musl build, glibc hosts get the glibc build. npm, pnpm and yarn honour the libc field and install only the right one; bun and deno install both, so detection settles it at launch. Set SVG_LIBC=musl or SVG_LIBC=glibc to override if detection is ever wrong.

Formatting behavior and options: https://github.com/kjanat/svg#readme

API

use svg_format::{
    format,
    format_with_options,
    AttributeLayout,
    AttributeSort,
    FormatOptions,
    QuoteStyle,
    WrappedAttributeIndent,
};

let pretty = format(source);

let pretty_custom = format_with_options(
    source,
    FormatOptions {
        indent_width: 4,
        insert_spaces: false,
        max_inline_tag_width: 100,
        attribute_sort: AttributeSort::Canonical,
        attribute_layout: AttributeLayout::Auto,
        attributes_per_line: 1,
        space_before_self_close: true,
        quote_style: QuoteStyle::Preserve,
        wrapped_attribute_indent: WrappedAttributeIndent::OneLevel,
    },
);

CLI

svg-format is also available as a CLI binary from the same crate (cargo install svg-format, or npm install --global svg-format / @svg-toolkit/svg-format for the prebuilt binary).

# Format from stdin to stdout
cat icon.svg | svg-format --stdin

# Check whether a file would change
svg-format --check icon.svg

# Format file in place
svg-format --in-place icon.svg

Keywords

svg

FAQs

Package last updated on 09 Sep 2026

Related posts