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 🙏

© 2026 – Pkg Stats / Ryan Hefner

open-icon-transform

v0.1.9

Published

Framework-agnostic SVG transformation pipeline used by open-icon.

Readme

open-icon-transform

Framework-agnostic SVG transformation engine used by open-icon tooling.

Installation

npm install open-icon-transform

Other Packages In This Repo

  • open-icon-svg: ships the raw Open Icon SVG files plus typed catalog helpers (names, categories, alias resolution, file/import path lookup).
  • vite-plugin-open-icon: Vite integration layer that runs this transform engine automatically when importing .svg?open-icon.

Use open-icon-transform directly when you want full control in scripts, custom build steps, CLIs, or non-Vite runtimes.

If you want your own SVGs to behave like Open Icon source icons, follow the icon authoring rules documented on the docs site:

  • https://open-icon.org/icons/authoring/

Quick Start

import { transformOpenIconSvg } from 'open-icon-transform';

const output = transformOpenIconSvg(
  '<svg><path style="fill:red;"/></svg>',
  '/icons/icon_demo.svg'
);

CLI

Transform a file directly from the command line:

npx open-icon-transform@latest src/my-icon.svg --output dist/my-icon-transformed.svg

Transform a folder recursively while preserving relative paths:

npx open-icon-transform@latest src/icons --output dist/icons

If the package is already installed in the project, the bin alias also works:

npx open-icon-transformer src/my-icon.svg --output dist/my-icon-transformed.svg

Without --output, the transformed SVG is written to stdout. Directory input requires --output.

First-class CLI flags

Use dedicated flags for the common transform settings:

npx open-icon-transform@latest src/my-icon.svg \
  --default-icon-fill '#123456' \
  --default-icon-stroke-width 6 \
  --remove-tag title \
  --remove-attribute data-name \
  --output dist/my-icon.svg

Available first-class flags:

| Flag | Repeatable | Maps to | |---|---|---| | --simplify-colors | no | simplifyColors: true | | --no-simplify-colors | no | simplifyColors: false | | --replace-name <value> | yes | replaceName | | --remove-data <value> | yes | removeData | | --remove-tag <tag> | yes | removeTags | | --remove-attribute <attribute> | yes | removeAttributes | | --default-icon-fill <value> | no | default.iconFill | | --default-icon-fill-opacity <value> | no | default.iconFillOpacity | | --default-icon-stroke-width <value> | no | default.iconStrokeWidth | | --default-icon-stroke-linecap <value> | no | default.iconStrokeLinecap | | --default-icon-stroke-linejoin <value> | no | default.iconStrokeLinejoin |

CLI config file

Load transform settings from a JSON or JS config file when you need the full surface, such as replaceData or configData:

npx open-icon-transform@latest src/my-icon.svg --config open-icon-transform.config.json --output dist/my-icon.svg
{
  "default": {
    "iconFill": "#123456"
  },
  "simplifyColors": true,
  "removeData": ["/<\\?xml.*?\\?>/", "/<!--.*?-->/"]
}

CLI inline settings

Pass any transform settings inline as JSON for advanced one-off runs:

npx open-icon-transform@latest src/my-icon.svg \
  --settings '{"default":{"iconFill":"#123456"},"simplifyColors":false}' \
  --output dist/my-icon.svg

CLI precedence

When more than one config source is provided, precedence is:

  1. first-class CLI flags
  2. --settings inline JSON
  3. --config file

That means dedicated flags are the primary interface, while config files and inline JSON remain available for advanced nested settings.

API

transformOpenIconSvg(svgContent, filePath, settings?)

Runs the full transformation pipeline:

  1. Optional color simplification (#hex -> nearest base color name)
  2. Group opacity flattening (<g style="opacity:..."> -> child style)
  3. removeData cleanup (literal + regex)
  4. replaceData substitutions
  5. removeTags / removeAttributes
  6. {{...}} variable interpolation

openIconSvgLoaderDefaults

Default pipeline settings mirrored from open-icon build config.

Types

  • OpenIconSvgLoaderSettings
  • OpenIconReplaceDataEntry
  • OpenIconSvgMeta

Settings Reference

| Key | Type | Description | |---|---|---| | query | string | Shared compatibility key (used by loader wrappers) | | replaceName | string \| string[] | Prefixes/fragments removed from source filename before metadata derivation | | replaceData | [string\|string[], string][] | Literal replacement rules | | removeData | string \| string[] | Literal or regex patterns (regex as /.../) removed from SVG | | removeTags | string \| string[] | Element tags removed from output | | removeAttributes | string \| string[] | Attributes removed from output | | simplifyColors | boolean | Enables color simplification | | default | object | Defaults used in interpolation templates | | configData | Record<string, unknown> | Custom interpolation values |

Variable Interpolation

Placeholders are supported in replacement strings:

  • {{componentName}}
  • {{fileName}}
  • {{default.iconFill}}
  • custom values like {{brand.primary}} from configData

Example: Custom Brand Color Variable

transformOpenIconSvg(svg, '/icons/icon_button.svg', {
  replaceData: [['fill:red;', 'fill: {{brand.primary}};']],
  configData: { brand: { primary: '#123456' } },
  simplifyColors: false,
  removeData: [],
});

Testing

npm test

Tests cover individual transforms and combined transformation scenarios.