mirror of
https://github.com/di-sukharev/opencommit.git
synced 2026-01-30 07:58:25 -05:00
♻️ refactor: clean up code formatting and improve readability
- Fix inconsistent indentation across multiple engine files - Remove trailing whitespace and add missing newlines - Improve code formatting in prompt generation functions - Break long lines for better readability - Standardize spacing and brackets placement
This commit is contained in:
@@ -4,20 +4,23 @@
|
||||
* @param tag The tag name without angle brackets (e.g., 'think' for '<think></think>')
|
||||
* @returns The content with the specified tags and their contents removed, and trimmed
|
||||
*/
|
||||
export function removeContentTags<T extends string | null | undefined>(content: T, tag: string): T {
|
||||
export function removeContentTags<T extends string | null | undefined>(
|
||||
content: T,
|
||||
tag: string
|
||||
): T {
|
||||
if (!content || typeof content !== 'string') {
|
||||
return content;
|
||||
}
|
||||
|
||||
|
||||
// Dynamic implementation for other cases
|
||||
const openTag = `<${tag}>`;
|
||||
const closeTag = `</${tag}>`;
|
||||
|
||||
|
||||
// Parse the content and remove tags
|
||||
let result = '';
|
||||
let skipUntil: number | null = null;
|
||||
let depth = 0;
|
||||
|
||||
|
||||
for (let i = 0; i < content.length; i++) {
|
||||
// Check for opening tag
|
||||
if (content.substring(i, i + openTag.length) === openTag) {
|
||||
@@ -29,7 +32,10 @@ export function removeContentTags<T extends string | null | undefined>(content:
|
||||
}
|
||||
}
|
||||
// Check for closing tag
|
||||
else if (content.substring(i, i + closeTag.length) === closeTag && depth > 0) {
|
||||
else if (
|
||||
content.substring(i, i + closeTag.length) === closeTag &&
|
||||
depth > 0
|
||||
) {
|
||||
depth--;
|
||||
if (depth === 0) {
|
||||
i = i + closeTag.length - 1; // Skip the closing tag
|
||||
@@ -37,7 +43,7 @@ export function removeContentTags<T extends string | null | undefined>(content:
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Only add character if not inside a tag
|
||||
if (skipUntil === null) {
|
||||
result += content[i];
|
||||
|
||||
Reference in New Issue
Block a user