Skip to content

Commit

Permalink
feat: add cleanSymbol config
Browse files Browse the repository at this point in the history
  • Loading branch information
nmerget committed Apr 4, 2024
1 parent e732a51 commit c786d98
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/figma-icon-exporter/download-icons/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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`;
Expand Down
5 changes: 5 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

0 comments on commit c786d98

Please sign in to comment.