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

@uxf/icons-generator

v11.32.0

Published

A well configurable tool for generating and managing custom SVG icons and sprites in web projects.

Downloads

892

Readme

@uxf/icons-generator

A well configurable tool for generating and managing custom SVG icons and sprites in web projects.

Quick Start

Installation

Use npm or yarn to install:

npm i -D @uxf/icons-generator
yarn add -D @uxf/icons-generator

Configuration

Create a icons.config.js file in your project's root:

module.exports = {
    icons: {
        test: {
            width: 24,
            height: 24,
            data: `<path fill="#fecd09" d="M33.03 17.44c-1.68 0-3.12-.99-3.79-2.42h7.58a4.181 4.181 0 01-3.79 2.42z" />`
        }
    }
}

See the full configuration options here.

Generating Icons

Run the generator:

icons-gen

For a custom config file name:

icons-gen --configFile=yourConfigFileName.js

Configuration Details

| Key | Type | Default | Required | Description | |-------------------------|-----------------------------------------------|-----------------------------------------------------------------------|----------|----------------------------------| | typescript | boolean | true | No | - | | configDirectory | string | "/src/config/" | No | - | | generatedDirectory | string | "/public/icons-generated/" | No | - | | spriteFileName | string | _icon-sprite.svg | No | Specify custom sprite file name | | typeName | string | IconsSet | No | - | | customDefinitionContent | string | - | No | - | | icons | Record<string, SimpleIcon \| SizedIcon \| IconFromAdapterFunction> | - | Yes | More details here | | fallbackFilesDirectory | - | - | No | More details here |

Icon Types

SimpleIcon

type SimpleIcon = {
    data: string;
    height: number;
    width: number;
};

Example:

test: {
    width: 50,
    height: 60,
    data: `<path fill="#fecd09" d="M33.03 17.44c-1.68 0-3.12-.99-3.79-2.42h7.58a4.181 4.181 0 01-3.79 2.42z" />`,
}

SizedIcon

type SizedIcon = Record<number, string>;

Example:

test: {
    24: `<path fill="#fecd09" d="M33.03 17.44c-1.68 0-3.12-.99-3.79-2.42h7.58a4.181 4.181 0 01-3.79 2.42z" />`,
    44: `<path fill="#fecd09" d="M33.03 17.44c-1.68 0-3.12-.99-3.79-2.42h7.58a4.181 4.181 0 01-3.79 2.42z" />`,
}

Predefined providers

Font Awesome Pro Adapter

Local Development Setup

// Set registry and token
npm config set "@fortawesome:registry" https://npm.fontawesome.com/
npm config set "//npm.fontawesome.com/:_authToken" YOUR_TOKEN

// Install package
npm install --save-dev @fortawesome/fontawesome-pro

Usage

const { faPro } = require('@uxf/icons-generator/providers/fa-pro');

icons: {
    // for icons with default name (preferred)
    ...faPro.adapter(["brands.linkedin"]),
    // to define custom name for an icon
    twitter: faPro.icon("brands.twitter"),
}

Without Private Key

If your project already contains generated icons, installing the Font Awesome Pro package is not necessary. The package automatically generates a 'fallback file' for the icons in use, ensuring functionality even without Font Awesome Pro. However, while this setup allows for the continued use of existing icons, adding new icons from the adapter will not be possible.

Recommended Usage (Step-by-Step)

1. Configuration

Create and configure your icon settings in a config file at the project's root.

2. Icon Generation

Execute icons-gen to produce:

  • SVG sprite and individual files.
  • Definition file with icon list and sizes.
  • Config file with icon version and sprite path.

3. Icon Component Setup

Incorporate the generated output into your project. Example for TypeScript and React:

import { ICONS, IconsSet } from "src/config/icons";
import { ICON_SPRITE } from "src/config/icons-config";

type IconProps = {
    name: IconsSet;
};

export const Icon: FC<IconProps> = ({ name }) => {
    const sizes = ICONS[name];

    return (
        <svg
            height={sizes.h}
            width={sizes.w}
            preserveAspectRatio="xMidYMid meet"
            role="img"
            viewBox={`0 0 ${sizes.w} ${sizes.h}`}
        >
            <use xlinkHref={`${ICON_SPRITE}#icon-sprite--${name}`} />
        </svg>
    );
};

4. Sprite Preloading (Optional)

import { ICON_SPRITE, ICONS_VERSION } from "src/config/icons-config";

// code here...

<Head>
    <link
        as="image"
        href={`${ICON_SPRITE}?v=${ICONS_VERSION}`}
        rel="preload"
        type="image/svg+xml"
    />
</Head>

5. Verification

Run icons-check to ensure icon consistency with the config. It's recommended to integrate this check into your CI process.