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

svg2sprite

v2.0.1

Published

A very simple module to generate SVG sprites

Downloads

37,415

Readme

svg2sprite

A very simple module to generate SVG sprites.

Travis Status

Install

$ npm i -D svg2sprite

Why?

Existing solutions have many dependencies.

Usage

const svgSprite = require('svg2sprite');
const sprite = svgSprite.collection({ inline: true });

sprite.add('chevron-up', '<svg><path d="M10 10l-1.5 1.5L5 7.75 1.5 11.5 0 10l5-5z"></path></svg>');
sprite.add('chevron-down', '<svg><path d="M5 11L0 6l1.5-1.5L5 8.25 8.5 4.5 10 6z"></path></svg>');

const svg = sprite.compile();

console.log(svg);
// <svg position="absolute" height="0" width="0">
//   <symbol id="chevron-up"><path d="M10 10l-1.5 1.5L5 7.75 1.5 11.5 0 10l5-5z"></path></symbol>
//   <symbol id="chevron-down"><path d="M5 11L0 6l1.5-1.5L5 8.25 8.5 4.5 10 6z"></path></symbol>
// </svg>

Supported methods

.collection([options])

This method creates a new item collection and returns the available methods for it. See all available options.

.add(name, content, options)

This method adds an item to the collection. Using the last argument you can transfer individual settings for that item (e.g. attributes). See all available options.

.get(name)

Returns the contents of a specified element.

.remove(name)

Removes the specified item from the collection.

.clean()

Removes all elements in the collection.

.compile()

Returns the builded sprite.

Supported options

rootAttributes

  • Type: Object
  • Default: {}

The attributes that will be added to the root svg tag.

inline

  • Type: Boolean
  • Default: false

If you want to embed the sprite into your HTML source, you will want to set this to true in order to prevent the creation of SVG namespace declarations and to set some other attributes for effectively hiding the library sprite.

iconAttributes

  • Type: Object
  • Default: {}

The attributes of each icon. Current attribute values will be overwritten.

iconPrefix

  • Type: String
  • Default: ''

The name prefix for each icon.

iconSuffix

  • Type: String
  • Default: ''

The name suffix for each icon.

clean.stripEmptyTags

  • Type: Boolean
  • Default: true

Removes empty tags such as <defs></defs> or <g></g>.

clean.stripTags

  • Type: Array
  • Default: ['title', 'desc']

Removes tags, that are listed in this list.

clean.stripAttrs

  • Type: Array
  • Default: []

Removes attributes, that are listed in this list.

If you specify a string, then use the strict comparison. You can also specify the object and the type of comparison.

{
  clean: {
    stripAttrs: [
      // true for: style=".."
      'style',
      // true for: stoke="..", stoke-width="..", etc.
      { pattern: 'stroke', strict: false }
    ]
  }
}

clean.stripExtraAttrs

  • Type: Boolean
  • Default: true

Removes Sketch and xmlns:* attributes.

clean.stripStyles

  • Type: Boolean|Array
  • Default: true

Removes style attributes from SVG definitions, or a list of the properties that will be removed from style tag and atrribute.

Related

Changelog

See the Releases section of our GitHub project for changelogs for each release version.

License

This software is released under the terms of the MIT license.