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

extract-svg-styles

v1.2.2

Published

Extract SVG element's <style> tags to files.

Downloads

33

Readme

extract-svg-styles

npm version

Extract <style> definitions from an SVG file to a CSS file.

For each SVG file a CSS file will be generated, containing the CSS-rules defined inside the SVG file.

Install

Install with npm

npm install extract-svg-styles --save

Usage

var extractSvg = require(‘extract-svg-styles’);
extractSvg.extract(options);

Options

  • src: Glob string with path to source SVGs
  • out: Output directories
    • svg: Output directory for SVGs (optional)
    • style: Output directory for Stylesheets
  • extension: File name extension for Stylesheets (default is ‘css’, useful for ’scss’)
  • classPrefix: Prefix for class names to target SVGs
  • idHandling: none Avoid ID collisions when using multiple SVGs in a page. class will transform the IDs to a class, remove will get rid of the IDs, prefix will keep the IDs but prefix them with the file name.

Example

Usage with an exapmle configuration object:

extractSvg.extract({
    src: './test/src/**/*.svg',
    out: {
        style: './test/dest/css',
        svg: './test/dest/svg'
    },
    classPrefix: 'icon-'
});

Usage with Grunt

This module can also be used in automated tasks using Grunt.

module.exports = function(grunt) {

    grunt.initConfig({
        'extract-svg-styles': {
            options: {
                styleDest: './test/dest/css',
                classPrefix: 'icon-',
            },
            all: {
                src: './test/src/**/*.svg',
                dest: './test/dest/svg'
            }
        }
    });

    grunt.loadNpmTasks('extract-svg-styles');

    grunt.registerTask('default', ['extract-svg-styles']);
}

Options to use extract-svg-styles with Grunt are the same as for the extract function with the exception of src and out.

out.style is styleDest in Grunt, out.svg is the regular Grunt dest property. If dest is omitted, only the stylesheets will be generated.

Usage with Gulp

This module can also be used in automated tasks using Gulp. Make sure to require the stream object of the plugin as in the example below:

var gulp = require('gulp');
var extractSvg = require('./index.js').stream;

gulp.task('extract-svg-styles', function () {
    gulp.src('./test/src/**/*.svg')
    .pipe(extractSvg.extract({
        styleDest: './test/dest/css',
        classPrefix: 'icon-',
        idHandling: 'class'
    }))
    .pipe(gulp.dest('./test/dest/svg'));
});

gulp.task('default', ['extract-svg-styles']);

Options to use with Gulp are the same as for the extract method with the exception of src and out. Use gulp.src and gulp.dest instead, styleDest is used to specify the output directory for the stylesheets.