"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.safeParseTomlObject = exports.parseTomlObject = void 0;
const smol_toml_1 = require("smol-toml");
function isTomlObject(value) {
    return typeof value === 'object' && value !== null && !Array.isArray(value);
}
function stripUtf8Bom(rawText) {
    return rawText.charCodeAt(0) === 0xfeff ? rawText.slice(1) : rawText;
}
function parseTomlObject(rawText) {
    const parseText = stripUtf8Bom(rawText);
    const trimmed = parseText.trim();
    if (!trimmed)
        return {};
    const parsed = (0, smol_toml_1.parse)(parseText);
    if (!isTomlObject(parsed)) {
        throw new Error('TOML root must be a table.');
    }
    return parsed;
}
exports.parseTomlObject = parseTomlObject;
function safeParseTomlObject(rawText) {
    try {
        return {
            config: parseTomlObject(rawText),
            parseError: null,
        };
    }
    catch (error) {
        return {
            config: null,
            parseError: error.message,
        };
    }
}
exports.safeParseTomlObject = safeParseTomlObject;
//# sourceMappingURL=toml-object.js.map