import { parse } from "yaml";
import { isObject } from "@scalar/helpers/object/is-object";
//#region src/v2/features/collection/components/Editor/helpers/parse-editor-object.ts
var safeParseJson = (value) => {
	try {
		return JSON.parse(value);
	} catch {
		return null;
	}
};
var safeParseYaml = (value) => {
	try {
		return parse(value);
	} catch {
		return null;
	}
};
/**
* Parses the editor value string in either JSON or YAML format.
* Returns the parsed object if valid and an object, otherwise returns null.
*
* @param value - The input string to parse.
* @param language - The language of the input string, either 'json' or 'yaml'.
* @returns The parsed object if it's valid, or null.
*/
var parseEditorObject = (value, language) => {
	const parsed = language === "yaml" ? safeParseYaml(value) : safeParseJson(value);
	if (!isObject(parsed)) return null;
	return parsed;
};
//#endregion
export { parseEditorObject };

//# sourceMappingURL=parse-editor-object.js.map