Skip to content

Commit

Permalink
feat(figma-plugin): stripBeforeIcon
Browse files Browse the repository at this point in the history
  • Loading branch information
junghyeonsu committed Nov 1, 2024
1 parent 59b61d0 commit 4c14fbd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
10 changes: 5 additions & 5 deletions figma-plugin/plugin-src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -214,7 +214,7 @@ export async function exportFromIconaIconData(
}, {} as Record<keyof IconaIconData["png"], string>);

// name = "icon_name"
const name = removeDotPrefix(component.name);
const name = stripBeforeIcon(component.name);
result[name] = {
...result[name],
png: {
Expand Down
13 changes: 9 additions & 4 deletions figma-plugin/plugin-src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 4c14fbd

Please sign in to comment.