Registry /
serialization / yaml-language-server-parser
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
load
✓ import { load } from 'yaml-language-server-parser';
✗ const load = require('yaml-language-server-parser').load;
The library primarily uses named exports and is designed for ESM consumption, though transpilation might allow CJS. TypeScript is fully supported.
YAMLNode
✓ import { YAMLNode, Kind, YAMLScalar, YamlMap, YAMLSequence } from 'yaml-language-server-parser';
✗ import YAMLNode from 'yaml-language-server-parser/YAMLNode';
Core AST node types (YAMLNode and its descendants like YAMLScalar, YamlMap, etc., along with the Kind enum) are named exports from the root module.
determineScalarType
✓ import { determineScalarType, parseYamlInteger } from 'yaml-language-server-parser';
✗ import { determineScalarType } from 'yaml-language-server-parser/lib/parser';
Helper functions for scalar type inference and parsing specific primitive types are named exports from the main package entry point.
Parses a multi-line YAML string into an Abstract Syntax Tree (AST), demonstrating how to navigate map and scalar nodes, identify their kinds, and use helper functions to determine and parse scalar values like integers and booleans. It also showcases accessing position information for nodes.
import { load, Kind, YAMLScalar, YamlMap, YAMLMapping, determineScalarType, parseYamlInteger, parseYamlBoolean } from 'yaml-language-server-parser';
const yamlString = `
# A simple YAML document
name: My Application
version: 1.0.0
config:
port: 8080
debug: true
features:
- user_auth
- logging
`;
// Load the YAML string into an AST
const yamlNode = load(yamlString);
console.log('--- AST Analysis ---');
if (yamlNode.kind === Kind.MAP) {
const rootMap = yamlNode as YamlMap;
console.log(`Root node is a Map with ${rootMap.mappings.length} mappings.`);
for (const mapping of rootMap.mappings) {
if (mapping.key.value === 'name' && mapping.value?.kind === Kind.SCALAR) {
const nameScalar = mapping.value as YAMLScalar;
console.log(`Application Name: ${nameScalar.value}`);
}
if (mapping.key.value === 'config' && mapping.value?.kind === Kind.MAP) {
const configMap = mapping.value as YamlMap;
console.log(` Config map found with ${configMap.mappings.length} items.`);
for (const configMapping of configMap.mappings) {
if (configMapping.key.value === 'port' && configMapping.value?.kind === Kind.SCALAR) {
const portScalar = configMapping.value as YAMLScalar;
console.log(` Port (raw): ${portScalar.value}`);
console.log(` Port (type determined): ${determineScalarType(portScalar)}`);
console.log(` Port (parsed int): ${parseYamlInteger(portScalar.value)}`);
}
if (configMapping.key.value === 'debug' && configMapping.value?.kind === Kind.SCALAR) {
const debugScalar = configMapping.value as YAMLScalar;
console.log(` Debug (raw): ${debugScalar.value}`);
console.log(` Debug (type determined): ${determineScalarType(debugScalar)}`);
console.log(` Debug (parsed bool): ${parseYamlBoolean(debugScalar.value)}`);
}
}
}
}
}
console.log(`\n'name' node starts at: ${yamlNode.mappings.find(m => m.key.value === 'name')?.key.startPosition}`);
console.log(`'name' node ends at: ${yamlNode.mappings.find(m => m.key.value === 'name')?.key.endPosition}`);
Errors
Common errors & fixes
TypeError: (0 , yaml_language_server_parser_1.load) is not a function
Attempting to use CommonJS `require` syntax (`const { load } = require('...')`) or incorrect destructuring when the module is primarily designed for ES Module (ESM) imports.
fixUse ES module import syntax: `import { load } from 'yaml-language-server-parser';`. Ensure your environment supports ESM or use a bundler/transpiler like Webpack/Rollup/Babel. Cannot find module 'yaml-language-server-parser' or its corresponding type declarations.
The package is not installed, installed incorrectly, or TypeScript cannot locate its type definitions.
fixRun `npm install yaml-language-server-parser` or `yarn add yaml-language-server-parser`. For TypeScript, ensure `esModuleInterop` is enabled in `tsconfig.json` if encountering import issues with older module resolutions.
Property 'value' does not exist on type 'YAMLNode'.
Attempting to access a property specific to a derived AST node type (e.g., `YAMLScalar.value`) directly on the base `YAMLNode` type without first checking its `kind` and casting.
fixAlways check the `kind` property of a `YAMLNode` against the `Kind` enum (e.g., `if (node.kind === Kind.SCALAR)`) and then cast it to the appropriate derived type (e.g., `(node as YAMLScalar).value`) before accessing type-specific properties.
Audit
Dependencies
No dependency data recorded yet.