yang-parser
raw JSON → 0.2.1 verified Fri May 01 auth: no javascript deprecated
A parser for the YANG data modeling language (RFC 7950) written in CoffeeScript using the Comparse functional parsing library. Current stable version 0.2.1 performs lexical analysis and returns a tree of YANG statements without syntactic or semantic validation. The package has not been updated since 2017 and is considered stable but unmaintained. It is primarily for Node.js usage and depends on Comparse.
Common errors
error Cannot find module 'yang-parser' ↓
cause Package not installed or module resolution fails.
fix
Run 'npm install yang-parser' in your project directory.
error TypeError: yangParser is not a function ↓
cause Using default import when named import is required.
fix
Use 'import { parse } from 'yang-parser'' instead.
Warnings
deprecated Package is unmaintained since 2017; may not support newer YANG RFCs or grammar changes. ↓
fix Consider migrating to a maintained YANG parser such as yang-parser-js or pyang.
gotcha Parser only performs lexical analysis; no syntactic or semantic validation. Invalid YANG may parse without error. ↓
fix Validate output with a separate tool like pyang.
breaking Depends on Comparse library which may have breaking changes in newer versions; not pinned. ↓
fix Install with legacy peer deps if using npm v7+.
Install
npm install yang-parser yarn add yang-parser pnpm add yang-parser Imports
- parse wrong
const yangParser = require('yang-parser');correctimport { parse } from 'yang-parser' - parse
const { parse } = require('yang-parser') - parse wrong
import parse from 'yang-parser'correctimport { parse } from 'yang-parser'
Quickstart
import { parse } from 'yang-parser';
const yangSource = `
module example {
namespace "urn:example:system";
prefix sys;
organization "Example Inc.";
contact "admin@example.com";
description "Example module";
revision 2024-01-01 {
description "Initial revision";
}
container system {
leaf hostname {
type string;
}
}
}`;
try {
const result = parse(yangSource);
console.log(JSON.stringify(result, null, 2));
} catch (err) {
console.error('Parse error:', err.message);
}