import { SNAKE_CASE } from '@pawel-up/jexl/string.js';
import DOMPurify from '../../lib/dom_purify.js';
export function sanitizeInput(input) {
    return DOMPurify.sanitize(input);
}
/**
 * Converts a string into a sanitized, database column friendly name.
 * - Sanitizes the input using DOMPurify.
 * - Converts to lowercase.
 * - Replaces spaces and multiple underscores with a single underscore.
 * - Removes any characters that are not alphanumeric or underscore.
 *
 * @param inputName The string to format.
 * @returns A database column friendly name.
 */
export function toDatabaseColumnName(inputName, defaultName = 'untitled_column') {
    // 1. Sanitize
    let name = sanitizeInput(inputName);
    // 2. Convert to lowercase
    name = SNAKE_CASE(name);
    // 3. Replace spaces and multiple hyphens/underscores with a single underscore
    name = name.replace(/[\s-]+/g, '_');
    // 4. Remove any characters that are not alphanumeric or underscore
    name = name.replace(/[^a-z0-9_]/g, '');
    // 5. Ensure it doesn't start or end with an underscore (optional, but good practice)
    name = name.replace(/^_+|_+$/g, '');
    return name || defaultName;
}
/**
 * Converts a string into a sanitized, database table friendly name.
 * - Sanitizes the input using DOMPurify.
 * - Converts to lowercase.
 * - Replaces spaces and multiple underscores with a single underscore.
 * - Removes any characters that are not alphanumeric or underscore.
 *
 * @param inputName The string to format.
 * @returns A database table friendly name.
 */
export function toDatabaseTableName(inputName, defaultName = 'untitled_table') {
    return toDatabaseColumnName(inputName, defaultName);
}
//# sourceMappingURL=database.js.map