Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

svgpipe

Package Overview
Dependencies
Maintainers
0
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

svgpipe

A flexible CLI tool around svgo for further postprocessing.

  • 0.0.20
  • latest
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

Svgpipe

A flexible wrapper arround SVGO to postprocess optimized SVGs. Svgpipe comes with predefined handlers that can be used to create a typed icon-component or similar. But it is easy to create a custom handler.

Installation

 npm i --save-dev svgpipe
 pnpm add -D svgpipe
 yarn add -D svgpipe

Usage

Create a config file and a folder scaffold.

npx svgpipe init

Drop your SVGs in ./svgpipe/in/<yourFolder> and update the config.

// svgpipe.config.ts
import { defineConfig } from "svgpipe";

export Default defineConfig({
  modules: {
    // load SVGs from "./svgpipe/in/logo and process with 'css-mask' handler"
    logo: "css-mask",
    // load svg from "./svgpipe/in/icon" and apply custom handler
    icon: {
      handler: (conf) => ({})
    }
  },
});

Process SVGs and create files.

npx svgpipe run

Built-in Handlers

NameOutput Note
css-maskView 
vue-css-maskView 
vue-inlineView Depends on vite-svg-loader.

Options

PropertyTypeDefaultDescription
baseIn?string  ./svgpipe/inRoot folder to find the input SVGs.
baseOut?string./svgpipe/.outRoot folder for all output files.
cleanupbooleantrueDelete files in the output folders that where not part of the current run.
modulesUserModuleConfig or HandlerNameConfig for one set of SVGs. See Handlers.

Module

PropertyTypeDefault Description
in?string  {baseIn}/{objectKeyOfModule}Folder where the SVGs for this module are. If undefined, the module key will be used.
out?string{baseOut}Folder for ouput.
typePath?string{baseOut}/typesFolder for the TypeScript type file. This has a type with all the SVG names as string literals.
tokenPath?string{baseOut}/tokenFolder for the TypeScript token file. This has a variable with an array with all SVG names.
ignoreBase?booleanfalseDon't prepend the base path.
prepareName?(str: string) => stringModify the SVG file name. The name will be used for types, classes e.g.
handlerCreateHandlerThe actual SVG handle.
svgo?UserModuleConfig["svgo"]{}SVGO Options.
SVGO
PropertyTypeDefaultDescription
config?SvgoConfig{}SVGO Config.
replace?booleanfalseOpt out of default config merging.
stdout?booleanfalsePrint the config to the console.

Custom Handler

import { type CreateHandler, File } from "svgpipe"

const myHanlder: CreateHandler = (moduleConfig) => ({
  onFile: (svgFile) => {
    // Do what ever you want. Return the file to keep it.
    return svgFile
  },
  onEnd: (context) => {
    // Do cleanup work or create addtional files
    const myFile = new File()
    return [myFile]
  }
  config: {
    multipass: true
  },
})

Implement a CreateHandler. This is a function that recieves every processed module config and returns a ISvgHandler.

onFile

Will be called for every processed input svg file. Retrun the file if you want to keep it.

onEnd

Will be called with the Context after all SVGs are processed. Return nothing or IWriter[] with additional files that you want to write to disk. Context provides a type handler that creates a TypeScript type file for the module and a corresponding token handler.

config

The default SVGO config that should be used. This can be modified from the user config.

All built-in handlers are exported in case you want to extend one.

Keywords

FAQs

Package last updated on 05 Oct 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

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc