safeParseAny
constsafeParseAny: (yaml) =>SafeParseAnyResult
Defined in: packages/core/src/parser/yaml-parser.ts:1679
Convenience function to detect and validate any supported document type
Detect the document type of a YAML string and validate it against the matching schema
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
yaml | string | YAML string to parse (a map block, a scrollytelling block, or a root document) |
Returns
Section titled “Returns”Discriminated result with the detected block type and the corresponding safeParse result
Remarks
Section titled “Remarks”Dispatches on the document’s top-level type: field:
type: map→ safeParseMapBlocktype: scrollytelling→ safeParseScrollytellingBlock- no
type:but apages:key → safeParse (root document)
Any other type: value produces a failure result listing the valid
values, as does a document that has neither type: nor pages:.
This method never throws.
Example
Section titled “Example”const { blockType, result } = YAMLParser.safeParseAny(yamlString);if (!result.success) { result.errors.forEach(err => console.error(`${err.path}: ${err.message}`));} else if (blockType === 'map') { renderMap(result.data);}yaml
YAML string to parse (map block, scrollytelling block, or root document)
Returns
Section titled “Returns”Discriminated result with the detected block type and safeParse result
Remarks
Section titled “Remarks”This is an alias for YAMLParser.safeParseAny for convenient imports.
Example
Section titled “Example”import { safeParseAny } from '@maplibre-yaml/core/parser';const { blockType, result } = safeParseAny(yamlString);