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

figma-svg-exporter

v1.1.1

Published

Export SVG assets from Figma with SVGO optimization and TypeScript type generation

Readme

figma-svg-exporter

Export SVG icons from a Figma file to a local directory — with SVGO optimization, fillcurrentColor normalization, and automatic TypeScript type generation.

What it does

  1. Fetches components (or instances) from a Figma file, optionally scoped to a canvas and frame
  2. Downloads their SVG exports via the Figma API in sequential batches
  3. Optimizes each SVG with SVGO and normalizes hardcoded fill colors to currentColor
  4. Generates a TypeScript union type from the exported filenames

Output example — alongside the SVG files, a types.ts is written to the output directory:

export type SvgIcons =
  | "arrow-left"
  | "arrow-right"
  | "check"
  | "close"
  | "spinner";

Installation

# One-off run without installing
npx figma-exporter --file-id <FILE_ID> --output ./src/assets/icons

# Dev dependency (recommended)
bun add -d figma-exporter
# or
npm install --save-dev figma-exporter

Quick start

1. Create a config file in the project root:

// figma-exporter.config.js
export default {
  fileId: "your-figma-file-id", // from the Figma URL
  outputDir: "./src/assets/icons",
  canvas: "Icons", // page name in Figma
  frame: "Export", // frame name inside that page
  clearOutputDir: true,
};

2. Set your Figma token:

export FIGMA_TOKEN=your_personal_access_token

Generate a token in Figma → Account Settings → Personal access tokens.

3. Run:

npx figma-exporter
# or, if installed locally:
bun figma-exporter

CLI reference

figma-exporter [options]

| Flag | Short | Default | Description | | -------------------- | ----- | --------------- | -------------------------------------------- | | --config <path> | -c | auto-discovered | Path to config file | | --token <token> | -t | $FIGMA_TOKEN | Figma personal access token | | --file-id <id> | -f | — | Figma file ID (required) | | --output <dir> | -o | ./svg-icons | Output directory | | --canvas <name> | | — | Canvas (page) name to scope the search | | --frame <name> | | — | Frame name within the canvas | | --clear | | false | Delete all files in output dir before export | | --type-name <name> | | SvgIcons | Name for the generated TypeScript union type | | --no-log | | — | Suppress all log output | | --version | -v | | Print version | | --help | -h | | Display help |

CLI flags override values from the config file. Advanced options (retry, concurrency, etc.) are config-file-only.

Config file

The config file is optional — all required fields can be passed as CLI flags. When present, it is loaded with dynamic import().

Supported filenames (searched in order in the current working directory):

figma-exporter.config.js
figma-exporter.config.cjs
figma-exporter.config.json

A custom path can be set with --config ./path/to/config.js.

Full config reference

| Option | Type | Default | CLI flag | Description | | --------------------- | -------------------------------------- | -------------- | ------------- | ---------------------------------------------------- | | token | string | — | --token | Figma personal access token (alternative to env var) | | fileId | string | — | --file-id | Figma file ID (found in the file URL) | | outputDir | string | ./svg-icons | --output | Directory where SVG files are written | | canvas | string | — | --canvas | Canvas (page) name to scope the search | | frame | string | — | --frame | Frame name within the canvas | | entityTypeForExport | 'components' \| 'instances' \| Array | 'components' | — | Which node types to export | | component | string \| (node) => boolean | — | — | Filter entities by name or a custom predicate | | batchSize | number | 100 | — | Nodes per fileImages API request | | clearOutputDir | boolean | false | --clear | Delete existing files before writing | | retryAttempts | number | 3 | — | Max retry attempts on API 429 responses | | retryDelay | number | 1000 | — | Initial backoff delay in ms (doubles each attempt) | | requestDelay | number | 0 | — | Delay in ms between sequential batch requests | | downloadConcurrency | number | 5 | — | Max concurrent SVG downloads | | typeName | string | SvgIcons | --type-name | Name for the generated TypeScript union type | | skipExisting | boolean | false | — | Skip files that already exist in outputDir. Ignored when clearOutputDir is true | | logger | Logger \| false \| null | built-in | — | Custom logger or false/null to disable |

Example with all options:

// figma-exporter.config.js
export default {
  fileId: "abc123xyz",
  outputDir: "./src/assets/icons",
  canvas: "Icons",
  frame: "Export",
  entityTypeForExport: "components",
  clearOutputDir: true,

  typeName: "IconName",

  // API resilience
  batchSize: 50,
  retryAttempts: 5,
  retryDelay: 2000,
  requestDelay: 200,
  downloadConcurrency: 10,
  skipExisting: true,
};

Rate limiting

The Figma API enforces rate limits. If you hit them, the export will fail with an error showing the suggested retry delay.

To reduce the chance of being rate limited:

export default {
  // ...
  batchSize: 50,         // fewer nodes per API request
  requestDelay: 1000,    // 1s pause between batch requests
  downloadConcurrency: 3,
  skipExisting: true,    // don't re-download files that already exist
};

skipExisting: true is the most effective option for incremental updates — on repeat runs only new or renamed icons are fetched from Figma.

Environment variables

| Variable | Description | | ------------- | ----------------------------------------------------------------------------------------------- | | FIGMA_TOKEN | Figma personal access token. Lower priority than --token, higher than token in config file. |

Programmatic API

import { exportFiles } from "figma-exporter";

await exportFiles(process.env.FIGMA_TOKEN!, {
  fileId: "abc123xyz",
  outputDir: "./src/assets/icons",
  canvas: "Icons",
  frame: "Export",
  clearOutputDir: true,
});

Exported types

import type { ExporterConfig, Logger, LoggerOption } from "figma-exporter";
import { consoleLogger } from "figma-exporter";

Logger customization

By default the built-in console logger prints colored output prefixed with [figma-exporter]:

[figma-exporter] > Stage 1/4: Fetching Figma file abc123...
[figma-exporter] > Found 142 components to export
[figma-exporter] > Requesting SVG export URLs in 2 batch(es) of up to 100...
[figma-exporter] > Stage 2/4: Downloading 142 SVG files to /src/assets/icons...
[figma-exporter] > Stage 3/4: Processing 142 SVG files (fill normalization + SVGO)...
[figma-exporter] > Stage 4/4: Generating TypeScript union type "SvgIcons"...
[figma-exporter] > Export finished successfully

Disable logging:

await exportFiles(token, { ...config, logger: false });
figma-exporter --no-log

Custom logger — any object with info, warn, and error methods works:

import type { Logger } from "figma-exporter";

const logger: Logger = {
  info: (msg) => myLogger.info(msg),
  warn: (msg) => myLogger.warn(msg),
  error: (msg) => myLogger.error(msg),
};

await exportFiles(token, { ...config, logger });

This is compatible with pino, winston, consola, and any other popular logger out of the box.