🚀 DAY 5 OF LAUNCH WEEK:Introducing Webhook Events for Alert Changes.Learn more →
Socket
Book a DemoInstallSign in
Socket

svg-to-ts

Package Overview
Dependencies
Maintainers
1
Versions
85
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

svg-to-ts

Command line util that converts SVGs from a directory into a single TypeScript file

Source
npmnpm
Version
1.0.0
Version published
Weekly downloads
19K
-20.01%
Maintainers
1
Weekly downloads
 
Created
Source

#Tsvg This module is designed for authors of UI frameworks which aim to provide an SVG Icon library in a tree shakable way.

To make SVGs tree shakeable its a good way to export them as string constants. Of course you don't always want to regenerate all the strings by hand. That's where tsvg comes in.

What it does

Tsvg automates the following things:

  • Reads the content of all svg icons in a folder
  • Optimized the svg content with svgo
    • cleanupAttrs
    • removeDoctype
    • removeXMLProcInst
    • removeComments
    • removeMetadata
    • removeTitle
    • removeDesc
    • removeUselessDefs
    • removeEditorsNSData
    • removeEmptyAttrs
    • removeHiddenElems
    • removeEmptyText
    • removeEmptyContainers
    • removeViewBox
    • cleanupEnableBackground
    • convertStyleToAttrs
    • convertColors
    • convertPathData
    • convertTransform
    • removeUnknownsAndDefaults
    • removeNonInheritableGroupAttrs
    • removeUselessStrokeAndFill
    • removeUnusedNS
    • cleanupIDs
    • cleanupNumericValues
    • moveElemsAttrsToGroup
    • moveGroupAttrsToElems
    • collapseGroups
    • removeRasterImages
    • mergePaths
    • convertShapeToPath
    • sortAttrs
    • removeDimensions
    • removeAttrs
  • It then creates a const for each svg (with the prefix + the file name in camelcase)
  • adds a name and a data attribute to the const. The name attribute can later be used to register the icon in a registry service.
  • exports an interface for the consts - (Interfacename can be passed as argument)

API

The CLI can be used with the tsvg command. This command accepts the following arguments.

-v--versionoutput the version number
-t--typeName name of the generated type
-p--prefix prefix for the generated svg constants
-i--interfaceName name for the generated interface
-s--srcDirectory name of the source directory (default: ".")
-o--outputDirectory name of the output directory (default: "./dist")
-h--helpoutput usage information

Example

Let's say we have the following four svg files in a inputfiles folder.

expressionless

  • expressionless.svg
  • full.svg
  • laughing.svg
  • smiling-face.svg

We can now run tsvg -i ./inputfiles and we end up with the following file in our dist folder.

output

Keywords

SVG

FAQs

Package last updated on 21 Nov 2019

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