mirror of
https://github.com/pheralb/svgl.git
synced 2025-12-29 08:01:36 +08:00
🛠️ Improve parseSvgFilename to support firstUpperCase option for component naming
This commit is contained in:
@@ -1,15 +1,18 @@
|
||||
interface ParseSvgFilename {
|
||||
file: string;
|
||||
log?: boolean;
|
||||
firstUpperCase?: boolean;
|
||||
}
|
||||
|
||||
export const parseSvgFilename = (params: ParseSvgFilename): string => {
|
||||
const { file, log } = params;
|
||||
const { file, log, firstUpperCase = false } = params;
|
||||
const name = file.replace(/\.svg$/i, "");
|
||||
|
||||
let component = name
|
||||
.replace(/[-_\s]+(.)?/g, (_, char) => (char ? char.toUpperCase() : ""))
|
||||
.replace(/^(.)/, (char) => char.toLowerCase());
|
||||
.replace(/^(.)/, (char) =>
|
||||
firstUpperCase ? char.toUpperCase() : char.toLowerCase(),
|
||||
);
|
||||
|
||||
if (/^\d/.test(component)) {
|
||||
if (log) {
|
||||
|
||||
Reference in New Issue
Block a user