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

svg-spritify

v1.2.1

Published

A CLI tool for you to generate SVG sprites ASAP with support for multi-theme and multi-breakpoint configurations

Downloads

44

Readme

svg-spritify NPM version NPM monthly downloads NPM total downloads

Creating SVG sprites has never been this easy. Easily generate sprites out of your SVG files.

A CLI tool for you to generate SVG sprites ASAP with support for multi-theme and multi-breakpoint configurations

Please consider following this project's author, Sina Bayandorian, and consider starring the project to show your :heart: and support.

Table of Contents

Install

Install with npm :

$ npm install -g svg-spritify

Usage

$ npx sprite

Configuration

This CLI comes with a proper default config that can be completely customized to best fit your needs. In order to override the default configuration you need to create a sprite.config.json at the root of your project :

| Name | Type | Default | Description | |:-----------------|:-----------------------------------------|:------------------------------------------|:--------------------------------------------------------------------| | rootDir | string | "icons" | the directory where you should put your SVG icons | | outDir | string | ".output" | the directory where sprite SVG(s) and CSS will be generated | | tag | string | no HTML tag | the HTML tag to be added to the generated CSS | | filename | string | "sprite" | output SVG files' prefix name | | className | string | "sprite" | the className to be used for both CSS and SVG files | | media | "min" | "max" | "min" | | themes | string[ ] | ["light"] | the themes that you want your icons to support | | defaultTheme | string | themes[0] | the default theme of your icons - explained below | | breakpoints | { [bp: string]: number } | { } | the breakpoints used for responsive icons | | breakpointUtils | boolean | true | if set to true, outputs per-breakpoint CSS utils - explained below | | css | { minify?: boolean; filename?: string } | { minify: false, filename: 'sprite' } | output CSS configuration | | demo | boolean | { [theme: string]: hex_color } | false | | typescript | boolean | { filename?: string; typeName?: string } | { filename?: string; typeName?: string } | outputs a TypeScript type for icon names unless set to false |

Config Variants

This CLI in its core has a function called resolvePaths that is responsible for resolving the inputs and outputs based the config variant you provide. There can be 4 different config variants based on how you choose to config the CLI :

  • single theme - single breakpoint place your SVG icons directly inside the rootDir.

    • rootDir
  • single theme - multi breakpoint you need one sub-folder per breakpoint directly inside the rootDir - the SVG icons of each breakpoint should be placed directly inside the related sub-folder.

    • rootDir/breakpoint
  • multi theme - single breakpoint you need one sub-folder per theme directly inside the rootDir - the SVG icons of each theme should be placed directly inside the related sub-folder

    • rootDir/theme
  • multi theme - multi breakpoint you need one sub-folder per theme directly inside the rootDir, and then one sub-folder per breakpoint directly inside each theme's sub-folder - the breakpoint's sub-folder is where you place the SVG icons

    • rootDir/theme/breakpoint
  • When managing multiple breakpoints, it's important to ensure there's a fallback for screen sizes that don't meet any specified conditions. This is achieved by using a DEFAULT folder alongside your breakpoint-specific folders.

    • Suppose you have the following breakpoint configuration "lg": 1024 with the media type set to min, the icons inside the lg folder will display when the viewport width is >= 1024px. For screen sizes below 1024px, the icons from the DEFAULT folder will be used.

Theming

Theming is implemented using classNames in this package. Once you define your themes inside sprite.config.json, the output css will look something like :

.<theme> .<icon-name> { ... }

You can show a given theme's icon by giving a className equal to the theme's name to a parent of the icon.

One thing to notice is the importance of the defaultTheme. There is no className defined for the defaultTheme. There is no className defined for the defaultTheme. The default icons are shown by default as the name implies.

  • Defaults to the first theme if not defined

Breakpoint Utils

If set to true, generates one utility class for each breakpoint to create breakpoint-specific icons. For example, given "md": 768, we have :

.sprite-md {
    display: none;
}

@media (min-width: 768px) {
    .sprite-md {
        display: inline-block;
    }
}

Demo

If set to true, a demo.html will be generated where you can see a list of your icons all at once - it can also be set to an object that accepts strings as keys and hex colors as values, each key is a theme specified in the config and each color is the background-color that is going to be used once you change the demo.html file's theme :

{
    "demo" {
        "light": "ffffff",
        "dark": "303030"
    }
}

make sure not to include the # in your hex string