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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@choiceform/icons-js

v1.0.3

Published

JavaScript library for SVG icons

Readme

@choiceform/icons-js

JavaScript library for SVG icons.

Installation

# npm
npm install @choiceform/icons-js

# pnpm
pnpm add @choiceform/icons-js

# yarn
yarn add @choiceform/icons-js

How to use

Choiceform Icons for JavaScript is built with ES Modules and is fully tree-shakable.

Each icon can be imported and used to generate SVG strings or DOM elements. This way, only the icons that are imported into your project are included in the final bundle. The rest of the icons are tree-shaken away.

Using with CDN

<!DOCTYPE html>
<body>
  <!-- Use data-icon attribute to specify icons -->
  <i data-icon="workspace"></i>
  <i data-icon="file-upload"></i>
  <i data-icon="settings"></i>

  <!-- Include the UMD version -->
  <script src="https://unpkg.com/@choiceform/icons-js@latest/dist/umd/icons-js.js"></script>
  <script>
    // Initialize all icons
    iconsJs.createIcons({
      icons: iconsJs.default,
    });
  </script>
</body>

Using with ES Modules

import {
  createIcons,
  Workspace,
  FileUpload,
  Settings,
} from "@choiceform/icons-js";

// Only import icons you need (recommended, reduces bundle size)
createIcons({
  icons: {
    Workspace,
    FileUpload,
    Settings,
  },
});

Generate SVG Strings

import { Search, CircleAdd, SettingsSolid } from "@choiceform/icons-js";

// Create an SVG string
const searchSvg = Search.toSvg({
  width: "16",
  height: "16",
  color: "currentColor",
});

// Append icon to element
document.getElementById("icon-container").innerHTML = searchSvg;

// Or create multiple icons
const icons = [Search, CircleAdd, SettingsSolid];
const container = document.getElementById("icons-container");

icons.forEach((icon) => {
  container.innerHTML += icon.toSvg();
});

Parameters

Each icon accepts the following parameters when calling toSvg():

| Name | Type | Default | Description | | -------- | ------------------ | ---------------- | ------------------- | | width | string \| number | '16' | Width of the icon | | height | string \| number | '16' | Height of the icon | | color | string | 'currentColor' | Color of the icon | | title | string | undefined | Accessibility title |

Applying parameters

import { Search } from "@choiceform/icons-js";

// Create an SVG with custom parameters
const searchSvg = Search.toSvg({
  width: "32",
  height: "32",
  color: "#1976d2",
  title: "Search icon",
});

document.getElementById("icon-container").innerHTML = searchSvg;

Advanced Usage

Custom attribute name

By default, the library uses the data-icon attribute to find elements to replace. You can customize this attribute name:

import { createIcons, Workspace, FileUpload } from "@choiceform/icons-js";

createIcons({
  nameAttr: "data-cf-icon", // Use data-cf-icon instead of data-icon
  icons: {
    Workspace,
    FileUpload,
  },
});

Then use it in HTML like this:

<i data-cf-icon="workspace"></i>

Custom attributes

You can set default attributes for all icons:

import { createIcons, Workspace, FileUpload } from "@choiceform/icons-js";

createIcons({
  attrs: {
    class: ["my-icon-class", "icon"], // Classes will be merged
    width: "20",
    height: "20",
    fill: "#333",
  },
  icons: {
    Workspace,
    FileUpload,
  },
});

Creating elements directly

You can create icon elements directly, instead of replacing placeholders:

import { createElement, Workspace } from "@choiceform/icons-js";

// Create an SVG element
const workspaceIcon = createElement(Workspace); // Returns HTMLElement (svg)

// Add to the DOM
const container = document.getElementById("icon-container");
container.appendChild(workspaceIcon);

Adding custom attributes

import { createElement, FileUpload } from "@choiceform/icons-js";

// Create an icon with custom attributes
const fileUploadIcon = createElement(FileUpload, {
  class: "custom-icon",
  width: "32",
  height: "32",
  fill: "#1976d2",
});

// Add to the DOM
document.body.appendChild(fileUploadIcon);

Styling with CSS

All icons include a default CSS class name (choiceform-icon) that can be used for styling:

.choiceform-icon {
  /* Your custom styles */
  filter: drop-shadow(0 0 2px rgba(0, 0, 0, 0.2));
}

Custom Class Name

The default class name can be changed globally by modifying the icon-config.json file at the root of the project:

{
  "iconClassName": "my-custom-icon-class"
}

After changing the configuration, regenerate the icons:

npm run generate

Using Icon Metadata

The library also exports icon metadata that can be useful for building icon pickers, documentation, or other features that need information about available icons.

import { iconMetadata } from "@choiceform/icons-js/metadata";

// Get total number of icons
console.log(`Total icons: ${iconMetadata.length}`);

// Create a list of all icon names with categories
const iconList = iconMetadata.map(
  (icon) => `${icon.name} - Category: ${icon.category}`
);

// Display the icon list
const container = document.getElementById("icon-list");
iconList.forEach((item) => {
  const li = document.createElement("li");
  li.textContent = item;
  container.appendChild(li);
});

Features

  • Tree Shakable: Only import the icons you use
  • TypeScript Support: Full TypeScript definitions
  • Framework Agnostic: Use with any JavaScript framework or vanilla JS
  • Accessible: Attributes for accessibility are applied automatically
  • Customizable: Easy to style with CSS
  • Optimized SVGs: All icons are optimized with SVGO
  • Multiple Usage Methods: Support for CDN, ES modules, and direct DOM manipulation

Metadata Properties

Each icon in the metadata includes:

| Property | Description | | ---------- | ---------------------------------- | | name | The name of the icon | | category | The category the icon belongs to | | tags | Array of tags for search/filtering | | filename | Original SVG filename | | width | Width of the SVG (if available) | | height | Height of the SVG (if available) |