npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

svgstore

v3.0.1

Published

Combines mulitple svg files into one.

Downloads

182,434

Readme

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.

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