GithubHelp home page GithubHelp logo

weizhenye / svgstore Goto Github PK

View Code? Open in Web Editor NEW

This project forked from svgstore/svgstore

0.0 0.0 0.0 246 KB

Combines multiple svg files into one.

Home Page: http://npm.im/svgstore

License: MIT License

JavaScript 100.00%

svgstore's Introduction

svgstore

NPM version Downloads

Combines multiple SVG files into one using <symbol> elements which you may <use> in your markup. Heavily inspired by grunt-svgstore and gulp-svgstore, this is a standalone module that may be used in any asset pipeline.

Install

$ npm install --save svgstore

Usage

var svgstore = require('svgstore');
var fs = require('fs');

var sprites = svgstore()
    .add('unicorn', fs.readFileSync('./unicorn.svg', 'utf8'))
    .add('rainbow', fs.readFileSync('./rainbow.svg', 'utf8'));

fs.writeFileSync('./sprites.svg', sprites);

The resulting file may be consumed in markup as external content.

<body>
    <svg role="img"><use xlink:href="./sprites.svg#unicorn"/></svg>
    <svg role="img"><use xlink:href="./sprites.svg#rainbow"/></svg>
</body>

See the examples directory for more detail.

API

svgstore([options]): SvgStore

Creates a container SVG sprites document.

.element

The current cheerio instance.

.add(id, svg [, options]): SvgStore

  • id {String} Unique id for this SVG file.
  • svg {String} Raw source of the SVG file.
  • options {Object} Same as the options of svgstore(), but will only apply to this SVG file's <symbol>.

Appends a file to the sprite with the given id.

.toString([options]): String

  • options {Object}
    • inline {Boolean} (default: false) Don't output <?xml ?>, DOCTYPE, and the xmlns attribute.

Outputs sprite as a string of XML.

Options

  • cleanDefs {Boolean|Array} (default: false) Remove style attributes from SVG definitions, or a list of attributes to remove.
  • cleanSymbols {Boolean|Array} (default: false) Remove style attributes from SVG objects, or a list of attributes to remove.
  • svgAttrs {Boolean|Object} (default: false) A map of attributes to set on the root <svg> element. If you set an attribute's value to null, you remove that attribute. Values may be functions like jQuery.
  • symbolAttrs {Boolean|Object} (default: false) A map of attributes to set on each <symbol> element. If you set an attribute's value to null, you remove that attribute. Values may be functions like jQuery.
  • copyAttrs {Boolean|Array} (default: false) Attributes to have svgstore attempt to copy to the newly created <symbol> tag from it's source <svg> tag. The viewBox, aria-labelledby, and role attributes are always copied.
  • renameDefs {Boolean} (default: false) Rename defs content ids to make them inherit files' names so that it would help to avoid defs with same ids in the output file.
  • fragmentIdentifier {Function} (default: null) Enable SVG Fragment Identifiers to allow the use of <img src="icons.svg#unicorn-view" />. You can custom fragment ID like (id) => 'view-' + id

Contributing

Standards for this project, including tests, code coverage, and semantics are enforced with a build tool. Pull requests must include passing tests with 100% code coverage and no linting errors.

Test

$ npm test

Future Goals

The svgstore organization began after it was noticed that the common build task of converting an <svg> into a <symbol> tag was being implemented in a similar manner by many different projects across the JavaScript ecosystem.

The long-term goal for this project, in particular, is to provide a single standalone module that can be plugged in to any asset pipeline, thus allowing pipeline tools to focus on providing clean APIs and interfaces related to their build process integration, rather than implementing/duplicating SVG conversion logic directly.

Current build tools using svgstore:


MIT © Shannon Moeller

svgstore's People

Contributors

freeformflow avatar lancedikson avatar shannonmoeller avatar silverwind avatar tomwayson avatar weizhenye 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.