From 4c14fbd995f53e5ad6590c97e4fd5e2ae7528d86 Mon Sep 17 00:00:00 2001 From: junghyeonsu Date: Fri, 1 Nov 2024 15:41:31 +0900 Subject: [PATCH] feat(figma-plugin): stripBeforeIcon --- figma-plugin/plugin-src/service.ts | 10 +++++----- figma-plugin/plugin-src/utils.ts | 13 +++++++++---- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/figma-plugin/plugin-src/service.ts b/figma-plugin/plugin-src/service.ts index 18fe788..4b70503 100644 --- a/figma-plugin/plugin-src/service.ts +++ b/figma-plugin/plugin-src/service.ts @@ -3,7 +3,7 @@ import type { IconaIconData } from "@icona/types"; import { Base64 } from "js-base64"; import type { PngOptionPayload } from "../common/types"; -import { removeDotPrefix } from "./utils"; +import { stripBeforeIcon } from "./utils"; type TargetNode = | ComponentNode @@ -125,7 +125,7 @@ export async function getSvgFromExtractedNodes(nodes: ExtractedNode[]) { metadatas.push(...metadatasRegexResult[1].split(",")); return { - name: removeDotPrefix(component.name), + name: stripBeforeIcon(component.name), svg: await node.exportAsync({ format: "SVG_STRING", svgIdAttribute: true, @@ -135,7 +135,7 @@ export async function getSvgFromExtractedNodes(nodes: ExtractedNode[]) { } return { - name: removeDotPrefix(component.name), + name: stripBeforeIcon(component.name), svg: await node.exportAsync({ format: "SVG_STRING", svgIdAttribute: true, @@ -149,7 +149,7 @@ export async function getSvgFromExtractedNodes(nodes: ExtractedNode[]) { if (cur.status === "rejected") console.error(cur.reason); if (cur.status === "fulfilled") { const { name, ...rest } = cur.value as IconaIconData; - const removedName = removeDotPrefix(name); + const removedName = stripBeforeIcon(name); acc[removedName] = { ...rest, name, @@ -214,7 +214,7 @@ export async function exportFromIconaIconData( }, {} as Record); // name = "icon_name" - const name = removeDotPrefix(component.name); + const name = stripBeforeIcon(component.name); result[name] = { ...result[name], png: { diff --git a/figma-plugin/plugin-src/utils.ts b/figma-plugin/plugin-src/utils.ts index 72ac562..1a9c19a 100644 --- a/figma-plugin/plugin-src/utils.ts +++ b/figma-plugin/plugin-src/utils.ts @@ -23,9 +23,14 @@ export function getIconaFrame(): FrameNode { } /** - * @description 컴포넌트 이름 맨 앞에 `.`이 붙어있는 경우에는 `.`을 없애요. - * + * @param name .icon_name or ❌icon_name + * @returns icon_name + * @description `icon` 앞에 있는 내용들은 전부 제거 후 반환 */ -export function removeDotPrefix(name: string) { - return name.startsWith(".") ? name.replace(".", "") : name; +export function stripBeforeIcon(name: string) { + if (name.includes("icon")) { + return name.replace(/.*icon/, "icon"); + } + + return name; }