Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

next
ts 46 lines 1.12 KB
Raw
1 /**
2 * Configuration for quote styles in string literals
3 */
4
5 export enum QuoteStyle {
6 /** Use double quotes: "hello" */
7 Double = 'double',
8 /** Use single quotes: 'hello' */
9 Single = 'single',
10 /** Use backticks for template literals: `hello` */
11 Backtick = 'backtick',
12 }
13
14 /**
15 * Configuration options for code generation
16 */
17 export interface FormattingOptions {
18 /** Quote style for string literals */
19 quoteStyle: QuoteStyle;
20 }
21
22 /**
23 * Default formatting options
24 */
25 export const DEFAULT_FORMATTING_OPTIONS: FormattingOptions = {
26 quoteStyle: QuoteStyle.Double,
27 };
28
29 /**
30 * Escapes a string content for the specified quote style
31 */
32 export function escapeStringContent(content: string, quoteStyle: QuoteStyle): string {
33 switch (quoteStyle) {
34 case QuoteStyle.Double:
35 return JSON.stringify(content);
36
37 case QuoteStyle.Single:
38 return "'" + content.replace(/\\/g, '\\\\').replace(/'/g, "\\'") + "'";
39
40 case QuoteStyle.Backtick:
41 return '`' + content.replace(/\\/g, '\\\\').replace(/`/g, '\\`').replace(/\$/g, '\\$') + '`';
42
43 default:
44 throw new Error(`Unsupported quote style: ${quoteStyle}`);
45 }
46 }