Registry / serialization / yaml-language-server-parser

yaml-language-server-parser

JSON →
library0.1.3jsnpmunverified

This package provides a robust YAML Abstract Syntax Tree (AST) parser, specifically a maintained fork of `YAML-AST-PARSER` tailored for use within the YAML Language Server ecosystem. It parses YAML documents into a detailed AST structure, offering features like error restoration during parsing, reporting errors directly as part of AST nodes, and built-in support for the non-standard `!include` tag commonly used in RAML specifications. The current stable version is 0.1.3, suggesting a focused, stable release cadence for its specific application. Its primary differentiators are its explicit maintenance for language server tooling, its robust error handling capabilities which are critical for IDE integration, and its direct lineage from `JS-YAML` for core parsing fidelity, combined with a focus on AST representation.

npm install yaml-language-server-parser
INSTALL
IMPORT
SIG · YAML-LANGUAGE-SERV
Y
yaml-language-server-parser
serializationjavascriptv0.1.3
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
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
musl
node 18226 runs
build_error
glibc
node 18226 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}`);
Debug
Known issues
gotchaThis package is a maintained fork specifically for the YAML Language Server. If you're looking for the original, less-maintained `YAML-AST-PARSER` or the general-purpose `JS-YAML`, ensure you're installing the correct package (`yaml-language-server-parser` for language server tooling).
fix
Verify your `package.json` to ensure `yaml-language-server-parser` is the intended dependency for language server related YAML parsing.
affects: >=0.1.0
gotchaThe parser includes built-in support for the `!include` tag, often used in RAML. This is a non-standard YAML extension. Users expecting strict YAML 1.2 parsing without custom tag handling might need to be aware of this behavior, as it deviates from standard YAML specifications.
fix
If `!include` tag behavior is undesired or causes conflicts, custom tag resolvers may be necessary, though the package is designed to support this specific extension.
affects: >=0.1.0
gotchaThe package version (e.g., 0.1.3) might imply an early development stage to some users. While it is a 'maintained fork' and stable for its intended use case (language servers), broader or high-traffic general-purpose YAML parsing might require evaluating its maturity for your specific requirements.
fix
Consult the GitHub repository for recent activity and issue trends to gauge ongoing maintenance and stability if using for critical, non-language-server applications.
affects: >=0.1.0
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.
fix
Use 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.
fix
Run `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.
fix
Always 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.
Upgrade
Version history
0.1.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
19 hits · last 30 days
node
16
OpenAI (training)
1
Resources
yaml-language-server-parser — npm install yaml-language-server-parser · libregistry