Coder Social home page Coder Social logo

cedricpoon / reyaml-core Goto Github PK

View Code? Open in Web Editor NEW
2.0 3.0 0.0 303 KB

๐Ÿ“ฆ Core & CLI in REyaml for YAML to D3 Hierarchy transformation, and more.

Home Page: https://cedricpoon.github.io/reyaml-web/

License: MIT License

JavaScript 100.00%
yaml cli nodejs node-module reyaml d3-hierarchy json js-yaml

reyaml-core's Introduction

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.

reyaml-core's People

Contributors

dependabot[bot] avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.