npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

yang-js

v0.24.69

Published

YANG parser and evaluator

Downloads

590

Readme

yang-js

YANG 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 Downloads

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 }
	],
  }
});

Installation

$ npm install yang-js

For development/testing, clone from repo and initialize:

$ 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):

$ npm run prepublishOnly

It will produce dist/yang.js that can then be used directly inside the web browser.

Features

  • 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.

Quick Start

Here's a quick example for using this module:

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:

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 a 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 module schemas will eval to generate a new Model instance.

Reference Guides

Bundled YANG Modules

Please refer to Working with Multiple Schemas section of the Getting Started Guide for usage examples.

API

Below are the list of methods provided by the yang-js module. You can click on each method entry for detailed info on usage.

Main module

The following operations are available from require('yang-js').

Please note that when you load the main module, it will attempt to automatically register .yang extension into require.extensions.

Yang instance

The Yang instance is created from parse/compose operations from the main module.

Property instance

The Property instances are created during Yang.eval operation and are bound to every node element defined by the underlying Yang schema expression.

Please refer to Property for a list of all available properties on this instance.

Model 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.

Please refer to Model for a list of all available properties on this instance.

Examples

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.

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 of multiple YANG data models in modeling complex systems. Please be sure to check it out to learn more about advanced usage of yang-js.

Tests

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.

License

Apache 2.0

This software is brought to you by Corenova Technologies. We'd love to hear your feedback. Please feel free to reach me at [email protected] anytime with questions, suggestions, etc.