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

@al00x/svg-packer

v1.0.1

Published

A Command-Line tool to Pack your SVG icons into a single file!

Downloads

11

Readme

@Al00X/SVG-Packer

🗃️ Pack all of your svg files into a single SVG file! (command-line tool)


So What's The Point Of This? 🧐❔

Basically, the problem came up when we wanted to use svg icons in an SSR website, and cache them; well we could have used a caching service and logics to handle things but that would take a lot of time to write a decent code; which consist of handling multiple requests or nasty race conditions that occurred.

Or in React (and other frameworks using jsx) we tend to generate a jsx file for each svg and customize them.

What if we want to add a size property to all the icons to controls the width and height simultaneously. or when we want to add a disabled and onClick event handlers.


The Solution Is Here! ✨

using this package you can combine all of your svg files into a singular file, each icon is inside a symbol, which then can be used by its id, and is accessed easily from anywhere with Benefits:

  • Just one fetch request to get all the icons
  • It's cached on the browser
  • A single component to rule all the svg properties
  • Type safe! icon names are saved into a d.ts file
  • washes the dishes for you
  • it's nice... really.

Getting Started 🚀

Install it using your preferred package manager:

npm i @al00x/svg-packer

Now you can call it from your terminal:

npx svg-packer

gather some SVGs and you are ready to go!


How To Use It? 🔦

The simplest way to generate the Packed SVG is to give an input & output to start the process:

npx svg-packer -i ./folder/to/svg/icons -o ./folder/to/output

After running this command you will get two files in the output:

  • Packed-SVG.svg contains all the svgs you pointed to.
  • Packed-SVG-types.d.ts contains all the icon names for type safety (extracted from the icons filename).

You are all set to use these files the way you like to; The samples below are made for each framework to gives you a quick start!

Samples 📔


Angular

import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
import { IconNameType } from './svg-packed-names';

@Component({
  selector: 'icon',
  template: `
    <div
      class="icon-wrapper"
    >
      <svg style="fill: currentColor !important; color: inherit" [style.width]="size" [style.height]="size">
        <use [attr.href]="'/assets/svg-packed.svg#' + name" />
      </svg>
    </div>
  `,
  styles: ``,
  standalone: true,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class IconComponent {
  @Input({ required: true }) name!: IconNameType;
  @Input() size?: string = '1.5rem';
}

Qwik

import iconsSprite from './svg-packed.svg';
import type { IconName } from './svg-packed-names';
import { component$ } from '@builder.io/qwik';

export default component$(
  ({
    name,
    size = '1.5rem',
    ...props
  }: {
    name: IconName;
    size?: string;
    class?: string;
  }) => {
    return (
      <svg {...props} class={`${props.class ?? ''}`} style={{ width: size, height: size }}>
        <use href={`${iconsSprite}#${name}`} />
      </svg>
    );
  },
);

Issues & Contributes are welcomed! 💞

If you find a bug, got a fix, have an idea, made a new feature, or ... feel free to send it right away!