Socket
Socket
Sign inDemoInstall

@ztrehagem/svg-bundler

Package Overview
Dependencies
1
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @ztrehagem/svg-bundler

SVG sprite tool. Bundle SVGs into a single SVG as a collection of symbols and generate manifest.


Version published
Weekly downloads
263
decreased by-29.87%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

@ztrehagem/svg-bundler

Latest Version Type Definitions License

Generating SVG sprite. Bundle SVGs into a single SVG as a collection of symbols, and generate manifest.

Features

Specified SVG files or strings are converted into <symbol> with id attribute, and bundled into single <svg>. Furthermore, a manifest JSON is generated that has id, width, height, and viewBox attributes of each SVG. Normally the parent of <use> is a <svg>, the manifest is useful for applying their attributes to the <svg>.

This library won't optimize SVGs like SVGO, just bundle.

Installation

npm install @ztrehagem/svg-bundler

Usage (CLI)

Note: Node.js >= 20.0.0 is required to use CLI.

npx @ztrehagem/svg-bundler --srcDir=./path/to/srcDir --outDir=./path/to/outDir
ArgumentTypeRequiredDefaultDescription
--srcDirstringPath to the directory that includes ".svg" files.
--outDirstringPath to the output directory.
--spriteFilenamestring"sprite.svg"Filename of the SVG sprite file.
--manifestFilenamestring"manifest.json"Filename of the manifest file.

Usage (JS API)

import { SvgBundler } from "@ztrehagem/svg-bundler";

const bundler = new SvgBundler();

bundler.add(
  "foo",
  '<svg width="24px" height="24px" viewBox="0 0 24 24">...</svg>',
);

const { bundled, manifest } = await bundler.bundle();

console.log(bundled);
// <svg width="0" height="0" style="display:none;">
//   <symbol id="foo" width="24px" height="24px" viewBox="0 0 24 24">
//   ...
//   </symbol>
// </svg>

console.log(manifest);
// {
//   foo: {
//     width: "24px",
//     height: "24px",
//     viewBox: "0 0 24 24"
//   }
// }

Keywords

FAQs

Last updated on 09 Feb 2024

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc