Skip to content

Commit

Permalink
fix: add json check for sliceOutObjectFromFile() to make css tokens a…
Browse files Browse the repository at this point in the history
…nd elements work together
  • Loading branch information
mikaelvesavuori committed Feb 19, 2024
1 parent ec016ce commit fe81311
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion bin/entities/FigmagicElement/logic/sliceOutObjectFromFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,16 @@ export const sliceOutObjectFromFile = (path: string): JsonFileData => {
if (!data) throw Error(ErrorSliceOutObjectFromFile);

const slicedData = data.slice(data.indexOf('{'), data.indexOf('}') + 1);
return JSON.parse(slicedData);
if (isJson(slicedData)) return JSON.parse(slicedData); // This is added because CSS generation breaks if using elements and CSS tokens
return slicedData as any;
};

const isJson = (input: any) => {
if (typeof input !== 'string') return false;
try {
JSON.parse(input);
return true;
} catch (error) {
return false;
}
};

0 comments on commit fe81311

Please sign in to comment.