-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(editor): move template rendering function to separate module
The template rendering function has been moved to a new file, `TemplateRender.ts`, to improve code organization. The `PromptsManager` now imports this function from the module. This change enhances readability and maintainability by separating concerns.
- Loading branch information
Showing
2 changed files
with
21 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export function render(template: string, data: Record<string, any>): string { | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-expect-error | ||
return template.replace(/\$\{([\s\S]+?)\}/g, (match, p1) => { | ||
const keys = p1.trim().split('.'); | ||
let value = data; | ||
for (const key of keys) { | ||
value = value[key]; | ||
if (value === undefined) { | ||
return ''; | ||
} | ||
} | ||
return value; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters