/**
 * Key utilities for the Field Library
 */
/**
 * Valid key characters: letters, numbers, underscore, plus, hyphen, hash
 */
const KEY_REGEX = /^[a-zA-Z0-9_+\-#]+$/;
/**
 * Sanitize a string to be a valid key
 * Strips characters not in [a-zA-Z0-9_+\-#], replaces spaces with underscores
 */
export function sanitize_key(input) {
    return input
        .trim()
        .replace(/\s+/g, '_')
        .replace(/[^a-zA-Z0-9_+\-#]/g, '')
        .replace(/_+/g, '_')
        .replace(/^_|_$/g, '');
}
/**
 * Generate a key from a label (lowercase, sanitized)
 */
export function label_to_key(label) {
    const sanitized = sanitize_key(label.toLowerCase());
    return sanitized || `element_${Date.now().toString(36)}`;
}
/**
 * Validate a key matches the allowed pattern
 */
export function validate_key(key) {
    return KEY_REGEX.test(key);
}
/**
 * Format a full key from area and key: "area.key"
 */
export function format_full_key(area, key) {
    return `${area}.${key}`;
}
/**
 * Parse a full key "area.key" into its parts
 * Splits on the first dot only
 */
export function parse_full_key(full_key) {
    const dot_index = full_key.indexOf('.');
    if (dot_index === -1) {
        return { area: full_key, key: '' };
    }
    return {
        area: full_key.substring(0, dot_index),
        key: full_key.substring(dot_index + 1),
    };
}
//# sourceMappingURL=key_utils.js.map