(input: string, alwaysQuote: boolean = true)
| 723 | } |
| 724 | |
| 725 | export function escapeIdentifier(input: string, alwaysQuote: boolean = true): string | null { |
| 726 | if (input == null) { |
| 727 | return null; |
| 728 | } |
| 729 | |
| 730 | const body = input.replace(SINGLE_QUOTE_ESCAPE_STRING_RE, (...match: string[]) => { |
| 731 | if (match[0] == '\n') { |
| 732 | return '\\n'; |
| 733 | } else if (match[0] == '\r') { |
| 734 | return '\\r'; |
| 735 | } else { |
| 736 | return `\\${match[0]}`; |
| 737 | } |
| 738 | }); |
| 739 | |
| 740 | const requiresQuotes = alwaysQuote || !LEGAL_IDENTIFIER_RE.test(body); |
| 741 | return requiresQuotes ? `'${body}'` : body; |
| 742 | } |
no test coverage detected
searching dependent graphs…