/*!
 * KoliBri - The accessible HTML-Standard
 */
import { isObject } from "../../../schema";
export function normalizeString(value) {
    if (typeof value === 'string') {
        return value;
    }
    if (typeof value === 'number' || typeof value === 'boolean' || typeof value === 'bigint') {
        return String(value);
    }
    throw new TypeError(`Cannot convert ${typeof value} to string`);
}
export function normalizeInteger(value) {
    if (typeof value === 'number') {
        return Number.isInteger(value) ? value : Math.round(value);
    }
    if (typeof value === 'string') {
        const parsed = parseInt(value, 10);
        if (!isNaN(parsed)) {
            return parsed;
        }
    }
    throw new Error(`Invalid integer: ${value}`);
}
export function normalizeNumber(value) {
    if (typeof value === 'number') {
        return value;
    }
    if (typeof value === 'string') {
        const parsed = Number(value);
        if (!isNaN(parsed)) {
            return parsed;
        }
    }
    throw new Error(`Invalid number: ${value}`);
}
export function normalizeBoolean(value) {
    if (typeof value === 'boolean') {
        return value;
    }
    if (typeof value === 'string') {
        return value.toLowerCase() === 'true';
    }
    throw new Error(`Invalid boolean: ${value}`);
}
export function normalizeObject(value) {
    if (isObject(value)) {
        return value;
    }
    if (typeof value === 'string') {
        const parsed = JSON.parse(value);
        if (isObject(parsed)) {
            return parsed;
        }
    }
    throw new Error(`Invalid object: ${value}`);
}
export function normalizeArray(value) {
    if (isObject(value) && Array.isArray(value)) {
        return value;
    }
    if (typeof value === 'string') {
        const parsed = JSON.parse(value);
        if (isObject(parsed) && Array.isArray(parsed)) {
            return parsed;
        }
    }
    throw new Error(`Invalid array: ${value}`);
}
//# sourceMappingURL=normalizers.js.map
