Skip to content
This repository was archived by the owner on Feb 14, 2025. It is now read-only.

feat: add cleanSymbol config #8

Merged
merged 1 commit into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading