UNPKG

rawsql-ts

Version:

[beta]High-performance SQL parser and AST analyzer written in TypeScript. Provides fast parsing and advanced transformation capabilities.

67 lines 2.7 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.resolveIndentCharOption = resolveIndentCharOption; exports.resolveNewlineOption = resolveNewlineOption; exports.resolveIdentifierEscapeOption = resolveIdentifierEscapeOption; const INDENT_CHAR_MAP = { space: ' ', tab: '\t', }; const NEWLINE_MAP = { lf: '\n', crlf: '\r\n', cr: '\r', }; const IDENTIFIER_ESCAPE_MAP = { quote: { start: '"', end: '"' }, backtick: { start: '`', end: '`' }, bracket: { start: '[', end: ']' }, none: { start: '', end: '' }, }; function resolveIndentCharOption(option) { if (option === undefined) { // Leave undefined so downstream defaults continue to apply. return undefined; } const normalized = typeof option === 'string' ? option.toLowerCase() : option; if (typeof normalized === 'string' && Object.prototype.hasOwnProperty.call(INDENT_CHAR_MAP, normalized)) { // Map logical names to their control character equivalents. return INDENT_CHAR_MAP[normalized]; } // Return the original value to preserve backward compatibility with control characters. return option; } function resolveNewlineOption(option) { if (option === undefined) { // Preserve undefined so existing defaults stay intact. return undefined; } const normalized = typeof option === 'string' ? option.toLowerCase() : option; if (typeof normalized === 'string' && Object.prototype.hasOwnProperty.call(NEWLINE_MAP, normalized)) { // Translate logical newline names into their escape sequence counterparts. return NEWLINE_MAP[normalized]; } // Return the provided raw newline to support legacy control character inputs. return option; } function resolveIdentifierEscapeOption(option) { var _a, _b; if (option === undefined) { // Allow undefined so presets can supply defaults. return undefined; } if (typeof option === 'string') { const normalized = option.toLowerCase(); if (!Object.prototype.hasOwnProperty.call(IDENTIFIER_ESCAPE_MAP, normalized)) { throw new Error(`Unknown identifierEscape option: ${option}`); } // Spread into a new object to avoid mutating shared map entries. const mapped = IDENTIFIER_ESCAPE_MAP[normalized]; return { start: mapped.start, end: mapped.end }; } const start = (_a = option.start) !== null && _a !== void 0 ? _a : ''; const end = (_b = option.end) !== null && _b !== void 0 ? _b : ''; // Return a copy so callers do not mutate the input reference. return { start, end }; } //# sourceMappingURL=FormatOptionResolver.js.map