Skip to content

safeParseYAMLConfig

const safeParseYAMLConfig: (yaml) => ParseResult

Defined in: packages/core/src/parser/yaml-parser.ts:1662

Convenience function to safely parse YAML config

Parse YAML string and validate, returning a result object

ParameterTypeDescription
yamlstringYAML string to parse

ParseResult

Result object with success flag and either data or errors

This is the non-throwing version of parse. Instead of throwing errors, it returns a result object that indicates success or failure. Use this when you want to handle errors gracefully without try/catch.

const result = YAMLParser.safeParse(yamlString);
if (result.success) {
console.log('Config:', result.data);
} else {
result.errors.forEach(err => {
console.error(`Error at ${err.path}: ${err.message}`);
});
}

yaml

YAML string to parse

Result object with success flag and data or errors

This is an alias for YAMLParser.safeParse for convenient imports.

import { safeParseYAMLConfig } from '@maplibre-yaml/core/parser';
const result = safeParseYAMLConfig(yamlString);
if (result.success) {
console.log(result.data);
}