From c786d986bd01f609e275ab23ecb5b9992d869060 Mon Sep 17 00:00:00 2001 From: NicolasMerget Date: Thu, 4 Apr 2024 13:20:38 +0200 Subject: [PATCH] feat: add cleanSymbol config --- src/figma-icon-exporter/download-icons/index.ts | 14 +++++++++++++- src/types.ts | 5 +++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/figma-icon-exporter/download-icons/index.ts b/src/figma-icon-exporter/download-icons/index.ts index 947e221..18cfd07 100644 --- a/src/figma-icon-exporter/download-icons/index.ts +++ b/src/figma-icon-exporter/download-icons/index.ts @@ -2,6 +2,9 @@ import { DownloadTaskType } from "../../types"; import { createWriteStream } from "fs"; import axios from "axios"; +const cleanSymbols = (iconName: string): string => + iconName.replaceAll("&", "and").replaceAll("/", "or"); + export const downloadIcons = async ({ icon, resolvedImages, @@ -30,8 +33,17 @@ export const downloadIcons = async ({ } else { iconName = iconName.trim().replaceAll(" ", "_"); } + + if ( + iconNameConfig.cleanSymbols === undefined || + iconNameConfig.cleanSymbols + ) { + iconName = cleanSymbols(iconName); + } } else { - iconName = iconName.toLowerCase().trim().replaceAll(" ", "_"); + iconName = cleanSymbols( + iconName.toLowerCase().trim().replaceAll(" ", "_"), + ); } const filePath = `${icon.dir}/${iconName}.svg`; diff --git a/src/types.ts b/src/types.ts index 794d5a5..31aa070 100644 --- a/src/types.ts +++ b/src/types.ts @@ -23,6 +23,11 @@ export type IconNameConfigType = { * Change the separator, defaults to '_' */ separator?: string; + + /** + * Replaces symbols(and,or,...), defaults to true + */ + cleanSymbols?: string; }; export type OptionsType = {