Skip to content

Commit

Permalink
fix(utils): correct JSON to PHP array conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
rifont committed Nov 11, 2024
1 parent 8a3d7c1 commit 8e7320e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions apps/dashboard/src/utils/code-snippets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,10 @@ const transformJsonToPhpArray = (data: Record<string, unknown>, indentLevel = 4)
const obj = entries
.map(([key, value]) => {
return `
${indent}'${key}' => '${JSON.stringify(value)}',`;
${indent}'${key}' => ${JSON.stringify(value)},`;
})
.join('');
.join('')
.replace(/"/g, "'");

return `${obj}${Object.keys(data).length > 0 ? `\n${new Array(indentLevel - 4).fill(' ').join('')}` : ''}`;
};
Expand Down
5 changes: 3 additions & 2 deletions apps/web/src/utils/codeSnippets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,10 @@ const transformJsonToPhpArray = (data: Record<string, unknown>, indentLevel = 4)
const obj = entries
.map(([key, value]) => {
return `
${indent}'${key}' => '${JSON.stringify(value)}',`;
${indent}'${key}' => ${JSON.stringify(value)},`;
})
.join('');
.join('')
.replace(/"/g, "'");

return `${obj}${Object.keys(data).length > 0 ? `\n${new Array(indentLevel - 4).fill(' ').join('')}` : ''}`;
};
Expand Down

0 comments on commit 8e7320e

Please sign in to comment.