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

grunt-svgpackager

v0.4.3

Published

Grunt plugin for SVG Packager

Downloads

6

Readme

grunt-svgpackager - v0.4.0

Grunt plugin for SVG Packager.

Recent bugs Fixed

This tool gathers all your SVG from a source folder and packages them all into a JSON file and/or a CSS file.

The name of the SVG file will become the key in the JSON file and the class name in the CSS file. If the file name has a dot (.), that dot will be replaced with a dash (-). Example: icon.clock.svg will become .icon-clock {}

The package name will be used as the parent class of the CSS classes. Example: Package name = myPackage.

CSS will become .myPackage .icon-clock {}

Getting Started

This plugin requires Grunt ~0.4.5

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-svgpackager --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-svgpackager');

The "svgpackager" task

Overview

In your project's Gruntfile, add a section named svgpackager to the data object passed into grunt.initConfig().

grunt.initConfig({
  svgpackager: {
    somePackage: {
      options: {
      }
    },
  },
});

Options

options.source - (required)

Type: String Default value: ''

A uri string to the target folder containing your SVG files.

options.dest - (required)

Type: String Default value: ''

A uri string to the destination folder where your CSS and/or JSON files should be saved.

options.package - (required)

Type: String Default value: 'svgpackager'

A string representing the name of the package. This value will also be used as the parent CSS class ie. .package .filename {}.

options.prefixsvg

Type: Boolean Default value: true

Will prefix the SVG or Base64 data with data:image/svg+xml;utf8, or data:image/svg+xml;base64, respectively.
NOTE: Default set to true.

options.prefix

Type: String Default value: ''

Option used to prefix all class names. If left as blank string, a global style will be created using file names as CSS class names...

.package .filename_1,
.package .filename_2,
.package .filename_3
/* ... all file names ... */
{
    display: inline-block;
    background-repeat: no-repeat;
    background-size: 100%;
    background-position: center center;
    vertical-align: middle;
}

.package .filename_1 {
    /* ... */
}
.package .filename_2 {
    /* ... */
}
.package .filename_3 {
    /* ... */
}

However, if prefix is defined then a global style will created using the following selectors. Therefore, prefix: 'icon-' will produce the following CSS:

.package [class^=".icon-"],
.package [class*=" .icon-"] {
    display: inline-block;
    background-repeat: no-repeat;
    background-size: 100%;
    background-position: center center;
    vertical-align: middle;
}

.package .icon-filename_1 {
    /* ... */
}
.package .icon-filename_2 {
    /* ... */
}
.package .icon-filename_3 {
    /* ... */
}

options.output

Type: String Default value: 'all'

A string value to determine which files should be generated.
Setting this to 'json' will generate only the JSON file.
Setting this to 'css' will generate only the CSS file.
Of course, 'all' will generate both JSON and CSS.

options.base64

Type: Boolean Default value: false

Can be set to true if you want the SVG data to be encoded to Base64.
Default is false only due to the fact that Base64 usually creates larger files.

options.debug

Type: Boolean Default value: false

Setting this option to true will execute a 'dry run'. Data will be output to console and no files will be generated.

options.silent

Type: Boolean Default value: false

Can be set to true if you do not wish to see any console output from svgpackager.

Usage Examples

grunt.initConfig({
  svgpackager: {
      myPackage: {
          options: {
              source:    'path/to/my/svg/files',
              dest:      'dist/assets/css',
              prefix:    'my-svg-'
          }
      },
      anotherPackage: {
          options: {
              source:    'path/to/the/other/svg/files',
              dest:      'dist/assets/css',
              prefix:    'other-',
              output:    'css',
              base64:    true
          }
      }
  },
});

Release History

v0.4.2
Improved error logging.

v0.4.1
Updated dependency to svgpackager.

v0.4.0
Fixed failure when desitantion not found. For real this time! Creates destination using mkdirp.

v0.3.0
Fixed failure when desitantion not found.
Options dest and package now required.

v0.2.1
Updated documentation.

v0.2.0
Added all svgpackager functionality.

v0.1.0
Initial commit.