safeParseYAMLConfig
constsafeParseYAMLConfig: (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
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
yaml | string | YAML string to parse |
Returns
Section titled “Returns”Result object with success flag and either data or errors
Remarks
Section titled “Remarks”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.
Example
Section titled “Example”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
Returns
Section titled “Returns”Result object with success flag and data or errors
Remarks
Section titled “Remarks”This is an alias for YAMLParser.safeParse for convenient imports.
Example
Section titled “Example”import { safeParseYAMLConfig } from '@maplibre-yaml/core/parser';const result = safeParseYAMLConfig(yamlString);if (result.success) { console.log(result.data);}