/tmp/wp_post_content.html
  
A high-performance TypeScript SDK for extracting Figma design data. Optimized for AI workflows with token-efficient TOON format (30-60% smaller), automatic pagination for large files, and parallel image processing.
requireEnv, logging, deduplication helpersnpm install figma-skill
yarn add figma-skill
pnpm add figma-skill
bun add figma-skill
import { FigmaExtractor } from "figma-skill";
const client = new FigmaExtractor({
token: process.env.FIGMA_ACCESS_TOKEN,
});
// Extract in TOON format (token-efficient)
const design = await client.getFile("abc123DEF", { format: "toon" });
// design is a string in TOON format
await Bun.write("design.toon", design);
import { FigmaExtractor } from "figma-skill";
const client = new FigmaExtractor({ token: process.env.FIGMA_TOKEN });
const design = await client.getFile("fileKey", { format: "json" });
// Access extracted data
design.nodes.forEach((node) => {
console.log(`${node.name}: ${node.type}`);
});
import { FigmaExtractor } from "figma-skill";
const client = new FigmaExtractor({ token: process.env.FIGMA_TOKEN });
// TOON format is 30-60% smaller than JSON
const toonDesign = await client.getFile("fileKey", { format: "toon" });
await Bun.write("design.toon", toonDesign);
// For programmatic access, use JSON format
const jsonDesign = await client.getFile("fileKey", { format: "json" });
console.log(jsonDesign.nodes.length);
import { FigmaExtractor } from "figma-skill";
const client = new FigmaExtractor({ token: process.env.FIGMA_TOKEN });
const design = await client.getNodes("fileKey", {
ids: ["1:2", "1:3", "1:4"],
});
import { FigmaExtractor } from "figma-skill";
// Deduplicated download (removes duplicates)
import { downloadImagesDeduplicated } from "figma-skill/images";
const client = new FigmaExtractor({ token: process.env.FIGMA_TOKEN });
// Basic download
const downloaded = await client.downloadImages("fileKey", {
ids: ["1:2", "1:3"],
outputDir: "./output/images",
format: "svg",
parallel: 5,
});
const deduped = await downloadImagesDeduplicated(
[
{ id: "1:2", url: "https://..." },
{ id: "1:3", url: "https://..." },
{ id: "1:2", url: "https://..." }, // duplicate removed
],
{ outputDir: "./output/images" }
);
import { FigmaExtractor } from "figma-skill";
const client = new FigmaExtractor({ token: process.env.FIGMA_TOKEN });
// For progress tracking on very large files (10K+ nodes)
const stream = await client.streamFile("fileKey", {
chunkSize: 100,
});
stream.progress.on("progress", (p) => {
console.log(`${p.percent}% - ${p.processed}/${p.total} nodes`);
});
for await (const chunk of stream) {
// Process chunk.nodes
}
// Note: getFile() also handles large files automatically via pagination
TOON is a token-efficient format for design data that reduces file size by 30-60% compared to JSON. It's optimized for AI consumption and processing.
import { FigmaExtractor, toToon, fromToon } from "figma-skill";
const client = new FigmaExtractor({ token: process.env.FIGMA_TOKEN });
// Extract directly to TOON
const toonString = await client.getFile("fileKey", { format: "toon" });
// Or convert existing design
const design = await client.getFile("fileKey", { format: "json" });
const toonString = toToon(design);
// Convert back from TOON
const restored = fromToon(toonString);
| Use Case | Format | Reason |
| ----------------------- | ------ | ---------------------- |
| AI processing | toon | Token efficiency |
| File storage | toon | Smaller file size |
| Node filtering/counting | json | Need structured access |
| Debugging | json | Human-readable |
| Final output | toon | Always use TOON |
Main client class for Figma API interactions.
new FigmaExtractor(config: FigmaExtractorConfig)
Options:
token (string, required): Figma access tokenbaseUrl (string, optional): API base URL (default: https://api.figma.com/v1)timeout (number, optional): Request timeout in ms (default: 30000)maxRetries (number, optional): Max retry attempts (default: 3)cache (boolean, optional): Enable caching (default: true)cacheSize (number, optional): Cache size (default: 100)concurrent (number, optional): Max concurrent requests (default: 10)getFile(fileKey, options?)Extract complete Figma file with automatic pagination fallback.
Returns: Promise<SimplifiedDesign | string> (string when format: "toon")
Options:
format ("json" | "toon"): Output format (default: "json")extractors: Custom extractor functionsmaxDepth: Maximum traversal depthnodeFilter: Filter function for nodesincludeComponents: Include component definitions (default: true)includeComponentSets: Include component set definitions (default: true)getNodes(fileKey, options)Extract specific nodes by IDs.
Returns: Promise<SimplifiedDesign>
Options:
ids (string[], required): Node IDs to fetchextractors: Custom extractor functionsmaxDepth: Maximum traversal depthnodeFilter: Filter function for nodesstreamFile(fileKey, config
(内容节选自官方 README)
安装
# 安装到当前项目
npx skills add figma-skill
# 全局安装
npx skills add figma-skill -g
来源
- 作者:
eekrain - 仓库:https://github.com/eekrain/figma-skill
- npm 包:
figma-skill
评论区