🛠️ Improve parseSvgFilename to support firstUpperCase option for component naming
📦 Build / 🛠️ Build app (push) Has been cancelled
🧑‍🚀 Check / ⚙️ Linting (push) Has been cancelled
🧑‍🚀 Check / 📦 SVGs Size (push) Has been cancelled

This commit is contained in:
pheralb
2025-08-31 16:35:30 +01:00
parent 4cd2c84273
commit 55199765be
2 changed files with 6 additions and 2 deletions
+1
View File
@@ -191,6 +191,7 @@ async function convertSvgToReact(svgPath: string): Promise<string> {
const componentName = parseSvgFilename({ const componentName = parseSvgFilename({
file: path.basename(svgPath, ".svg"), file: path.basename(svgPath, ".svg"),
log: true, log: true,
firstUpperCase: true,
}); });
const code = await parseReactSvgContent({ const code = await parseReactSvgContent({
componentName, componentName,
+5 -2
View File
@@ -1,15 +1,18 @@
interface ParseSvgFilename { interface ParseSvgFilename {
file: string; file: string;
log?: boolean; log?: boolean;
firstUpperCase?: boolean;
} }
export const parseSvgFilename = (params: ParseSvgFilename): string => { export const parseSvgFilename = (params: ParseSvgFilename): string => {
const { file, log } = params; const { file, log, firstUpperCase = false } = params;
const name = file.replace(/\.svg$/i, ""); const name = file.replace(/\.svg$/i, "");
let component = name let component = name
.replace(/[-_\s]+(.)?/g, (_, char) => (char ? char.toUpperCase() : "")) .replace(/[-_\s]+(.)?/g, (_, char) => (char ? char.toUpperCase() : ""))
.replace(/^(.)/, (char) => char.toLowerCase()); .replace(/^(.)/, (char) =>
firstUpperCase ? char.toUpperCase() : char.toLowerCase(),
);
if (/^\d/.test(component)) { if (/^\d/.test(component)) {
if (log) { if (log) {