/** * Escapes a string for use in an SQL query. * @example Examples * util.escape('test string') // 'test string' * util.escape("O'Connor") // "O''Connor" * util.escape('string with "quotes"') // 'string with "quotes"' * util.escape('') // '' * util.escape(null) // null * util.escape(123) // '123' * util.escape(true) // 'true' * util.escape("'; DROP TABLE users; --") // "''; DROP TABLE users; --" * @param {string|number|boolean|null|undefined} stringExp - The value to escape. * @returns {string|null|undefined} The escaped string, or null/undefined if input was null/undefined. * @throws {Error} If the value is an unexpected type (object, array, function, etc.). */ export function escape(stringExp: string | number | boolean | null | undefined): string | null | undefined; /** * Escapes a string for use in SQL LIKE patterns, preventing wildcard injection. * This should be used when the operator is LIKE or NOT LIKE. * @example Examples * util.escapeLike('test') // 'test' * util.escapeLike('100%') // '100[%]' * util.escapeLike('test_value') // 'test[_]value' * util.escapeLike('[admin]') // '[[[]admin]' * util.escapeLike("O'Connor%") // "O''Connor[%]" * @param {string} pattern - The pattern to escape. * @returns {string} The escaped pattern safe for use in LIKE clauses. */ export function escapeLike(pattern: string): string; /** * Escapes an SQL identifier (table or column name) to prevent SQL injection. * Uses bracket notation for SQL Server which is safer than validating patterns. * @example Examples * util.escapeIdentifier('users') // '[users]' * util.escapeIdentifier('first_name') // '[first_name]' * util.escapeIdentifier('user]table') // '[user]]table]' * util.escapeIdentifier('my.table') // '[my.table]' * @param {string} identifier - The identifier to escape. * @returns {string} The escaped identifier wrapped in brackets. * @throws {Error} If the identifier is not a string or is empty. */ export function escapeIdentifier(identifier: string): string; /** * Validates and normalizes SQL operators to prevent SQL injection. * @example Examples * util.validateOperator('=') // '=' * util.validateOperator('like') // 'LIKE' * util.validateOperator('>=') // '>=' * util.validateOperator("' OR '1'='1") // throws Error * @param {string} operator - The operator to validate. * @returns {string} The validated and normalized operator. * @throws {Error} If the operator is not in the allowed list. */ export function validateOperator(operator: string): string;