Code Monkey home page Code Monkey logo

generate-svg-symbols's Introduction

README

npm version

A command line tool to convert SVG files to symbols.

npx generate-svg-symbols -d ./path/to/svg/dir -o ./symbols.svg

This command will convert every SVG file found in the source directory to SVG symbol and put all the generated symbols into a single SVG file. This command generates SVG file by default, but you can wrap it to different files. The available wrappers are:

  • svg Output a SVG file.
  • ts Output a TypeScript file that export the SVG content as its default export.
  • js Output a JavaScript file that export the SVG content as its default export.
  • js-bundle Output a JavaScript file that will inject the SVG content to document.body automatically.

If you want to optimize the SVG content (remove redundant and useless information in the SVG content), you can install svgo to your project. If svgo is detected, the SVG content will be optimized with svgo before it get converted to SVG symbol automatically (to avoid this, you can use the --skipSvgo option).

Options

Usage:
  generate-svg-symbols -d ./path/to/svg/dir

Options:
  -d --dir        Specify the directory
  -o --output     Specify output filename
  -w --wrapper    Specify output wrapper (svg, ts, js, js-bundle)
  -p --prefix     Specify the prefix of the id
  -c --class      Specify the class name
  -t --types      Generate TypesScript types (can be boolean or string)
  -a --attrs      Specify extra attributes to the svg tag
  -h --help       Print this help message
  --skipSvgo      Skip optimizing svg with svgo
  --skipComments  Skip generating comments for ts or js
  --keepXmlns     Keep xmlns attribute
  --keepVersion   Keep version attribute

API usage

You can also use the API to generate SVG symbols. For example:

import { generate } from 'generate-svg-symbols'

const { ids, names, symbols, svg } = generate({ dir: './svg' })

console.log(ids)
console.log(names)
console.log(symbols)
console.log(svg)

License

MIT

generate-svg-symbols's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.