Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #11

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@

.idea/*


node_modules/

Docs/
node_modules/*
Docs/*
80 changes: 78 additions & 2 deletions CommandFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@ import * as json2yaml from 'json-to-pretty-yaml';
import * as json_format from 'json-format';
import showdown from 'showdown';
import xml2js from 'xml2js';
import { JSDOM } from 'jsdom';
import { JSDOM } from 'jsdom'
import Papaparse from 'papaparse'
import { htmlToText } from 'html-to-text';
import { jsPDF } from 'jspdf';
import * as Mammoth from 'mammoth';

const tomlParser = json2toml.default;

/**
* Takes a path to an XML file which will be transformed into JSON
* @param { Object } options - Program options
* @param { String } options.path - Path to XML file to be morphed JSON
**/
const jsonify_xml = (options) => {
const xml_string = fs.readFileSync(options.path, { "encoding": "utf8" });
Expand All @@ -32,6 +37,7 @@ const jsonify_xml = (options) => {
/**
* Takes a path to a JSON file which will be transformed into XML
* @param { Object } options - Program options
* @param { String } options.path - Path to JSON file to be morphed XML
**/
const xmlify_json = (options) => {
const xml_json = JSON.parse(fs.readFileSync(options.path, { "encoding": "utf8" }));
Expand All @@ -43,6 +49,7 @@ const xmlify_json = (options) => {
/**
* Takes a path to a JSON file which will be transformed into YAML
* @param { Object } options - Program options
* @param { String } options.path - Path to JSON file to be morphed into YAML
**/
const yamlify_json = (options) => {
const json_string = fs.readFileSync(options.path, { "encoding": "utf8" });
Expand All @@ -54,6 +61,7 @@ const yamlify_json = (options) => {
/**
* Takes a path to a JSON file which will be transformed into TOML
* @param { Object } options - Program options
* @param { String } options.path - Path to JSON file to be morphed into TOML
**/
const tomlify_json = (options) => {
const json_string = fs.readFileSync(options.path, { "encoding": "utf8" });
Expand All @@ -68,6 +76,7 @@ const tomlify_json = (options) => {
/**
* Takes a path to a markdown file which will be transformed into HTML
* @param { Object } options - Program options
* @param { String } options.path - Path to Markdown file to be morphed HTML
**/
const htmlify_markdown = (options) => {
const markdown_string = fs.readFileSync(options.path, { "encoding": "utf8" });
Expand All @@ -79,6 +88,7 @@ const htmlify_markdown = (options) => {
/**
* Takes a path to an HTML file which will be transformed into Markdown
* @param { Object } options - Program options
* @param { String } options.path - Path to HTML file to be morphed into Markdown
**/
const markdownify_html = (options) => {
/**
Expand All @@ -91,4 +101,70 @@ const markdownify_html = (options) => {
console.log(converter.makeMarkdown(html_string));
}

export { xmlify_json, markdownify_html, htmlify_markdown, jsonify_xml, yamlify_json, tomlify_json };
/**
* Takes a path to a JSON file which will be transformed into CSV
* @param { Object } options - Program options
* @param { String } options.path - Path to JSON file to be morphed into CSV
**/
const csvify_json = (options) => {
const json = JSON.parse(fs.readFileSync(options.path, { "encoding": "utf8" }));
const csv_string = Papaparse.unparse([json.Flow]);
console.log(csv_string);
}

/**
* Takes a path to an CSV file which will be transformed into JSON
* @param { Object } options - Program options
* @param { String } options.path - Path to CSV file to be morphed into JSON
**/
const jsonify_csv = (options) => {
const csv_string = fs.readFileSync(options.path, { "encoding": "utf8" });
const csv_json = Papaparse.parse(csv_string);
console.log(JSON.stringify(csv_json.data));
}

/**
* Takes a path to an HTML file which will be transformed into Plain Text
* @param { Object } options - Program options
* @param { String } options.path - Path to HTML file to be morphed into Plain Text
**/
const textify_html = (options) => {
const html_string = fs.readFileSync(options.path, { "encoding": "utf8" });
const html_plain_text = htmlToText(html_string, {
"wordwrap": 130
});
console.log(html_plain_text);
}

const pdfify_plain_text = (options) => {
const plain_text = fs.readFileSync(options.path, { "encoding": "utf8" });
const pdfDocument = new jsPDF()
pdfDocument.text(`Hello World`, 10, 10);
pdfDocument.save(`${options.fileName}.pdf`)
console.log(`${options.fileName}.pdf: Created successfully!`);
}

const htmlify_docx = async (options) => {
const docx_html = await Mammoth.convertToHtml({ "path" : options.path })
console.log(docx_html.value);
}

//TODO: Adds JSON validation method using ajv
//TODO: Add CSV validation method using csv-file-validation
//TODO: Add general string validator using validator
//TODO: Add JSON dupe key checker using json-dup-key-validator
//TODO: Add glob to Regex validation helper using glob-to-regexp

export {
csvify_json,
htmlify_markdown,
htmlify_docx,
jsonify_csv,
jsonify_xml,
markdownify_html,
pdfify_plain_text,
textify_html,
tomlify_json,
xmlify_json,
yamlify_json
};
56 changes: 55 additions & 1 deletion Commands.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
'use strict';

/** Local Modules **/
import { jsonify_xml, xmlify_json, markdownify_html, htmlify_markdown, yamlify_json, tomlify_json } from "./CommandFunctions.js";
import {
csvify_json,
htmlify_markdown,
htmlify_docx,
jsonify_csv,
jsonify_xml,
pdfify_plain_text,
markdownify_html,
textify_html,
tomlify_json,
xmlify_json,
yamlify_json
} from "./CommandFunctions.js";

/**
* Commands - Map
Expand Down Expand Up @@ -57,6 +69,48 @@ const MapCommands = (Program) => {
.action(function(options) {
htmlify_markdown(options);
});

Program
.command(`jsonify_csv`)
.description(`parse a html file into a markdown string`)
.option(`--path [string]`, `path to the markdown file to build the html from`)
.action(function(options) {
jsonify_csv(options);
});

Program
.command(`csvify_json`)
.description(`parse a html file into a markdown string`)
.option(`--path [string]`, `path to the markdown file to build the html from`)
.action(function(options) {
csvify_json(options);
});

Program
.command(`textify_html`)
.description(`parse a html file into a plain text string`)
.option(`--path [string]`, `path to the HTML file to build the plain text string from`)
.action(function(options) {
textify_html(options);
});

Program
.command(`pdfify_plain_text`)
.description(`parse a plain text string or file into a PDF document`)
.option(`--path [string]`, `path to a plain_text file to process into a PDF`)
.option(`--fileName [string]`, `newly created PDF document file name`)
.action(function(options) {
pdfify_plain_text(options);
});

Program
.command(`htmlify_docx`)
.description(`parse a docx file into HTML`)
.option(`--path [string]`, `path to a docx file to process into a HTML`)
.option(`--fileName [string]`, `newly created HTML file name`)
.action(function(options) {
htmlify_docx(options);
});
}

export { MapCommands };
6 changes: 6 additions & 0 deletions Examples/Csv/example.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
John,Doe,120 jefferson st.,Riverside, NJ, 08075
Jack,McGinnis,220 hobo Av.,Phila, PA,09119
"John ""Da Man""",Repici,120 Jefferson St.,Riverside, NJ,08075
Stephen,Tyler,"7452 Terrace ""At the Plaza"" road",SomeTown,SD, 91234
,Blankman,,SomeTown, SD, 00298
"Joan ""the bone"", Anne",Jet,"9th, at Terrace plc",Desert City,CO,00123
Binary file added Examples/Docx/example.docx
Binary file not shown.
Loading