Skip to content

Commit

Permalink
fix(collectionToJS, stringTransformation): make toCamelCase fn handle…
Browse files Browse the repository at this point in the history
… all-caps strings

- update collectionToJS calls
  • Loading branch information
hefler committed Jan 7, 2025
1 parent 4f9af29 commit 74fa864
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/utils/collectionToJS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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';
}
Expand Down
9 changes: 7 additions & 2 deletions src/utils/stringTransformation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -18,4 +23,4 @@ export const toCamelCase = (string: string) => {
})
.replace(/-/g, '')
.replace(/\./g, '_');
}
}

0 comments on commit 74fa864

Please sign in to comment.