diff --git a/src/utils/collectionToJS.ts b/src/utils/collectionToJS.ts index b8ffc87..9a97fa4 100644 --- a/src/utils/collectionToJS.ts +++ b/src/utils/collectionToJS.ts @@ -20,7 +20,7 @@ async function processCollection({ if (value !== undefined && validTypes.has(resolvedType)) { let currentObj = variables[toCamelCase(mode.name)]; - const parts = name.split("/").map(toCamelCase); + const parts = name.split("/").map((str) => toCamelCase(str)); parts.forEach(async (part, i) => { if (i === parts.length - 1) { @@ -32,7 +32,7 @@ async function processCollection({ const collPrefix = linkedVarCollection && linkedVarCollection.name !== name ? `${toCamelCase(linkedVarCollection.name)}.` : ''; - currentObj[part] = `${collPrefix}${toCamelCase(mode.name)}.${linkedVar.name.split('/').map(toCamelCase).join('.')}`; + currentObj[part] = `${collPrefix}${toCamelCase(mode.name)}.${linkedVar.name.split('/').map((str) => toCamelCase(str)).join('.')}`; } else { currentObj[part] = '_unlinked'; } diff --git a/src/utils/stringTransformation.ts b/src/utils/stringTransformation.ts index cd4371e..70718ce 100644 --- a/src/utils/stringTransformation.ts +++ b/src/utils/stringTransformation.ts @@ -7,7 +7,12 @@ export const toCssVar = (string: string, prependDoubleDash: boolean = false) => return string; } -export const toCamelCase = (string: string) => { +export const toCamelCase = (string: string, detectAllCaps = true) => { + + if (detectAllCaps && /^[A-Z][A-Z0-9_\s]*$/.test(string)) { + return string.replace(/\s+/g, ''); + } + return string .trim() .replace(/(?:^\w|[A-Z]|\b\w|\s+\w|\s*\d+)/g, (match, index) => { @@ -18,4 +23,4 @@ export const toCamelCase = (string: string) => { }) .replace(/-/g, '') .replace(/\./g, '_'); -} +} \ No newline at end of file