1.0.6 • Published 4 years ago

reyaml-core v1.0.6

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

REyaml-Core 📦

npm version npm publish David Known Vulnerabilities

Core & CLI in REyaml for YAML to D3 Hierarchy transformation, YAML textual processing, JSON Object Promise.js alike traversal with modification, JSON Object window sliding, and more.

Inspired by and proudly using js-yaml.

new Ryaml('foo: bar').toRjson().toD3()

Philosophy

Two major Classes are exported for instantiation in this module, namely Ryaml and Rjson.

Ryaml is an immutable Object which wraps a YAML string as source reference.

Rjson is an immutable Object which wraps a JSON object as source reference.

The underlying source JSON object or YAML string will be transformed according to its member methods by the given behaviours. Transformational member methods are designed as functional procedures and will instantiate new immutable Object on every call.

In order to serve the aim of converting YAML to D3 hierarchy, Ryaml provides .toRjson([profile = 'default']) for bridging YAML and JSON Object powered by js-yaml, while Rjson provides .toD3([profile = 'default']) for ultimately mutating to legit D3 Hierarchical JSON Object.

Built Environment

  1. Node.js >= v12.x.x
  2. npm >= 6.x.x

Installation

Node.js

npm install reyaml-core

Usage

const { Ryaml, Rjson } = require('reyaml-core');
// or
import { Ryaml, Rjson } from 'reyaml-core';

CLI Standalone Executable

npm install -g reyaml-core

Usage

usage: rc [-h] [-v] [-Y YAML] [-J JSON] [ACTION] ...

Optional arguments:
  -h, --help            Show this help message and exit.
  -v, --version         Show program's version number and exit.
  -Y YAML, --yaml YAML  Source YAML as utf-8 file.
  -J JSON, --json JSON  Source JSON as utf-8 file.

Commands:
  [ACTION]              List of available Actions.
    insert              Insert YAML insertee under each key in Source.
    transform-d3        Transform Source into D3 Hierarchical JSON.
    transform-js        Transform Source into JSON using "js-yaml" module.
    count-key           Count number of keys in Source.
    mark-line           Mark lineNo in Source using markerMap in "config.js".
    count-junk-line     Count number of junk line in source YAML before 
                        lineNo.
    truncate            Truncate vertically by level and horizontally by size 
                        in YAML pivoted on lineNo.
    patch-yaml          Patch source YAML with the given patcher.

Bundled Library for Browsers

jsDelivr is suggested as CDN for this bundle.

HTML Demo

<script src="reyaml-core.js"></script>

Usage

<!-- js-yaml is required as library dependency -->
<script src="https://cdn.jsdelivr.net/gh/nodeca/js-yaml/dist/js-yaml.min.js"></script>

<!-- jsDelivr CDN link to reyaml-core -->
<script src="https://cdn.jsdelivr.net/npm/reyaml-core/dist/reyaml-core.min.js"></script>

<script type="text/javascript">
  document.write(JSON.stringify(
    new rc.Ryaml('foo: bar').toRjson().toD3()
  ));
</script>

Testing

npm run test

In REPL

# Linux/MacOS
npm run debug
# Windows
npm run debug-windows

API

All the user-facing Classes and methods are commented with in-code JSDoc. Please refer to GitHub Wiki page of REyaml-Core for further documentations.

License

MIT.

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago