YANG parser and evaluator
npm install yang-jsYANG parser and evaluator
Super light-weight and fast. Produces adaptive JS objects bound by
YANG schema expressions according to
RFC 6020
specifications. Composes dynamic YANG schema expressions by analyzing
arbitrary JS objects.
[![NPM Version][npm-image]][npm-url]
[![NPM Downloads][downloads-image]][downloads-url]
``javascript
const Yang = require('yang-js');
const schema =
container foo {
leaf a { type string; }
leaf b { type uint8; }
list bar {
key "b1";
leaf b1 { type uint16; }
container blob;
}
};`
const model = Yang(schema)({
foo: {
a: 'apple',
b: 10,
bar: [
{ b1: 100 }
],
}
});
`bash`
$ npm install yang-js
For development/testing, clone from repo and initialize:
`bash`
$ git clone https://github.com/corenova/yang-js
$ cd yang-js
$ npm install
When using with the web browser, you can generate a browserified version
from the repo (or find it in dist/yang.js):
`bash`
$ npm run prepublishOnly
It will produce dist/yang.js that can then be used directly
inside the web browser.
* Robust parsing
* Focus on high performance
* Extensive test coverage
* Flexible control logic binding
* Powerful XPATH expressions
* Isomorphic runtime
* Adaptive validations
* Dynamic schema generation
* Granular event subscriptions
Please note that yang-js is not a code-stub generator based on YANG
schema input. It directly embeds YANG schema compliance into ordinary
JS objects as well as generates YANG schema(s) from ordinary JS
objects.
Here's a quick example for using this module:
`javascript
const Yang = require('yang-js');
const schema =
container foo {
leaf a { type string; }
leaf b { type uint8; }
};`
const model = Yang.parse(schema).eval({
foo: {
a: 'apple',
b: 10,
}
});
The example above uses the explict long-hand version of using this
module, which uses the parse
method to generate the Yang expression and
immediately perform an eval
using the Yang expression for the passed-in JS
data object.
Since the above is a common usage pattern sequence, this module also
provides a cast-style short-hand version as follows:
`javascript`
const model = Yang(schema)({
foo: {
a: 'apple',
b: 10,
}
});
It is functionally equivalent to the explicit version but provides
cleaner syntactic expression regarding how the data object is being
cast with the Yang expression to get back a new schema-driven
object.
Once you have the model instance, you can directly interact with its
properties and see the schema enforcement and validations in action.
As the above example illustrates, the yang-js module takes amodule
free-form approach when dealing with YANG schema statements. You can
use any YANG statement as the top of the expression and
parse it to return a
corresponding YANG expression instance. However, only YANG expressions
that represent a data node element will
eval to generate a new
Property instance. Also, only
schemas will eval to generate a
new Model instance.
- Getting Started Guide
- Storing Data
- Expressing Interfaces
- Automating Documentation
- Coverage Report
- iana-crypt-hash.yang
- ietf-yang-types.yang
- ietf-inet-types.yang
- ietf-yang-library.yang (bindings)
- yang-meta-types.yang
Please refer to
Working with Multiple Schemas
section of the Getting Started Guide for usage
examples.
Below are the list of methods provided by the yang-js module. You
can click on each method entry for detailed info on usage.
The following operations are available from require('yang-js').
- parse (schema)
- compose (data)
- resolve (name)
- import (name)
Please note that when you load the main module, it will attempt to
automatically register .yang extension into require.extensions.
The Yang instance is created from
parse/compose operations from the main module.
- compile ()
- bind (obj)
- eval (data)
- extends (schema)
- locate (ypath)
- toString ()
- toJSON ()
The Property instances are created during
Yang.eval operation and are
bound to every node element defined by the underlying
Yang schema expression.
- join (obj)
- get (pattern)
- set (value)
- merge (value)
- create (value)
- remove ()
- find (pattern)
- in (pattern)
- do (args...)
- toJSON ()
Please refer to Property for a list of all
available properties on this instance.
The Model instance is created from
Yang.eval operation for
YANG module schema and aggregates
Property instances.
This instance also inherits all Property
methods and properties.
- access (model)
- enable (feature)
- save ()
- rollback ()
- on (event)
- do (path, args...)
Please refer to Model for a list of all
available properties on this instance.
Jukebox is a simple example YANG module extracted from
RFC 6020. This example
implementation is included in this repository's example
folder and exercised as part of the test suite. It demonstrates use of
the register and
import facilities for
loading the YANG schema file and binding various control logic
behavior.
- YANG Schema
- Schema Bindings
Promise is a resource reservation module implemented for
OPNFV. This example implementation is hosted in a
separate GitHub repository
opnfv/promise and utilizes
yang-js for the complete implementation. It demonstrates use ofyang-js
multiple YANG data models in modeling complex systems. Please be sure
to check it out to learn more about
advanced usage of .
To run the test suite, first install the dependencies, then run npm
test:```
$ npm install
$ npm test
Also refer to Compliance Report
for the latest RFC 6020 YANG
specification compliance. There's also active effort to support
the latest YANG 1.1 draft specifications. You can take a look at
the mocha test suite in the test directory for compliance
coverage unit-tests and other examples.
This software is brought to you by
Corenova Technologies. We'd love to hear
your feedback. Please feel free to reach me at
anytime with questions, suggestions, etc.
[npm-image]: https://img.shields.io/npm/v/yang-js.svg
[npm-url]: https://npmjs.org/package/yang-js
[downloads-image]: https://img.shields.io/npm/dt/yang-js.svg
[downloads-url]: https://npmjs.org/package/yang-js