File size: 464 Bytes
65567a2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
export function miniPrompt(strings: TemplateStringsArray, ...args: unknown[]) {
	return strings
		.flatMap((string, index) => [string, args[index] ?? ""])
		.join("")
		.replace(/^\s+/gm, "")
		.replace(/^\n+/g, "\n")
		.trim();
}

export function extractCode(string: string) {
	const codeBlockPattern = /(`{3,})(\w*)\n([\s\S]*?)\1/g;
	const matches = codeBlockPattern.exec(string);
	if (matches && matches.length >= 4) {
		return matches[3];
	}
	return string;
}